/* ============================================================
   Dashboard ข้อมูลพื้นฐานสถานศึกษาเพื่อการนิเทศ — สพป.สุโขทัย เขต 1
   ============================================================ */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e2e8f0;
  --text: #0f172a;
  --text-dim: #64748b;
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-soft: #dbeafe;
  --accent: #0d9488;

  --green: #16a34a;
  --green-soft: #dcfce7;
  --yellow: #eab308;
  --yellow-soft: #fef9c3;
  --orange: #ea580c;
  --orange-soft: #ffedd5;
  --red: #dc2626;
  --red-soft: #fee2e2;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.10);
  --font: "Sarabun", "Leelawadee UI", "Tahoma", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.3; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(120deg, #1e3a8a, #1e40af 55%, #0e7490);
  color: #fff;
  box-shadow: var(--shadow-lg);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; cursor: pointer; }
.brand-logo {
  width: 48px; height: 48px; border-radius: 12px; flex: none;
  background: rgba(255,255,255,.15); display: grid; place-items: center; font-size: 26px;
  border: 1px solid rgba(255,255,255,.25);
}
.brand-text h1 { font-size: 18px; letter-spacing: .1px; }
.brand-text p { margin: 2px 0 0; font-size: 12.5px; opacity: .82; }
.mainnav { display: flex; gap: 6px; flex-wrap: wrap; }
.mainnav a {
  padding: 8px 15px; border-radius: 999px; font-size: 14px; font-weight: 600;
  color: rgba(255,255,255,.85); transition: .15s; white-space: nowrap;
}
.mainnav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.mainnav a.active { background: #fff; color: var(--primary); }

/* ---------- Layout ---------- */
.container { max-width: 1240px; margin: 0 auto; padding: 26px 20px 60px; }
.footer {
  text-align: center; color: var(--text-dim); font-size: 12.5px;
  padding: 24px 20px 40px; border-top: 1px solid var(--line); margin-top: 20px;
}
.loading { text-align: center; color: var(--text-dim); padding: 80px 0; font-size: 16px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head h2 { font-size: 24px; }
.page-head .sub { color: var(--text-dim); font-size: 14px; margin-top: 4px; }
.breadcrumb { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.breadcrumb a { color: var(--primary-light); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: 14px;
  transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--primary-light); color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1b3a9e; color: #fff; }
.btn-danger { color: var(--red); border-color: var(--red-soft); background: var(--red-soft); }
.btn-danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px 22px; }
.section {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 20px; overflow: hidden;
}
.section-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.section-head .num {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: var(--primary); color: #fff; display: grid; place-items: center;
  font-size: 14px; font-weight: 700;
}
.section-head h3 { font-size: 16.5px; }
.section-head .spacer { flex: 1; }
.section-body { padding: 18px 20px; }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--primary); }
.stat.green::before { background: var(--green); }
.stat.yellow::before { background: var(--yellow); }
.stat.orange::before { background: var(--orange); }
.stat.red::before { background: var(--red); }
.stat.teal::before { background: var(--accent); }
.stat .label { color: var(--text-dim); font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 30px; font-weight: 800; margin-top: 6px; letter-spacing: -.5px; }
.stat .unit { font-size: 14px; font-weight: 600; color: var(--text-dim); margin-left: 3px; }
.stat .foot { font-size: 12.5px; color: var(--text-dim); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
@media (max-width: 900px){ .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { background: var(--surface-2); font-weight: 700; color: var(--text-dim); font-size: 13px; white-space: nowrap; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.center, .tbl th.center { text-align: center; }
.tbl-wrap { overflow-x: auto; }
.tbl .row-link { cursor: pointer; }

/* ---------- Badges / status ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }
.badge.green { background: var(--green-soft); color: #15803d; }
.badge.yellow { background: var(--yellow-soft); color: #a16207; }
.badge.orange { background: var(--orange-soft); color: #c2410c; }
.badge.red { background: var(--red-soft); color: #b91c1c; }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.gray { background: #f1f5f9; color: var(--text-dim); }

.dot { width: 13px; height: 13px; border-radius: 50%; display: inline-block; vertical-align: -1px; }
.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.orange { background: var(--orange); }
.dot.red { background: var(--red); }

.trend { font-weight: 800; font-size: 16px; }
.trend.up { color: var(--green); }
.trend.down { color: var(--red); }
.trend.flat { color: var(--text-dim); }

/* ---------- Traffic-light picker ---------- */
.light-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.light-row:last-child { border-bottom: none; }
.light-row .name { flex: 1; font-weight: 600; font-size: 14.5px; }
.lights { display: flex; gap: 6px; }
.lights button {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent;
  background: #e2e8f0; transition: .12s; position: relative; opacity: .35;
}
.lights button.g { background: var(--green); }
.lights button.y { background: var(--yellow); }
.lights button.o { background: var(--orange); }
.lights button.r { background: var(--red); }
.lights button.active { opacity: 1; transform: scale(1.12); box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.lights.readonly button { cursor: default; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px,1fr)); gap: 14px 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 700; color: var(--text-dim); }
.field input, .field select, .field textarea {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--text);
  transition: .15s; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field textarea { resize: vertical; min-height: 74px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 15px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff;
  font-weight: 600; font-size: 14px; transition: .12s; color: var(--text-dim);
}
.chip.sel { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.chip.green.sel { border-color: var(--green); background: var(--green-soft); color: #15803d; }
.chip.yellow.sel { border-color: var(--yellow); background: var(--yellow-soft); color: #a16207; }
.chip.orange.sel { border-color: var(--orange); background: var(--orange-soft); color: #c2410c; }
.chip.red.sel { border-color: var(--red); background: var(--red-soft); color: #b91c1c; }

/* ---------- SWOT ---------- */
.swot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px){ .swot-grid { grid-template-columns: 1fr; } }
.swot-box { border-radius: var(--radius-sm); padding: 14px 16px; border: 1px solid var(--line); }
.swot-box h4 { font-size: 14.5px; margin-bottom: 7px; display: flex; align-items: center; gap: 7px; }
.swot-box p, .swot-box textarea { font-size: 14px; margin: 0; white-space: pre-wrap; }
.swot-box.s { background: var(--green-soft); border-color: #bbf7d0; }
.swot-box.w { background: var(--red-soft); border-color: #fecaca; }
.swot-box.o { background: var(--primary-soft); border-color: #bfdbfe; }
.swot-box.t { background: var(--orange-soft); border-color: #fed7aa; }
.swot-box textarea { background: rgba(255,255,255,.6); border: 1px solid rgba(0,0,0,.08); border-radius: 8px; width: 100%; min-height: 90px; }

/* ---------- Progress bar ---------- */
.pbar { height: 9px; border-radius: 6px; background: var(--line); overflow: hidden; min-width: 90px; }
.pbar > span { display: block; height: 100%; border-radius: 6px; background: var(--primary-light); }
.pbar.green > span { background: var(--green); }
.pbar.orange > span { background: var(--orange); }
.pbar.red > span { background: var(--red); }

/* ---------- School / student list cards ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px,1fr)); gap: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 0; overflow: hidden; cursor: pointer; transition: .15s;
  border-left: 6px solid var(--primary);
}
.tile:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.tile.green { border-left-color: var(--green); }
.tile.yellow { border-left-color: var(--yellow); }
.tile.orange { border-left-color: var(--orange); }
.tile.red { border-left-color: var(--red); }
.tile-head { padding: 15px 18px 10px; }
.tile-head h3 { font-size: 16px; }
.tile-head .meta { color: var(--text-dim); font-size: 13px; margin-top: 3px; }
.tile-body { padding: 0 18px 15px; display: flex; gap: 18px; flex-wrap: wrap; }
.tile-body .kv { font-size: 13px; }
.tile-body .kv b { display: block; font-size: 18px; font-weight: 800; }
.tile-foot { padding: 10px 18px; border-top: 1px solid var(--line); background: var(--surface-2); display: flex; justify-content: space-between; align-items: center; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.toolbar input[type="search"], .toolbar select {
  padding: 9px 13px; border: 1px solid var(--line); border-radius: 10px; background: #fff; min-width: 180px;
}
.toolbar .spacer { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: #fff; padding: 12px 22px; border-radius: 12px; font-weight: 600;
  box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transition: .25s; z-index: 200; font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #b91c1c; }
.toast.ok { background: #15803d; }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 150;
  display: grid; place-items: center; padding: 20px; backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
}
.modal.wide { max-width: 900px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 20px 22px; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; background: var(--surface); }
.x-btn { border: none; background: transparent; font-size: 24px; color: var(--text-dim); line-height: 1; }

.empty { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty .big { font-size: 46px; margin-bottom: 10px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--text-dim); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.help-list { line-height: 1.9; }
.help-list li { margin-bottom: 4px; }
.kbd { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; font-family: ui-monospace, monospace; font-size: 13px; }

.mini-note { font-size: 12.5px; color: var(--text-dim); }
hr.sep { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---------- Charts ---------- */
.chart { display: block; }
.barsh { display: flex; flex-direction: column; gap: 12px; }
.barsh-row { display: grid; grid-template-columns: 200px 1fr 66px; align-items: center; gap: 12px; }
.barsh-label { font-size: 14px; font-weight: 600; }
.barsh-track { background: var(--line); border-radius: 7px; height: 15px; overflow: hidden; }
.barsh-fill { height: 100%; border-radius: 7px; transition: width .5s ease; min-width: 2px; }
.barsh-val { font-size: 14px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 640px){ .barsh-row { grid-template-columns: 120px 1fr 52px; } .barsh-label { font-size: 12.5px; } }
.donut-legend { display: flex; flex-direction: column; gap: 8px; min-width: 190px; }
.donut-legend > div { display: grid; grid-template-columns: 16px 1fr auto; align-items: center; gap: 9px; font-size: 13.5px; }
.donut-legend .sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }
.donut-legend .lb { color: var(--text); }
.donut-legend b { font-weight: 800; font-size: 15px; }
.spark { vertical-align: middle; }

/* ---------- Print ---------- */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; font-size: 12px; }
  .container { max-width: none; padding: 0; }
  .section, .card, .stat, .tile { box-shadow: none; break-inside: avoid; }
  .section { border: 1px solid #cbd5e1; margin-bottom: 12px; }
  .page-head h2 { font-size: 20px; }
  a { color: inherit; }
}

@media (max-width: 640px){
  .brand-text h1 { font-size: 15px; }
  .stat .value { font-size: 25px; }
  .topbar-inner { padding: 10px 14px; }
  .container { padding: 18px 14px 50px; }
}
