/* ============================================================================
   Brokerage Desk — a design system for a Dubai real-estate commission CRM.
   Ink navigation rail + cool daylight workspace; money always in brass,
   in tabular figures. Layered over Bootstrap 5.3 (structure/JS kept).
   ========================================================================== */

@font-face {
    font-family: 'Space Grotesk';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('/static/vendor/fonts/space-grotesk-500.woff2') format('woff2');
}
@font-face {
    font-family: 'Space Grotesk';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('/static/vendor/fonts/space-grotesk-700.woff2') format('woff2');
}

:root {
    /* Ink rail */
    --ink-900: #0F1B2A;
    --ink-800: #16273A;
    --ink-700: #21374F;
    --ink-line: #26384E;

    /* Daylight workspace */
    --paper:   #EEF1F5;
    --surface: #FFFFFF;
    --surface-2: #F7F9FC;
    --text:    #17232F;
    --muted:   #64748B;
    --line:    #DCE2EA;
    --line-strong: #C8D1DC;

    /* Money + semantics */
    --brass:      #B4863F;
    --brass-soft: #F1E6D2;
    --brass-ink:  #8A6528;
    --sky:        #2C6FB3;
    --sky-ink:    #1F5893;
    --sky-soft:   #E4EEF8;
    --paid:       #1C7C63;
    --paid-soft:  #DCEEE7;
    --amber:      #B4832A;
    --amber-soft: #F6ECD4;
    --danger:     #B23A34;
    --danger-soft:#F6DEDC;

    /* Ad-platform chart colors — single source for bars + legend.
       Blue vs. warm amber: differ in hue AND lightness, so they stay
       distinct for red/green colour-blind viewers too. */
    --ad-google:   #F9AB00;   /* warm amber — Google Ads */
    --ad-facebook: #1877F2;   /* blue        — Facebook Ads */

    --display: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
    --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 27, 42, .06), 0 1px 3px rgba(15, 27, 42, .05);
    --shadow-md: 0 6px 20px -8px rgba(15, 27, 42, .18);
    --rail-w: 248px;

    /* Recolor Bootstrap primitives so stock components inherit the identity */
    --bs-primary: var(--sky);
    --bs-primary-rgb: 44, 111, 179;
    --bs-body-color: var(--text);
    --bs-body-bg: var(--paper);
    --bs-border-color: var(--line);
    --bs-link-color: var(--sky-ink);
    --bs-link-hover-color: var(--ink-900);
}

* { -webkit-tap-highlight-color: transparent; }

body {
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--paper);
}

/* Tabular figures everywhere numbers matter */
.money, .table td, .table th, .kpi__value, .meter__pct, .stat, .num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

/* ------------------------------------------------------------------ Money */
.money {
    font-family: var(--display);
    font-weight: 500;
    color: var(--brass-ink);
    letter-spacing: -.01em;
}
.money--lg { font-size: 1.5rem; font-weight: 700; }
.money--muted { color: var(--muted); font-family: var(--sans); }
.cur { font-size: .78em; color: var(--muted); font-family: var(--sans); margin-left: .15em; letter-spacing: .02em; }

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

.rail {
    width: var(--rail-w);
    flex: 0 0 var(--rail-w);
    background: var(--ink-900);
    color: #C7D2DE;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    padding-top: env(safe-area-inset-top);
    border-right: 1px solid #000;
    z-index: 1040;
}

.rail__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 22px 20px;
    color: #fff;
    text-decoration: none;
}
.rail__mark {
    width: 34px; height: 34px; flex: 0 0 34px;
    border-radius: 9px;
    background: linear-gradient(145deg, var(--brass) 0%, #8A6528 100%);
    display: grid; place-items: center;
    color: #1a1205; font-family: var(--display); font-weight: 700; font-size: 17px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}
.rail__wordmark { font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: .04em; line-height: 1; }
.rail__wordmark small { display: block; font-family: var(--sans); font-weight: 500; font-size: 10px; letter-spacing: .22em; color: #6E8299; margin-top: 4px; text-transform: uppercase; }

.rail__nav { display: flex; flex-direction: column; gap: 2px; padding: 12px; }
.rail__link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: #A8B6C6;
    text-decoration: none;
    font-weight: 500;
    letter-spacing: .01em;
    transition: background .15s ease, color .15s ease;
}
.rail__link i { font-size: 17px; width: 20px; text-align: center; color: #6E8299; transition: color .15s ease; }
.rail__link:hover { background: var(--ink-800); color: #E7EDF3; }
.rail__link:hover i { color: #A8B6C6; }
.rail__link.active { background: var(--ink-800); color: #fff; box-shadow: inset 3px 0 0 var(--brass); }
.rail__link.active i { color: var(--brass); }

.rail__spacer { flex: 1 1 auto; }
.rail__user {
    margin: 12px; padding: 12px;
    border-top: 1px solid var(--ink-line);
    display: flex; align-items: center; gap: 10px;
}
.rail__avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--ink-700); color: #DCE6F0;
    display: grid; place-items: center; font-weight: 600; font-size: 13px;
    text-transform: uppercase; flex: 0 0 32px;
}
.rail__user-name { font-size: 13px; font-weight: 600; color: #E7EDF3; line-height: 1.2; }
.rail__logout { margin-left: auto; color: #6E8299; font-size: 18px; text-decoration: none; }
.rail__logout:hover { color: var(--danger); }

/* ------------------------------------------------------------- Workspace */
.workspace { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    display: none; /* only shown on mobile */
    align-items: center; gap: 12px;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    background: var(--ink-900); color: #fff;
    position: sticky; top: 0; z-index: 1030;
}
.topbar__toggle {
    background: transparent; border: 1px solid var(--ink-700);
    color: #fff; border-radius: 8px; width: 38px; height: 38px; font-size: 18px;
}
.topbar__title { font-family: var(--display); font-weight: 700; letter-spacing: .04em; }

.content { padding: 26px 30px 60px; max-width: 1320px; width: 100%; }

/* ============================================================ Typography */
h1, h2, h3, h4, h5, .h4 { font-family: var(--display); color: var(--ink-900); letter-spacing: -.01em; }
h4, .h4 { font-weight: 700; }

.eyebrow {
    font-family: var(--sans); font-size: 11px; font-weight: 600;
    letter-spacing: .16em; text-transform: uppercase; color: var(--muted);
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-head h4 { margin: 0; font-size: 1.5rem; }

/* ================================================================= Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--line);
    font-family: var(--sans);
    font-weight: 600; font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
    color: var(--muted);
    padding: 14px 18px;
}
.card-body { padding: 18px; }
.shadow { box-shadow: var(--shadow-md) !important; }

/* ================================================================ Tables */
.table { --bs-table-bg: transparent; color: var(--text); margin-bottom: 0; }
.table > :not(caption) > * > * { padding: 11px 12px; }
.table thead th, .table > thead.table-light th {
    background: var(--surface-2);
    color: var(--muted);
    font-family: var(--sans);
    font-weight: 600; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
    border-bottom: 1px solid var(--line-strong);
    white-space: nowrap;
}
.table td { font-size: 13px; border-color: var(--line); vertical-align: middle; }
.table-hover > tbody > tr { transition: background .12s ease; }
.table-hover > tbody > tr:hover > * { background: var(--sky-soft); }
.table a { color: var(--ink-900); font-weight: 600; text-decoration: none; }
.table a:hover { color: var(--sky-ink); text-decoration: underline; text-underline-offset: 2px; }

/* Wrap plain tables in a card-like surface (keep horizontal scroll for wide tables) */
.table-responsive {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}
.table-responsive .table { border-collapse: separate; margin-bottom: 0; }

.table-success td, tr.table-success > * { background-color: var(--paid-soft) !important; }
.table-danger td,  tr.table-danger  > * { background-color: var(--danger-soft) !important; }
.table-warning td, tr.table-warning > * { background-color: var(--amber-soft) !important; }

/* ============================================================ Status pills */
.badge {
    font-family: var(--sans);
    font-weight: 600; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
    padding: .42em .72em; border-radius: 999px; border: 1px solid transparent;
}
.badge.bg-secondary { background: var(--surface-2) !important; color: var(--muted); border-color: var(--line-strong); }
.badge.bg-success   { background: var(--paid-soft) !important;   color: var(--paid); border-color: #BFE0D5; }
.badge.bg-danger    { background: var(--danger-soft) !important; color: var(--danger); border-color: #EBC4C1; }
.badge.bg-warning   { background: var(--amber-soft) !important;  color: var(--amber); border-color: #E7D4A6; }
.badge.bg-primary   { background: var(--sky-soft) !important;    color: var(--sky-ink); border-color: #C4DBF0; }
.badge.bg-info      { background: var(--brass-soft) !important;  color: var(--brass-ink); border-color: #E6D3AE; }

/* =============================================================== Buttons */
.btn { font-weight: 600; border-radius: var(--radius-sm); letter-spacing: .01em; transition: all .15s ease; }
.btn-sm { font-size: 12.5px; padding: .38rem .7rem; }
.btn-primary { background: var(--sky); border-color: var(--sky); box-shadow: 0 1px 2px rgba(44,111,179,.3); }
.btn-primary:hover, .btn-primary:focus { background: var(--sky-ink); border-color: var(--sky-ink); }
.btn-outline-secondary { color: var(--muted); border-color: var(--line-strong); }
.btn-outline-secondary:hover { background: var(--ink-900); border-color: var(--ink-900); color: #fff; }
.btn-outline-primary { color: var(--sky-ink); border-color: #B9D2EC; }
.btn-outline-primary:hover { background: var(--sky); border-color: var(--sky); color: #fff; }
.btn-outline-danger { color: var(--danger); border-color: #E6C3C0; }
.btn-outline-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-outline-success { color: var(--paid); border-color: #BFE0D5; }
.btn-outline-success:hover { background: var(--paid); border-color: var(--paid); color: #fff; }

/* ================================================================= Forms */
.form-control, .form-select {
    border-color: var(--line-strong); border-radius: var(--radius-sm);
    color: var(--text); font-size: 14px;
}
.form-control-sm, .form-select-sm { font-size: 13px; border-radius: var(--radius-sm); }
.form-control:focus, .form-select:focus {
    border-color: var(--sky); box-shadow: 0 0 0 3px var(--sky-soft);
}
.form-label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; margin-bottom: 5px; }
.form-check-input:checked { background-color: var(--sky); border-color: var(--sky); }

/* ============================================== Ledger meter (signature) */
.progress {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    height: 18px !important;
    overflow: hidden;
    position: relative;
}
.progress-bar {
    background: linear-gradient(180deg, #C79A50, var(--brass)) !important;
    color: #2a1e08; font-weight: 700; font-size: 10.5px; letter-spacing: .04em;
    font-variant-numeric: tabular-nums;
    border-radius: 999px;
    transition: width .5s cubic-bezier(.2,.7,.2,1);
}
.progress-bar.bg-success { background: linear-gradient(180deg, #2AA07E, var(--paid)) !important; color: #eafff7; }
.progress-bar.bg-info    { background: linear-gradient(180deg, #4a8fd0, var(--sky)) !important; color: #fff; }

/* ================================================================ Alerts */
.alert { border: 1px solid transparent; border-radius: var(--radius-sm); font-size: 13.5px; }
.alert-success { background: var(--paid-soft); color: #0f5b46; border-color: #BFE0D5; }
.alert-danger  { background: var(--danger-soft); color: #872b26; border-color: #EBC4C1; }
.alert-warning { background: var(--amber-soft); color: #7a5810; border-color: #E7D4A6; }
.alert-secondary { background: var(--surface-2); color: var(--muted); border-color: var(--line); }

/* ================================================================== Tabs */
.nav-tabs { border-bottom: 1px solid var(--line); gap: 2px; }
.nav-tabs .nav-link {
    font-size: 13.5px; font-weight: 600; color: var(--muted);
    border: none; border-bottom: 2px solid transparent; border-radius: 0;
    padding: 10px 14px;
}
.nav-tabs .nav-link:hover { color: var(--ink-900); border-bottom-color: var(--line-strong); background: transparent; }
.nav-tabs .nav-link.active { color: var(--ink-900); background: transparent; border-bottom-color: var(--brass); }
.nav-tabs .nav-link .badge { font-size: 10px; margin-left: 4px; vertical-align: middle; }

/* =========================================================== Pagination */
.pagination { --bs-pagination-color: var(--muted); --bs-pagination-hover-color: var(--ink-900); }
.page-link { border-color: var(--line); border-radius: var(--radius-sm) !important; margin: 0 2px; font-size: 13px; font-weight: 600; }
.page-item.active .page-link { background: var(--ink-900); border-color: var(--ink-900); }
.page-link:focus { box-shadow: 0 0 0 3px var(--sky-soft); }

/* =============================================================== Auth page */
.auth-shell {
    min-height: 100vh;
    display: grid; grid-template-columns: 1.1fr .9fr;
    background: var(--paper);
}
.auth-brand {
    background:
        radial-gradient(120% 120% at 100% 0%, #1D3350 0, transparent 60%),
        linear-gradient(160deg, #16273A 0%, #0F1B2A 72%);
    color: #fff; padding: 60px; display: flex; flex-direction: column; justify-content: space-between;
    position: relative; overflow: hidden;
}
.auth-brand::after {
    content: ""; position: absolute; inset: 0;
    background: radial-gradient(60% 50% at 90% 100%, rgba(180,134,63,.22), transparent 70%);
    pointer-events: none;
}
.auth-brand__mark { display: flex; align-items: center; gap: 14px; }
.auth-brand__mark .rail__mark { width: 44px; height: 44px; flex-basis: 44px; font-size: 22px; border-radius: 12px; }
.auth-brand__lead { max-width: 30ch; }
.auth-brand__lead h1 { color: #fff; font-size: clamp(2rem, 3.4vw, 3rem); line-height: 1.05; margin-bottom: 14px; }
.auth-brand__lead p { color: #93A6BB; font-size: 15px; }
.auth-brand__stats { display: flex; gap: 34px; }
.auth-brand__stats .eyebrow { color: #6E8299; margin-bottom: 6px; }
.auth-brand__stats .money { color: #E7C98A; }
.auth-form-wrap { display: grid; place-items: center; padding: 40px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card h4 { font-size: 1.4rem; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 22px; }

@media (max-width: 860px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { display: none; }
}

/* =============================================================== Utilities */
.text-muted { color: var(--muted) !important; }
.text-success { color: var(--paid) !important; }
.text-danger { color: var(--danger) !important; }
.divider { height: 1px; background: var(--line); border: 0; margin: 18px 0; }

/* ============================================================== Responsive */
@media (max-width: 992px) {
    .rail {
        position: fixed; left: 0; top: 0;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: var(--shadow-md);
    }
    .app.rail-open .rail { transform: translateX(0); }
    .app.rail-open::after {
        content: ""; position: fixed; inset: 0; background: rgba(15,27,42,.5); z-index: 1035;
    }
    .topbar { display: flex; }
    .content { padding: 18px 16px 50px; }
    .page-head { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Visible keyboard focus */
a:focus-visible, button:focus-visible, .btn:focus-visible, .form-control:focus-visible, .rail__link:focus-visible {
    outline: 2px solid var(--sky); outline-offset: 2px;
}
