/* Pipeline: clean, neutral, light and dark, follows the device setting. */
:root {
  --bg: #f6f6f8;
  --panel: #ffffff;
  --panel-2: #fafafb;
  --ink: #15161a;
  --muted: #6b6f7b;
  --line: #e5e6eb;
  --accent: #3a2e8c;
  --brand-navy: #3a2e8c;
  --brand-sky: #05b3ec;
  --accent-ink: #ffffff;
  --accent-soft: #ececfb;
  --hot: #d9572f;
  --warm: #c98a1f;
  --cold: #3f78c9;
  --ok: #23905f;
  --lost: #8b8f9a;
  --danger: #c2412d;
  --shadow: 0 1px 2px rgba(16, 17, 20, 0.04), 0 6px 20px rgba(16, 17, 20, 0.05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0e11;
    --panel: #15161b;
    --panel-2: #1a1b21;
    --ink: #eceef3;
    --muted: #8d93a0;
    --line: #26282f;
    --accent: #9d97f5;
    --brand-navy: #c9c4ff;
    --brand-sky: #38c8f5;
    --accent-ink: #0d0e11;
    --accent-soft: #23243a;
    --hot: #ef7b5a;
    --warm: #e2aa52;
    --cold: #7aa8e6;
    --ok: #4cc08a;
    --lost: #7d8290;
    --danger: #f08a77;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0e11;
  --panel: #15161b;
  --panel-2: #1a1b21;
  --ink: #eceef3;
  --muted: #8d93a0;
  --line: #26282f;
  --accent: #9d97f5;
  --brand-navy: #c9c4ff;
  --brand-sky: #38c8f5;
  --accent-ink: #0d0e11;
  --accent-soft: #23243a;
  --hot: #ef7b5a;
  --warm: #e2aa52;
  --cold: #7aa8e6;
  --ok: #4cc08a;
  --lost: #7d8290;
  --danger: #f08a77;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.err { color: var(--danger); font-size: 13px; }
.ok-text { color: var(--ok); }
.center { text-align: center; padding: 48px 16px; }
.loading { padding: 48px 16px; color: var(--muted); text-align: center; }
.num { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* Buttons and fields */
.btn {
  font: inherit; font-size: 13.5px; font-weight: 500;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--panel-2); border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--panel-2); }
.btn.block { display: block; width: 100%; text-align: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; padding: 2px 4px; }
.link:hover { color: var(--ink); }
.link.danger:hover { color: var(--danger); }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input, select {
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%;
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.stack { display: grid; gap: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline input { flex: 1 1 160px; width: auto; }
.inline select { width: auto; flex: 0 0 auto; }

/* Login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 28px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin-top: 14px; }
.auth-card .stack { margin-top: 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 15px;
}

/* Shell */
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.side {
  border-right: 1px solid var(--line); background: var(--panel);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-logo {
  width: 44px; height: 44px; flex: 0 0 44px; object-fit: contain; border-radius: 10px;
  background: #fff; padding: 3px; border: 1px solid var(--line);
}
.brand-text { display: grid; line-height: 1.2; }
.brand-text strong { font-size: 14px; font-weight: 700; color: var(--brand-navy); }
.brand-text span { font-size: 12px; color: var(--muted); }
.auth-card .brand-logo { width: 96px; height: 96px; padding: 8px; margin: 0 auto; display: block; }
.auth-card h1 { text-align: center; }
.auth-card .muted { text-align: center; }
.side nav { display: grid; gap: 2px; }
.nav {
  font: inherit; text-align: left; background: none; border: 0; color: var(--muted);
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font-weight: 500;
}
.nav:hover { color: var(--ink); background: var(--panel-2); }
.nav.on { color: var(--ink); background: var(--accent-soft); }
.me { margin-top: auto; display: flex; gap: 10px; align-items: center; padding: 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12px; flex: 0 0 auto;
}
.main { padding: 28px clamp(16px, 2.2vw, 40px) 60px; min-width: 0; max-width: none; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; align-items: end; margin-bottom: 22px; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; }
.filters label { min-width: 150px; }

/* Cards and stats */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat .muted { font-size: 12.5px; margin-bottom: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.narrow { max-width: 420px; }
.empty { color: var(--muted); text-align: center; }

/* Counselor panels */
.counselor { padding: 0; margin-bottom: 14px; overflow: hidden; }
.counselor > summary {
  list-style: none; cursor: pointer; padding: 16px 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
}
.counselor > summary::-webkit-details-marker { display: none; }
.counselor > summary h2 { margin: 0 0 2px; }
.counselor > summary::after { content: "+"; color: var(--muted); font-size: 18px; }
.counselor[open] > summary::after { content: "-"; }
.days { border-top: 1px solid var(--line); }
.day { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.day:last-child { border-bottom: 0; }
.day-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.day-head strong { font-weight: 600; }
.add { display: flex; gap: 8px; flex: 1 1 260px; max-width: 420px; }
.add input { width: auto; flex: 1; }
.empty-row { padding: 4px 0; }

/* Student rows */
.student { border-top: 1px dashed var(--line); padding: 12px 0; display: grid; gap: 10px; }
.student-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.student-head strong { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn {
  font: inherit; font-size: 12.5px; font-weight: 500; color: var(--muted);
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; cursor: pointer;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.on { color: #fff; border-color: transparent; }
.seg-btn.hot.on { background: var(--hot); }
.seg-btn.warm.on { background: var(--warm); }
.seg-btn.cold.on { background: var(--cold); }
.seg-btn.registered.on { background: var(--ok); }
.seg-btn.lost.on { background: var(--lost); }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.field { min-width: 0; }

/* Lists and pills */
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.users li { display: block; }
.user-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.user-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.user-actions form { display: flex; gap: 6px; }
.user-actions input { width: 150px; }
.pill { font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.off { background: color-mix(in srgb, var(--lost) 18%, transparent); color: var(--muted); }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: all 0.2s; max-width: calc(100vw - 32px);
  box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--danger); color: #fff; }

/* Theme switch, overdue alerts, add-student form */
.theme-switch { display: flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tbtn { flex: 1; font: inherit; font-size: 12.5px; font-weight: 500; color: var(--muted); background: transparent; border: 0; border-radius: 7px; padding: 5px 4px; cursor: pointer; }
.tbtn:hover { color: var(--ink); }
.tbtn.on { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.overdue-card { border-color: color-mix(in srgb, var(--hot) 45%, var(--line)); margin-bottom: 20px; }
.overdue-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.overdue-head h2 { color: var(--hot); margin: 0; }
.od-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.od-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.od-actions input[type="date"] { width: auto; }
.pill.overdue { background: color-mix(in srgb, var(--hot) 16%, transparent); color: var(--hot); margin-left: 8px; }
.add-student { display: grid; grid-template-columns: 1fr minmax(170px, auto) auto; gap: 10px; align-items: end; padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.date-field { display: grid; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.date-field input { width: auto; }
@media (max-width: 620px) { .add-student { grid-template-columns: 1fr; } }

/* Dashboard bars, mini table, report checkboxes */
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 44px; gap: 10px; align-items: center; padding: 6px 0; font-size: 13px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.bar-track { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: 999px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
table.mini th, table.mini td { padding: 8px 6px; }
.num-c { text-align: right; font-variant-numeric: tabular-nums; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); cursor: pointer; }
.check input { width: auto; }
.check .flag { flex: 0 0 auto; }
.report .filters { margin-bottom: 4px; }

/* Target countries, colleges and courses */
.targets { display: grid; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.target-row { display: grid; grid-template-columns: 26px minmax(120px, 1.1fr) minmax(120px, 1.4fr) minmax(120px, 1.4fr) auto; gap: 8px; align-items: center; }
.target-row input, .target-row select { width: 100%; }
.target-row .link { white-space: nowrap; }
.flag { display: block; border-radius: 3px; box-shadow: 0 0 0 1px var(--line); object-fit: cover; }
.flag-slot { display: inline-flex; width: 22px; height: 16px; }
.target-add { border-top: 1px dashed var(--line); padding-top: 8px; }
@media (max-width: 720px) {
  .target-row { grid-template-columns: 26px 1fr; }
  .target-row select, .target-row input { grid-column: 2; }
}

/* Small screens: menu becomes a top bar */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: static; height: auto; flex-direction: row; flex-wrap: wrap;
    align-items: center; padding: 12px 14px; gap: 10px;
  }
  .side nav { display: flex; gap: 4px; flex-wrap: wrap; }
  .me { margin: 0 0 0 auto; border: 0; padding: 0; }
  .me > div:last-child { display: none; }
  .side > .btn.ghost { order: 3; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .row2 { grid-template-columns: 1fr; }
  .add { max-width: none; }
  .user-actions input { width: 100%; }
}

/* Keep the Add student button always visible at every width */
.add-student { grid-template-columns: minmax(0, 1fr) auto auto; }
.add-student input[name="name"] { min-width: 0; width: 100%; }
.add-student .btn { white-space: nowrap; }
.add-student .date-field input { width: auto; }
@media (max-width: 620px) { .add-student { grid-template-columns: 1fr; } }

/* Country / college / course rows: Add and Remove buttons always visible */
.target-row { flex-wrap: wrap; }
.target-row select, .target-row input { flex: 1 1 150px; min-width: 0; }
.target-row .btn, .target-row .link { flex: 0 0 auto; white-space: nowrap; }
.target-add { background: var(--panel-2); border-radius: 10px; padding: 8px; }
