:root {
    --ink: #101828;
    --ink-soft: #344054;
    --muted: #667085;
    --muted-2: #98a2b3;
    --line: #e4e7ec;
    --line-soft: #f0f2f5;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --sidebar: #111827;
    --sidebar-2: #0b1220;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --accent-soft: #ecfdf9;
    --gold: #b7791f;
    --danger: #b42318;
    --danger-soft: #fef3f2;
    --warning: #b54708;
    --warning-soft: #fffaeb;
    --info: #175cd3;
    --info-soft: #eff8ff;
    --success: #067647;
    --success-soft: #ecfdf3;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
.icon { width: 20px; height: 20px; flex: 0 0 auto; }
.icon-sm { width: 15px; height: 15px; }
hr { border: 0; border-top: 1px solid var(--line); }

/* ---------- Shell ---------- */
.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 248px;
    background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%);
    color: #d0d5dd;
    display: flex;
    flex-direction: column;
    padding: 20px 14px 16px;
    z-index: 50;
}
.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 8px 22px;
    color: #fff;
    text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-logo {
    width: 44px;
    height: 44px;
    border-radius: 9px;
    box-shadow: 0 0 0 1px rgba(255,255,255,.12);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: -.01em; color: #fff; }
.brand-text small { color: #98a2b3; font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; }
.side-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; padding-top: 4px; }
.nav-label {
    margin: 18px 10px 6px;
    font-size: 10px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #667085;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 40px;
    padding: 9px 11px;
    border-radius: 8px;
    color: #b9c0cc;
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s ease, color .15s ease;
}
.nav-item .icon { width: 18px; height: 18px; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.is-active { background: rgba(255,255,255,.10); color: #fff; box-shadow: inset 2px 0 0 #5eead4; }
.nav-item.is-active .icon { opacity: 1; color: #5eead4; }
.sidebar-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 4px 0;
    border-top: 1px solid rgba(255,255,255,.09);
    margin-top: 12px;
}
.user-card { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; color: #fff; text-decoration: none; }
.user-card:hover { text-decoration: none; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: #1f2937; color: #99f6e4; font-weight: 700; font-size: 13px;
    border: 1px solid rgba(255,255,255,.12);
}
.user-copy { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-copy strong { font-size: 12.5px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-copy small { font-size: 10.5px; color: #98a2b3; }
.sidebar-logout { color: #98a2b3; }
.sidebar-logout:hover { color: #fff; background: rgba(255,255,255,.08); }
.main-area { margin-left: 248px; min-height: 100vh; display: flex; flex-direction: column; }
.sidebar-overlay { display: none; }

/* ---------- Topbar ---------- */
.topbar {
    min-height: 72px;
    background: rgba(255,255,255,.94);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 13px 28px;
    position: sticky;
    top: 0;
    z-index: 30;
    backdrop-filter: blur(8px);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.page-heading h1 { margin: 0; font-size: 19px; line-height: 1.25; letter-spacing: -.02em; font-weight: 700; }
.page-heading p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.menu-btn { display: none !important; }
.content { padding: 24px 28px 40px; width: 100%; max-width: 1500px; margin: 0 auto; flex: 1; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: #f9fafb; border-color: #d0d5dd; color: var(--ink); text-decoration: none; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(15,118,110,.25); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--danger); border-color: #fecdca; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); border-color: #fda29b; color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); box-shadow: none; }
.btn-ghost:hover { background: var(--line-soft); border-color: transparent; color: var(--ink); }
.btn-sm { min-height: 31px; padding: 5px 9px; font-size: 12px; border-radius: 7px; }
.btn-lg { min-height: 44px; padding: 11px 18px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border: 1px solid transparent; border-radius: 8px;
    background: transparent; color: var(--muted); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.icon-btn .icon { width: 18px; height: 18px; }
.icon-btn.is-danger:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- Quick add ---------- */
.quick-add { position: relative; }
.quick-add summary { list-style: none; }
.quick-add summary::-webkit-details-marker { display: none; }
.quick-menu {
    position: absolute; right: 0; top: calc(100% + 7px); width: 214px;
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 12px 30px rgba(16,24,40,.13); padding: 5px; z-index: 60;
}
.quick-menu a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 7px; color: var(--ink-soft); font-size: 13px; text-decoration: none; }
.quick-menu a:hover { background: var(--bg); text-decoration: none; }
.quick-menu form { margin: 0; }
.quick-menu button {
    width: 100%; display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border: 0; border-radius: 7px; background: transparent;
    color: var(--ink-soft); font-size: 13px; text-align: left; cursor: pointer;
}
.quick-menu button:hover { background: var(--bg); }
.quick-menu .icon { width: 17px; height: 17px; color: var(--muted); }

/* ---------- Cards ---------- */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 17px 20px; border-bottom: 1px solid var(--line-soft); }
.card-header h2, .card-header h3 { margin: 0; font-size: 14px; font-weight: 700; letter-spacing: -.01em; }
.card-header p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.card-body { padding: 20px; }
.card-body.tight { padding: 14px 20px; }
.card-footer { padding: 13px 20px; border-top: 1px solid var(--line-soft); background: #fcfcfd; border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 17px 18px 15px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat-label { font-size: 11.5px; font-weight: 600; color: var(--muted); letter-spacing: .03em; text-transform: uppercase; }
.stat-icon { width: 32px; height: 32px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent-dark); }
.stat-icon .icon { width: 17px; height: 17px; }
.stat-value { margin-top: 12px; font-size: 25px; line-height: 1.1; letter-spacing: -.03em; font-weight: 700; }
.stat-note { margin-top: 7px; font-size: 11.5px; color: var(--muted); }
.stat-note strong { color: var(--ink-soft); }
.stat-card.is-alert .stat-icon { background: var(--danger-soft); color: var(--danger); }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr); gap: 18px; align-items: start; }
.dash-stack { display: flex; flex-direction: column; gap: 18px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
    text-align: left; padding: 10px 16px; white-space: nowrap;
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); font-weight: 700; background: #fcfcfd;
    border-bottom: 1px solid var(--line);
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fbfcfd; }
table.data .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data .center { text-align: center; }
table.data .strong { font-weight: 600; }
.cell-main { font-weight: 600; color: var(--ink); }
.cell-sub { margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.doc-link { font-weight: 600; color: var(--ink); text-decoration: none; }
.doc-link:hover { color: var(--accent-dark); text-decoration: none; }
.row-actions { display: flex; justify-content: flex-end; gap: 2px; }
.row-actions form { display: inline; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
    white-space: nowrap; line-height: 1.4;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .75; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: #f2f4f7; color: var(--muted); }
.badge-accent { background: var(--accent-soft); color: var(--accent-dark); }
.type-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.type-chip .icon { width: 14px; height: 14px; }

/* ---------- Toolbar & filters ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search-form { display: flex; align-items: center; gap: 8px; }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted-2); pointer-events: none; }
.search-box input { padding-left: 32px; min-width: 220px; }
.filter-select { min-height: 38px; padding: 7px 30px 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 12.5px; color: var(--ink-soft); }
.result-count { font-size: 12px; color: var(--muted); }
.result-count strong { color: var(--ink); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 18px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: span 3; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.field .req { color: var(--danger); }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], input[type="search"], select, textarea {
    width: 100%;
    min-height: 39px;
    padding: 8px 11px;
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    background: #fff;
    font-size: 13.5px;
    color: var(--ink);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 80px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input[readonly], input:disabled, textarea[readonly] { background: #f9fafb; color: var(--muted); }
.help { font-size: 11.5px; color: var(--muted); }
.field-error { font-size: 11.5px; color: var(--danger); }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding-top: 17px; margin-top: 18px; border-top: 1px solid var(--line-soft); }
.form-actions .left { margin-right: auto; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 13px; font-weight: 700; }
.section-title .icon { width: 17px; height: 17px; color: var(--accent); }
.form-card + .form-card { margin-top: 16px; }
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.form-main { min-width: 0; }
.form-side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 92px; }

/* ---------- Alerts ---------- */
.flash {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 11px 14px; margin-bottom: 14px;
    border: 1px solid var(--line); border-radius: 9px;
    background: #fff; font-size: 13px; box-shadow: var(--shadow-sm);
}
.flash .icon { width: 18px; height: 18px; margin-top: 1px; }
.flash span { flex: 1; }
.flash-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 2px; }
.flash-success { border-color: #abefc6; background: var(--success-soft); color: #05603a; }
.flash-danger { border-color: #fecdca; background: var(--danger-soft); color: #912018; }
.flash-warning { border-color: #fedf89; background: var(--warning-soft); color: #93370d; }
.flash-info { border-color: #b2ddff; background: var(--info-soft); color: #194185; }
.errors { border: 1px solid #fecdca; background: var(--danger-soft); color: #912018; padding: 12px 14px; border-radius: 9px; margin-bottom: 16px; font-size: 12.5px; }
.errors ul { margin: 0; padding-left: 18px; }
.errors li + li { margin-top: 3px; }

/* ---------- Empty state ---------- */
.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty .empty-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--bg); color: var(--muted-2); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.empty h3 { margin: 0 0 5px; color: var(--ink); font-size: 14px; }
.empty p { margin: 0 0 14px; font-size: 12.5px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line-soft); font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.pager { display: flex; gap: 4px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 30px; height: 30px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; text-decoration: none; color: var(--ink-soft); font-size: 12px; }
.pager a:hover { background: var(--bg); text-decoration: none; }
.pager .current { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* ---------- Customer detail ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.info-list { display: grid; gap: 0; }
.info-row { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.info-row:last-child { border-bottom: 0; }
.info-row dt { color: var(--muted); font-size: 12px; }
.info-row dd { margin: 0; color: var(--ink); }
.address-block { white-space: pre-line; line-height: 1.55; }
.entity-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.entity-title { display: flex; align-items: center; gap: 13px; min-width: 0; }
.entity-avatar { width: 44px; height: 44px; border-radius: 11px; background: var(--accent-soft); color: var(--accent-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; flex: 0 0 auto; }
.entity-title h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.entity-title p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.entity-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Document detail ---------- */
.doc-banner { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 20px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.doc-banner-main { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.doc-badge { width: 46px; height: 46px; border-radius: 11px; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent-dark); }
.doc-badge .icon { width: 22px; height: 22px; }
.doc-banner h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.doc-banner .sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 5px; font-size: 12px; color: var(--muted); }
.doc-banner-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.doc-meta-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; border-bottom: 1px solid var(--line-soft); }
.doc-meta { padding: 14px 20px; border-right: 1px solid var(--line-soft); }
.doc-meta:last-child { border-right: 0; }
.doc-meta .label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.doc-meta .value { margin-top: 4px; font-size: 13px; font-weight: 600; }
.doc-body-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 18px; align-items: start; }
.doc-side { display: flex; flex-direction: column; gap: 16px; }
.item-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.item-table th { text-align: left; padding: 9px 14px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--line); background: #fcfcfd; }
.item-table td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.item-table tr:last-child td { border-bottom: 0; }
.item-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.item-table .center { text-align: center; }
.item-desc { white-space: pre-line; line-height: 1.5; }
.totals { margin-left: auto; width: 100%; max-width: 340px; font-size: 13px; }
.totals-row { display: flex; justify-content: space-between; gap: 20px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.totals-row:last-child { border-bottom: 0; }
.totals-row .label { color: var(--muted); }
.totals-row .value { font-variant-numeric: tabular-nums; font-weight: 600; }
.totals-row.grand { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 10px; }
.totals-row.grand .label, .totals-row.grand .value { color: var(--ink); font-size: 15px; font-weight: 700; }
.totals-row.balance .value { color: var(--danger); }
.totals-row.paid .value { color: var(--success); }
.payment-list { display: flex; flex-direction: column; }
.payment-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.payment-item:last-child { border-bottom: 0; }
.payment-item .amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.payment-item .meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.payment-form { border-top: 1px solid var(--line-soft); margin-top: 6px; padding-top: 14px; }
.payment-form .form-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
.payment-form .span-2 { grid-column: span 2; }
.timeline-note { padding: 12px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; white-space: pre-line; line-height: 1.55; }
.timeline-note:last-child { border-bottom: 0; }
.source-links { display: flex; flex-direction: column; gap: 7px; }
.source-links a { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-soft); text-decoration: none; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.source-links a:hover { border-color: #d0d5dd; background: #fcfcfd; text-decoration: none; }
.source-links .icon { width: 16px; height: 16px; color: var(--muted); }

/* ---------- Document item editor ---------- */
.items-editor { width: 100%; border-collapse: collapse; }
.items-editor th { padding: 8px 8px; text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--line); }
.items-editor td { padding: 7px 6px; vertical-align: top; border-bottom: 1px solid var(--line-soft); }
.items-editor tr:last-child td { border-bottom: 0; }
.items-editor .col-no { width: 34px; text-align: center; color: var(--muted); font-size: 12px; padding-top: 16px; }
.items-editor .col-desc { min-width: 270px; }
.items-editor .col-qty { width: 95px; }
.items-editor .col-price { width: 135px; }
.items-editor .col-total { width: 120px; text-align: right; padding-top: 16px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.items-editor .col-remove { width: 38px; padding-top: 10px; }
.items-editor textarea { min-height: 38px; height: 38px; padding: 8px 10px; resize: vertical; overflow: hidden; }
.items-editor input { min-height: 38px; padding: 8px 10px; }
.items-editor .qty-input { text-align: center; }
.items-editor .price-input { text-align: right; }
.items-editor-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 12px; }
.editor-totals { display: grid; gap: 6px; margin-top: 15px; margin-left: auto; width: 100%; max-width: 300px; font-size: 13px; }
.editor-totals .row { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.editor-totals .row span:first-child { color: var(--muted); }
.editor-totals .row strong { font-variant-numeric: tabular-nums; }
.editor-totals .row.grand { padding-top: 8px; border-top: 1px solid var(--line); margin-top: 3px; font-size: 15px; }
.editor-totals input { max-width: 120px; text-align: right; }
.discount-row input { max-width: 130px; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 22px; align-items: start; }
.settings-tabs { display: flex; flex-direction: column; gap: 3px; position: sticky; top: 92px; }
.settings-tab { text-align: left; padding: 9px 12px; border-radius: 8px; border: 0; background: transparent; color: var(--muted); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.settings-tab:hover { background: #eef0f3; color: var(--ink); }
.settings-tab.is-active { background: #fff; color: var(--ink); box-shadow: var(--shadow-sm), inset 2px 0 0 var(--accent); border: 1px solid var(--line); }
.settings-pane { display: none; }
.settings-pane.is-active { display: block; }
.logo-preview { display: flex; align-items: center; gap: 14px; }
.logo-preview img { width: 64px; height: 64px; border-radius: 10px; border: 1px solid var(--line); }
.logo-preview .help { max-width: 330px; }

/* ---------- Login / setup ---------- */
.guest-body { background: #0b1220; }
.guest-shell { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); min-height: 100vh; }
.guest-brand { background: radial-gradient(circle at 18% 18%, rgba(20,184,166,.16), transparent 40%), linear-gradient(160deg, #111827 0%, #0b1220 75%); color: #fff; display: flex; align-items: center; justify-content: center; padding: 48px; }
.guest-brand-inner { max-width: 470px; width: 100%; display: flex; flex-direction: column; gap: 42px; }
.guest-logo { width: 92px; height: 92px; border-radius: 16px; box-shadow: 0 0 0 1px rgba(255,255,255,.12), 0 22px 40px rgba(0,0,0,.28); }
.eyebrow { margin: 0 0 12px; font-size: 10.5px; letter-spacing: .15em; text-transform: uppercase; color: #5eead4; font-weight: 700; }
.guest-brand h1 { margin: 0 0 16px; font-size: clamp(30px, 3.4vw, 45px); line-height: 1.08; letter-spacing: -.045em; font-weight: 650; color: #f8fafc; }
.guest-lede { margin: 0; color: #9aa4b2; font-size: 14px; line-height: 1.65; max-width: 390px; }
.guest-points { display: flex; flex-direction: column; gap: 11px; color: #c5ccd6; font-size: 12.5px; }
.guest-points span { display: flex; align-items: center; gap: 9px; }
.guest-points .icon { width: 15px; height: 15px; color: #5eead4; }
.guest-foot { border-top: 1px solid rgba(255,255,255,.09); padding-top: 18px; font-size: 10.5px; color: #667085; letter-spacing: .04em; }
.guest-panel { display: flex; align-items: center; justify-content: center; background: #f6f7f9; padding: 40px 24px; }
.guest-card { width: 100%; max-width: 410px; }
.auth-head { margin-bottom: 22px; }
.auth-head h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: -.03em; }
.auth-head p { margin: 0; color: var(--muted); font-size: 13px; }
.auth-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 24px; box-shadow: 0 10px 30px rgba(16,24,40,.06); }
.auth-card .field + .field { margin-top: 14px; }
.auth-card .btn-block { margin-top: 18px; min-height: 43px; }
.auth-foot { margin-top: 16px; font-size: 11px; color: var(--muted-2); text-align: center; }
.steps { display: flex; gap: 6px; margin-bottom: 20px; }
.steps span { height: 3px; flex: 1; background: var(--line); border-radius: 99px; }
.steps span.on { background: var(--accent); }

/* ---------- Flash position in guest ---------- */
.guest-card .flash { margin-bottom: 14px; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 18px; }
.mt-4 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 18px; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 6px; }
.gap-2 { gap: 12px; }
.divider { height: 1px; background: var(--line-soft); margin: 16px 0; }
.kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; font-size: 10px; color: var(--muted); background: #fff; }
.progress { height: 6px; background: var(--line-soft); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.address-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.legend .dot-danger { background: var(--danger); }
.legend .dot-warning { background: var(--warning); }
.legend .dot-success { background: var(--success); }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
    .dash-grid { grid-template-columns: 1fr; }
    .form-layout { grid-template-columns: 1fr; }
    .form-side { position: static; }
    .doc-body-grid { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.35); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 40; }
    .main-area { margin-left: 0; }
    .menu-btn { display: inline-flex !important; }
    .topbar { padding: 12px 18px; }
    .content { padding: 18px 18px 32px; }
    .settings-grid { grid-template-columns: 1fr; }
    .settings-tabs { flex-direction: row; flex-wrap: wrap; position: static; }
    .settings-tab.is-active { border: 0; box-shadow: inset 0 -2px 0 var(--accent); background: transparent; }
    .doc-meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .doc-meta:nth-child(2) { border-right: 0; }
    .doc-meta:nth-child(-n+2) { border-bottom: 1px solid var(--line-soft); }
    .guest-shell { grid-template-columns: 1fr; }
    .guest-brand { display: none; }
}
@media (max-width: 640px) {
    .page-heading h1 { font-size: 16px; }
    .page-heading p { display: none; }
    .stat-grid { grid-template-columns: 1fr; }
    .form-grid, .form-grid.three, .detail-grid, .address-split { grid-template-columns: 1fr; }
    .form-grid .span-2, .form-grid .span-3 { grid-column: span 1; }
    .doc-body-grid { gap: 12px; }
    .doc-banner, .entity-head { padding: 16px; }
    .doc-banner-actions { width: 100%; }
    .doc-banner-actions .btn { flex: 1; }
    .filter-select { flex: 1; }
    .search-box input { min-width: 0; width: 100%; }
    .search-form { width: 100%; }
    .search-box { flex: 1; }
    .toolbar { align-items: stretch; }
    .toolbar-group { width: 100%; }
    .items-editor .col-qty { width: 74px; }
    .items-editor .col-price { width: 105px; }
    .items-editor .col-total { width: 88px; }
    .items-editor .col-desc { min-width: 180px; }
    .topbar-actions .btn span { display: none; }
    .topbar-actions .quick-add summary .icon-sm { display: none; }
}
