/* ============ Lead Accounting Web — design system ============ */
:root {
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-soft: #eef2ff;
    --accent: #0d9488;
    --accent-soft: #f0fdfa;
    --bg: #f4f5fb;
    --surface: #ffffff;
    --ink: #1e2235;
    --ink-soft: #5a6072;
    --ink-faint: #9298ab;
    --line: #e6e8f0;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --success: #16a34a;
    --success-soft: #f0fdf4;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 3px rgba(30, 34, 53, .06), 0 8px 24px rgba(30, 34, 53, .05);
    --shadow-lg: 0 12px 40px rgba(30, 34, 53, .14);
    --sidebar-w: 264px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.02em; }

a { color: var(--brand); text-decoration: none; }

/* ---------- boot ---------- */
.boot-screen {
    height: 100vh; display: flex; align-items: center; justify-content: center;
}
.spinner {
    width: 42px; height: 42px; border-radius: 50%;
    border: 4px solid var(--line); border-top-color: var(--brand);
    animation: spin .8s linear infinite;
}
.spinner.sm { width: 22px; height: 22px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- app shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: #171b2d;
    color: #c7cbe0;
    display: flex; flex-direction: column;
    position: fixed; inset: 0 auto 0 0;
    z-index: 50;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 20px 20px 16px;
}
.brand-badge {
    width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, var(--brand), #7c6cf0);
    color: #fff; font-weight: 800; font-size: 20px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 14px rgba(79, 70, 229, .45);
}
.brand-name { color: #fff; font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: #8b91ad; }

.sidebar-nav {
    flex: 1; overflow-y: auto; padding: 4px 12px 12px;
    scrollbar-width: none;           /* Firefox */
    -ms-overflow-style: none;        /* old Edge/IE */
}
.sidebar-nav::-webkit-scrollbar { display: none; }  /* WebKit */
.nav-section {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em;
    color: #6d7390; margin: 18px 10px 6px; font-weight: 600;
}
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; margin: 2px 0;
    border-radius: 9px; color: #c7cbe0;
    font-size: 14px; font-weight: 500;
    cursor: pointer; border: none; background: none; width: 100%;
    font-family: inherit; text-align: left;
    transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active {
    background: var(--brand); color: #fff;
    box-shadow: 0 4px 12px rgba(79, 70, 229, .4);
}
.nav-ico { width: 20px; text-align: center; font-size: 15px; flex: none; }

.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.logout-btn:hover { background: rgba(220, 38, 38, .18); color: #fca5a5; }

.sidebar-scrim { display: none; }

.main-column {
    flex: 1; min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex; flex-direction: column;
}

.topbar {
    height: 60px; background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 14px;
    padding: 0 22px;
    position: sticky; top: 0; z-index: 40;
}
.topbar-spacer { flex: 1; }
.topbar-link {
    display: flex; align-items: center; gap: 6px;
    color: var(--ink-soft); font-weight: 500; font-size: 14px;
    padding: 7px 12px; border-radius: 9px;
}
.topbar-link:hover { background: var(--brand-soft); color: var(--brand); }
.hamburger {
    display: none; background: none; border: none; font-size: 20px;
    cursor: pointer; color: var(--ink); padding: 6px;
}
.user-chip {
    display: flex; align-items: center; gap: 9px;
    font-weight: 600; font-size: 14px; color: var(--ink);
    background: var(--bg); padding: 6px 14px 6px 6px; border-radius: 999px;
    border: none; cursor: pointer; font-family: inherit;
    transition: box-shadow .15s;
}
.user-chip:hover { box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }

/* profile popover */
.profile-anchor { position: relative; }
.profile-scrim { position: fixed; inset: 0; z-index: 59; }
.profile-pop {
    position: absolute; top: calc(100% + 10px); right: 0; z-index: 60;
    width: 340px; max-width: calc(100vw - 32px);
    background: var(--surface); border-radius: 16px;
    box-shadow: var(--shadow-lg); border: 1px solid var(--line);
    animation: slideup .18s ease;
    max-height: min(560px, calc(100vh - 90px)); overflow-y: auto;
}
.profile-head { display: flex; gap: 13px; align-items: center; padding: 16px 16px 12px; }
.profile-meta {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px;
    padding: 4px 16px 12px; font-size: 13px;
}
.profile-meta b { display: block; color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.profile-privs-title {
    padding: 10px 16px 4px; font-size: 11px; text-transform: uppercase;
    letter-spacing: .08em; color: var(--ink-faint); font-weight: 700;
    border-top: 1px solid var(--line);
}
.profile-privs { padding: 4px 16px 12px; }
.priv-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 5px 0; font-size: 13.5px;
}
.priv-badges { display: flex; gap: 5px; }
.priv-badges .badge { font-size: 10.5px; padding: 2px 8px; }
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #14b8a6);
    color: #fff; font-size: 13px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}

.page-content { padding: 26px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- login ---------- */
.login-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(1000px 600px at 80% -10%, #e0e7ff 0%, transparent 60%),
                radial-gradient(800px 500px at -10% 110%, #ccfbf1 0%, transparent 55%),
                var(--bg);
    padding: 24px;
}
.login-card {
    width: 100%; max-width: 420px;
    background: var(--surface); border-radius: 20px;
    box-shadow: var(--shadow-lg);
    padding: 38px 36px;
}
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 26px; }
.login-brand .brand-badge { width: 46px; height: 46px; font-size: 23px; }
.login-title { font-size: 21px; font-weight: 800; }
.login-sub { color: var(--ink-soft); font-size: 13.5px; }
.login-footer {
    margin-top: 22px; text-align: center; font-size: 13px; color: var(--ink-soft);
}

/* ---------- cards, panels ---------- */
.card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 22px;
}
.card + .card { margin-top: 18px; }

.page-head {
    display: flex; align-items: flex-end; justify-content: space-between;
    flex-wrap: wrap; gap: 14px; margin-bottom: 20px;
}
.page-head h1 { font-size: 23px; }
.page-head .sub { color: var(--ink-soft); font-size: 13.5px; margin-top: 3px; }

.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

/* stat card */
.stat-card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 18px 20px;
    display: flex; flex-direction: column; gap: 4px;
}
.stat-label { font-size: 12.5px; color: var(--ink-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.stat-value.pos { color: var(--success); }
.stat-value.neg { color: var(--danger); }

/* ---------- forms ---------- */
.field { margin-bottom: 15px; }
.field label {
    display: block; font-size: 13px; font-weight: 600;
    color: var(--ink-soft); margin-bottom: 6px;
}
.input, .select, .textarea {
    width: 100%; padding: 10px 13px;
    border: 1.5px solid var(--line); border-radius: var(--radius-sm);
    font-family: inherit; font-size: 14.5px; color: var(--ink);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .13);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: var(--radius-sm);
    font-family: inherit; font-size: 14.5px; font-weight: 600;
    border: none; cursor: pointer; transition: all .15s;
    text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.3); }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: #0f766e; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1.5px solid var(--line); }
.btn-ghost:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1.5px solid #fecaca; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table.data {
    width: 100%; border-collapse: collapse; font-size: 14px;
    background: var(--surface);
}
table.data th {
    text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink-faint); font-weight: 600;
    padding: 11px 14px; border-bottom: 1.5px solid var(--line);
    white-space: nowrap;
}
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .12s; }
table.data tbody tr:hover { background: #f8f9fe; }
table.data tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- badges, pills ---------- */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
}
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }
.badge-indigo { background: var(--brand-soft); color: var(--brand); }
.badge-gray { background: #f1f2f7; color: var(--ink-soft); }

/* tabs */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tab {
    padding: 8px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
    background: var(--surface); color: var(--ink-soft);
    border: 1.5px solid var(--line); cursor: pointer; font-family: inherit;
    transition: all .15s;
}
.tab:hover { border-color: var(--brand); color: var(--brand); }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- alerts / empty / toast ---------- */
.alert { padding: 13px 16px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 16px; }
.alert-error { background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: var(--success-soft); color: #166534; border: 1px solid #bbf7d0; }

.empty-state {
    text-align: center; padding: 48px 20px; color: var(--ink-faint);
}
.empty-state .glyph { font-size: 40px; margin-bottom: 10px; }

.loading-row { display: flex; align-items: center; gap: 10px; padding: 24px; color: var(--ink-soft); justify-content: center; }

/* toast */
.toast {
    position: fixed; bottom: 26px; right: 26px; z-index: 100;
    background: #1e2235; color: #fff; padding: 14px 20px;
    border-radius: 12px; box-shadow: var(--shadow-lg);
    font-size: 14.5px; max-width: 380px;
    animation: slideup .25s ease;
}
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
@keyframes slideup { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

/* pagination */
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 14px; font-size: 13.5px; color: var(--ink-soft); }

/* search dropdown */
.search-box { position: relative; }
.search-results {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
    background: var(--surface); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg); border: 1px solid var(--line);
    max-height: 280px; overflow-y: auto;
}
.search-result-item { padding: 10px 14px; cursor: pointer; font-size: 14px; }
.search-result-item:hover { background: var(--brand-soft); }
.search-result-item .meta { font-size: 12px; color: var(--ink-faint); }

/* line-item editor */
.line-items-table .input { padding: 7px 10px; font-size: 13.5px; }

/* chart canvas */
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 380px; }

/* invoice totals */
.totals-panel {
    background: var(--brand-soft); border-radius: var(--radius);
    padding: 18px 22px; display: flex; flex-direction: column; gap: 8px;
}
.totals-row { display: flex; justify-content: space-between; font-size: 14.5px; }
.totals-row.grand { font-size: 19px; font-weight: 800; border-top: 1.5px solid #c7d2fe; padding-top: 10px; margin-top: 4px; }

/* detail header block */
.doc-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 18px; }
.doc-head .kv { font-size: 14px; }
.doc-head .kv b { display: block; font-size: 12px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; margin-bottom: 2px; }

/* report tiles */
.report-tile {
    display: flex; align-items: center; gap: 15px;
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px;
    cursor: pointer; transition: transform .15s, box-shadow .15s;
    border: none; font-family: inherit; text-align: left; width: 100%;
}
.report-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.report-tile .tile-ico {
    width: 46px; height: 46px; border-radius: 13px; flex: none;
    display: flex; align-items: center; justify-content: center; font-size: 21px;
}
.report-tile .tile-name { font-weight: 700; font-size: 15px; }
.report-tile .tile-sub { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); }
    .app-shell.sidebar-open .sidebar { transform: none; }
    .app-shell.sidebar-open .sidebar-scrim {
        display: block; position: fixed; inset: 0; z-index: 45;
        background: rgba(15, 18, 34, .5);
    }
    .main-column { margin-left: 0; }
    .hamburger { display: block; }
    .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
    .page-content { padding: 18px; }
    .hide-sm { display: none; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
}

/* ---------- centered narrow forms ---------- */
.form-page { display: grid; grid-template-columns: minmax(0, 680px); justify-content: center; }

/* ---------- modal / picker ---------- */
.modal-scrim {
    position: fixed; inset: 0; z-index: 80;
    background: rgba(15, 18, 34, .5);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: fadein .15s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: var(--surface); border-radius: 18px;
    box-shadow: var(--shadow-lg);
    width: 100%; max-width: 640px;
    max-height: calc(100vh - 60px);
    display: flex; flex-direction: column;
    animation: slideup .2s ease;
}
.modal.wide { max-width: 860px; }
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 16.5px; }
.modal-close {
    background: none; border: none; font-size: 19px; cursor: pointer;
    color: var(--ink-faint); padding: 4px 8px; border-radius: 8px;
}
.modal-close:hover { background: var(--bg); color: var(--ink); }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* picker rows */
.pick-row {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px; cursor: pointer;
    transition: background .12s;
}
.pick-row:hover { background: var(--brand-soft); }
.pick-row .thumb {
    width: 42px; height: 42px; border-radius: 10px; flex: none;
    background: var(--bg); display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: var(--ink-faint); overflow: hidden;
}
.pick-row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.pick-row .pick-main { flex: 1; min-width: 0; }
.pick-row .pick-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-row .pick-sub { font-size: 12px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-row .pick-end { text-align: right; font-size: 13px; font-weight: 600; white-space: nowrap; }

/* ---------- item cards grid ---------- */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.item-card {
    background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden; cursor: pointer;
    transition: transform .15s, box-shadow .15s;
    border: none; text-align: left; font-family: inherit; padding: 0;
}
.item-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.item-card .item-img {
    height: 130px; background: linear-gradient(135deg, #f4f5fb, #e9ebf5);
    display: flex; align-items: center; justify-content: center;
    font-size: 34px; color: #c3c8da; overflow: hidden;
}
.item-card .item-img img { width: 100%; height: 100%; object-fit: cover; }
.item-card .item-body { padding: 13px 15px 15px; }
.item-card .item-name { font-weight: 700; font-size: 14.5px; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-card .item-desc { font-size: 12px; color: var(--ink-faint); margin-bottom: 8px; height: 30px; overflow: hidden; }
.item-card .item-foot { display: flex; justify-content: space-between; align-items: center; }
.item-card .item-price { font-weight: 800; font-size: 15px; }

/* image gallery in detail */
.img-gallery { display: flex; gap: 10px; flex-wrap: wrap; }
.img-gallery img {
    width: 110px; height: 110px; object-fit: cover; border-radius: 12px;
    border: 1px solid var(--line);
}
.detail-hero {
    width: 100%; max-height: 260px; object-fit: contain; border-radius: 14px;
    background: var(--bg);
}

/* key-value grid for detail views */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 18px; }
.kv-grid b { display: block; font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; margin-bottom: 2px; }
.kv-grid > div { font-size: 14px; }

/* drawer (right side) */
.drawer-scrim {
    position: fixed; inset: 0; z-index: 80; background: rgba(15, 18, 34, .45);
    animation: fadein .15s ease;
}
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 81;
    width: 420px; max-width: 94vw;
    background: var(--surface); box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
    animation: slidein .22s ease;
}
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 18px 20px; overflow-y: auto; flex: 1; }

/* report percent bars */
.share-bar { height: 7px; border-radius: 99px; background: var(--bg); overflow: hidden; min-width: 90px; }
.share-fill { height: 100%; border-radius: 99px; background: var(--brand); }

/* segmented control */
.seg { display: inline-flex; background: var(--bg); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button {
    border: none; background: transparent; padding: 7px 14px; border-radius: 9px;
    font-family: inherit; font-size: 13px; font-weight: 600; color: var(--ink-soft);
    cursor: pointer; transition: all .13s;
}
.seg button.on { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }

/* ---------- extra mobile polish ---------- */
@media (max-width: 960px) {
    .two-col-form { grid-template-columns: 1fr !important; }
    .modal { max-width: none; border-radius: 16px; }
    .sticky-side { position: static !important; }
    .page-head h1 { font-size: 20px; }
    .stat-value { font-size: 20px; }
    .chart-box { height: 240px; }
    .chart-box.tall { height: 300px; }
    table.data th, table.data td { padding: 9px 10px; font-size: 13px; }
    .item-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .item-card .item-img { height: 100px; }
}
@media (max-width: 560px) {
    .drawer { width: 100vw; max-width: 100vw; }
    .modal-scrim { padding: 10px; align-items: flex-end; }
    .modal { max-height: calc(100vh - 40px); }
    .pager { justify-content: center; }
    .page-content { padding: 14px; }
    .tabs { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
    .tab { white-space: nowrap; flex: none; }
}
