/* Scientific Gate — Cash Flow Budgeting System
   Palette taken from the corporate mark: deep corporate blue, the cyan of
   the logo swirl, and the charcoal of the wordmark.
   Written with CSS logical properties so the Arabic (RTL) layout is a
   genuine mirror rather than a patch. */

:root {
    --brand-deep: #1B5584;   /* headers, primary actions */
    --brand: #2E7FB8;        /* links, accents */
    --brand-bright: #4FC0F0; /* highlights, active marker */
    --brand-pale: #9CD8E4;
    --brand-wash: #eaf4fb;
    --charcoal: #231F20;     /* the wordmark */

    --ink: #17232e;
    --muted: #5d6b78;
    --line: #dbe2e8;
    --bg: #f2f5f8;
    --card: #ffffff;

    --in: #0a7d4f;
    --in-bg: #e8f5ee;
    --out: #b4342b;
    --out-bg: #fdecea;
    --warn: #8a5a00;
    --warn-bg: #fdf3e0;

    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 36, 54, .06), 0 2px 8px rgba(16, 36, 54, .05);
    --nav-h: 42px;
}

* { box-sizing: border-box; }

html[dir="rtl"] body { font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Cairo", sans-serif; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}

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

/* ---------- header & sticky navigation ---------- */
.topbar {
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: 8px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.topbar .logo { height: 40px; width: auto; display: block; }
.topbar .brand { line-height: 1.25; }
.topbar .brand b { display: block; font-size: 14px; color: var(--charcoal); }
.topbar .brand small { color: var(--muted); font-size: 11.5px; }
.topbar .spacer { flex: 1; }
.topbar .chip {
    background: var(--brand-wash); color: var(--brand-deep);
    padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 500;
    border: 1px solid #cfe4f2;
}
.topbar .chip.alert { background: var(--out-bg); color: var(--out); border-color: #f0b6b1; }

nav.main {
    position: sticky;
    top: 0;
    z-index: 60;
    background: var(--brand-deep);
    padding: 0 10px;
    display: flex; flex-wrap: wrap; gap: 2px;
    box-shadow: 0 2px 6px rgba(16, 36, 54, .18);
}
nav.main a, nav.main .dd > span {
    color: #ffffff; padding: 12px 15px; font-size: 14px; font-weight: 600;
    letter-spacing: .2px; display: inline-block; cursor: pointer;
    border-bottom: 3px solid transparent;
}
nav.main a:hover, nav.main .dd:hover > span, nav.main .dd:focus-within > span {
    background: rgba(255, 255, 255, .18); text-decoration: none; color: #fff;
}
nav.main a.on {
    background: var(--bg); color: var(--brand-deep); font-weight: 700;
    border-bottom-color: var(--brand-bright);
}

.dd { position: relative; }
.dd-menu {
    display: none; position: absolute; inset-inline-start: 0; top: 100%;
    background: #fff; min-width: 290px; box-shadow: var(--shadow);
    border: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius);
    z-index: 70; padding: 6px 0;
}
.dd:hover .dd-menu, .dd:focus-within .dd-menu { display: block; }
/* These selectors carry `nav.main` deliberately: without it the white
   `nav.main a` rule wins on specificity and the dropdown entries come out
   white on a white panel — invisible. */
nav.main .dd-menu a, .dd-menu a {
    display: block; color: var(--ink); padding: 8px 15px;
    font-size: 13.5px; font-weight: 500; letter-spacing: 0;
    border-bottom: none; background: transparent;
}
nav.main .dd-menu a:hover, .dd-menu a:hover {
    background: var(--brand-wash); text-decoration: none; color: var(--brand-deep);
}
nav.main .dd-menu a.on, .dd-menu a.on {
    background: var(--brand-wash); color: var(--brand-deep); font-weight: 700;
}
.dd-menu .hdr {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .7px;
    color: var(--muted); padding: 9px 15px 3px; font-weight: 600;
}
.dd-menu .sep { height: 1px; background: var(--line); margin: 6px 0; }

main { padding: 18px; max-width: 1560px; margin: 0 auto; }

h1 { font-size: 21px; margin: 0 0 4px; color: var(--charcoal); }
h2 { font-size: 16px; margin: 22px 0 8px; color: var(--brand-deep); }
h3 { font-size: 13.5px; margin: 14px 0 6px; color: var(--ink); }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 13px; }

/* ---------- cards & grid ---------- */
.card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 14px 16px; margin-bottom: 16px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.split { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 14px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

/* ---------- available cash: the traffic light ---------- */
.health {
    display: flex; flex-wrap: wrap; gap: 26px; align-items: center;
    border-radius: var(--radius); padding: 18px 22px; margin-bottom: 14px;
    border: 2px solid; box-shadow: var(--shadow);
}
.health .figure { min-width: 260px; }
.health .lbl {
    font-size: 11px; text-transform: uppercase; letter-spacing: .8px; opacity: .85;
}
.health .amount {
    font-size: 42px; font-weight: 700; line-height: 1.05; margin-top: 2px;
    font-variant-numeric: tabular-nums;
}
.health .amount .ccy { font-size: 18px; font-weight: 600; }
.health .note { font-size: 12.5px; margin-top: 4px; opacity: .9; }
.health .verdict { flex: 1; min-width: 300px; }
.health .state { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.health table.mini { width: auto; min-width: 300px; font-size: 12.5px; }
.health table.mini td {
    border: none; padding: 2px 0; background: transparent;
}
.health table.mini td.num { text-align: end; padding-inline-start: 26px; font-weight: 600; }

.health.green { background: #e7f6ee; border-color: #7dc9a2; color: #0a5b3a; }
.health.green .amount { color: #0a7d4f; }
.health.amber { background: #fdf3e0; border-color: #e8b455; color: #7a4e00; }
.health.amber .amount { color: #b06a00; }
.health.red { background: #fdecea; border-color: #e08079; color: #8e2019; }
.health.red .amount { color: var(--out); }
.health .neg { color: inherit !important; }
.health.red .neg { color: var(--out) !important; }

/* ---------- the headline cash figure ---------- */
.hero {
    background: linear-gradient(135deg, var(--brand-deep), #24699e 55%, var(--brand) 100%);
    color: #fff; border-radius: var(--radius); padding: 18px 22px;
    box-shadow: var(--shadow); margin-bottom: 16px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 26px;
}
.hero .lbl {
    font-size: 11px; text-transform: uppercase; letter-spacing: .8px; opacity: .85;
}
.hero .big {
    font-size: 40px; font-weight: 700; line-height: 1.1; margin-top: 2px;
    font-variant-numeric: tabular-nums;
}
.hero .big.neg { color: #ffb3ac; }
.hero .split-ccy { font-size: 13px; opacity: .9; margin-top: 4px; }
.hero .side { border-inline-start: 1px solid rgba(255, 255, 255, .28); padding-inline-start: 22px; }
.hero .side .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hero .side .v.neg { color: #ffb3ac; }
.hero .grow { flex: 1; }

.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.kpi .val { font-size: 21px; font-weight: 600; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.in .val { color: var(--in); }
.kpi.out .val { color: var(--out); }
.kpi .val.neg, .kpi.bad .val { color: var(--out); }
.kpi.bad { border-color: #f0b6b1; background: var(--out-bg); }
.kpi.warn { border-color: #e8cf9a; background: var(--warn-bg); }
.kpi.ok { border-color: #b6ddc6; background: var(--in-bg); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th {
    background: #eaeff4; font-size: 11px; text-transform: uppercase;
    letter-spacing: .5px; color: #3d4c58; font-weight: 600; white-space: nowrap;
}
th.grp {
    background: var(--brand-deep); color: #fff; text-align: center;
    border-inline-end: 2px solid #fff;
}
th.grp.usd { background: #2a6f9e; }
th.grp.eqv { background: var(--charcoal); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: #f7fafc; }
tr.total td { font-weight: 700; background: #eaeff4; border-top: 2px solid var(--brand-deep); }
tr.subtotal td { font-weight: 600; background: #f2f6f9; border-top: 1px solid var(--line); }
tr.now td { background: var(--brand-wash); box-shadow: inset 0 0 0 1px #cfe4f2; }

/* Balances table leads the dashboard. */
.card.balances { border-color: #cfe4f2; }
.card.balances h2 { margin-top: 0; }
tr.past td { color: var(--muted); background: #fafbfc; }
.scroll { overflow-x: auto; }
.tight td, .tight th { padding: 5px 8px; }
td.sep, th.sep { border-inline-start: 2px solid var(--line); }

/* Negative figures are red everywhere, without exception. */
.neg, td.neg, .num.neg { color: var(--out) !important; font-weight: 600; }
.pos { color: var(--in); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; unicode-bidi: isolate; }
.right { text-align: end; }
.center { text-align: center; }
.b { font-weight: 700; }

/* ---------- forms ---------- */
label { display: block; font-size: 12px; color: #3c4a56; margin-bottom: 3px; font-weight: 500; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=email], input[type=file], select, textarea {
    width: 100%; padding: 7px 9px; border: 1px solid #c3cdd6; border-radius: 6px;
    font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-pale); border-color: var(--brand); }
textarea { min-height: 62px; resize: vertical; }
.field { margin-bottom: 12px; }
.field .err { color: var(--out); font-size: 12px; margin-top: 3px; }
.field.bad input, .field.bad select { border-color: var(--out); }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 14px; }
legend { font-size: 12px; font-weight: 600; color: var(--brand-deep); padding: 0 6px; }

.btn {
    display: inline-block; padding: 7px 14px; border-radius: 6px; border: 1px solid transparent;
    background: var(--brand-deep); color: #fff; font: inherit; font-weight: 500; cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: #14456c; text-decoration: none; color: #fff; }
.btn.sec { background: #fff; color: var(--brand-deep); border-color: #bfcdd9; }
.btn.sec:hover { background: var(--brand-wash); color: var(--brand-deep); }
.btn.danger { background: var(--out); }
.btn.danger:hover { background: #93271f; }
.btn.go { background: var(--in); }
.btn.go:hover { background: #08633e; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn[disabled], .btn.off { opacity: .45; pointer-events: none; }
.row-actions { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .field { margin-bottom: 0; }
.toolbar .grow { flex: 1; min-width: 160px; }

/* ---------- badges & flashes ---------- */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.b-draft { background: #eceff2; color: #4d5b67; }
.b-submitted { background: #e4eefb; color: #1d4f8f; }
.b-approved { background: var(--in-bg); color: var(--in); }
.b-rejected { background: var(--out-bg); color: var(--out); }
.b-cancelled { background: #eceff2; color: #8d99a4; }
.b-settled { background: var(--brand-wash); color: var(--brand-deep); }
.b-in { background: var(--in-bg); color: var(--in); }
.b-out { background: var(--out-bg); color: var(--out); }
.b-warn { background: var(--warn-bg); color: var(--warn); }

.flash { padding: 9px 14px; border-radius: var(--radius); margin-bottom: 12px; border: 1px solid; }
.flash.success { background: var(--in-bg); border-color: #b6ddc6; color: #0a5b3a; }
.flash.danger { background: var(--out-bg); border-color: #f0b6b1; color: #8e2019; }
.flash.warning { background: var(--warn-bg); border-color: #e8cf9a; color: var(--warn); }
.flash.info { background: var(--brand-wash); border-color: #cfe4f2; color: var(--brand-deep); }

/* ---------- forecast grid ---------- */
.fc th.wk { min-width: 120px; }
.fc td.short { background: var(--out-bg); color: var(--out); font-weight: 700; }
.fc td.low { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.fc td.ovr { box-shadow: inset 3px 0 0 var(--brand-bright); }
html[dir="rtl"] .fc td.ovr { box-shadow: inset -3px 0 0 var(--brand-bright); }

.bar { height: 8px; background: #e6ebef; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.matrix td, .matrix th { padding: 4px 6px; font-size: 12px; text-align: center; }
.matrix th.rowh, .matrix td.rowh { text-align: start; white-space: nowrap; font-weight: 500; }
.matrix input[type=checkbox] { width: 16px; height: 16px; }
.matrix tr:nth-child(even) td { background: #fafbfc; }

/* ---------- charts ---------- */
.chart { display: block; max-width: 100%; height: auto; }
.chart-card { padding: 12px 14px 6px; }
.spark { vertical-align: middle; }

/* completeness matrix */
.cells td.cell { text-align: center; font-variant-numeric: tabular-nums; }
.cells td.gap { background: var(--out-bg); color: var(--out); font-weight: 700; }
.cells td.has { background: var(--in-bg); color: var(--in); }
.cells td.none { background: #f3f5f7; color: #aab4bd; }

/* tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 14px; }
.tabs a {
    padding: 8px 14px; font-size: 13px; color: var(--ink); font-weight: 500;
    border: 1px solid transparent;
    border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; margin-bottom: -2px;
}
.tabs a.on { background: #fff; color: var(--brand-deep); font-weight: 600; border-color: var(--line); border-bottom: 2px solid #fff; }
.tabs a:hover { text-decoration: none; background: var(--brand-wash); }

footer { color: var(--muted); font-size: 12px; padding: 18px; text-align: center; }

/* ---------- print ---------- */
@page { size: A4 landscape; margin: 12mm; }
@media print {
    .topbar, nav.main, .toolbar, .row-actions, footer, .noprint, .tabs { display: none !important; }
    body { background: #fff; font-size: 11px; }
    main { padding: 0; max-width: none; }
    .card { box-shadow: none; border-color: #ccc; break-inside: avoid; margin-bottom: 10px; }
    .hero { background: #fff !important; color: var(--ink) !important; border: 1px solid #ccc; }
    .hero .big { color: var(--ink); }
    .hero .big.neg, .hero .side .v.neg { color: var(--out) !important; }
    .chart { break-inside: avoid; }
    h1 { font-size: 16px; }
    h2 { font-size: 13px; }
    .print-head { display: block !important; }
    tr, img, svg { break-inside: avoid; }
    thead { display: table-header-group; }
}
.print-head { display: none; border-bottom: 2px solid var(--brand-deep); padding-bottom: 6px; margin-bottom: 10px; }
.print-head img { height: 38px; }

/* ---------- charts on the dashboard ---------- */
.chart-card { padding-bottom: 10px; }
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; width: 100%; height: auto; min-width: 520px; }
html[dir="rtl"] .chart-wrap svg { direction: ltr; }
