/* SUNAC Smart Business Manager - Finance UI theme */
:root {
    --brand:        #064d44;
    --brand-2:      #0a7a6b;
    --brand-soft:   #e6f2f0;
    --accent:       #0b8f7e;
    --ink:          #0c1f1c;
    --ink-2:        #2c3e3a;
    --muted:        #6b7a76;
    --line:         #e3eae8;
    --line-2:       #cfd9d6;
    --bg:           #f4f6f5;
    --surface:      #ffffff;
    --good:         #128a52;
    --good-soft:    #e7f6ee;
    --warn:         #b46b00;
    --warn-soft:    #fff4dd;
    --bad:          #b3261e;
    --bad-soft:     #fde7e6;
    --info:         #1565c0;
    --info-soft:    #e3f2fd;
    --shadow-sm:    0 1px 2px rgba(8,30,28,0.06);
    --shadow:       0 4px 12px rgba(8,30,28,0.08);
    --radius:       10px;
    --radius-sm:    6px;
    --sidebar-w:    248px;
    --topbar-h:     60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* numerals — tabular figures for finance tables */
.num, td.num, th.num, .table-finance td, .table-finance th {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { color: var(--accent); text-decoration: underline; }

/* ── Topbar ── */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    padding: 0 24px;
    z-index: 50;
}
.topbar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
    color: var(--ink);
    width: var(--sidebar-w);
    margin-left: -24px;
    padding-left: 24px;
}
.topbar .brand .mark {
    width: 32px; height: 32px;
    background: var(--brand);
    color: white;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}
.topbar .brand .name { line-height: 1.1; }
.topbar .brand .name small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.topbar-spacer { flex: 1; }
.topbar .profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 999px;
    cursor: pointer;
    color: var(--ink);
    border: 1px solid var(--line);
    background: var(--surface);
    transition: background .12s;
}
.topbar .profile:hover { background: var(--brand-soft); text-decoration: none; }
.topbar .profile .avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--brand-2);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
}
.topbar .profile .who { line-height: 1.15; font-size: 13px; }
.topbar .profile .who small { color: var(--muted); display: block; font-size: 11px; }
.profile-menu {
    position: absolute;
    top: calc(var(--topbar-h) - 2px);
    right: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 220px;
    padding: 6px;
    display: none;
    z-index: 60;
}
.profile-menu.open { display: block; }
.profile-menu a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-size: 13px;
}
.profile-menu a:hover { background: var(--brand-soft); text-decoration: none; }
.profile-menu .sep { height: 1px; background: var(--line); margin: 4px 0; }

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--line);
    overflow-y: auto;
    padding: 14px 10px;
}
.sidebar .group-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 14px 12px 6px;
    font-weight: 600;
}
.sidebar a.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--ink-2);
    font-size: 13.5px;
    font-weight: 500;
    margin-bottom: 2px;
    transition: background .12s, color .12s;
}
.sidebar a.nav-link i { font-size: 16px; color: var(--muted); width: 18px; text-align: center; }
.sidebar a.nav-link:hover { background: var(--brand-soft); color: var(--brand); text-decoration: none; }
.sidebar a.nav-link:hover i { color: var(--brand); }
.sidebar a.nav-link.active {
    background: var(--brand);
    color: #fff;
}
.sidebar a.nav-link.active i { color: #fff; }
.sidebar a.nav-link .badge-pill {
    margin-left: auto;
    background: var(--bad);
    color: #fff;
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 999px;
}

/* ── Main content ── */
.app-main {
    margin-left: var(--sidebar-w);
    margin-top: var(--topbar-h);
    padding: 24px 28px 60px;
    min-height: calc(100vh - var(--topbar-h));
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}
/* Allow grid children to shrink instead of overflowing the page */
.app-main [style*="grid-template-columns"] > * { min-width: 0; }
.app-main > * { min-width: 0; max-width: 100%; }
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.page-head h1 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--ink);
}
.page-head .sub {
    color: var(--muted);
    font-size: 13px;
    margin-top: 3px;
}
.crumbs { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--brand); }

/* ── Cards ── */
.card-fin {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    min-width: 0;
    overflow: hidden;
}
.card-fin .card-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-fin .card-head h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}
.card-fin .card-body { padding: 18px; }
.card-fin .card-foot {
    padding: 12px 18px;
    border-top: 1px solid var(--line);
    background: #fafbfb;
    border-radius: 0 0 var(--radius) var(--radius);
    font-size: 13px;
}

/* ── KPI strip ── */
.kpi-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.kpi {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.kpi .kpi-label {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.kpi .kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}
.kpi .kpi-sub { color: var(--muted); font-size: 12px; margin-top: 3px; }
.kpi.kpi-good { border-left: 3px solid var(--good); }
.kpi.kpi-bad  { border-left: 3px solid var(--bad); }
.kpi.kpi-warn { border-left: 3px solid var(--warn); }
.kpi.kpi-info { border-left: 3px solid var(--info); }
.kpi.kpi-brand { border-left: 3px solid var(--brand); }
.kpi .kpi-trend {
    font-size: 11px;
    font-weight: 600;
    margin-top: 4px;
}
.kpi .kpi-trend.up   { color: var(--good); }
.kpi .kpi-trend.down { color: var(--bad); }

/* ── Tables ── */
/* Wrap tables inside cards in a horizontal scroll container so a wide
   table doesn't push the surrounding card past the viewport. */
.card-fin .card-body { overflow-x: auto; }

.table-finance {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: auto;
}
.table-finance th {
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 11px;
    color: var(--muted);
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: #fafbfb;
    font-weight: 600;
}
.table-finance td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    color: var(--ink);
    vertical-align: middle;
}
.table-finance tbody tr:hover { background: #fafdfc; }
.table-finance tbody tr:last-child td { border-bottom: none; }
.table-finance .num, .table-finance th.num, .table-finance td.num { text-align: right; }
.table-finance .muted { color: var(--muted); font-size: 12px; }

/* ── Status pills ── */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad  { background: var(--bad-soft);  color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.muted{ background: #eff2f1; color: var(--muted); }

/* ── Buttons ── */
.btn-fin {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
    text-decoration: none;
}
.btn-fin.primary { background: var(--brand); color: #fff; }
.btn-fin.primary:hover { background: var(--brand-2); color: #fff; text-decoration: none; }
.btn-fin.ghost { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn-fin.ghost:hover { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn-fin.danger { background: var(--bad); color: #fff; }
.btn-fin.danger:hover { background: #8e1c16; color: #fff; text-decoration: none; }
.btn-fin.success { background: var(--good); color: #fff; }
.btn-fin.success:hover { background: #0e6e41; color: #fff; text-decoration: none; }
.btn-fin.sm { padding: 5px 10px; font-size: 12px; }
.btn-fin.lg { padding: 11px 20px; font-size: 14px; }

/* ── Forms ── */
.form-fin label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-2);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.form-fin input, .form-fin select, .form-fin textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-family: inherit;
    color: var(--ink);
    background: var(--surface);
    transition: border-color .12s, box-shadow .12s;
}
.form-fin input:focus, .form-fin select:focus, .form-fin textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(11, 143, 126, 0.15);
}
.form-fin textarea { min-height: 70px; resize: vertical; }
.form-fin .row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-fin .row.row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-fin .row.row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.form-fin .field { margin-bottom: 14px; }
.form-fin .help { color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.form-fin .switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

/* ── Alerts ── */
.alert-fin {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border-left: 3px solid;
    font-size: 13px;
    margin-bottom: 14px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.alert-fin.good { background: var(--good-soft); border-color: var(--good); color: #0c5d3a; }
.alert-fin.bad  { background: var(--bad-soft);  border-color: var(--bad);  color: #71150f; }
.alert-fin.warn { background: var(--warn-soft); border-color: var(--warn); color: #6e4100; }
.alert-fin.info { background: var(--info-soft); border-color: var(--info); color: #0d3f78; }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 18px;
}
.tabs a {
    padding: 9px 14px;
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tabs a.active { color: var(--brand); border-color: var(--brand); }
.tabs a:hover { color: var(--brand); text-decoration: none; }

/* ── Timeline ── */
.timeline { position: relative; padding-left: 22px; }
.timeline::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--line);
}
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item::before {
    content: '';
    position: absolute;
    left: -19px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--brand);
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 1px var(--brand);
}
.tl-item.good::before { background: var(--good); box-shadow: 0 0 0 1px var(--good); }
.tl-item.bad::before  { background: var(--bad);  box-shadow: 0 0 0 1px var(--bad); }
.tl-item.warn::before { background: var(--warn); box-shadow: 0 0 0 1px var(--warn); }
.tl-item.info::before { background: var(--info); box-shadow: 0 0 0 1px var(--info); }
.tl-date { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.tl-title { font-weight: 600; color: var(--ink); margin: 1px 0 2px; }
.tl-meta { color: var(--muted); font-size: 12px; }

/* ── Utilities ── */
.text-good { color: var(--good); }
.text-bad  { color: var(--bad); }
.text-warn { color: var(--warn); }
.text-muted { color: var(--muted); }
.text-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 12px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.flex { display: flex; }
.flex.gap-2 { gap: 8px; }
.flex.gap-3 { gap: 12px; }
.flex.gap-4 { gap: 16px; }
.flex.between { justify-content: space-between; }
.flex.center { align-items: center; }
.fw { width: 100%; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; }

/* ── Medium screens: flatten 2-column page grids into one column ── */
@media (max-width: 1100px) {
    .app-main [style*="grid-template-columns: 2fr 1fr"],
    .app-main [style*="grid-template-columns: 1fr 1fr"],
    .app-main [style*="grid-template-columns: 1.2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* ── Responsive: collapse sidebar on small screens ── */
@media (max-width: 900px) {
    :root { --sidebar-w: 0px; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s;
        z-index: 70;
        width: 240px;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .topbar .brand { width: auto; }
    .app-main { padding: 16px; }
    .menu-toggle { display: inline-flex !important; }
}
.menu-toggle {
    display: none;
    width: 38px; height: 38px;
    border: 1px solid var(--line-2);
    background: var(--surface);
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--ink);
    margin-right: 8px;
}

/* Pager */
.pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-top: 1px solid var(--line);
    flex-wrap: wrap;
    gap: 10px;
    background: #fafbfb;
    border-radius: 0 0 var(--radius) var(--radius);
}
.pager-info { font-size: 12.5px; }
.pager-pages { display: flex; gap: 4px; align-items: center; }
.pager-pages .btn-fin { min-width: 30px; justify-content: center; }
.pager-gap { color: var(--muted); padding: 0 4px; }

/* Print */
@media print {
    .topbar, .sidebar, .no-print { display: none !important; }
    .app-main { margin: 0; padding: 0; }
    body { background: white; }
}
