/* Intelligent Systems control panel
   One stylesheet for the sign-in page and the panel. Brand colours are the tokens below. */

:root {
  color-scheme: light;

  --brand: #097dd4;
  --brand-dark: #0764ab;
  --brand-soft: #e8f3fc;
  --navy: #0a1f36;
  --navy-2: #0e3a63;

  --ink: #111c2b;
  --muted: #5b6b7f;
  --line: #dde4ec;
  --bg: #f4f7fa;
  --surface: #ffffff;
  --danger: #b42318;
  --danger-bg: #fef3f2;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(10, 31, 54, .06), 0 8px 24px rgba(10, 31, 54, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3, p { margin: 0; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .88em; background: var(--brand-soft); color: var(--brand-dark); padding: 1px 6px; border-radius: 6px; }

:focus-visible { outline: 3px solid rgba(9, 125, 212, .45); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: .95rem;
  padding: 11px 18px; border-radius: 10px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .7; cursor: progress; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); padding: 8px 14px; }
.btn-ghost:hover { background: var(--bg); }
.btn-block { width: 100%; padding: 13px 18px; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--ink); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Sign-in page ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-single { grid-template-columns: 1fr; }

.auth-brand {
  position: relative; overflow: hidden; display: flex; align-items: flex-end;
  padding: clamp(32px, 6vw, 72px); color: #fff;
  background:
    radial-gradient(circle at 18% 12%, rgba(9, 125, 212, .55), transparent 46%),
    radial-gradient(circle at 85% 90%, rgba(86, 184, 230, .28), transparent 40%),
    linear-gradient(155deg, var(--navy), var(--navy-2));
}
.auth-brand::before {
  content: ""; position: absolute; inset: 0; opacity: .5;
  background-image:
    linear-gradient(rgba(255, 255, 255, .06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .06) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent 85%);
          mask-image: linear-gradient(to bottom, #000, transparent 85%);
}
.auth-brand-inner { position: relative; max-width: 460px; }
.eyebrow { font-size: .8rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #9fd4f6; margin-bottom: 14px; }
.auth-brand h2 { font-size: clamp(2rem, 3.6vw, 3rem); line-height: 1.1; font-weight: 750; letter-spacing: -.02em; margin-bottom: 14px; }
.auth-brand p:last-child { color: #c3d6e8; font-size: 1.05rem; }

.auth-form-wrap { display: flex; align-items: center; justify-content: center; padding: 32px 20px; background: var(--surface); }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { display: block; width: 210px; max-width: 70%; height: auto; margin: 0 0 28px -6px; }
.auth-card h1 { font-size: 1.75rem; line-height: 1.2; letter-spacing: -.01em; margin-bottom: 6px; }
.muted { color: var(--muted); }
.auth-card .muted { margin-bottom: 26px; }
.auth-foot { margin-top: 32px; font-size: .82rem; color: var(--muted); }

.field { margin-bottom: 18px; }
.field label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  padding: 12px 14px; border: 1px solid #c4cfdb; border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.field input:hover { border-color: #9fb0c3; }
.field input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(9, 125, 212, .18); }
.field input.input-validation-error { border-color: var(--danger); }
.field-error { display: block; margin-top: 6px; font-size: .85rem; color: var(--danger); }
.field-error:empty { display: none; }

.password { position: relative; }
.password input { padding-right: 48px; }
.reveal { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--muted); border-radius: 8px; cursor: pointer; }
.reveal:hover { background: var(--bg); color: var(--ink); }
.reveal svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.reveal[aria-pressed="true"] { color: var(--brand); }

.alert { display: block; margin-bottom: 18px; padding: 11px 14px; border-radius: 10px; background: var(--danger-bg); color: var(--danger); border: 1px solid #fecdca; font-size: .92rem; font-weight: 500; }
.alert ul { margin: 0; padding: 0; list-style: none; }
.validation-summary-valid { display: none; }

/* ---------- PIN screen: blurs the sign-in page until the PIN is accepted ---------- */
.auth { transition: filter .35s ease, transform .35s ease; }
.auth.locked { filter: blur(14px); transform: scale(1.02); pointer-events: none; user-select: none; }

.pin-backdrop {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(10, 31, 54, .38); transition: opacity .3s ease;
}
.pin-backdrop.closing { opacity: 0; pointer-events: none; }
.pin-dialog {
  width: 100%; max-width: 360px; padding: 32px 28px 28px; text-align: center;
  background: var(--surface); border-radius: 18px; box-shadow: 0 24px 64px rgba(10, 31, 54, .35);
  animation: pinIn .28s ease;
}
.pin-dialog.shake { animation: pinShake .35s ease; }
.pin-icon { display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); margin-bottom: 14px; }
.pin-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pin-dialog h2 { font-size: 1.35rem; margin-bottom: 4px; }
.pin-dialog .muted { margin-bottom: 20px; font-size: .95rem; }
.pin-input {
  width: 100%; text-align: center; font: inherit; font-size: 1.8rem; font-weight: 700; letter-spacing: .5em; text-indent: .5em;
  padding: 12px 14px; border: 1px solid #c4cfdb; border-radius: 12px; color: var(--ink); background: #fff;
}
.pin-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(9, 125, 212, .18); }
.pin-error { min-height: 1.4em; margin: 10px 0 14px; font-size: .88rem; font-weight: 500; color: var(--danger); }
@keyframes pinIn { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes pinShake { 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }

/* ---------- Control panel ---------- */
.panel { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }

.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar-brand { display: block; padding: 4px 8px 20px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.sidebar-brand img { display: block; width: 168px; max-width: 100%; height: auto; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: .95rem; text-decoration: none; }
.nav-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-link:hover { background: var(--bg); color: var(--ink); }
.nav-link.active { background: var(--brand-soft); color: var(--brand-dark); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 14px; padding: 12px 28px; min-height: 68px; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-title { font-size: 1.15rem; font-weight: 700; flex: 1; min-width: 0; }
.menu-btn { display: none; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.user-name { font-weight: 600; font-size: .92rem; }
.signout-form { margin: 0; }

.content { padding: 28px; max-width: 1100px; width: 100%; }
.welcome { margin-bottom: 24px; }
.welcome h2 { font-size: 1.6rem; letter-spacing: -.01em; margin-bottom: 4px; }
.welcome p { color: var(--muted); max-width: 62ch; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card h3 { font-size: 1rem; margin-bottom: 14px; }

.sidebar-scrim { position: fixed; inset: 0; background: rgba(10, 31, 54, .45); z-index: 9; }

/* ---------- Sidebar: projects ---------- */
.nav-label { margin: 18px 12px 6px; font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.nav-logo { width: 24px; height: 24px; border-radius: 6px; object-fit: cover; flex: none; }
.nav-logo-madrsti { object-fit: contain; background: #fff; }

/* ---------- Project pages ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; white-space: nowrap; }
.strong { font-weight: 600; }
.small { font-size: .82rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.page-head { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head-text { flex: 1; min-width: 160px; }
.page-head h2 { font-size: 1.6rem; letter-spacing: -.01em; }
.project-icon { width: 56px; height: 56px; border-radius: 14px; object-fit: cover; box-shadow: var(--shadow); flex: none; }
.project-icon-madrsti { object-fit: contain; background: #fff; border: 1px solid var(--line); }
.project-icon-glyph { display: inline-flex; align-items: center; justify-content: center; background: var(--brand-soft); color: var(--brand); box-shadow: none; }
.project-icon-glyph svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.section { margin-bottom: 20px; padding: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 14px; }
.section-head h3 { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: 10px; }
.count { display: inline-flex; align-items: center; justify-content: center; min-width: 24px; height: 24px; padding: 0 8px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-dark); font-size: .8rem; font-weight: 700; }
.empty { padding: 30px 22px 34px; text-align: center; color: var(--muted); display: grid; gap: 14px; justify-items: center; border-top: 1px solid var(--line); }

.table-wrap { overflow-x: auto; border-top: 1px solid var(--line); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .76rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); padding: 10px 16px; background: #f8fafc; white-space: nowrap; }
.table td { padding: 12px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
.table th.num { text-align: right; }
.table tbody tr:first-child td { border-top: 0; }
.table tbody tr:hover { background: #fafcfe; }
.col-actions { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.school-name-cell { min-width: 140px; }
.row-actions { display: inline-flex; gap: 6px; flex-wrap: nowrap; justify-content: flex-end; }
.note-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.overdue { color: var(--danger); font-weight: 600; }
.overdue .small { margin-left: 6px; font-weight: 700; }

.school-cell { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.school-logo { width: 40px; height: 40px; border-radius: 10px; object-fit: contain; background: #fff; border: 1px solid var(--line); flex: none; }
.school-logo-empty { display: inline-flex; align-items: center; justify-content: center; background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; border-color: transparent; }

/* ---------- Schools: total, holding cards, school cards ---------- */
.stat-card { display: flex; align-items: center; justify-content: space-between; gap: 18px 28px; flex-wrap: wrap; padding: 20px 24px; margin-bottom: 20px; }
.stat-main { display: flex; align-items: baseline; gap: 12px; }
.stat-value { font-size: 2.8rem; font-weight: 750; line-height: 1; letter-spacing: -.02em; color: var(--brand-dark); }
.stat-label { color: var(--muted); font-weight: 600; }
.stat-students .stat-value { color: #17803d; }
.holding-students { font-weight: 600; color: var(--brand-dark); }
.group-label .holding-students { text-transform: none; letter-spacing: 0; }
.stat-breakdown { list-style: none; margin: 0; padding: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.stat-breakdown li { padding: 6px 12px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: .88rem; color: var(--muted); }
.stat-breakdown strong { color: var(--ink); margin-right: 3px; }

.school-groups { display: grid; gap: 18px; padding: 18px 22px 22px; border-top: 1px solid var(--line); }
.school-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
.group-label { margin: 6px 0 -6px; font-size: .78rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }


.holding-card { border: 1px solid #cfe0f0; border-radius: var(--radius); background: linear-gradient(180deg, #f1f8fe, #fff 140px); overflow: hidden; }
.holding-head { width: 100%; display: flex; align-items: center; gap: 14px; padding: 16px 18px; border: 0; background: transparent; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.holding-head:hover { background: rgba(9, 125, 212, .05); }
.holding-icon { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 12px; background: var(--brand); color: #fff; flex: none; }
.holding-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.holding-title { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.holding-title strong { font-size: 1.1rem; }
.chevron { width: 22px; height: 22px; flex: none; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s ease; }
.holding-head[aria-expanded="false"] .chevron { transform: rotate(-90deg); }
.holding-body { padding: 16px 18px 18px; border-top: 1px solid #dbe8f4; }
.holding-body[hidden] { display: none; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.badge-service { background: var(--brand-soft); color: var(--brand-dark); }
.badge-unpaid { background: #f1f4f8; color: #475467; }
.badge-due { background: #fff4e0; color: #b25e09; }
.badge-paid { background: #e6f6ec; color: #17803d; }

.btn-sm { padding: 6px 12px; font-size: .84rem; border-radius: 8px; background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-sm:hover { background: var(--bg); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: #fecdca; }
.btn-success { color: #17803d; }
.btn-success:hover { background: #e6f6ec; border-color: #b7e4c7; }
.btn:disabled { opacity: .6; cursor: progress; }


/* Compact school card: coloured header with a big logo and the student count, then name + services */
.school-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font: inherit; color: inherit; text-align: center; cursor: pointer; box-shadow: 0 1px 2px rgba(10, 31, 54, .05); transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.school-card:hover { transform: translateY(-1px); border-color: #b9d6ee; box-shadow: 0 8px 22px rgba(10, 31, 54, .12); }
.school-card-head { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 8px 8px; background: linear-gradient(135deg, var(--navy-2), var(--brand)); color: #fff; }
.school-logo-xl { display: inline-flex; align-items: center; justify-content: center; width: 60px; height: 60px; padding: 4px; border-radius: 14px; background: #fff; object-fit: contain; box-shadow: 0 4px 10px rgba(0, 0, 0, .22); font-size: 1.4rem; font-weight: 700; }
.school-logo-xl.school-logo-empty { color: var(--brand-dark); }
.student-count { padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .18); font-size: .7rem; font-weight: 600; white-space: nowrap; }
.school-card-body { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 8px 8px 10px; }
.school-card .badge { padding: 1px 8px; font-size: .68rem; }
.school-card-name { font-weight: 700; font-size: .84rem; line-height: 1.25; overflow-wrap: anywhere; }

/* ---------- Details modal (centred) ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 42; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(10, 31, 54, .5); opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility 0s linear .2s; }
.modal-backdrop.open { opacity: 1; visibility: visible; transition: opacity .2s ease; }
.modal { width: 100%; max-width: 500px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--surface); border-radius: 18px; overflow: hidden; box-shadow: 0 24px 64px rgba(10, 31, 54, .35); transform: translateY(12px) scale(.98); transition: transform .2s ease; }
.modal-backdrop.open .modal { transform: none; }
.modal-head { position: relative; display: flex; align-items: center; gap: 16px; padding: 20px 56px 20px 22px; background: linear-gradient(135deg, var(--navy-2), var(--brand)); color: #fff; }
.modal-logo { display: inline-flex; align-items: center; justify-content: center; width: 72px; height: 72px; flex: none; border-radius: 16px; background: #fff; color: var(--brand-dark); font-size: 1.8rem; font-weight: 700; box-shadow: 0 6px 16px rgba(0, 0, 0, .22); overflow: hidden; }
.modal-logo img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.modal-title { min-width: 0; }
.modal-title h2 { margin: 0; font-size: 1.25rem; line-height: 1.25; overflow-wrap: anywhere; }
.modal-title p { margin: 2px 0 0; color: rgba(255, 255, 255, .8); }
.modal-close { position: absolute; top: 14px; right: 14px; background: rgba(255, 255, 255, .15); border-color: transparent; color: #fff; }
.modal-close:hover { background: rgba(255, 255, 255, .28); }
.modal-body { padding: 8px 22px; overflow-y: auto; }
.detail-list { margin: 0; }
.detail-list > div { display: flex; justify-content: space-between; gap: 18px; padding: 12px 0; border-top: 1px solid var(--line); }
.detail-list > div:first-child { border-top: 0; }
.detail-list dt { color: var(--muted); font-size: .9rem; flex: none; }
.detail-list dd { margin: 0; font-weight: 600; font-size: .92rem; text-align: right; overflow-wrap: anywhere; }
.detail-list .detail-note { flex-direction: column; gap: 6px; }
.detail-list .detail-note dd { text-align: left; font-weight: 400; white-space: pre-wrap; color: var(--ink); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); }
.btn-danger-solid { background: var(--danger-bg); color: var(--danger); border-color: #fecdca; }
.btn-danger-solid:hover { background: #fee4e2; }
/* ---------- Right-hand drawer ---------- */
.drawer-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(10, 31, 54, .45); opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility 0s linear .25s; }
.drawer-scrim.open { opacity: 1; visibility: visible; transition: opacity .25s ease; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41; width: min(480px, 100%);
  display: flex; flex-direction: column; background: var(--surface); box-shadow: -12px 0 40px rgba(10, 31, 54, .22);
  transform: translateX(100%); visibility: hidden; transition: transform .28s ease, visibility 0s linear .28s;
}
.drawer.open { transform: none; visibility: visible; transition: transform .28s ease; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 1.2rem; }
.drawer-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.drawer-scroll { flex: 1; overflow-y: auto; padding: 22px 24px 8px; }
.drawer-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--line); background: var(--surface); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field select, .field textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff; padding: 12px 14px;
  border: 1px solid #c4cfdb; border-radius: 10px; transition: border-color .15s, box-shadow .15s;
}
.field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(9, 125, 212, .18); }
.field textarea { resize: vertical; min-height: 84px; }
.field input[type="file"] { padding: 9px 12px; font-size: .9rem; background: #fff; }
.field input[type="file"]::file-selector-button { margin-right: 12px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font: inherit; font-size: .85rem; cursor: pointer; }
.field-hint { display: block; margin-top: 6px; font-size: .82rem; color: var(--muted); }
.field-hint[hidden] { display: none; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }
.alert[hidden] { display: none; }
body.no-scroll { overflow: hidden; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; max-width: min(92vw, 460px); padding: 12px 18px; border-radius: 10px; background: var(--navy); color: #fff; font-size: .92rem; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }

/* ---------- Control panel home: Madrsti highlights ---------- */
.highlights-section { margin-bottom: 24px; }
.highlights-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.highlights-head h3 { margin: 0; font-size: 1.05rem; }
.highlights { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
/* Each tile sets --tone (strong colour) and --tint (soft background) */
.highlight { --tone: var(--brand-dark); --tint: var(--brand-soft); display: grid; gap: 4px; padding: 16px 18px; color: inherit; text-decoration: none;
  background: var(--tint); border-color: transparent; border-top: 4px solid var(--tone); }
a.highlight:hover { filter: brightness(.98); }
.highlight-schools { --tone: #6941c6; --tint: #f4f0fe; }
.highlight-revenue { --tone: #0764ab; --tint: #e8f3fc; }
.highlight-good { --tone: #17803d; --tint: #e6f6ec; }
.highlight-bad { --tone: #b42318; --tint: #fef0ee; }
.highlight-label { color: var(--tone); font-size: .8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.highlight-value { color: var(--tone); font-size: 1.7rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.15; overflow-wrap: anywhere; }
.highlight-sub { color: var(--muted); font-size: .8rem; }

.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.pie-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.pie { width: 150px; height: 150px; flex: none; }
.pie-empty { fill: #eef2f6; }
.pie-slice { fill: none; stroke-width: 16; }
.pie-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; flex: 1 1 160px; min-width: 0; }
.pie-legend li { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.legend-label { color: var(--muted); }
.legend-value { margin-left: auto; font-weight: 650; text-align: right; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.pie-slice.pie-paid { stroke: #17803d; }     .swatch.pie-paid { background: #17803d; }
.pie-slice.pie-due { stroke: #e08a1e; }      .swatch.pie-due { background: #e08a1e; }
.pie-slice.pie-unpaid { stroke: #98a2b3; }   .swatch.pie-unpaid { background: #98a2b3; }
.pie-slice.pie-revenue { stroke: #097dd4; }  .swatch.pie-revenue { background: #097dd4; }
.pie-slice.pie-expenses { stroke: #d92d20; } .swatch.pie-expenses { background: #d92d20; }

@media (max-width: 1000px) {
  .highlights { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .charts { grid-template-columns: 1fr; }
}

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-form-wrap { align-items: flex-start; padding-top: clamp(32px, 10vh, 80px); }
}

@media (max-width: 860px) {
  .panel { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 10; top: 0; left: 0; width: 260px; transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 20px 16px; }
  .user-name { display: none; }
  .section-head { padding: 16px; }
  .school-groups { padding: 14px 14px 18px; }
  .holding-head, .holding-body { padding-left: 14px; padding-right: 14px; }
  .stat-card { padding: 18px; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .drawer-head, .drawer-scroll, .drawer-foot { padding-left: 18px; padding-right: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
/* ---------- Madrsti: schools beside payments / expenses ---------- */
.content-wide { max-width: 1600px; }
.split { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 20px; align-items: start; }
.split-main, .split-side { min-width: 0; }
.split-side { display: grid; gap: 20px; }
.split .section { margin-bottom: 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 22px 10px; }
.toolbar select, .toolbar input { font: inherit; font-size: .86rem; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); min-width: 0; }
.toolbar .tool-search { flex: 1 1 170px; }
.list-summary { margin: 0; padding: 0 22px 12px; }

.pay-groups { border-top: 1px solid var(--line); }
.pay-group { border-bottom: 1px solid var(--line); }
.pay-group:last-child { border-bottom: 0; }
.pay-group[hidden] { display: none; }
.pay-group-head { width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px 22px; border: 0; background: #f8fafc; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.pay-group-head:hover { background: #f1f6fb; }
.pay-group-head[aria-expanded="false"] .chevron { transform: rotate(-90deg); }
.pay-group-head .chevron { width: 18px; height: 18px; }
.pay-group-name { font-weight: 700; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pay-group-meta { color: var(--muted); white-space: nowrap; }
.pay-group-meta strong { color: var(--ink); }
.pay-group-body[hidden] { display: none; }
.pay-group-body .table-wrap { border-top: 1px solid var(--line); }
.badge-overdue { background: #fef0ee; color: #b42318; }
.badge[hidden] { display: none; }

.table-compact th, .table-compact td { padding: 9px 12px; }
.table-compact th:first-child, .table-compact td:first-child { padding-left: 22px; }
.table-compact th:last-child, .table-compact td:last-child { padding-right: 22px; }
.table-compact tr[hidden] { display: none; }
.expense-cell { display: flex; flex-direction: column; gap: 1px; min-width: 130px; }
.split-side > .section > .table-wrap { border-top: 1px solid var(--line); }
.empty[hidden] { display: none; }

/* ---------- Home: what is coming up and what is due ---------- */
.agenda-section { margin-top: 26px; }
.agenda-section > h3 { margin-bottom: 4px; }
.agenda-section > .muted { margin: 0 0 12px; }
.agenda { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.agenda-card { padding: 0; overflow: hidden; border-top: 4px solid var(--brand); }
.agenda-due .agenda-card, .agenda-card.agenda-bad { border-top-color: #d92d20; }
.agenda-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 14px 18px 10px; }
.agenda-head h4 { margin: 0; font-size: .98rem; }
.agenda-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.agenda-list { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; border-top: 1px solid var(--line); }
.agenda-list li { display: flex; align-items: center; gap: 10px; padding: 9px 18px; border-top: 1px solid var(--line); font-size: .9rem; }
.agenda-list li:first-child { border-top: 0; }
.agenda-date { flex: none; width: 82px; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .84rem; }
.agenda-date.overdue { color: var(--danger); font-weight: 600; }
.agenda-what { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.agenda-what span:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agenda-amount { flex: none; font-weight: 650; font-variant-numeric: tabular-nums; }
.agenda-empty { padding: 18px; color: var(--muted); font-size: .9rem; border-top: 1px solid var(--line); }

@media (max-width: 1180px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 700px) {
  .agenda { grid-template-columns: 1fr; }
  .toolbar, .list-summary, .pay-group-head { padding-left: 16px; padding-right: 16px; }
}

/* Each school's payment group gets its own header colour (tone = accent bar, tint = background) */
.pay-group { --tone: #0764ab; --tint: #e8f3fc; }
.pg-tone-0 { --tone: #0764ab; --tint: #e8f3fc; }
.pg-tone-1 { --tone: #6941c6; --tint: #f1ecfd; }
.pg-tone-2 { --tone: #17803d; --tint: #e6f6ec; }
.pg-tone-3 { --tone: #b25e09; --tint: #fff1dc; }
.pg-tone-4 { --tone: #0e7490; --tint: #e0f4f8; }
.pg-tone-5 { --tone: #be185d; --tint: #fde8f1; }
.pg-tone-6 { --tone: #4d5bd6; --tint: #e9ebfd; }
.pg-tone-7 { --tone: #4d7c0f; --tint: #eef6dc; }
.pay-group-head { background: var(--tint); border-left: 5px solid var(--tone); padding-left: 17px; }
.pay-group-head:hover { background: var(--tint); filter: brightness(.97); }
.pay-group-name, .pay-group-head .chevron { color: var(--tone); stroke: var(--tone); }
.pay-group-name { stroke: none; }
@media (max-width: 700px) { .pay-group-head { padding-left: 11px; } }

/* ---------- Weshop and the home overview ---------- */
.overview-divider { height: 1px; margin: 34px 0 26px; background: var(--line); }
.shop-site { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .7rem; }

/* ---------- Domains ---------- */
.domain-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.domain-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 22px; border-top: 1px solid var(--line); }
.domain-item:first-child { border-top: 0; }
.domain-main { display: grid; gap: 4px; min-width: 0; }
.domain-name { font-size: 1.02rem; overflow-wrap: anywhere; }
.expiry { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .88rem; overflow-wrap: anywhere; }
.expiry-label { flex: none; width: 52px; color: var(--muted); font-size: .76rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
@media (max-width: 700px) { .domain-item { padding: 12px 16px; flex-direction: column; } }

/* Domain cards: a coloured header (tone comes from the pg-tone-N class), details below, actions at the bottom */
.domain-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; padding: 16px 22px 22px; border-top: 1px solid var(--line); }
.domain-card { display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 1px 2px rgba(10, 31, 54, .05); }
.domain-card-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--tone); color: #fff; }
.domain-card-head svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.domain-card-head .domain-name { font-size: 1rem; overflow-wrap: anywhere; }
.domain-card-body { display: grid; gap: 8px; padding: 14px; flex: 1; background: linear-gradient(180deg, var(--tint), #fff 70%); }
.domain-card-foot { display: flex; justify-content: flex-end; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--line); }
@media (max-width: 700px) { .domain-cards { padding: 14px 16px 18px; } }

/* Domain state: a pill in the card header; inactive domains turn grey */
.domain-card-head .domain-name { flex: 1; min-width: 0; }
.domain-state { flex: none; padding: 2px 10px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: rgba(255, 255, 255, .22); color: #fff; }
.domain-card.domain-inactive { --tone: #667085; --tint: #f2f4f7; }
.domain-card.domain-inactive .domain-card-body { opacity: .85; }

/* ---------- Home: project filter, combined overview ---------- */
.project-filter { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 22px; }
.chip { display: inline-flex; align-items: center; padding: 8px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-weight: 600; font-size: .92rem; text-decoration: none; }
.chip:hover { background: var(--bg); color: var(--ink); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-madrsti.active { background: #6941c6; border-color: #6941c6; }
.chip-weshop.active { background: #0e7490; border-color: #0e7490; }
.chip-domains.active { background: #b25e09; border-color: #b25e09; }

.highlights-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.highlight-madrsti { --tone: #6941c6; --tint: #f4f0fe; }
.highlight-weshop { --tone: #0e7490; --tint: #e0f4f8; }
.highlight-domains { --tone: #b25e09; --tint: #fff1dc; }
.charts-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.charts-3 .pie-wrap { gap: 16px; }
.pie-slice.pie-madrsti { stroke: #6941c6; }  .swatch.pie-madrsti { background: #6941c6; }
.pie-slice.pie-weshop { stroke: #0e7490; }   .swatch.pie-weshop { background: #0e7490; }
.pie-slice.pie-domains { stroke: #e08a1e; }  .swatch.pie-domains { background: #e08a1e; }

.project-tag { display: inline-block; margin-right: 6px; padding: 0 7px; border-radius: 999px; font-size: .68rem; font-weight: 700; color: #fff; background: var(--muted); vertical-align: 1px; }
.project-tag-madrsti { background: #6941c6; }
.project-tag-weshop { background: #0e7490; }
.project-tag-domains { background: #b25e09; }

@media (max-width: 1200px) { .charts-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1000px) { .highlights-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .charts-3 { grid-template-columns: 1fr; } .highlights-6 { grid-template-columns: 1fr; } }

/* ---------- Settings: database backups ---------- */
.backup-body { display: grid; gap: 14px; padding: 0 22px 22px; }
.backup-body > p { margin: 0; max-width: 78ch; }
.backup-group { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.backup-group-head { display: flex; align-items: baseline; gap: 10px; padding: 12px 16px; background: #f8fafc; border-bottom: 1px solid var(--line); }
.backup-list { list-style: none; margin: 0; padding: 0; }
.backup-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.backup-item:first-child { border-top: 0; }
.backup-info { display: grid; gap: 2px; min-width: 0; }
.backup-info code { font-size: .86rem; padding: 1px 6px; border-radius: 6px; background: var(--bg); }
.backup-off .backup-info > strong { color: var(--muted); }
.backup-form { margin: 0; }
.backup-group > .alert { margin: 12px 16px 0; }
@media (max-width: 700px) { .backup-body { padding: 0 16px 18px; } .backup-item { flex-direction: column; align-items: flex-start; } }

/* ---------- Backup progress: bar and timeline ---------- */
.backup-modal { max-width: 560px; }
.progress { height: 10px; border-radius: 999px; background: #e9eef4; overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--brand), #3fb6ff); transition: width .35s ease; }
.progress-fill.done { background: #17803d; }
.progress-fill.failed { background: #d92d20; }
.progress-label { display: flex; align-items: baseline; gap: 8px; margin: 8px 0 14px; }

.timeline { list-style: none; margin: 0; padding: 0; max-height: min(46vh, 360px); overflow-y: auto; }
.timeline li { position: relative; display: grid; grid-template-columns: 22px 1fr; gap: 10px; padding: 0 0 14px; }
.timeline li::before { content: ""; position: absolute; left: 10px; top: 22px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child { padding-bottom: 2px; }
.timeline li:last-child::before { display: none; }
.tl-dot { position: relative; z-index: 1; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #c5ced9; background: var(--surface); display: inline-flex; align-items: center; justify-content: center; font-size: .72rem; font-weight: 800; line-height: 1; color: #fff; }
.tl-text { display: grid; gap: 1px; min-width: 0; }
.tl-title { font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
.tl-detail { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.timeline li.pending .tl-title { color: var(--muted); font-weight: 500; }
.timeline li.running .tl-dot { border-color: var(--brand); border-top-color: transparent; animation: tl-spin .8s linear infinite; }
.timeline li.done .tl-dot { border-color: #17803d; background: #17803d; }
.timeline li.done .tl-dot::after { content: "\2713"; }
.timeline li.failed .tl-dot { border-color: #d92d20; background: #d92d20; }
.timeline li.failed .tl-dot::after { content: "!"; }
.timeline li.failed .tl-detail { color: #b42318; }
.timeline li.skipped .tl-dot { border-color: #c5ced9; background: #c5ced9; }
.timeline li.skipped .tl-dot::after { content: "\2013"; }
@keyframes tl-spin { to { transform: rotate(360deg); } }

/* ---------- Settings: each database as a card with a coloured header (colour = project) ---------- */
.backup-section { display: grid; gap: 10px; }
.backup-heading { margin: 6px 0 0; font-size: .82rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); display: flex; align-items: baseline; gap: 10px; }
.backup-heading .small { text-transform: none; letter-spacing: 0; font-weight: 500; }
.bk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.bk-card { --tone: #0764ab; --tint: #e8f3fc; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 1px 2px rgba(10, 31, 54, .05); }
.bk-tone-app { --tone: #0764ab; --tint: #e8f3fc; }
.bk-tone-madrsti { --tone: #6941c6; --tint: #f4f0fe; }
.bk-tone-weshop { --tone: #0e7490; --tint: #e0f4f8; }
.bk-tone-domains { --tone: #b25e09; --tint: #fff1dc; }
.bk-card.bk-off { --tone: #667085; --tint: #f2f4f7; }
.bk-card-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--tone); color: #fff; }
.bk-card-head svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .92; }
.bk-card-title { flex: 1; min-width: 0; font-size: .98rem; overflow-wrap: anywhere; }
.bk-kind { flex: none; padding: 2px 9px; border-radius: 999px; font-size: .68rem; font-weight: 700; background: rgba(255, 255, 255, .22); }
.bk-card-body { display: grid; gap: 6px; align-content: start; padding: 14px; flex: 1; background: linear-gradient(180deg, var(--tint), #fff 75%); }
.bk-db code { font-size: .86rem; padding: 2px 8px; border-radius: 6px; background: rgba(255, 255, 255, .85); border: 1px solid var(--line); overflow-wrap: anywhere; }
.bk-card-foot { display: flex; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line); }
.bk-card-foot .backup-form { margin: 0; }

/* ---------- Payment groups: header bar holds the expand button and the statement link ---------- */
.pay-group-bar { display: flex; align-items: center; gap: 8px; background: var(--tint); border-left: 5px solid var(--tone); padding-right: 14px; }
.pay-group-bar .pay-group-head { flex: 1; width: auto; min-width: 0; background: transparent; border-left: 0; padding-left: 12px; }
.pay-group-bar .pay-group-head:hover { background: rgba(255, 255, 255, .35); filter: none; }
.pay-group-export { flex: none; text-decoration: none; }
.row-actions a.btn { text-decoration: none; }
@media (max-width: 700px) { .pay-group-bar { padding-right: 10px; } .pay-group-bar .pay-group-head { padding-left: 8px; } }

.agenda-single { grid-template-columns: 1fr; }
