/* ==========================================================================
   School ERP — one stylesheet.
   Palette (brand tokens are the five given colours; the -ink variants are the
   darkened versions used wherever text or a filled control needs real contrast
   against white).
   ========================================================================== */

:root {
  /* brand */
  --coral:        #ed6a5a;
  --lemon:        #f4f1bb;
  --ash:          #9bc1bc;
  --linen:        #e6ebe0;
  --cyan:         #36c9c6;

  /* accessible variants */
  --coral-ink:    #c9432f;
  --coral-deep:   #a8331f;
  --cyan-ink:     #10807e;
  --cyan-deep:    #0b5f5e;
  --ash-ink:      #4c6a66;

  /* neutrals, biased toward the ash/cyan family so nothing looks bolted on */
  --ink:          #16302e;
  --ink-2:        #3b524f;
  --muted:        #6b807d;
  --line:         #cfdad4;
  --line-soft:    #e2e9e1;
  --surface:      #ffffff;
  --surface-2:    #f6f8f4;
  --bg:           var(--linen);

  /* sidebar */
  --nav-a:        #163f3d;
  --nav-b:        #0e2b2a;
  --nav-text:     rgba(255, 255, 255, .74);
  --nav-strong:   #ffffff;

  --radius:       14px;
  --radius-sm:    9px;
  --shadow:       0 1px 2px rgba(22, 48, 46, .06), 0 3px 10px rgba(22, 48, 46, .05);
  --shadow-md:    0 4px 18px rgba(22, 48, 46, .12);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Niramit', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--cyan-ink); }
a:hover { color: var(--cyan-deep); }

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

/* ── App frame ─────────────────────────────────────────────────────────── */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: linear-gradient(170deg, var(--nav-a), var(--nav-b));
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 18px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.brand__mark {
  width: 38px; height: 38px;
  flex: 0 0 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--coral), var(--lemon));
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px; color: #5a2018;
}
.brand__name { color: var(--nav-strong); font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand__sub { font-size: 11.5px; color: var(--nav-text); }

.nav { padding: 12px 10px 24px; flex: 1; }
.nav__group {
  padding: 14px 10px 6px;
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .42);
}
.nav__item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--nav-text);
  text-decoration: none;
  font-size: 14px;
}
.nav__item:hover { background: rgba(255, 255, 255, .08); color: var(--nav-strong); }
.nav__item.is-on {
  background: linear-gradient(100deg, var(--cyan), #2aa8a6);
  color: #04302f;
  font-weight: 700;
}
.nav__item.is-on .nav__ico { opacity: 1; }
.nav__ico { width: 18px; text-align: center; opacity: .85; font-style: normal; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 26px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar__title { font-size: 18px; }
.topbar__sub { font-size: 12.5px; color: var(--muted); }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.who { display: flex; align-items: center; gap: 9px; }
.who__av {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--ash); color: #123734;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12.5px;
}
.who__name { font-size: 13.5px; font-weight: 600; line-height: 1.2; }
.who__role { font-size: 11.5px; color: var(--muted); }

.content { padding: 22px 26px 60px; max-width: 1400px; width: 100%; }

/* ── Cards ─────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.card__head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.card__title { font-size: 15px; }
.card__tools { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card__body { padding: 16px 18px 18px; }
.card__body--flush { padding: 0; }

.grid { display: grid; gap: 20px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* ── Stat tiles ────────────────────────────────────────────────────────── */

.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 20px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ash);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat--coral { border-left-color: var(--coral); }
.stat--cyan  { border-left-color: var(--cyan); }
.stat--lemon { border-left-color: #ddd76a; }
.stat__label { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stat__value { font-size: 27px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat__hint { font-size: 12px; color: var(--muted); }

/* ── Tables ────────────────────────────────────────────────────────────── */

.tablewrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th, table.tbl td { padding: 10px 14px; text-align: left; vertical-align: middle; }
table.tbl thead th {
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; white-space: nowrap;
}
table.tbl tbody tr { border-bottom: 1px solid var(--line-soft); }
table.tbl tbody tr:last-child { border-bottom: 0; }
table.tbl tbody tr:hover { background: #fbfcfa; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl .muted { color: var(--muted); font-size: 12.5px; }
table.tbl tfoot td { padding: 11px 14px; border-top: 2px solid var(--line); font-weight: 700; }

/* ── Badges & chips ────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.badge--good    { background: #d9f2ea; color: #0d6b52; }
.badge--warn    { background: var(--lemon); color: #7a6a12; }
.badge--bad     { background: #fbdfd9; color: var(--coral-deep); }
.badge--info    { background: #d6f2f1; color: var(--cyan-deep); }
.badge--neutral { background: var(--linen); color: var(--ink-2); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2); text-decoration: none;
}
.chip.is-on { background: var(--cyan); border-color: var(--cyan); color: #06302f; font-weight: 700; }
.chip:hover { border-color: var(--cyan); }

/* ── Buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--cyan); color: var(--cyan-deep); }
.btn:focus-visible { outline: 2px solid var(--cyan-ink); outline-offset: 2px; }
.btn--primary { background: var(--coral-ink); border-color: var(--coral-ink); color: #fff; }
.btn--primary:hover { background: var(--coral-deep); border-color: var(--coral-deep); color: #fff; }
.btn--cyan { background: var(--cyan-ink); border-color: var(--cyan-ink); color: #fff; }
.btn--cyan:hover { background: var(--cyan-deep); border-color: var(--cyan-deep); color: #fff; }
.btn--sm { padding: 5px 11px; font-size: 12.5px; }
.btn--danger { color: var(--coral-deep); }
.btn--danger:hover { border-color: var(--coral-ink); color: var(--coral-deep); }

/* ── Forms ─────────────────────────────────────────────────────────────── */

.form { display: grid; gap: 14px; }
.form__row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: 12.5px; font-weight: 700; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=time], input[type=number], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  font: inherit; font-size: 14px;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(54, 201, 198, .18);
}
textarea { min-height: 84px; resize: vertical; }
.form__actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.filters {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  margin-bottom: 4px;
}
.filters .field { min-width: 150px; }

/* ── Alerts & empties ──────────────────────────────────────────────────── */

.alert {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
  border-left: 4px solid var(--ash);
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.alert--ok   { border-left-color: var(--cyan); background: #eefbfa; }
.alert--warn { border-left-color: #ddd76a; background: #fdfcef; }
.alert--err  { border-left-color: var(--coral); background: #fdf0ee; }

.empty { color: var(--muted); font-style: italic; margin: 6px 0; }

/* ── Calendar ──────────────────────────────────────────────────────────── */

.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal th {
  padding: 8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); border-bottom: 1px solid var(--line);
}
.cal td {
  border: 1px solid var(--line-soft);
  vertical-align: top;
  height: 104px;
  padding: 6px 7px;
}
.cal td.is-out { background: var(--surface-2); }
.cal td.is-today { background: #eefbfa; box-shadow: inset 0 0 0 2px var(--cyan); }
.cal td.is-holiday { background: #fdf0ee; }
.cal__day { font-size: 12.5px; font-weight: 700; color: var(--ink-2); }
.cal__ev {
  display: block;
  margin-top: 4px; padding: 2px 6px;
  border-radius: 5px;
  font-size: 11.5px;
  line-height: 1.35;
  text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal__ev--holiday { background: #fbdfd9; color: var(--coral-deep); }
.cal__ev--exam    { background: var(--lemon); color: #7a6a12; }
.cal__ev--event   { background: #d6f2f1; color: var(--cyan-deep); }
.cal__ev--term    { background: var(--ash); color: #123734; }

/* ── Timetable grid ────────────────────────────────────────────────────── */

.tt { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 13px; }
.tt th, .tt td { border: 1px solid var(--line-soft); padding: 6px; vertical-align: top; }
.tt thead th {
  background: var(--surface-2); font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted);
}
.tt tbody th {
  background: var(--surface-2); text-align: left; width: 108px;
  font-size: 12px; font-weight: 700; color: var(--ink-2);
}
.tt tbody th small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.tt td { height: 62px; }
.tt td.is-break { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 6px, #eef1ea 6px, #eef1ea 12px); }
.tt__cell { display: block; text-decoration: none; color: inherit; height: 100%; }
.tt__sub { display: block; font-weight: 700; font-size: 12.5px; color: var(--ink); line-height: 1.35; }
.tt__meta { display: block; font-size: 11px; color: var(--muted); line-height: 1.35; }
.tt__free {
  display: grid; place-items: center; height: 100%;
  color: #b7c4bf; font-size: 17px; text-decoration: none;
}
.tt__free:hover { background: #f2f8f6; color: var(--cyan-ink); }

/* ── Register (student attendance) ─────────────────────────────────────── */

.reg { width: 100%; border-collapse: collapse; font-size: 14px; }
.reg th, .reg td { padding: 8px 12px; border-bottom: 1px solid var(--line-soft); }
.reg thead th { background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; color: var(--muted); }
.reg__opts { display: flex; gap: 5px; flex-wrap: wrap; }
.reg__opt { position: relative; }
.reg__opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.reg__opt span {
  display: inline-block; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 12px; font-weight: 600;
  color: var(--ink-2); background: #fff; cursor: pointer;
}
.reg__opt input:checked + span { border-color: transparent; }
.reg__opt input:focus-visible + span { outline: 2px solid var(--cyan-ink); outline-offset: 2px; }
.reg__opt.is-present input:checked + span { background: #d9f2ea; color: #0d6b52; }
.reg__opt.is-late    input:checked + span { background: var(--lemon); color: #7a6a12; }
.reg__opt.is-sick    input:checked + span { background: #d6f2f1; color: var(--cyan-deep); }
.reg__opt.is-absent  input:checked + span { background: #fbdfd9; color: var(--coral-deep); }

/* ── Login ─────────────────────────────────────────────────────────────── */

.login {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 30px 18px;
  background:
    radial-gradient(1100px 460px at 15% -10%, rgba(54, 201, 198, .30), transparent 60%),
    radial-gradient(900px 420px at 95% 8%, rgba(237, 106, 90, .22), transparent 62%),
    var(--linen);
}
.login__box {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 28px 26px 24px;
}
.login__brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login__title { font-size: 20px; }
.login__sub { color: var(--muted); font-size: 13px; }
.login__demo {
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-soft);
  font-size: 12.5px; color: var(--muted);
}
.login__demo code { background: var(--linen); padding: 1px 6px; border-radius: 5px; color: var(--ink); }

/* ── Print ─────────────────────────────────────────────────────────────── */

@media print {
  .sidebar, .topbar, .card__tools, .btn, .filters { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  body { background: #fff; }
}

/* ── Small screens ─────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; height: auto; position: static;
    flex-direction: row; align-items: center; overflow-x: auto;
  }
  .brand { border-bottom: 0; border-right: 1px solid rgba(255,255,255,.1); padding: 12px 14px; }
  .brand__sub { display: none; }
  .nav { display: flex; gap: 4px; padding: 8px; flex: 1; }
  .nav__group { display: none; }
  .nav__item { margin-bottom: 0; white-space: nowrap; }
  .content { padding: 16px 14px 50px; }
  .topbar { padding: 12px 14px; }
  .topbar__sub { display: none; }
}
