/*
 * ArtCode Finance — v4
 * Bold dark canvas, ArtCode-brand cyan/blue accent (sourced from logo), glassy frosted cards.
 * Mobile-first. RTL-first.
 */

/* ───────── Tokens ───────── */
:root {
    --bg:           #0a0a0f;
    --bg-2:         #0e0e16;
    --bg-3:         #14141d;
    --surface:      rgba(255, 255, 255, 0.025);
    --surface-2:    rgba(255, 255, 255, 0.04);
    --surface-3:    rgba(255, 255, 255, 0.06);

    --text:         #e9e9f1;
    --text-strong:  #ffffff;
    --text-muted:   #9999a8;
    --text-faint:   #5e5e6e;

    --border:       rgba(255, 255, 255, 0.07);
    --border-2:     rgba(255, 255, 255, 0.12);

    /* Brand palette — all three logo families: cyan/blue, yellow/orange, magenta/pink */
    --brand-cyan:    #00a4db;
    --brand-blue:    #3c60df;
    --brand-yellow:  #fbe900;
    --brand-orange:  #ff7127;
    --brand-pink:    #ff166d;
    --brand-magenta: #e80d62;
    --brand-gradient: linear-gradient(135deg, #00a4db 0%, #3c60df 35%, #ff166d 70%, #ff7127 100%);

    --accent:       var(--brand-cyan);
    --accent-2:     var(--brand-blue);
    --accent-glow:  rgba(0, 164, 219, 0.42);
    --accent-soft:  rgba(0, 164, 219, 0.14);

    /* "Good" = warm yellow→orange (logo's success tone) */
    --good:         var(--brand-orange);
    --good-soft:    rgba(255, 113, 39, 0.14);
    --good-2:       var(--brand-yellow);
    --good-2-soft:  rgba(251, 233, 0, 0.14);

    /* "Bad" / debts / danger = logo magenta */
    --bad:          var(--brand-pink);
    --bad-soft:     rgba(255, 22, 109, 0.14);

    /* "Warn" = orange (same family as good but used for caution) */
    --warn:         var(--brand-orange);
    --warn-soft:    rgba(255, 113, 39, 0.14);

    --highlight:    var(--brand-yellow);
    --highlight-soft: rgba(251, 233, 0, 0.14);

    --r-sm: 10px;
    --r:    16px;
    --r-lg: 22px;
    --r-xl: 28px;

    --t:  220ms cubic-bezier(.4,0,.2,1);
    --t2: 380ms cubic-bezier(.4,0,.2,1);
}

/* ───────── Light theme overrides ───────── */
body.light-mode {
    --bg:           #f5f5f8;
    --bg-2:         #ffffff;
    --bg-3:         #ffffff;
    --surface:      rgba(15, 15, 25, 0.025);
    --surface-2:    rgba(15, 15, 25, 0.045);
    --surface-3:    rgba(15, 15, 25, 0.07);

    --text:         #1a1a2a;
    --text-strong:  #0a0a14;
    --text-muted:   #6b6b80;
    --text-faint:   #9c9cb0;

    --border:       rgba(15, 15, 25, 0.08);
    --border-2:     rgba(15, 15, 25, 0.16);

    --accent:       #007aa8;
    --accent-2:     #2b48c9;
    --accent-glow:  rgba(0, 122, 168, 0.30);
    --accent-soft:  rgba(0, 164, 219, 0.10);
    --good:         #c25513;
    --good-soft:    rgba(255, 113, 39, 0.12);
    --good-2:       #a08600;
    --good-2-soft:  rgba(184, 154, 0, 0.14);
    --bad:          #cf0e54;
    --bad-soft:     rgba(207, 14, 84, 0.10);
    --warn:         #c25513;
    --warn-soft:    rgba(255, 113, 39, 0.12);
    --highlight:    #a08600;
    --highlight-soft: rgba(184, 154, 0, 0.14);
}

/* Ambient glow softens for light mode but keeps the tri-color theme. */
body.light-mode::before {
    background:
        radial-gradient(700px circle at 90% -10%, rgba(0,164,219,0.10), transparent 60%),
        radial-gradient(600px circle at -10% 110%, rgba(255,22,109,0.08), transparent 55%),
        radial-gradient(500px circle at 110% 95%, rgba(255,113,39,0.06), transparent 55%);
}

/* Mobile drawer on light theme uses a solid white panel */
@media (max-width: 980px) {
    body.light-mode .sidebar { background: #ffffff; box-shadow: -20px 0 60px rgba(15,15,25,0.18); }
    body.light-mode .scrim { background: rgba(15,15,25,0.35); }
    body.light-mode .sidebar .user-pill,
    body.light-mode .sidebar .lang-switch,
    body.light-mode .sidebar .icon-btn { background: var(--surface); border-color: var(--border); }
    body.light-mode .sidebar .nav-link.active { background: var(--surface-2); }
}

/* Sidebar on desktop in light mode */
body.light-mode .sidebar {
    background:
        linear-gradient(180deg, rgba(15,15,25,0.01), rgba(15,15,25,0) 30%),
        #fafafd;
}

/* Card surfaces feel more substantial on light bg */
body.light-mode .card,
body.light-mode .stat,
body.light-mode .chart-card,
body.light-mode .modal-card,
body.light-mode .auth-card,
body.light-mode .error-card {
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(15,15,25,0.04), 0 4px 16px rgba(15,15,25,0.04);
}
body.light-mode .modal-card { box-shadow: 0 30px 80px rgba(15,15,25,0.20); }
body.light-mode .auth-card,
body.light-mode .error-card { box-shadow: 0 24px 60px rgba(15,15,25,0.10); }

/* Toasts on light theme */
body.light-mode .toast {
    background: #ffffff;
    box-shadow: 0 16px 40px rgba(15,15,25,0.16);
}

/* Top bar on light theme — translucent white */
body.light-mode .topbar { background: rgba(255,255,255,0.85); }

/* Inputs on light theme look better without the dark surface bg */
body.light-mode input,
body.light-mode select,
body.light-mode textarea {
    background: #ffffff;
    border-color: rgba(15,15,25,0.14);
}
body.light-mode input:focus,
body.light-mode select:focus,
body.light-mode textarea:focus {
    background: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Brand mark text invert for light bg */
body.light-mode .brand-mark img { filter: brightness(0) invert(1); }

/* Theme-color meta dynamically (visual only — does nothing functionally, kept for parity) */

/* ───────── Fonts ───────── */
@font-face {
    font-family: 'Bahij';
    src: url('../fonts/Bahij_TheSansArabic-Plain.ttf') format('truetype');
    font-display: swap;
}
@font-face {
    font-family: 'Bahij-Bold';
    src: url('../fonts/Bahij_TheSansArabic-Bold.ttf') format('truetype');
    font-display: swap;
}

/* ───────── Reset ───────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; font-family: 'Bahij', system-ui, -apple-system, 'Segoe UI', sans-serif; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
    direction: rtl;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    position: relative;
}

/* Ambient glow layer — fixed, behind everything. Uses all three logo families. */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(700px circle at 90% -10%, rgba(0,164,219,0.18), transparent 60%),
        radial-gradient(600px circle at -10% 110%, rgba(255,22,109,0.14), transparent 55%),
        radial-gradient(500px circle at 110% 95%, rgba(255,113,39,0.10), transparent 55%);
}

a { color: var(--accent-2); text-decoration: none; }
::selection { background: var(--accent-soft); color: var(--text-strong); }
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 6px;
}

button { font: inherit; color: inherit; }

/* Numerals everywhere LTR for tabular feel */
.num, .value, .record-amount, .stat-value, .banner-clock .time,
.modal-stat-value {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1, 'lnum' 1;
}

/* ───────── App shell ───────── */
.app {
    display: grid;
    grid-template-columns: 264px 1fr;
    min-height: 100vh;
}

/* ───────── Sidebar ───────── */
.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    padding: 22px 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    border-inline-start: 1px solid var(--border);
    background:
        linear-gradient(180deg, rgba(255,255,255,0.012), rgba(255,255,255,0) 30%),
        var(--bg-2);
    z-index: 50;
}

.sidebar-top { display: contents; }
.sidebar-close {
    display: none;
    width: 38px; height: 38px;
    border-radius: 11px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    place-items: center;
    cursor: pointer;
    transition: var(--t);
    flex-shrink: 0;
    font-size: 0.95rem;
}
.sidebar-close:hover { color: var(--text-strong); background: var(--surface-3); border-color: var(--border-2); }

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 10px 14px;
    border-bottom: 1px solid var(--border);
}
.brand-mark {
    width: 38px; height: 38px;
    border-radius: 11px;
    background: var(--brand-gradient);
    display: grid; place-items: center;
    box-shadow: 0 0 24px var(--accent-glow), 0 0 18px rgba(255, 22, 109, 0.25);
    flex-shrink: 0;
    overflow: hidden;
}
.brand-mark img { width: 26px; height: 26px; filter: brightness(0) invert(1); }
.brand-name {
    display: flex; flex-direction: column;
    line-height: 1.1;
}
.brand-name strong {
    font-family: 'Bahij-Bold';
    color: var(--text-strong);
    font-size: 1.02rem;
    letter-spacing: 0.2px;
}
.brand-name span {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.nav {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1;
}
.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 12px;
    color: var(--text-muted);
    font-size: 0.93rem;
    font-family: 'Bahij-Bold';
    transition: color var(--t), background var(--t);
    position: relative;
}
.nav-link i { width: 22px; font-size: 0.95rem; opacity: 0.85; }
.nav-link:hover { color: var(--text-strong); background: var(--surface); }
.nav-link.active {
    color: var(--text-strong);
    background: var(--surface-2);
}
.nav-link.active::before {
    content: '';
    position: absolute;
    top: 10px; bottom: 10px;
    inset-inline-start: 0;
    width: 3px;
    background: linear-gradient(180deg, var(--brand-cyan) 0%, var(--brand-pink) 55%, var(--brand-orange) 100%);
    border-radius: 999px;
    box-shadow: 0 0 12px var(--accent-glow);
}

.sidebar-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    padding: 10px;
    border-radius: 14px;
    border: 1px solid var(--border);
}
.avatar {
    width: 36px; height: 36px;
    border-radius: 12px;
    background: var(--brand-gradient);
    display: grid; place-items: center;
    color: white;
    font-family: 'Bahij-Bold';
    font-size: 0.95rem;
    box-shadow: 0 0 16px var(--accent-glow);
    flex-shrink: 0;
}
.user-meta { min-width: 0; flex: 1; }
.user-meta .who {
    font-family: 'Bahij-Bold';
    font-size: 0.88rem;
    color: var(--text-strong);
    white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.user-meta .role { font-size: 0.7rem; color: var(--text-faint); }

.sidebar-foot-row { display: flex; gap: 6px; }
.icon-btn {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 10px;
    border-radius: 11px;
    cursor: pointer;
    display: grid; place-items: center;
    transition: var(--t);
    font-size: 0.85rem;
}
.icon-btn:hover { color: var(--text-strong); background: var(--surface-2); border-color: var(--border-2); }
.icon-btn.danger:hover { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }

.lang-switch {
    display: flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 3px;
    gap: 2px;
}
.lang-pill {
    flex: 1;
    text-align: center;
    padding: 7px 6px;
    font-size: 0.75rem;
    border-radius: 8px;
    color: var(--text-muted);
    font-family: 'Bahij-Bold';
    transition: var(--t);
}
.lang-pill:hover { color: var(--text-strong); }
.lang-pill.active {
    background: var(--brand-gradient);
    color: white;
    box-shadow: 0 0 14px var(--accent-glow);
}

/* ───────── Main area ───────── */
.main {
    padding: 22px 28px 60px;
    min-width: 0;
    position: relative;
}

/* Mobile top-bar (hidden on desktop) */
.topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    background: rgba(10,10,15,0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    z-index: 70;
    margin-bottom: 16px;
    min-width: 0;
}
.topbar .brand {
    border: none;
    padding: 0;
    min-width: 0;
    flex: 1;
}
.topbar .brand-name { min-width: 0; overflow: hidden; }
.topbar .brand-name strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn {
    width: 42px; height: 42px;
    border-radius: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-strong);
    cursor: pointer;
    display: grid; place-items: center;
    font-size: 1rem;
    transition: var(--t);
}
.menu-btn:hover { background: var(--surface-3); }

/* ───────── Page header ───────── */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}
.page-head .h {
    display: flex; flex-direction: column; gap: 4px;
    min-width: 0;
    flex: 1 1 220px;
}
.page-head h1 {
    font-family: 'Bahij-Bold';
    font-size: 1.85rem;
    color: var(--text-strong);
    letter-spacing: -0.5px;
    line-height: 1.15;
    word-break: break-word;
}
.page-head p { color: var(--text-muted); font-size: 0.92rem; }
.clock-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 10px 16px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 120px;
}
.clock-card .time {
    font-family: 'Bahij-Bold';
    font-size: 1.4rem;
    color: var(--text-strong);
    line-height: 1.1;
    letter-spacing: 0.5px;
}
.clock-card .date {
    font-size: 0.74rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.section-title {
    font-family: 'Bahij-Bold';
    font-size: 0.78rem;
    color: var(--text-faint);
    letter-spacing: 1.2px;
    text-transform: uppercase;
    margin-bottom: 12px;
    margin-top: 6px;
}

/* ───────── Cards ───────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 22px;
    position: relative;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    transition: border-color var(--t), background var(--t), transform var(--t);
}
.card.hover-lift { cursor: pointer; }
.card.hover-lift:hover {
    border-color: var(--border-2);
    background: var(--surface-2);
    transform: translateY(-2px);
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}
.card-title {
    font-family: 'Bahij-Bold';
    font-size: 1rem;
    color: var(--text-strong);
    display: flex; align-items: center; gap: 10px;
}
.card-title i { color: var(--accent-2); font-size: 0.9rem; }

/* ───────── Stat tiles (the headliner numbers) ───────── */
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 22px;
}
.stats.stats-2 { grid-template-columns: repeat(2, 1fr); }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 20px 20px 18px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    position: relative;
    overflow: hidden;
    transition: border-color var(--t), background var(--t), transform var(--t);
    animation: rise 0.55s var(--t2) backwards;
}
.stat:nth-child(2) { animation-delay: 0.06s; }
.stat:nth-child(3) { animation-delay: 0.12s; }
.stat:nth-child(4) { animation-delay: 0.18s; }
.stat:hover {
    border-color: var(--border-2);
    background: var(--surface-2);
    transform: translateY(-2px);
}
.stat::after {
    content: '';
    position: absolute;
    top: 0; inset-inline-end: 0;
    width: 110px; height: 110px;
    background: radial-gradient(circle, var(--accent-soft), transparent 70%);
    pointer-events: none;
    opacity: 0.6;
}
.stat .label {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px;
    font-size: 0.74rem;
    color: var(--text-muted);
    letter-spacing: 0.8px;
    text-transform: uppercase;
    margin-bottom: 14px;
    position: relative;
    z-index: 1;
}
.stat .label .ico {
    width: 30px; height: 30px;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--accent-2);
    display: grid; place-items: center;
    font-size: 0.85rem;
}
.stat .value {
    font-family: 'Bahij-Bold';
    font-size: 1.85rem;
    color: var(--text-strong);
    line-height: 1.1;
    letter-spacing: -0.5px;
    position: relative;
    z-index: 1;
    word-break: keep-all;
}
.stat .value.good { color: var(--good); }
.stat .value.bad  { color: var(--bad); }
.stat .sub {
    margin-top: 10px;
    font-size: 0.76rem;
    color: var(--text-muted);
    position: relative;
    z-index: 1;
    display: flex; align-items: center; gap: 6px;
    flex-wrap: wrap;
}

/* ───────── Badges / chips ───────── */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-family: 'Bahij-Bold';
    line-height: 1.5;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
}
.chip-good { color: var(--good); background: var(--good-soft); border-color: rgba(52,211,153,0.20); }
.chip-bad  { color: var(--bad);  background: var(--bad-soft);  border-color: rgba(248,113,113,0.22); }
.chip-warn { color: var(--warn); background: var(--warn-soft); border-color: rgba(251,191,36,0.22); }
.chip-accent { color: var(--accent-2); background: var(--accent-soft); border-color: rgba(0,164,219,0.30); }

/* ───────── Chart card ───────── */
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 22px 22px 12px;
    margin-bottom: 22px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    animation: rise 0.6s var(--t2) 0.2s backwards;
}
.chart-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px; flex-wrap: wrap; gap: 10px;
}
.chart-legend { display: flex; gap: 14px; font-size: 0.78rem; color: var(--text-muted); }
.legend-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    margin-inline-end: 6px;
    vertical-align: middle;
    box-shadow: 0 0 8px currentColor;
}
.chart-host {
    width: 100%;
    height: 220px;
    position: relative;
    color: var(--text-muted);
}
.chart-host svg { width: 100%; height: 100%; display: block; }

/* ───────── Two-column dashboard rows ───────── */
.row-2 {
    display: grid;
    grid-template-columns: 1fr 1.55fr;
    gap: 18px;
    align-items: start;
    margin-bottom: 22px;
}
.col { display: flex; flex-direction: column; gap: 18px; }

/* ───────── Forms ───────── */
.field { margin-bottom: 14px; }
.field label {
    display: block;
    font-size: 0.74rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-family: 'Bahij-Bold';
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.field-row {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}

input, select, textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.94rem;
    transition: var(--t);
    font-family: inherit;
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface-2);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input[readonly] { opacity: 0.65; cursor: not-allowed; }

select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%239999a8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 14px center;
    padding-inline-start: 36px;
}
html[dir="rtl"] select { background-position: left 14px center; }
html[dir="ltr"] select { background-position: right 14px center; padding-inline-start: 14px; padding-inline-end: 36px; }

/* ───────── Buttons ───────── */
.btn {
    width: 100%;
    padding: 13px 18px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    font-family: 'Bahij-Bold';
    font-size: 0.96rem;
    cursor: pointer;
    transition: var(--t);
    box-shadow: 0 8px 24px -8px var(--accent-glow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 12px 32px -8px var(--accent-glow);
    filter: brightness(1.08);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-strong);
    box-shadow: none;
}
.btn.ghost:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--border-2);
    filter: none;
}
.btn.danger {
    background: linear-gradient(135deg, #b91c1c, #ef4444);
    box-shadow: 0 8px 24px -8px rgba(239,68,68,0.5);
}
.btn.success {
    background: linear-gradient(135deg, #047857, #10b981);
    box-shadow: 0 8px 24px -8px rgba(16,185,129,0.5);
}
.btn.w-auto { width: auto; }
.btn-icon {
    width: 42px; height: 42px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 11px;
    cursor: pointer;
    display: grid; place-items: center;
    transition: var(--t);
    flex-shrink: 0;
}
.btn-icon:hover { color: var(--text-strong); border-color: var(--border-2); background: var(--surface-3); }
.btn-icon.danger:hover { color: var(--bad); border-color: rgba(248,113,113,0.30); background: var(--bad-soft); }

/* Compact action button with icon + label that auto-fits its text */
.half-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 12px;
    border-radius: 10px;
    background: var(--bad-soft);
    border: 1px solid rgba(248,113,113,0.28);
    color: var(--bad);
    font-family: 'Bahij-Bold';
    font-size: 0.82rem;
    line-height: 1.2;
    cursor: pointer;
    transition: var(--t);
    width: auto;
    white-space: nowrap;
}
.half-btn i { font-size: 0.78rem; }
.half-btn:hover { filter: brightness(1.1); border-color: rgba(248,113,113,0.45); }
.half-btn.is-done {
    background: var(--good-soft);
    border-color: rgba(52,211,153,0.28);
    color: var(--good);
}
.half-btn.is-done:hover { border-color: rgba(52,211,153,0.45); }

/* ───────── Lists (projects / expenses items) ───────── */
.row-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 16px 18px;
    margin-bottom: 10px;
    transition: var(--t);
    animation: rise 0.4s var(--t2) backwards;
}
.row-item:hover { border-color: var(--border-2); background: var(--surface-2); }
.row-item.clickable { cursor: pointer; }
.row-item.clickable:hover { transform: translateY(-1px); }
.row-item.muted { opacity: 0.45; }

.row-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 8px;
}
.row-top h4 {
    font-family: 'Bahij-Bold';
    color: var(--text-strong);
    font-size: 1rem;
    word-break: break-word;
    line-height: 1.3;
}
.row-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 4px;
}
.row-meta i { color: var(--accent-2); font-size: 0.72rem; }

.record-amount {
    font-family: 'Bahij-Bold';
    color: var(--text-strong);
    font-size: 1.1rem;
    letter-spacing: -0.3px;
    white-space: nowrap;
}

/* ───────── Progress bar ───────── */
.progress {
    background: var(--surface-2);
    border-radius: 999px;
    height: 7px;
    overflow: hidden;
    margin: 8px 0 4px;
    position: relative;
    border: 1px solid var(--border);
}
.progress-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    box-shadow: 0 0 10px var(--accent-glow);
    transition: width 0.9s cubic-bezier(.4,0,.2,1);
    position: relative;
}
.progress-fill.done {
    background: linear-gradient(90deg, #059669, var(--good));
    box-shadow: 0 0 10px rgba(52,211,153,0.5);
}
.progress-meta {
    display: flex; justify-content: space-between;
    font-size: 0.74rem; color: var(--text-muted);
    margin-top: 6px;
    flex-wrap: wrap; gap: 6px;
}

/* ───────── Search ───────── */
.search {
    position: relative;
    margin-bottom: 14px;
}
.search input { padding-inline-end: 40px; }
.search i {
    position: absolute;
    inset-inline-end: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
    font-size: 0.88rem;
}

/* ───────── Empty / skeleton ───────── */
.empty {
    text-align: center;
    padding: 36px 16px;
    color: var(--text-muted);
}
.empty i {
    display: block;
    font-size: 2rem;
    margin-bottom: 12px;
    color: var(--text-faint);
}
.empty p { font-family: 'Bahij-Bold'; font-size: 0.92rem; }

.skel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 16px 18px;
    margin-bottom: 10px;
    display: flex; justify-content: space-between; align-items: center;
}
.skel-line {
    border-radius: 6px;
    background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.10) 50%, rgba(255,255,255,0.04) 75%);
    background-size: 300% 100%;
    animation: shimmer 1.5s infinite;
}

/* ───────── Toasts ───────── */
#toasts {
    position: fixed;
    bottom: 22px;
    inset-inline-start: 22px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
.toast {
    background: var(--bg-3);
    border: 1px solid var(--border-2);
    border-radius: 14px;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.5);
    font-size: 0.9rem;
    font-family: 'Bahij-Bold';
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(.4,0,.2,1);
    min-width: 240px;
    max-width: 380px;
    pointer-events: all;
    color: var(--text);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: rgba(52,211,153,0.4); box-shadow: 0 16px 40px rgba(0,0,0,0.5), 0 0 24px rgba(52,211,153,0.2); }
.toast.success i { color: var(--good); }
.toast.error { border-color: rgba(248,113,113,0.4); box-shadow: 0 16px 40px rgba(0,0,0,0.5), 0 0 24px rgba(248,113,113,0.2); }
.toast.error i { color: var(--bad); }

/* ───────── Flash banners ───────── */
.flash {
    padding: 12px 18px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-family: 'Bahij-Bold';
    font-size: 0.9rem;
    display: flex; align-items: center; gap: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
}
.flash.error { border-color: rgba(248,113,113,0.35); color: var(--bad); background: var(--bad-soft); }
.flash.ok    { border-color: rgba(52,211,153,0.35);  color: var(--good); background: var(--good-soft); }

/* ───────── Modal ───────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 5000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.show { display: flex; animation: fadein 0.2s ease; }

.modal-card {
    background: var(--bg-3);
    border: 1px solid var(--border-2);
    border-radius: var(--r-lg);
    padding: 28px;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 30px 80px rgba(0,0,0,0.6), 0 0 60px rgba(0,164,219,0.08);
    position: relative;
    animation: zoom 0.22s ease;
}
.modal-close {
    position: absolute;
    top: 16px;
    inset-inline-end: 16px;
    width: 36px; height: 36px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 11px;
    cursor: pointer;
    display: grid; place-items: center;
    transition: var(--t);
}
.modal-close:hover { color: var(--bad); border-color: rgba(248,113,113,0.30); background: var(--bad-soft); }

.modal-card.sm { max-width: 400px; padding: 30px 26px; text-align: center; }
.modal-card.sm .icon {
    width: 56px; height: 56px;
    border-radius: 16px;
    background: var(--bad-soft);
    color: var(--bad);
    display: grid; place-items: center;
    margin: 0 auto 14px;
    font-size: 1.4rem;
    border: 1px solid rgba(248,113,113,0.30);
}
.modal-card.sm p {
    font-family: 'Bahij-Bold';
    font-size: 1rem;
    color: var(--text-strong);
    margin-bottom: 22px;
    line-height: 1.55;
}
.confirm-actions { display: flex; gap: 10px; }

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 18px;
    padding-inline-end: 44px;
}
.modal-head h2 {
    font-family: 'Bahij-Bold';
    color: var(--text-strong);
    font-size: 1.4rem;
    letter-spacing: -0.3px;
    line-height: 1.2;
    margin-bottom: 4px;
}
.modal-head p { font-size: 0.82rem; color: var(--text-muted); }
.modal-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    background: var(--surface);
    padding: 16px;
    border-radius: 16px;
    border: 1px solid var(--border);
    margin-bottom: 14px;
}
.modal-stat { text-align: center; }
.modal-stat-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 4px; letter-spacing: 0.5px; text-transform: uppercase; }
.modal-stat-value {
    font-family: 'Bahij-Bold';
    font-size: 1.1rem;
    color: var(--text-strong);
}
.modal-stat-value.good { color: var(--good); }
.modal-stat-value.bad  { color: var(--bad); }
.modal-client-info {
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: none;
}
.modal-pay-form {
    display: flex; gap: 10px; align-items: flex-end;
    margin-bottom: 20px;
}
.modal-pay-form .field { flex: 1; margin-bottom: 0; }
.modal-history-h {
    font-family: 'Bahij-Bold';
    font-size: 0.74rem;
    color: var(--text-faint);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 12px;
}
.modal-payments {
    display: flex; flex-direction: column; gap: 8px;
}
.modal-payment-row {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 12px 16px;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.88rem;
}

/* ───────── Login page ───────── */
.auth-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    position: relative;
    z-index: 1;
}
.auth-stack {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
}
.auth-bg-grid {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
    background-size: 56px 56px;
    mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 70%);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--r-xl);
    padding: 38px 32px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 30px 80px rgba(0,0,0,0.5), 0 0 60px rgba(0,164,219,0.10), 0 0 80px rgba(255,22,109,0.06);
    animation: zoom 0.4s ease;
    position: relative;
    z-index: 1;
}
.auth-brand {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 28px;
}
.auth-brand .brand-mark { width: 44px; height: 44px; }
.auth-brand .brand-mark img { width: 30px; height: 30px; }
.auth-brand strong { font-family: 'Bahij-Bold'; font-size: 1.2rem; color: var(--text-strong); }
.auth-brand span { font-size: 0.72rem; color: var(--text-muted); display: block; letter-spacing: 0.5px; text-transform: uppercase; }
.auth-card h1 {
    font-family: 'Bahij-Bold';
    font-size: 1.5rem;
    color: var(--text-strong);
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}
.auth-card .sub {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 22px;
}
.auth-langs {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}
.auth-langs .lang-pill {
    flex: 0 0 auto;
    padding: 6px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
}

/* ───────── Error page ───────── */
.error-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    position: relative;
    z-index: 1;
}
.error-card {
    text-align: center;
    max-width: 480px;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--r-xl);
    padding: 44px 32px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}
.error-card .code {
    font-family: 'Bahij-Bold';
    font-size: 5rem;
    line-height: 1;
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    letter-spacing: -2px;
}
.error-card h1 {
    font-family: 'Bahij-Bold';
    color: var(--text-strong);
    font-size: 1.3rem;
    margin-bottom: 8px;
}
.error-card p { color: var(--text-muted); margin-bottom: 22px; }
.error-card .btn { width: auto; padding: 12px 22px; display: inline-flex; }
.error-debug, .error-trace {
    text-align: start;
    background: var(--bad-soft);
    padding: 14px;
    border-radius: 12px;
    margin-top: 22px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.78rem;
    color: var(--bad);
    white-space: pre-wrap;
    word-break: break-word;
    border: 1px solid rgba(248,113,113,0.25);
}
.error-trace {
    color: var(--text-muted);
    background: var(--surface);
    border-color: var(--border);
    font-size: 0.7rem;
}

/* ───────── Sidebar scrim (mobile) ───────── */
.scrim {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 80;
    opacity: 0;
    pointer-events: none;
    transition: opacity 240ms cubic-bezier(.4,0,.2,1);
}
.scrim.show { opacity: 1; pointer-events: all; }

body.no-scroll { overflow: hidden; }

/* ───────── Responsive ───────── */
@media (max-width: 980px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        height: 100dvh;
        width: min(300px, 84vw);
        padding: 18px 14px 18px;
        border-radius: 0;
        z-index: 90;
        transition: transform 280ms cubic-bezier(.4,0,.2,1), visibility 280ms;
        visibility: hidden;
        box-shadow: -20px 0 60px rgba(0,0,0,0.55);
        background: #1c1f2a;
    }
    .sidebar .user-pill,
    .sidebar .lang-switch,
    .sidebar .icon-btn { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.10); }
    .sidebar .nav-link.active { background: rgba(255,255,255,0.07); }
    /* RTL: drawer lives on the right edge, slides out to the right */
    html[dir="rtl"] .sidebar {
        right: 0; left: auto;
        transform: translateX(110%);
        border-inline-start: 1px solid var(--border-2);
        border-inline-end: none;
    }
    /* LTR: drawer lives on the left edge, slides out to the left */
    html[dir="ltr"] .sidebar {
        left: 0; right: auto;
        transform: translateX(-110%);
        border-inline-end: 1px solid var(--border-2);
        border-inline-start: none;
        box-shadow: 20px 0 60px rgba(0,0,0,0.55);
    }
    .sidebar.open {
        transform: translateX(0) !important;
        visibility: visible;
    }
    .sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
    .sidebar-top .brand { flex: 1; border-bottom: none; padding-bottom: 0; }
    .sidebar-close { display: grid !important; }
    .sidebar .nav { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); }

    .topbar { display: flex; }
    /* Edge-to-edge topbar: zero side padding on main, restore gutter on inner children */
    .main { padding: 0 0 80px; }
    .main > :not(.topbar) { margin-inline-start: 16px; margin-inline-end: 16px; }

    .stats, .stats.stats-2 { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px; }
    .row-2 { grid-template-columns: 1fr; gap: 14px; margin-bottom: 18px; }

    .page-head { align-items: stretch; gap: 12px; margin-bottom: 18px; }
    .page-head h1 { font-size: 1.45rem; }
    .clock-card { width: 100%; align-items: flex-start; padding: 12px 14px; }

    .stat { padding: 18px; }
    .stat .value { font-size: 1.55rem; }

    .card { padding: 18px; }
    .chart-card { padding: 18px 14px 8px; margin-bottom: 18px; }
    .chart-host { height: 200px; }

    .modal-stats { grid-template-columns: 1fr; gap: 8px; }
    .modal-head { padding-inline-end: 50px; }
    .modal-head h2 { font-size: 1.2rem; }

    /* Row items: keep amount + button on one line, allow title to truncate */
    .row-top { gap: 10px; }
    .row-top h4 { font-size: 0.95rem; min-width: 0; }
    .record-amount { font-size: 1rem; }
}

@media (max-width: 560px) {
    .topbar { padding: 10px 14px; }
    .main > :not(.topbar) { margin-inline-start: 14px; margin-inline-end: 14px; }

    .stats, .stats.stats-2 { grid-template-columns: 1fr; }
    .field-row { grid-template-columns: 1fr; gap: 0; }

    .page-head h1 { font-size: 1.3rem; }
    .stat { padding: 16px; }
    .stat .label { margin-bottom: 10px; font-size: 0.7rem; }
    .stat .value { font-size: 1.4rem; }
    .stat::after { width: 80px; height: 80px; opacity: 0.4; }

    .card { padding: 16px; border-radius: 18px; }
    .chart-card { padding: 16px 10px 4px; border-radius: 18px; }
    .chart-host { height: 180px; }

    .modal { padding: 12px; }
    .modal-card { padding: 20px 18px; max-height: calc(100vh - 24px); }
    .modal-pay-form { flex-direction: column; align-items: stretch; gap: 10px; }
    .modal-pay-form .btn.w-auto { width: 100%; padding: 12px; }

    .auth-card { padding: 26px 20px; }
    .auth-card h1 { font-size: 1.3rem; }
    .auth-shell { padding: 14px 14px 28px; align-items: flex-start; padding-top: 6vh; }

    /* Row items: stack amount under title when very narrow */
    .row-top { flex-wrap: wrap; }
    .row-top h4 { flex: 1 1 100%; }

    .error-card { padding: 32px 22px; }
    .error-card .code { font-size: 3.8rem; }
}

@media (max-width: 380px) {
    .stat .value { font-size: 1.25rem; letter-spacing: -0.3px; }
    .page-head h1 { font-size: 1.2rem; }
    .brand-name strong { font-size: 0.95rem; }
    .brand-name span { font-size: 0.65rem; }
}

/* ───────── Anims ───────── */
@keyframes rise    { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadein  { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoom    { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
