/* === DH Billing Admin CSS === */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Playfair+Display:wght@400;700&display=swap');

:root {
    --charcoal: #1a1a1a;
    --green: #2e7d32;
    --green-light: #e8f5e9;
    --green-dark: #1b5e20;
    --green-border: #a5d6a7;
    --white: #fff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --red: #dc2626;
    --red-light: #fef2f2;
    --blue: #2563eb;
    --blue-light: #eff6ff;
    --yellow: #d97706;
    --yellow-light: #fffbeb;
    --sidebar-width: 240px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--gray-50);
    color: var(--gray-800);
    font-size: 14px;
    line-height: 1.5;
}

/* === Layout === */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    background: var(--charcoal);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.brand-text {
    font-family: 'Playfair Display', serif;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 3px;
}

.brand-sub {
    font-size: 13px;
    font-weight: 300;
    color: var(--gray-400);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--gray-400);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    color: var(--white);
    background: rgba(255,255,255,0.05);
}

.nav-link.active {
    color: var(--white);
    background: rgba(46,125,50,0.2);
    border-left-color: var(--green);
}

.nav-link svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-link.active svg,
.nav-link:hover svg {
    opacity: 1;
}

.nav-divider {
    height: 1px;
    background: rgba(255,255,255,0.08);
    margin: 8px 20px;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-name {
    font-size: 12px;
    color: var(--gray-400);
}

.logout-link {
    font-size: 12px;
    color: var(--gray-500);
    text-decoration: none;
}
.logout-link:hover {
    color: var(--red);
}

/* === Main Content === */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
}

.top-bar {
    padding: 16px 28px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-600);
    padding: 4px;
}

.page-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
}

.content-area {
    padding: 24px 28px;
}

/* === Cards === */
.card {
    background: var(--white);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    padding: 20px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--gray-900);
}

/* === Stat Cards === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
    padding: 20px;
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
}

.stat-value.text-green { color: var(--green); }
.stat-value.text-red { color: var(--red); }
.stat-value.text-blue { color: var(--blue); }

/* === Tables === */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    background: var(--gray-50);
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--gray-100);
    font-size: 13px;
    color: var(--gray-700);
}

table tr:hover {
    background: var(--gray-50);
}

table td a {
    color: var(--green);
    text-decoration: none;
    font-weight: 500;
}

table td a:hover {
    text-decoration: underline;
}

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-nowrap { white-space: nowrap; }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success {
    background: var(--green-light);
    color: var(--green-dark);
}

.badge-danger {
    background: var(--red-light);
    color: var(--red);
}

.badge-warning {
    background: var(--yellow-light);
    color: var(--yellow);
}

.badge-info {
    background: var(--blue-light);
    color: var(--blue);
}

.badge-secondary {
    background: var(--gray-100);
    color: var(--gray-500);
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    font-family: inherit;
    line-height: 1.4;
}

.btn-primary {
    background: var(--green);
    color: var(--white);
    border-color: var(--green);
}
.btn-primary:hover {
    background: var(--green-dark);
    border-color: var(--green-dark);
}

.btn-secondary {
    background: var(--white);
    color: var(--gray-700);
    border-color: var(--gray-300);
}
.btn-secondary:hover {
    background: var(--gray-50);
}

.btn-danger {
    background: var(--red);
    color: var(--white);
}
.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* === Forms === */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 4px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    background: var(--white);
    color: var(--gray-800);
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(46,125,50,0.1);
}

select.form-control {
    cursor: pointer;
}

textarea.form-control {
    min-height: 80px;
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-200);
}

/* === Alerts === */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin: 0 28px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}

.alert-success {
    background: var(--green-light);
    color: var(--green-dark);
    border: 1px solid var(--green-border);
}

.alert-error {
    background: var(--red-light);
    color: var(--red);
    border: 1px solid #fecaca;
}

.alert-warning {
    background: var(--yellow-light);
    color: var(--yellow);
    border: 1px solid #fde68a;
}

.alert-close {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
}

/* === Filters / Toolbar === */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.filters .form-control {
    width: auto;
    min-width: 140px;
    padding: 6px 10px;
    font-size: 13px;
}

.search-input {
    position: relative;
}

.search-input input {
    padding-left: 32px;
}

/* === Empty State === */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--gray-400);
}

.empty-state svg {
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 16px;
}

/* === Invoice Line Items (dynamic) === */
.line-items-table {
    margin-bottom: 16px;
}

.line-items-table th {
    background: var(--green);
    color: var(--white);
    padding: 10px 12px;
    font-size: 11px;
}

.line-items-table td {
    padding: 8px 10px;
    vertical-align: top;
}

.line-items-table .form-control {
    padding: 6px 8px;
    font-size: 13px;
}

.line-items-table .remove-row {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
}

.line-items-totals {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.line-items-totals table {
    width: auto;
    min-width: 250px;
}

.line-items-totals td {
    padding: 6px 14px;
    border: none;
}

.line-items-totals .total-row {
    background: var(--green);
    color: var(--white);
    font-weight: 600;
}

.line-items-totals .total-row td {
    padding: 10px 14px;
}

/* === Modal === */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--white);
    border-radius: 8px;
    padding: 24px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* === Pagination === */
.pagination {
    display: flex;
    gap: 4px;
    margin-top: 16px;
    justify-content: center;
}

.pagination a,
.pagination span {
    padding: 6px 12px;
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    font-size: 13px;
    text-decoration: none;
    color: var(--gray-600);
}

.pagination a:hover {
    background: var(--gray-50);
}

.pagination .active {
    background: var(--green);
    color: var(--white);
    border-color: var(--green);
}

/* === Login Page === */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--charcoal);
}

.login-card {
    background: var(--white);
    border-radius: 8px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-brand {
    text-align: center;
    margin-bottom: 28px;
}

.login-brand h1 {
    font-family: 'Playfair Display', serif;
    font-size: 32px;
    letter-spacing: 4px;
    color: var(--charcoal);
}

.login-brand p {
    font-size: 13px;
    color: var(--gray-400);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-top: 4px;
}

.login-error {
    background: var(--red-light);
    color: var(--red);
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}

.login-card .btn-primary {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    margin-top: 8px;
}

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .menu-toggle {
        display: block;
    }
    .content-area {
        padding: 16px;
    }
    .form-row,
    .form-row-3 {
        grid-template-columns: 1fr;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
}

/* === Detail View (invoice-view, client-view) === */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.detail-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 16px;
    font-size: 13px;
}

.detail-meta dt {
    font-weight: 500;
    color: var(--gray-500);
}

.detail-meta dd {
    color: var(--gray-800);
}

/* === Utility === */
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.text-muted { color: var(--gray-400); }
.text-sm { font-size: 12px; }
.fw-600 { font-weight: 600; }
.d-flex { display: flex; }
.gap-2 { gap: 16px; }
.flex-1 { flex: 1; }
