:root {
    --ink: #122033;
    --muted: #5d6b7a;
    --line: #d9e0e7;
    --paper: #eef2f0;
    --card: #ffffff;
    --sidebar: #12352c;
    --sidebar-2: #0e2a23;
    --accent: #1f6a56;
    --accent-dark: #155243;
    --accent-soft: #e4f3ee;
    --warn: #9a6b12;
    --warn-soft: #fff4d6;
    --danger: #9b2c2c;
    --danger-soft: #fde8e8;
    --info: #1d4e89;
    --info-soft: #e7f0fa;
    --shadow: 0 10px 30px rgba(18, 32, 51, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: "Source Sans 3", sans-serif;
    color: var(--ink);
    background: var(--paper);
}

a { color: var(--accent); }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
h1 { font-size: 28px; }
h2 { font-size: 18px; }

.app {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px 1fr;
}
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
.nav-backdrop { display: none; }

.sidebar {
    background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
    color: #e8f3ef;
    padding: 18px 14px 28px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 50;
}
.sidebar-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sidebar .brand { font-weight: 700; letter-spacing: .04em; padding: 6px 10px 12px; }
.sidebar .brand small { display: block; margin-top: 4px; color: #b7d0c8; font-weight: 400; letter-spacing: 0; }
.sidebar .nav-label {
    margin: 18px 10px 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: #8fb3a8;
}
.sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #d7ebe4;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 10px;
    font-weight: 600;
}
.sidebar a:hover, .sidebar a.active { background: rgba(255,255,255,.1); color: #fff; }
.sidebar .icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .88; }

.app-main { min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
.app-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 22px;
    background: rgba(255,255,255,.92);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 30;
    backdrop-filter: blur(12px);
}
.top-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.app-content { padding: 22px 24px 48px; max-width: 1080px; width: 100%; }

.icon { width: 20px; height: 20px; display: block; }
.icon-btn {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    flex-shrink: 0;
}
.icon-btn:hover { background: #f4f8f6; }
.icon-btn.menu-btn,
.icon-btn.sidebar-close { display: none; }
@media (min-width: 961px) {
    .icon-btn.menu-btn,
    .icon-btn.sidebar-close { display: none !important; }
}
.icon-btn .dot {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: grid;
    place-items: center;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    border: 0;
    list-style: none;
}
.profile-menu { position: relative; }
.profile-menu summary { list-style: none; }
.profile-menu summary::-webkit-details-marker { display: none; }
.dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: min(260px, 82vw);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(18, 32, 51, .12);
    padding: 8px;
    z-index: 40;
}
.dropdown-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.dropdown-head strong { display: block; }
.dropdown-head span { display: block; color: var(--muted); font-size: 12px; }
.dropdown a, .dropdown button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    color: var(--ink);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 10px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.dropdown .icon { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); }
.dropdown a:hover, .dropdown button:hover { background: #f4f8f6; }
.dropdown form { margin: 0; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 22px;
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}
.page-head p { margin: 6px 0 0; color: var(--muted); }

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

.btn, button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 10px;
    padding: 10px 16px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover { background: #f6f8f7; }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--accent); padding-left: 0; }

.filters {
    display: grid;
    grid-template-columns: minmax(200px, 1.3fr) repeat(auto-fill, minmax(160px, 200px)) auto;
    gap: 10px;
    margin-bottom: 16px;
    align-items: end;
    max-width: 920px;
}
.filters .field { margin: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
tr:hover td { background: #f8fbf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 700;
    background: #eef1f4;
    color: #44515e;
    text-transform: capitalize;
}
.badge.draft, .badge.inactive { background: #eef1f4; }
.badge.assigned, .badge.individual { background: var(--info-soft); color: var(--info); }
.badge.in_progress, .badge.active { background: var(--accent-soft); color: var(--accent-dark); }
.badge.completed, .badge.paid, .badge.business { background: #e7f6ea; color: #1f7a3a; }
.badge.pending_invoice, .badge.partially_paid { background: var(--warn-soft); color: var(--warn); }
.badge.invoiced, .badge.synced { background: #ece7fb; color: #4c348f; }
.badge.cancelled, .badge.unpaid { background: var(--danger-soft); color: var(--danger); }
.badge.tax_invoice { background: var(--accent-soft); color: var(--accent-dark); }
.badge.bill_of_supply { background: var(--warn-soft); color: var(--warn); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.metric { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.metric span { display: block; color: var(--muted); font-size: 13px; text-transform: capitalize; }
.metric strong { font-size: 26px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 260px)); gap: 12px 16px; max-width: 920px; }
.form-grid .wide { grid-column: 1 / -1; }
.field { margin-bottom: 14px; }
label { display: block; margin: 0 0 6px; font-weight: 600; font-size: 14px; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 11px 13px;
    font: inherit;
    background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: 2px solid #b7ddd1;
    border-color: var(--accent);
}
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; margin: 0 0 12px; }
.notice, .flash {
    background: var(--accent-soft);
    border: 1px solid #b7ddd1;
    color: var(--accent-dark);
    border-radius: 12px;
    padding: 12px 14px;
    margin: 0 0 16px;
}
.notice.warn { background: var(--warn-soft); border-color: #ead7a8; color: var(--warn); }

.split { display: grid; grid-template-columns: 1.4fr .8fr; gap: 16px; }
.totals { background: #f6faf8; border-radius: 12px; padding: 14px; }
.totals div { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .grand { font-weight: 700; font-size: 18px; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 18px; border-left: 2px solid #d5e6e0; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
    content: "";
    width: 9px; height: 9px;
    background: var(--accent);
    border-radius: 50%;
    position: absolute;
    left: -6px; top: 4px;
}

.empty {
    text-align: center;
    padding: 36px 16px;
    color: var(--muted);
}

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
    radial-gradient(circle at top right, #d7ebe4, transparent 36%), var(--paper); }
.login-card { width: min(100%, 440px); }
.brand { font-weight: 700; letter-spacing: .04em; }
.brand small { display: block; font-weight: 400; color: var(--muted); letter-spacing: 0; }

.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.pagination a, .pagination span {
    display: inline-flex;
    min-width: 34px;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    text-decoration: none;
    color: var(--ink);
    background: #fff;
}
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.notif { padding: 10px 0; border-bottom: 1px solid var(--line); }
.notif:last-child { border-bottom: 0; }
.notif.unread { font-weight: 700; }

@media (max-width: 960px) {
    .app { grid-template-columns: 1fr; }
    .icon-btn.menu-btn,
    .icon-btn.sidebar-close { display: inline-flex; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(86vw, 300px);
        height: 100dvh;
        transform: translateX(-105%);
        transition: transform .22s ease;
        box-shadow: 12px 0 32px rgba(10, 18, 16, .18);
    }
    .nav-toggle:checked ~ .sidebar { transform: translateX(0); }
    .nav-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(10, 18, 16, .42);
        opacity: 0;
        pointer-events: none;
        z-index: 40;
        transition: opacity .2s ease;
    }
    .nav-toggle:checked ~ .nav-backdrop {
        opacity: 1;
        pointer-events: auto;
    }
    body:has(.nav-toggle:checked) { overflow: hidden; }
    .split, .page-head, .toolbar { grid-template-columns: 1fr; }
    .page-head, .toolbar { flex-direction: column; align-items: stretch; }
    .app-content, .app-top { padding-left: 14px; padding-right: 14px; }
    .filters { grid-template-columns: 1fr; }
    .row-actions .btn { width: 100%; }
}

.invoice-page { max-width: 920px; margin: 0 auto; padding: 18px 16px 40px; }
.invoice-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.invoice-sheet {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 22px;
}
.invoice-head, .invoice-parties, .invoice-foot {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 16px;
}
.invoice-head { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 14px; }
.invoice-head .brand { font-weight: 700; font-size: 20px; }
.invoice-head p, .invoice-parties p, .invoice-foot p { margin: 4px 0; color: var(--ink); }
.invoice-meta h1 { font-size: 22px; margin-bottom: 6px; }
.invoice-parties { margin-bottom: 16px; }
.invoice-parties h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; }
.invoice-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.invoice-table th, .invoice-table td { border: 1px solid var(--line); padding: 8px; font-size: 13px; }
.invoice-totals { background: #f6faf8; border-radius: 10px; padding: 12px; }
.invoice-totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.invoice-totals .grand { font-weight: 700; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }
.invoice-totals .sign { margin-top: 18px; text-align: right; }

@media print {
    body { background: #fff; }
    .no-print { display: none !important; }
    .invoice-page { max-width: none; padding: 0; }
    .invoice-sheet { border: 0; border-radius: 0; padding: 0; box-shadow: none; }
}
