@font-face {
    font-family: "Fraunces";
    src: url("/static/fonts/fraunces-var.woff2") format("woff2");
    font-weight: 300 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: "Public Sans";
    src: url("/static/fonts/publicsans-var.woff2") format("woff2");
    font-weight: 300 800;
    font-style: normal;
    font-display: swap;
}

:root {
    --bg: #0f1115;
    --bg-card: #171a21;
    --bg-raised: #1d212a;
    --border: #262b36;
    --border-soft: #1d212a;
    --text: #e9eaee;
    --text-dim: #8b93a3;
    --text-faint: #565f70;
    --accent: #3ba776;
    --accent-bright: #4bc78e;
    --accent-dim: #1c3a2c;
    --gold: #c9a227;
    --gold-dim: #3a3120;
    --danger: #c0524a;
    --danger-dim: #3a2220;
    --radius: 14px;
    --radius-sm: 9px;
    --font-display: "Fraunces", Georgia, serif;
    --font-body: "Public Sans", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.45;
    position: relative;
}

/* Subtle atmosphere: faint grain + top glow, purely decorative */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(ellipse 120% 60% at 50% -10%, rgba(59, 167, 118, 0.10), transparent 60%),
        radial-gradient(ellipse 90% 50% at 100% 0%, rgba(201, 162, 39, 0.05), transparent 55%);
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.035;
    mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

.wrap {
    position: relative;
    z-index: 1;
    max-width: 640px;
    margin: 0 auto;
    padding:
        calc(var(--safe-top) + 14px)
        calc(var(--safe-right) + 14px)
        calc(var(--safe-bottom) + 84px)
        calc(var(--safe-left) + 14px);
}

@media (min-width: 720px) {
    .wrap { max-width: 860px; padding-left: 24px; padding-right: 24px; }
}

/* ---- Header ---- */
header.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(var(--safe-top) + 14px) 0 12px;
    margin: calc(-1 * var(--safe-top)) -14px 18px;
    padding-left: calc(var(--safe-left) + 14px);
    padding-right: calc(var(--safe-right) + 14px);
    background: rgba(15, 17, 21, 0.86);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    border-bottom: 1px solid var(--border-soft);
}

header.topbar .brand { display: flex; align-items: center; gap: 9px; }

header.topbar .mark {
    width: 26px; height: 26px; border-radius: 8px;
    background: linear-gradient(160deg, var(--accent) 0%, var(--accent-dim) 130%);
    display: flex; align-items: end; justify-content: center; gap: 2px;
    padding: 5px 5px 4px;
    flex-shrink: 0;
}
header.topbar .mark span { width: 3px; background: #eafff4; border-radius: 1px; }
header.topbar .mark span:nth-child(1) { height: 5px; }
header.topbar .mark span:nth-child(2) { height: 9px; }
header.topbar .mark span:nth-child(3) { height: 13px; }

header.topbar h1 {
    font-family: var(--font-display);
    font-optical-sizing: auto;
    font-weight: 600;
    font-size: 1.3rem;
    margin: 0;
    letter-spacing: 0.01em;
}

header.topbar .sub {
    color: var(--text-dim);
    font-size: 0.72rem;
    letter-spacing: 0.03em;
}

/* ---- Buttons & inputs (touch-friendly, min 44px targets) ---- */
button, .btn {
    background: var(--accent);
    color: #06140e;
    border: none;
    border-radius: var(--radius-sm);
    padding: 11px 16px;
    font-weight: 700;
    font-family: var(--font-body);
    cursor: pointer;
    font-size: 0.92rem;
    min-height: 44px;
    transition: transform 0.12s ease, filter 0.12s ease;
}
button:active { transform: scale(0.97); filter: brightness(0.94); }

button.secondary, .btn.secondary {
    background: var(--bg-raised);
    color: var(--text);
    border: 1px solid var(--border);
}

button.danger { background: var(--danger); color: #fff; }
button:disabled { opacity: 0.45; cursor: default; transform: none; }

button.icon-btn {
    min-height: 38px; min-width: 38px;
    padding: 8px 10px;
    background: var(--bg-raised);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

input, select {
    background: #0a0c0f;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 12px 12px;
    font-size: 1rem;
    font-family: var(--font-body);
    min-height: 44px;
    width: 100%;
}
input:focus, select:focus, button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

select#findings-theme-filter {
    width: auto;
    min-height: 38px;
    padding: 6px 10px;
    font-size: 0.8rem;
}

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 14px;
    animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    .card { animation: none; }
}

/* ---- KPI strip: horizontal scroll-snap on mobile, grid on wider screens ---- */
.kpi-scroller {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding: 2px 2px 10px;
    margin: 0 -2px 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.kpi-scroller::-webkit-scrollbar { display: none; }

.kpi {
    scroll-snap-align: start;
    flex: 0 0 auto;
    min-width: 42vw;
    max-width: 220px;
    margin-bottom: 0;
}

@media (min-width: 560px) {
    .kpi-scroller {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        overflow: visible;
    }
    .kpi { min-width: 0; max-width: none; }
}

.kpi.zakat { border-color: var(--gold-dim); }

.kpi .label {
    color: var(--text-dim);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}
.kpi .value {
    font-family: var(--font-display);
    font-optical-sizing: auto;
    font-size: 1.7rem;
    font-weight: 600;
    margin-top: 6px;
    letter-spacing: -0.01em;
}
.kpi .value.small { font-size: 1.25rem; }
.kpi.zakat .value { color: var(--gold); }

/* ---- List rows (replaces tables for mobile) ---- */
.list { display: flex; flex-direction: column; gap: 8px; }

.list-row {
    background: var(--bg-raised);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.list-row .row-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
}

.list-row .row-title {
    font-weight: 600;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-row .row-amount {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.05rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.list-row .row-meta {
    color: var(--text-dim);
    font-size: 0.78rem;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.list-row .row-notes {
    color: var(--text-faint);
    font-size: 0.8rem;
    margin-top: 2px;
}

.list-row .row-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.list-row .row-actions button {
    flex: 1;
    padding: 8px 10px;
    font-size: 0.8rem;
    min-height: 36px;
}

/* Compact table still used for short numeric grids (projections) */
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 9px 4px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--text-dim); font-weight: 600; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-family: var(--font-display); }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    align-items: end;
}

.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.75rem;
    color: var(--text-dim);
    font-weight: 600;
}

.form-grid button { grid-column: 1 / -1; }
@media (min-width: 480px) {
    .form-grid button { grid-column: auto; }
}

.section-title {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0 0 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.note {
    color: var(--text-faint);
    font-size: 0.78rem;
    margin-top: 8px;
    line-height: 1.5;
}

/* ---- Login ---- */
.login-box {
    max-width: 380px;
    margin: 0 auto;
    padding-top: max(18vh, calc(var(--safe-top) + 40px));
    text-align: center;
    position: relative;
    z-index: 1;
}

.login-box .brand-mark {
    width: 52px; height: 52px; border-radius: 16px;
    background: linear-gradient(160deg, var(--accent) 0%, var(--accent-dim) 130%);
    margin: 0 auto 18px;
    display: flex; align-items: end; justify-content: center; gap: 4px;
    padding: 11px 11px 9px;
    box-shadow: 0 8px 30px -8px rgba(59, 167, 118, 0.45);
}
.login-box .brand-mark span { width: 6px; background: #eafff4; border-radius: 2px; }
.login-box .brand-mark span:nth-child(1) { height: 10px; }
.login-box .brand-mark span:nth-child(2) { height: 18px; }
.login-box .brand-mark span:nth-child(3) { height: 26px; }

.login-box .card { text-align: left; }
.login-box h1 {
    font-family: var(--font-display);
    font-size: 1.9rem;
    font-weight: 600;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
}
.login-box .sub { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 24px; }

.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-box label { text-align: left; font-size: 0.78rem; color: var(--text-dim); font-weight: 600; display: block; margin-bottom: 5px; }

.error-msg {
    color: var(--danger);
    font-size: 0.85rem;
    min-height: 1.2em;
}

.hidden { display: none !important; }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 700;
    background: var(--accent-dim);
    color: var(--accent-bright);
    letter-spacing: 0.02em;
}
.badge.gold { background: var(--gold-dim); color: var(--gold); }

/* ---- Bottom tab bar ---- */
nav.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    display: flex;
    justify-content: space-around;
    background: rgba(23, 26, 33, 0.92);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border-top: 1px solid var(--border-soft);
    padding: 8px calc(var(--safe-left)) calc(var(--safe-bottom) + 6px) calc(var(--safe-right));
}

nav.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--text-faint);
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    padding: 4px 2px;
    min-height: 44px;
    justify-content: center;
}
nav.tabbar a svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }
nav.tabbar a.active { color: var(--accent-bright); }

@media (min-width: 720px) {
    nav.tabbar { display: none; }
    .wrap { padding-bottom: 40px; }
}
