/* CEO Dashboard — theme tokens on :root only (dark overrides swap them globally) */
:root {
  color-scheme: light;
  --page: #f4f6f9;
  --surface-1: #ffffff;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --muted: #8a919c;
  --grid: #e5e8ee;
  --baseline: #c6ccd6;
  --border: rgba(17, 24, 39, 0.09);
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.05), 0 4px 14px rgba(17, 24, 39, 0.05);
  --accent: #2563eb;
  --series-1: #2a78d6;   /* validated categorical slot 1 (blue) */
  --series-2: #008300;   /* slot 2 (green) */
  --div-pos: #2a78d6;    /* diverging + pole */
  --div-neg: #e34948;    /* diverging − pole */
  --good: #0ca30c;
  --critical: #d03b3b;
  --delta-good: #006300;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0f1420;
    --surface-1: #1a2130;
    --text-primary: #f3f5f9;
    --text-secondary: #c0c8d4;
    --muted: #8a919c;
    --grid: #2a3243;
    --baseline: #3d4759;
    --border: rgba(255, 255, 255, 0.10);
    --shadow: none;
    --accent: #5b96f0;
    --series-1: #3987e5;
    --div-pos: #3987e5;
    --div-neg: #e66767;
    --delta-good: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f1420;
  --surface-1: #1a2130;
  --text-primary: #f3f5f9;
  --text-secondary: #c0c8d4;
  --muted: #8a919c;
  --grid: #2a3243;
  --baseline: #3d4759;
  --border: rgba(255, 255, 255, 0.10);
  --shadow: none;
  --accent: #5b96f0;
  --series-1: #3987e5;
  --div-pos: #3987e5;
  --div-neg: #e66767;
  --delta-good: #0ca30c;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.85rem 1.4rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface-1); z-index: 5; flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 1.02rem; margin: 0; letter-spacing: 0.01em; }
.actions { display: flex; gap: 0.5rem; align-items: center; }
button {
  font: inherit; font-size: 0.85rem; padding: 0.4rem 0.85rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-primary); cursor: pointer;
}
.actions button { background: var(--accent); border-color: var(--accent); color: #fff; }
.actions button:hover { filter: brightness(1.08); }
.actions button:disabled { opacity: 0.55; cursor: wait; }
#refresh-status { color: var(--text-secondary); font-size: 0.85rem; }

.filterbar {
  display: flex; align-items: center; gap: 0.7rem;
  margin: 1.9rem 0 0.9rem; padding: 0.65rem 0.9rem;
  flex-wrap: wrap; position: sticky; top: 52px; z-index: 4;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
}
.filterbar-label { font-size: 0.8rem; color: var(--text-secondary); }
.datefield { font-size: 0.78rem; color: var(--text-secondary); display: inline-flex; align-items: center; gap: 0.3rem; }
.datefield input[type="date"] {
  font: inherit; font-size: 0.8rem; padding: 0.28rem 0.45rem; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary);
  color-scheme: light dark;
}

.navlink {
  font-size: 0.85rem; padding: 0.4rem 0.85rem; border-radius: 8px;
  border: 1px solid var(--accent); background: transparent; color: var(--accent);
  text-decoration: none; white-space: nowrap;
}
.navlink:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* CFO receivables: wrap long client names to max 2 lines (no horizontal scroll) */
#sec-receivables td:first-child { white-space: normal; }
#sec-receivables .clientname {
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
  max-width: 380px; line-height: 1.25;
}

.collapse-toggle {
  display: flex; align-items: center; gap: 0.4rem; width: 100%; text-align: left;
  font: inherit; font-size: 0.85rem; font-weight: 600; color: var(--text-primary);
  background: transparent; border: 0; padding: 0.2rem 0 0.6rem; cursor: pointer;
}
.collapse-toggle .chevron { display: inline-block; transition: transform 0.2s ease; }
.collapse-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.collapsible { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.25s ease; }
.collapsible.open { grid-template-rows: 1fr; }
.collapsible-inner { overflow: hidden; min-height: 0; }

main { max-width: 1120px; margin: 0 auto; padding: 1.2rem 1.4rem 3rem; }
section { margin: 1.9rem 0; }
.sec-head { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 0.7rem; }
h2 { font-size: 1.02rem; margin: 0; }
h3 { font-size: 0.82rem; margin: 0 0 0.6rem; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

/* story-group: visually binds two or more sections into one narrative chapter
   (e.g. Ταμείο = ρευστότητα + απαιτήσεις) so they read as one place, not two */
.story-group { margin: 1.9rem 0; }
.story-group > .story-title { font-size: 1.02rem; margin: 0 0 0.9rem; }
.story-group section { margin: 0 0 1.3rem; padding-left: 0.95rem; border-left: 2px solid var(--border); }
.story-group section:last-child { margin-bottom: 0; }

.badge {
  font-size: 0.72rem; padding: 0.15rem 0.6rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-secondary);
  background: var(--surface-1);
}
.badge.fresh::before { content: "● "; color: var(--good); }
.badge.stale::before { content: "▲ "; color: var(--critical); }
.badge.missing::before { content: "○ "; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 0.8rem; margin-bottom: 0.8rem; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.8rem 1rem; box-shadow: var(--shadow);
}
.tile .label { font-size: 0.74rem; color: var(--text-secondary); }
.tile .value { font-size: 1.5rem; font-weight: 700; margin-top: 0.2rem; letter-spacing: -0.01em; }
.tile .delta { font-size: 0.75rem; margin-top: 0.2rem; color: var(--text-secondary); }
.tile .delta.up { color: var(--delta-good); }
.tile .delta.down { color: var(--critical); }
.tile.stub .value { color: var(--muted); font-size: 0.95rem; font-weight: 500; }

/* target tiles */
.tile .target-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.35rem; }
.tile .edit-target { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 0.2rem; font-size: 0.85rem; }
.tile .edit-target:hover { color: var(--accent); }
.progress { height: 6px; border-radius: 999px; background: var(--grid); margin-top: 0.45rem; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--series-1); }
.progress.ok > span { background: var(--good); }
.progress.warn > span { background: var(--critical); }
.tile.breach { border-color: var(--critical); }
.tile .breach-note { font-size: 0.72rem; color: var(--critical); margin-top: 0.3rem; }

.panel {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.9rem 1rem; margin-bottom: 0.8rem;
  overflow-x: auto; box-shadow: var(--shadow);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.row2 .panel { margin-bottom: 0.8rem; min-width: 0; }
@media (max-width: 880px) { .row2 { grid-template-columns: 1fr; } }
.subhead { margin-top: 0.4rem; }
.note { color: var(--muted); font-size: 0.75rem; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface-1); }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--text-secondary); }
.seg button.active { background: var(--accent); color: #fff; }

table { border-collapse: collapse; width: 100%; font-size: 0.8rem; }
th, td { padding: 0.4rem 0.6rem; text-align: right; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-secondary); font-weight: 600; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
tr.sum-row td { font-weight: 700; color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
td.pos { color: var(--delta-good); font-weight: 600; }
td.neg { color: var(--critical); font-weight: 600; }
.wd-line { display: flex; justify-content: space-between; font-size: 0.82rem; padding: 0.3rem 0; border-bottom: 1px solid var(--grid); }
.wd-line b { font-variant-numeric: tabular-nums; }
.wd-highlight { font-size: 0.95rem; }
.pace-sym { margin-right: 0.25rem; }

.funnel-row { display: flex; align-items: center; gap: 0.7rem; margin: 0.35rem 0; }
.funnel-row .name { flex: 0 0 210px; font-size: 0.8rem; }
.funnel-row .bar { height: 15px; border-radius: 4px; background: var(--series-1); min-width: 3px; }
.funnel-row .bar.count { background: var(--baseline); }
.funnel-row .num { font-size: 0.8rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

svg text { fill: var(--muted); font-size: 10px; font-family: inherit; }
svg .gridline { stroke: var(--grid); stroke-width: 1; }
svg .baseline { stroke: var(--baseline); stroke-width: 1; }

footer { text-align: center; padding: 1rem; color: var(--muted); font-size: 0.75rem; }
footer a { color: var(--text-secondary); }

/* hover tooltip */
#tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--text-primary); color: var(--page);
  font-size: 0.75rem; line-height: 1.35;
  padding: 0.35rem 0.55rem; border-radius: 7px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  max-width: 260px; white-space: nowrap;
}
#tip b { font-variant-numeric: tabular-nums; }
svg .hit { fill: transparent; cursor: crosshair; }
svg .hit:hover + circle, svg rect:hover { filter: brightness(1.15); }

/* --- Auth / admin (login form, admin CRUD) -------------------------------- */
.auth-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.auth-form { width: 100%; max-width: 320px; }
.auth-form h1 { font-size: 1.05rem; margin: 0 0 1rem; }
.field { margin-bottom: 0.8rem; display: flex; flex-direction: column; gap: 0.3rem; }
.field label { font-size: 0.78rem; color: var(--text-secondary); }
.field input, .field select {
  font: inherit; padding: 0.5rem 0.6rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-1); color: var(--text-primary);
}
.btn {
  font: inherit; padding: 0.5rem 0.9rem; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: transparent; color: var(--text-primary); border-color: var(--border); }
.error-msg { color: var(--critical); font-size: 0.82rem; margin-bottom: 0.6rem; }
.flash {
  background: color-mix(in srgb, var(--good) 12%, transparent); border: 1px solid var(--good);
  border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.85rem; margin-bottom: 0.8rem;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--grid); vertical-align: top; }
.checkbox-row { display: flex; gap: 0.9rem; flex-wrap: wrap; margin: 0.3rem 0; }
.checkbox-row label { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; }
