:root {
    --accent: #1a56db;
    --accent-ink: #fff;
    --bg: #f3efe6;
    --surface: #fffcf7;
    --ink: #14161c;
    --muted: #6d675e;
    --line: #e4ddd0;
    --sidebar: #12151c;
    --sidebar-text: #c9c3b6;
    --danger: #9b2c2c;
    --ok: #1f6b4a;
    --warn: #8a5a12;
    --shadow: 0 18px 40px rgba(20, 22, 28, 0.06);
    --radius: 14px;
    --font: "Helvetica World", Helvetica, Arial, "Noto Sans Khmer", sans-serif;
    --serif: "Helvetica World", Helvetica, Arial, "Noto Sans Khmer", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 268px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 28px 20px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar-brand {
    margin-bottom: 28px;
}
.sidebar-brand a { display: block; }
.sidebar-brand img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 72px;
    object-fit: contain;
    object-position: left center;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav a {
    color: var(--sidebar-text);
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
}
.sidebar-nav a:hover, .sidebar-nav a.is-active {
    background: rgba(255,255,255,0.07);
    color: #fff;
}
.nav-label {
    margin: 22px 12px 6px;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #7d776c;
}
.sidebar-cta { margin-top: auto; padding-top: 16px; }
.sidebar-signout {
    display: block;
    margin-top: 10px;
    text-align: center;
    color: var(--sidebar-text);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 10px;
}
.sidebar-signout:hover { color: #fff; background: rgba(255,255,255,0.07); }
.app-main { flex: 1; min-width: 0; }
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 22px 32px 8px;
}
.topbar-title { flex: 1; }
.topbar h1 {
    margin: 0;
    font-family: var(--serif);
    font-size: 28px;
    font-weight: 500;
    letter-spacing: -0.03em;
}
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar-user-name { font-weight: 600; }
.page { padding: 16px 32px 48px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    border-radius: 10px; padding: 9px 14px; font: inherit; font-size: 14px; font-weight: 600;
    cursor: pointer; transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-accent { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { background: #fff5f5; border-color: #f0c6c6; color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.card-head h2, .section-title {
    margin: 0;
    font-size: 16px;
    font-weight: 650;
}

.stat-grid, .grid-2, .grid-3 { display: grid; gap: 16px; }
.stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.grid-2 { grid-template-columns: 1.4fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat {
    padding: 20px;
}
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-value { font-family: var(--serif); font-size: 30px; letter-spacing: -0.03em; margin-top: 6px; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
table.data th {
    text-align: left;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0 10px 10px;
    border-bottom: 1px solid var(--line);
}
table.data td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tr:hover td { background: rgba(20,22,28,0.015); }

.badge {
    display: inline-flex; align-items: center;
    padding: 3px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
    background: #eee8dc; color: #4d483f;
}
.badge-muted { background: #ece8df; }
.badge-draft { background: #eee8dc; color: #5c574c; }
.badge-sent, .badge-viewed { background: #e4edff; color: #1a56db; }
.badge-paid, .badge-accepted { background: #ddf3e8; color: #1f6b4a; }
.badge-overdue, .badge-rejected, .badge-cancelled { background: #fde8e8; color: #9b2c2c; }
.badge-expired { background: #f4ead6; color: #8a5a12; }
.badge-invoice { background: #e4edff; color: #1a56db; }
.badge-quotation { background: #efe6ff; color: #5b3cc4; }
.badge-receipt { background: #ddf3e8; color: #1f6b4a; }

.alert {
    padding: 12px 14px; border-radius: 12px; margin-bottom: 16px;
    border: 1px solid var(--line); background: #fff;
}
.alert-success { border-color: #bfe3d0; background: #f3fbf6; color: var(--ok); }
.alert-error { border-color: #f0c6c6; background: #fff6f6; color: var(--danger); }
.alert-info { border-color: #c9d7f5; background: #f5f8ff; }

label { display: block; font-size: 13px; font-weight: 650; margin-bottom: 6px; }
.hint { font-weight: 500; color: var(--muted); font-size: 12px; }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="url"], input[type="search"], input[type="color"],
select, textarea {
    width: 100%;
    appearance: none;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 96px; resize: vertical; white-space: pre-wrap; }
.line-item textarea { min-height: 72px; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
}
.toolbar {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
    margin-bottom: 16px;
}
.toolbar .field { margin: 0; min-width: 160px; }
.search-grow { flex: 1; min-width: 220px; }

.empty {
    text-align: center;
    padding: 48px 20px;
    color: var(--muted);
}
.empty h3 { margin: 0 0 8px; color: var(--ink); font-family: var(--serif); font-weight: 500; font-size: 26px; }

.thumb {
    width: 42px; height: 42px; object-fit: cover; border-radius: 8px;
    background: #efe9dc; border: 1px solid var(--line);
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(900px 420px at 10% 0%, color-mix(in srgb, var(--accent) 18%, #f3efe6), transparent),
        var(--bg);
    padding: 24px;
}
.login-card { width: min(440px, 100%); padding: 36px; }
.login-logo {
    display: block;
    width: 100%;
    height: auto;
    max-height: 72px;
    object-fit: contain;
    object-position: left center;
    margin: 0 0 18px;
    background: #12151c;
    border-radius: 12px;
    padding: 10px 12px;
}
.login-card p.lead { color: var(--muted); margin: 0 0 28px; }
.auth-switch { margin: 20px 0 0; text-align: center; color: var(--muted); font-size: 14px; }
.auth-switch a { color: var(--accent); font-weight: 600; }

.signup-screen {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(360px, 0.92fr) minmax(420px, 1.08fr);
    background: var(--bg);
}
.signup-brand {
    background:
        radial-gradient(720px 420px at 10% 0%, color-mix(in srgb, var(--accent) 28%, transparent), transparent),
        var(--sidebar);
    color: #f4efe4;
    padding: 48px 56px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100vh;
}
.signup-logo {
    display: block;
    height: 72px;
    width: auto;
    max-width: 360px;
    object-fit: contain;
    object-position: left center;
    background: none;
    padding: 0;
    border-radius: 0;
}
.signup-brand-copy { max-width: 460px; padding-bottom: 24px; }
.signup-brand h1 {
    margin: 0 0 16px;
    font-family: var(--serif);
    font-size: clamp(28px, 3.2vw, 42px);
    font-weight: 500;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: #fff;
}
.signup-brand p {
    margin: 0 0 28px;
    color: #c9c3b6;
    font-size: 16px;
    line-height: 1.55;
}
.signup-brand ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 12px;
}
.signup-brand li {
    color: #e8e2d6;
    font-size: 15px;
    padding-left: 22px;
    position: relative;
}
.signup-brand li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.55em;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}
.signup-panel {
    display: grid;
    place-items: center;
    padding: 48px 64px;
    min-height: 100vh;
    background: var(--surface);
}
.signup-form-wrap {
    width: 100%;
    max-width: 560px;
}
.signup-form-wrap h2 {
    margin: 0 0 8px;
    font-family: var(--serif);
    font-size: 32px;
    font-weight: 500;
    letter-spacing: -0.03em;
}
.signup-form-wrap > .lead {
    color: var(--muted);
    margin: 0 0 28px;
}
.signup-form-wrap .field-row { margin-bottom: 0; }
.signup-form-wrap input[type="text"],
.signup-form-wrap input[type="email"],
.signup-form-wrap input[type="password"] {
    padding: 12px 14px;
}
.signup-form-wrap .btn-block {
    margin-top: 8px;
    padding: 12px 14px;
}
.signup-form-wrap .auth-switch { text-align: left; }

@media (max-width: 900px) {
    .signup-screen { grid-template-columns: 1fr; }
    .signup-brand {
        min-height: auto;
        padding: 28px 24px 24px;
    }
    .signup-brand-copy { padding-bottom: 0; }
    .signup-brand h1 { font-size: 26px; margin-bottom: 10px; }
    .signup-brand p, .signup-brand ul { display: none; }
    .signup-panel {
        min-height: auto;
        padding: 28px 20px 40px;
        place-items: start stretch;
    }
}

.profit-panel {
    background: #14161c;
    color: #f4efe4;
    border: 0;
}
.profit-panel h2 { color: #fff; }
.profit-panel .muted { color: #9b9488; }
.profit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.profit-grid strong { display: block; font-family: var(--serif); font-size: 22px; margin-top: 4px; }

.line-items { display: flex; flex-direction: column; gap: 12px; }
.line-item {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
    background: #fff;
    animation: rise .22s ease;
}
.line-item-top { display: grid; grid-template-columns: 72px 1fr auto; gap: 12px; }
.line-item-meta { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.line-item-image {
    width: 72px; height: 72px; border-radius: 10px; overflow: hidden;
    background: #efe9dc; border: 1px dashed var(--line);
    display: grid; place-items: center; font-size: 11px; color: var(--muted); text-align: center;
}
.line-item-image img { width: 100%; height: 100%; object-fit: cover; }
.drag-handle { cursor: grab; color: var(--muted); font-size: 12px; font-weight: 700; }

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(20,22,28,0.45);
    display: none; place-items: center; padding: 24px; z-index: 40;
}
.modal-backdrop.is-open { display: grid; }
.modal {
    width: min(640px, 100%);
    background: var(--surface);
    border-radius: 16px;
    padding: 22px;
    max-height: 80vh;
    overflow: auto;
}
.catalog-result {
    display: flex; gap: 10px; align-items: center;
    padding: 10px; border-radius: 10px; cursor: pointer;
}
.catalog-result:hover { background: #f4efe6; }

.icon-btn {
    display: none; border: 0; background: transparent; padding: 8px; cursor: pointer;
}
.icon-btn span { display: block; width: 18px; height: 2px; background: var(--ink); margin: 4px 0; }
.sidebar-backdrop { display: none; }

.actions-inline { display: flex; flex-wrap: wrap; gap: 6px; }

@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

@media (max-width: 1100px) {
    .stat-grid, .grid-2, .grid-3, .profit-grid, .field-row-3, .line-item-meta, .dash-charts, .dash-mid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 30;
        transform: translateX(-105%); transition: transform .2s ease;
    }
    .sidebar.is-open { transform: none; }
    .sidebar-backdrop.is-open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
    .icon-btn { display: inline-block; }
    .page, .topbar { padding-left: 16px; padding-right: 16px; }
    .stat-grid, .grid-2, .field-row, .line-item-top { grid-template-columns: 1fr; }
    .topbar h1 { font-size: 22px; }
    .dash-charts, .dash-mid, .dash-profit-grid, .dash-donut-wrap, .dash-steps { grid-template-columns: 1fr; }
}

body.app-body {
    --bg: #070b14;
    --surface: rgba(12, 18, 32, 0.72);
    --ink: #f4efe4;
    --muted: #9aa3b5;
    --line: rgba(56, 189, 255, 0.16);
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
    --ok: #34d399;
    --danger: #fb7185;
    --warn: #fbbf24;
    color: var(--ink);
    background:
        radial-gradient(900px 480px at 8% -8%, rgba(56, 189, 255, 0.16), transparent 55%),
        radial-gradient(720px 420px at 100% 0%, rgba(251, 146, 60, 0.10), transparent 50%),
        #070b14;
}
.app-body .sidebar {
    background: rgba(6, 9, 16, 0.88);
    border-right: 1px solid var(--line);
    backdrop-filter: blur(18px);
}
.app-body .sidebar-nav a:hover,
.app-body .sidebar-nav a.is-active {
    background: rgba(56, 189, 255, 0.14);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(56, 189, 255, 0.28);
}
.app-body .card {
    background: rgba(12, 18, 32, 0.72);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}
.app-body .btn {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--line);
    color: var(--ink);
}
.app-body .btn-accent { background: var(--accent); border-color: transparent; color: #fff; }
.app-body .btn-ghost { background: transparent; border-color: transparent; }
.app-body .btn-danger { background: rgba(251, 113, 133, 0.12); border-color: rgba(251, 113, 133, 0.3); color: #fb7185; }
.app-body table.data tr:hover td { background: rgba(56, 189, 255, 0.04); }
.app-body a { color: #7dd3fc; }
.app-body .badge { background: rgba(255,255,255,0.08); color: #d6d3c9; }
.app-body .badge-sent, .app-body .badge-viewed, .app-body .badge-invoice { background: rgba(56, 189, 255, 0.16); color: #7dd3fc; }
.app-body .badge-paid, .app-body .badge-accepted, .app-body .badge-receipt { background: rgba(52, 211, 153, 0.16); color: #6ee7b7; }
.app-body .badge-quotation { background: rgba(167, 139, 250, 0.16); color: #c4b5fd; }
.app-body .badge-overdue, .app-body .badge-rejected, .app-body .badge-cancelled { background: rgba(251, 113, 133, 0.16); color: #fda4af; }
.app-body .alert { background: rgba(12, 18, 32, 0.8); }
.app-body input[type="text"], .app-body input[type="email"], .app-body input[type="password"],
.app-body input[type="number"], .app-body input[type="date"], .app-body input[type="url"],
.app-body input[type="search"], .app-body select, .app-body textarea {
    background: rgba(7, 11, 20, 0.7);
    color: var(--ink);
    border-color: var(--line);
}
.app-body .line-item { background: rgba(12, 18, 32, 0.55); }
.app-body .icon-btn span { background: #f4efe4; }
.app-body .empty h3 { color: #fff; }

/* Column headers stay pinned while the page scrolls (desktop). The wrapper's
   horizontal scroll would trap the sticky header, so it is released here;
   narrow screens keep the sideways-scrolling table. */
@media (min-width: 1100px) {
    .table-wrap { overflow: visible; }
    table.data thead th {
        position: sticky;
        top: 0;
        z-index: 3;
        padding-top: 12px;
        background: var(--surface);
        box-shadow: inset 0 -1px 0 var(--line);
    }
    .app-body table.data thead th { background: #0a0f1b; }
}

.dash { display: flex; flex-direction: column; gap: 16px; }
.dash .stat-grid { margin-bottom: 0; }
.dash-up { color: #34d399; font-weight: 700; }
.dash-down { color: #fb7185; font-weight: 700; }
.dash-charts, .dash-mid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 16px;
}
.dash-chart-card { min-height: 320px; }
.dash-area-wrap { height: 240px; }
.dash-area-wrap svg { width: 100%; height: 220px; display: block; }
.dash-area-labels {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 11px;
    padding: 0 4px;
}
.dash-donut-wrap {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 16px;
    align-items: center;
}
.dash-donut-wrap svg { width: 200px; height: 200px; }
.dash-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.dash-legend li { display: grid; grid-template-columns: 10px 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.dash-legend i { width: 10px; height: 10px; border-radius: 50%; display: block; box-shadow: 0 0 10px currentColor; }
.dash-legend strong { color: #fff; font-size: 12px; }
.dash-profit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dash-bars { display: flex; align-items: end; gap: 6px; height: 56px; margin-top: 12px; }
.dash-bars span {
    flex: 1;
    background: linear-gradient(180deg, #38bdf8, rgba(56, 189, 255, 0.2));
    border-radius: 4px 4px 0 0;
}
.dash-steps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}
.dash-steps a {
    display: block;
    padding: 14px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(56, 189, 255, 0.06);
    color: #d6d3c9;
    text-decoration: none;
}
.dash-steps a.is-accent {
    border-color: rgba(251, 146, 60, 0.45);
    background: rgba(251, 146, 60, 0.12);
    box-shadow: 0 0 24px rgba(251, 146, 60, 0.12);
}
.dash-steps span { display: block; color: #7dd3fc; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; margin-bottom: 6px; }
.dash-steps a.is-accent span { color: #fb923c; }
.dash-steps strong { color: #fff; font-size: 13px; }

