/* Finance — design tokens & shell.
   Dark by default. Amounts formatted in SAR. */

:root {
    /* Palette */
    --bg-0:      #0b0d1a;
    --bg-1:      #0f1220;
    --bg-2:      #171a2e;
    --bg-3:      #1e2138;
    --border:    #262b45;
    --border-2:  #333a5a;
    --ink:       #e6e9f4;
    --ink-2:     #b7bdd6;
    --muted:     #8b90ad;
    --accent:    #7c8ff5;
    --accent-2:  #a8b3ff;
    --pos:       #4caf80;
    --neg:       #f26b6b;
    --warn:      #f2b35c;
    --info:      #5cc2f2;
    --violet:    #b985f2;

    /* Sizing */
    --radius:    12px;
    --radius-sm: 8px;
    --shadow:    0 12px 40px rgba(0,0,0,.4);
    --side-w:    240px;

    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    background: var(--bg-0);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
                 "Cairo", "Noto Sans Arabic", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

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

.muted { color: var(--muted); }
.mono  { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.pos   { color: var(--pos); }
.neg   { color: var(--neg); }

/* ================================================
   Buttons & inputs
   ================================================ */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem .9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-2);
    background: var(--bg-2);
    color: var(--ink);
    font-size: .9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--bg-3); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--accent);
    color: #0b0d1a;
    border-color: var(--accent);
    font-weight: 600;
}
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--bg-2); color: var(--ink); border-color: var(--border); }
.btn-danger { color: var(--neg); border-color: transparent; background: transparent; }
.btn-danger:hover { background: rgba(242,107,107,.12); border-color: rgba(242,107,107,.3); }
.btn-sm { padding: .35rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; }

input, select, textarea {
    width: 100%;
    background: var(--bg-1);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .55rem .7rem;
    font-size: .95rem;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124,143,245,.18);
}
label { display: block; font-size: .8rem; color: var(--muted); margin: .8rem 0 .3rem; font-weight: 500; }

/* ================================================
   Auth pages
   ================================================ */

.auth-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 2rem;
    background: radial-gradient(1200px 800px at 50% -20%, rgba(124,143,245,.15), transparent 60%),
                var(--bg-0);
}
.auth-card {
    width: 100%; max-width: 26rem;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 1.4rem; margin: 1rem 0 .25rem; }
.auth-card .muted { margin-bottom: 1.25rem; font-size: .9rem; }
.brand { display: flex; align-items: center; gap: .8rem; }
.brand-mark {
    width: 42px; height: 42px; border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--violet));
    display: grid; place-items: center;
    color: white; font-weight: 700; font-size: 1.2rem;
}
.brand-name { font-weight: 700; letter-spacing: .01em; }
.brand-sub  { color: var(--muted); font-size: .8rem; }

.alert {
    padding: .6rem .8rem;
    border-radius: var(--radius-sm);
    font-size: .9rem;
    margin: .5rem 0 .8rem;
}
.alert-error { background: rgba(242,107,107,.1); color: #f9adad; border: 1px solid rgba(242,107,107,.3); }
.alert-ok    { background: rgba(76,175,128,.08); color: #a5e2bd; border: 1px solid rgba(76,175,128,.3); }

/* ================================================
   Application shell
   ================================================ */

.app {
    display: grid;
    grid-template-columns: var(--side-w) 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--bg-1);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 1.25rem 0;
    position: sticky; top: 0; height: 100vh;
    overflow-y: auto;
}
.sidebar .brand { padding: 0 1.25rem 1.5rem; border-bottom: 1px solid var(--border); }

.nav { padding: .75rem; display: flex; flex-direction: column; gap: 2px; }
.nav a {
    display: flex; align-items: center; gap: .7rem;
    padding: .55rem .75rem;
    border-radius: 8px;
    color: var(--ink-2);
    font-size: .92rem;
    font-weight: 500;
}
.nav a:hover { background: var(--bg-2); color: var(--ink); text-decoration: none; }
.nav a.active {
    background: linear-gradient(90deg, rgba(124,143,245,.18), rgba(124,143,245,.04));
    color: var(--ink);
    box-shadow: inset 3px 0 0 var(--accent);
}
.nav .nav-icon { width: 18px; height: 18px; display: inline-block; opacity: .85; }

.sidebar-footer {
    margin-top: auto;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: .8rem;
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}

.main {
    display: flex; flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-1);
    position: sticky; top: 0;
    z-index: 10;
}
.topbar h1 { margin: 0; font-size: 1.15rem; font-weight: 600; }
.topbar .actions { display: flex; align-items: center; gap: .5rem; }

.content { padding: 1.5rem; max-width: 1400px; width: 100%; }

/* ================================================
   Cards, KPI, charts
   ================================================ */

.card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1rem;
}
.card-header h2 { margin: 0; font-size: 1rem; font-weight: 600; letter-spacing: .01em; }
.card-header .sub { color: var(--muted); font-size: .85rem; }

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

.kpi { padding: 1.1rem 1.25rem; }
.kpi .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 1.55rem; font-weight: 700; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.kpi .sub   { color: var(--muted); font-size: .82rem; margin-top: .25rem; }

.tag {
    display: inline-block;
    padding: .12rem .5rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    background: var(--bg-3);
    color: var(--ink-2);
    border: 1px solid var(--border);
}
.tag-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .4rem; vertical-align: middle; }

/* ================================================
   Tables
   ================================================ */

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: .65rem .8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table th {
    font-weight: 600; color: var(--muted); font-size: .78rem;
    text-transform: uppercase; letter-spacing: .05em;
}
.table td.amount { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.table tbody tr:hover { background: var(--bg-3); }
.table-wrap { overflow-x: auto; }
.table-empty { padding: 2.5rem; text-align: center; color: var(--muted); }

/* ================================================
   Filters bar
   ================================================ */

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: .75rem;
    margin-bottom: 1rem;
}
.filters label { margin: 0 0 .25rem; }
.filters .filter-actions { display: flex; align-items: end; gap: .5rem; }

/* ================================================
   Modal
   ================================================ */

.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    display: none; align-items: center; justify-content: center;
    z-index: 100;
    padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 30rem;
    width: 100%;
    padding: 1.5rem;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h2 { margin: 0 0 .25rem; font-size: 1.1rem; }
.modal .form-actions { display: flex; gap: .5rem; margin-top: 1.25rem; justify-content: flex-end; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* ================================================
   Toast
   ================================================ */

.toast {
    position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
    background: var(--bg-3);
    color: var(--ink);
    padding: .7rem 1rem;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    z-index: 200;
    opacity: 0; transition: opacity .2s, transform .2s;
    box-shadow: var(--shadow);
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { border-color: rgba(242,107,107,.4); color: #f9adad; }
.toast.ok  { border-color: rgba(76,175,128,.4); color: #a5e2bd; }

/* ================================================
   Charts
   ================================================ */

.chart-wrap { position: relative; height: 240px; }

.bar {
    background: var(--bg-3);
    border-radius: 999px;
    overflow: hidden;
    height: 8px;
    width: 100%;
}
.bar > span {
    display: block; height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    border-radius: 999px;
}

/* ================================================
   Responsive
   ================================================ */

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: static; height: auto;
        border-right: 0; border-bottom: 1px solid var(--border);
        flex-direction: row; flex-wrap: wrap;
        padding: .5rem;
    }
    .sidebar .brand { border: 0; padding: .5rem .75rem; }
    .nav { flex-direction: row; flex-wrap: wrap; padding: .25rem; }
    .nav a { padding: .4rem .7rem; }
    .sidebar-footer { display: none; }
    .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
    .grid-2-3, .grid-3-2 { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .content { padding: 1rem; }
}
@media (max-width: 520px) {
    .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
