:root {
    --ink: #172233;
    --muted: #657184;
    --line: #dfe5ec;
    --surface: #ffffff;
    --page: #f4f7fa;
    --navy: #17304d;
    --navy-dark: #10243a;
    --blue-soft: #eaf2fb;
    --green: #177556;
    --green-soft: #e5f5ee;
    --red: #b43b43;
    --red-soft: #fdebed;
    --shadow: 0 10px 30px rgba(24, 42, 67, .07);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font: 15px/1.5 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; }
.topbar {
    height: 72px;
    padding: 0 max(24px, calc((100vw - 1180px) / 2));
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 750; text-decoration: none; font-size: 17px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
    color: white; background: var(--navy); font-size: 13px; letter-spacing: .05em;
}
.top-actions { display: flex; align-items: center; gap: 7px; }
.nav-link { color: var(--muted); font-size: 14px; font-weight: 700; padding: 9px 11px; text-decoration: none; border-radius: 8px; }
.nav-link:hover { color: var(--ink); background: var(--page); }
.user-menu { display: flex; align-items: center; gap: 9px; margin-left: 5px; padding-left: 13px; border-left: 1px solid var(--line); }
.user-menu span { font-size: 13px; font-weight: 700; }
.user-menu form { margin: 0; }
.user-menu button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 3px; font-size: 12px; text-decoration: underline; }
.shell { width: min(1180px, calc(100% - 32px)); margin: 38px auto 80px; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 26px; }
h1 { margin: 4px 0 2px; font-size: clamp(28px, 4vw, 38px); line-height: 1.2; letter-spacing: -.035em; }
h2, h3, p { margin-top: 0; }
.page-heading p { color: var(--muted); margin: 7px 0 0; }
.back-link { color: var(--muted); font-size: 14px; text-decoration: none; }
.button {
    border: 1px solid transparent; border-radius: 9px; padding: 10px 16px; display: inline-flex;
    justify-content: center; align-items: center; gap: 8px; font-weight: 700; text-decoration: none;
    cursor: pointer; transition: .16s ease; line-height: 1.25; background: white;
}
.button:hover { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(23, 48, 77, .12); }
.button-primary { background: var(--navy); color: white; }
.button-primary:hover { background: var(--navy-dark); }
.button-secondary { border-color: var(--line); color: var(--ink); }
.button-success { background: var(--green); color: white; }
.button-full { width: 100%; }
.button-large { padding: 13px 23px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 22px; }
.summary-card { background: white; border: 1px solid var(--line); border-radius: 13px; padding: 22px; }
.summary-card span { color: var(--muted); font-size: 13px; display: block; margin-bottom: 7px; }
.summary-card strong { font-size: 27px; letter-spacing: -.03em; }
.search-bar { display: flex; gap: 9px; margin-bottom: 18px; }
.search-input { position: relative; flex: 1; }
.search-input span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 19px; }
.search-input input { margin: 0; padding-left: 42px; height: 43px; }
.list-card { overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { color: var(--muted); font-size: 11px; letter-spacing: .055em; text-transform: uppercase; text-align: left; }
.invoice-list th, .invoice-list td { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.invoice-list tbody tr { cursor: pointer; }
.invoice-list tbody tr:hover { background: #f9fbfd; }
.invoice-list tbody tr:last-child td { border-bottom: 0; }
.invoice-list a { font-weight: 750; text-decoration: none; }
.status { display: inline-flex; padding: 4px 9px; border-radius: 99px; font-size: 12px; font-weight: 750; }
.status-unpaid { color: #9a5a10; background: #fff4d9; }
.status-paid { color: var(--green); background: var(--green-soft); }
.empty-state { padding: 70px 24px; text-align: center; }
.empty-state h2 { margin-bottom: 5px; }
.empty-state p { color: var(--muted); margin-bottom: 22px; }
.empty-icon { width: 52px; height: 52px; border-radius: 15px; background: var(--blue-soft); color: var(--navy); display: grid; place-items: center; margin: 0 auto 17px; font-size: 24px; }
.alert { margin-bottom: 20px; padding: 13px 16px; border-radius: 10px; font-weight: 650; }
.alert-success { background: var(--green-soft); color: var(--green); }
.alert-error { background: var(--red-soft); color: var(--red); }
.invoice-form { display: grid; gap: 18px; }
.form-section { padding: 26px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 23px; }
.section-heading > div { display: flex; align-items: center; gap: 11px; }
.section-heading h2 { margin: 0; font-size: 18px; }
.step { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 8px; background: var(--navy); color: white; font-size: 12px; font-weight: 800; }
.tag { background: var(--blue-soft); color: var(--navy); border-radius: 99px; padding: 5px 10px; font-size: 12px; font-weight: 750; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
label { color: #3d4858; font-size: 13px; font-weight: 700; }
input, select, textarea {
    width: 100%; margin-top: 7px; border: 1px solid #ccd5df; border-radius: 8px; padding: 10px 11px;
    color: var(--ink); background: white; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: #7795b7; box-shadow: 0 0 0 3px rgba(57, 104, 155, .12); }
textarea { resize: vertical; }
.full-width { grid-column: 1 / -1; }
.items-table { min-width: 780px; }
.items-table th { padding: 0 7px 9px; }
.items-table td { padding: 6px 7px; vertical-align: middle; }
.items-table th:first-child { width: 40%; }
.items-table th:nth-child(2) { width: 10%; }
.items-table th:nth-child(3) { width: 16%; }
.items-table th:nth-child(4) { width: 13%; }
.items-table input, .items-table select { margin: 0; }
.line-total { font-weight: 750; text-align: right; white-space: nowrap; }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 22px; cursor: pointer; padding: 3px 7px; }
.invoice-bottom { display: flex; justify-content: space-between; gap: 35px; margin-top: 25px; }
.notes-field, .notes-display { width: min(52%, 500px); }
.totals-preview { width: min(310px, 100%); margin-left: auto; }
.totals-preview > div { display: flex; justify-content: space-between; gap: 30px; padding: 8px 0; }
.totals-preview span { color: var(--muted); }
.totals-preview .grand-total { background: var(--navy); color: white; padding: 14px 16px; margin-top: 7px; border-radius: 9px; }
.totals-preview .grand-total span { color: #d9e3ee; }
.totals-preview .grand-total strong { font-size: 18px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 11px; padding-top: 3px; }
.view-heading { align-items: center; }
.title-line { display: flex; align-items: center; gap: 13px; }
.action-group { display: flex; gap: 10px; }
.view-layout { display: grid; grid-template-columns: minmax(0, 1fr) 285px; gap: 20px; align-items: start; }
.invoice-preview { padding: 35px; }
.preview-top { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; min-height: 160px; }
.preview-top h2 { margin: 7px 0; font-size: 17px; }
.preview-top p { color: var(--muted); margin: 3px 0; white-space: normal; }
.preview-customer { padding-left: 25px; border-left: 1px solid var(--line); }
.eyebrow { color: var(--muted); font-size: 10px; letter-spacing: .08em; font-weight: 800; }
.meta-row { display: grid; grid-template-columns: repeat(3, 1fr); background: #f3f6f9; border-radius: 10px; margin: 15px 0 25px; }
.meta-row div { padding: 14px 17px; border-right: 1px solid var(--line); }
.meta-row div:last-child { border: 0; }
.meta-row span, .meta-row strong { display: block; }
.meta-row span { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.preview-table th, .preview-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: right; }
.preview-table th:first-child, .preview-table td:first-child { text-align: left; padding-left: 0; }
.preview-table th:last-child, .preview-table td:last-child { padding-right: 0; }
.notes-display p { color: var(--muted); margin-top: 8px; }
.side-panel { display: grid; gap: 15px; }
.compact-card { padding: 19px; }
.compact-card h3 { font-size: 15px; margin-bottom: 14px; }
.stack-form { display: grid; gap: 12px; }
.hint { color: var(--muted); font-size: 11px; margin: 12px 0 0; }
.danger-zone { box-shadow: none; text-align: center; }
.text-danger { border: 0; background: none; color: var(--red); text-decoration: underline; cursor: pointer; }
.report-filter {
    padding: 18px; display: grid; grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
    align-items: end; gap: 14px; margin-bottom: 18px;
}
.report-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.featured-summary { background: var(--navy); color: white; border-color: var(--navy); }
.featured-summary span { color: #d9e3ee; }
.report-table-card { margin-bottom: 18px; }
.card-title-row { padding: 22px 20px 4px; }
.card-title-row h2 { margin-bottom: 2px; font-size: 18px; }
.card-title-row p, .muted-copy { color: var(--muted); margin-bottom: 10px; }
.report-table tbody tr { cursor: default; }
.report-table tfoot { background: #eef3f8; }
.report-table tfoot th { padding: 15px 20px; color: var(--ink); font-size: 12px; }
.report-settings-grid { display: grid; grid-template-columns: 1.35fr .65fr; gap: 18px; align-items: start; }
.toggle-row { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 9px; padding: 12px; }
.toggle-row input { width: 18px; height: 18px; margin: 0; }
.compact-empty { padding: 45px 24px; }
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #edf2f7; }
.auth-shell { width: min(430px, 100%); }
.auth-card { background: white; border: 1px solid var(--line); border-radius: 16px; padding: 34px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 11px; font-weight: 800; margin-bottom: 30px; }
.auth-card h1 { font-size: 30px; margin-bottom: 6px; }
.auth-card > p { color: var(--muted); margin-bottom: 23px; }
.auth-form { gap: 16px; }
.users-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 18px; align-items: start; }
.add-user-card { position: sticky; top: 20px; }
.users-table tbody tr { cursor: default; }
.user-actions { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.small-action { border: 0; background: none; color: var(--navy); font-weight: 700; padding: 0; cursor: pointer; text-decoration: underline; }
.password-reset { position: relative; }
.password-reset summary { color: var(--navy); font-weight: 700; cursor: pointer; text-decoration: underline; }
.password-reset[open] form {
    position: absolute; right: 0; z-index: 5; width: 260px; padding: 16px; margin-top: 8px;
    background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}

@media (max-width: 800px) {
    .shell { margin-top: 25px; }
    .summary-grid, .report-summary { grid-template-columns: 1fr 1fr; }
    .page-heading, .invoice-bottom { align-items: stretch; flex-direction: column; }
    .form-grid, .preview-top, .meta-row { grid-template-columns: 1fr; }
    .full-width { grid-column: auto; }
    .notes-field, .notes-display { width: 100%; }
    .view-layout { grid-template-columns: 1fr; }
    .report-settings-grid, .users-layout { grid-template-columns: 1fr; }
    .add-user-card { position: static; }
    .report-filter { grid-template-columns: 1fr 1fr; }
    .report-filter .button { grid-column: 1 / -1; }
    .action-group { flex-wrap: wrap; }
    .preview-customer { padding: 20px 0 0; border-left: 0; border-top: 1px solid var(--line); }
    .meta-row div { border-right: 0; border-bottom: 1px solid var(--line); }
    .topbar { padding: 0 16px; }
    .nav-link { display: none; }
    .user-menu span { display: none; }
    .search-bar { flex-wrap: wrap; }
    .search-input { flex-basis: 100%; }
}

@media print {
    .topbar, .side-panel, .action-group, .back-link { display: none !important; }
    body { background: white; }
    .shell { width: 100%; margin: 0; }
    .view-layout { display: block; }
    .invoice-preview { border: 0; box-shadow: none; }
}
