/* ============================================================
   Fuji-san Japanese Center — design system
   Quiet, minimal, generous whitespace. Colour carries meaning
   only: navy for structure, crimson for the one main action,
   green/amber/red for payment and attendance state. Nothing else.
   Self-contained: no CDN, no build step, works offline.
   ============================================================ */

:root {
  --navy:        #0f1d36;
  --navy-soft:   #1a2b4c;
  --blue:        #1e40af;
  --blue-bright: #2563eb;
  --crimson:     #dc2626;
  --amber:       #b45309;
  --green:       #15803d;

  --ink:         #17202e;   /* primary text */
  --ink-2:       #5b6676;   /* secondary text */
  --ink-3:       #939daa;   /* tertiary / hints */

  --bg:          #f6f6f4;   /* page — warm off-white, matches the logo field */
  --surface:     #ffffff;
  --surface-2:   #fafafa;
  --line:        #e8e8e5;   /* hairlines */
  --line-2:      #d9dbd8;

  --radius:   12px;
  --radius-s: 9px;
  --shadow:   0 1px 2px rgba(23, 32, 46, .04);
  --ring:     0 0 0 3px rgba(37, 99, 235, .16);
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --jp: "Noto Sans JP", var(--sans);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:lang(ja) { font-family: var(--jp); }

.shell { width: 100%; max-width: 1160px; margin: 0 auto; padding: 0 22px; }

/* ---------- header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .86);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 60px; }

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; min-width: 0; }
.brand-mark { flex: none; display: block; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-text strong { font-size: 14.5px; font-weight: 600; letter-spacing: -.1px; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-tools { display: flex; align-items: center; gap: 10px; }

.lang-switch { display: flex; gap: 1px; }
.lang-btn {
  border: 0; background: transparent; color: var(--ink-3); cursor: pointer;
  font: inherit; font-size: 12.5px; font-weight: 500;
  padding: 5px 8px; border-radius: 7px; line-height: 1; white-space: nowrap;
}
.lang-btn:hover { color: var(--ink); background: var(--surface-2); }
.lang-btn[aria-pressed="true"] { color: var(--navy); font-weight: 600; background: #eef0ee; }
.lang-btn .lab { margin-inline-start: 5px; }

.session-box { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.session-user { display: flex; flex-direction: column; line-height: 1.2; text-align: end; }
.session-user b { font-size: 13px; font-weight: 600; color: var(--ink); }
.session-user span { font-size: 11px; color: var(--ink-3); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.nav-toggle { display: none; }

/* ---------- nav ---------- */
.app-nav { background: transparent; border-bottom: 1px solid var(--line); }
.nav-row { display: flex; gap: 26px; overflow-x: auto; scrollbar-width: none; }
.nav-row::-webkit-scrollbar { display: none; }
.nav-btn {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: 13.5px; font-weight: 500; color: var(--ink-2);
  padding: 11px 0; display: inline-flex; align-items: center; gap: 7px;
  border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px;
}
.nav-btn:hover { color: var(--ink); }
.nav-btn[aria-current="page"] { color: var(--navy); font-weight: 600; border-bottom-color: var(--navy); }

.app-main { flex: 1; padding-top: 32px; padding-bottom: 56px; }

/* ---------- footer ---------- */
.app-footer { border-top: 1px solid var(--line); color: var(--ink-3); font-size: 12px; padding: 20px 0; }
.app-footer .shell { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- typography ---------- */
h1, h2, h3 { margin: 0; line-height: 1.25; color: var(--ink); letter-spacing: -.2px; }
h1 { font-size: 24px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13.5px; font-weight: 600; }
.muted { color: var(--ink-2); }
.tiny { font-size: 12px; }
.jp { font-family: var(--jp); }

.section-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 22px;
}
.section-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section-head .actions select,
.section-head .actions input { width: auto; max-width: 260px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-head {
  padding: 15px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.card-body { padding: 18px; }
.card-body.tight { padding: 12px 16px; }

/* ---------- KPI row ---------- */
.kpi-grid {
  display: grid; gap: 0; margin-bottom: 26px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.kpi { padding: 17px 20px; border-inline-start: 1px solid var(--line); }
.kpi:first-child { border-inline-start: 0; }
.kpi-label { font-size: 11.5px; font-weight: 500; color: var(--ink-3); letter-spacing: .1px; }
.kpi-value {
  font-size: 27px; font-weight: 600; color: var(--ink); line-height: 1.15;
  margin-top: 5px; letter-spacing: -.8px; font-variant-numeric: tabular-nums;
}
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--ink-3); margin-inline-start: 3px; letter-spacing: 0; }
.kpi-sub { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; }
.kpi-sub.warn { color: var(--amber); }
.kpi-sub.danger { color: var(--crimson); }

/* ---------- buttons ---------- */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 13.5px; font-weight: 500;
  border-radius: var(--radius-s); padding: 8px 15px; border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: background .13s, border-color .13s, color .13s; white-space: nowrap;
  text-decoration: none;
}
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-primary { background: var(--crimson); color: #fff; font-weight: 500; }
.btn-primary:hover { background: #b91c1c; }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-soft); }
.btn-blue { background: var(--blue-bright); color: #fff; }
.btn-blue:hover { background: var(--blue); }
.btn-ghost { background: var(--surface); color: var(--ink-2); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--ink-3); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], input[type="month"], select, textarea {
  font: inherit; font-size: 14px; width: 100%;
  padding: 9px 11px; border: 1px solid var(--line-2); border-radius: var(--radius-s);
  background: var(--surface); color: var(--ink);
  transition: border-color .13s, box-shadow .13s;
}
@media (max-width: 640px) {
  /* 16px stops iOS Safari zooming when a field is focused */
  input[type="text"], input[type="email"], input[type="password"], input[type="number"],
  input[type="date"], input[type="search"], input[type="month"], select, textarea { font-size: 16px; }
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue-bright); box-shadow: var(--ring); }
input::placeholder { color: var(--ink-3); }
textarea { min-height: 72px; resize: vertical; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.checkline input { width: auto; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 500;
  padding: 3px 9px; border-radius: 6px; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-jlpt  { background: transparent; color: var(--crimson); border-color: #f3c9c9; font-weight: 600; }
.badge-quiet { background: var(--surface-2); color: var(--ink-2); }
.badge-navy  { background: var(--surface-2); color: var(--navy); }
.badge-blue  { background: #f2f6fd; color: var(--blue); border-color: #dbe6fa; }
.badge-green { background: #f2f9f4; color: var(--green); border-color: #d6ecdc; }
.badge-amber { background: #fdf7ec; color: var(--amber); border-color: #f2e2c5; }
.badge-red   { background: #fdf3f3; color: var(--crimson); border-color: #f5d7d7; }
.badge-slate { background: var(--surface-2); color: var(--ink-3); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 640px; }
table.data th {
  text-align: start; font-size: 11.5px; font-weight: 500; color: var(--ink-3);
  padding: 11px 14px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data .num { text-align: end; font-variant-numeric: tabular-nums; }
.code-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  color: var(--ink-2); white-space: nowrap;
}

/* ---------- progress ---------- */
.bar { height: 4px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--navy); transition: width .35s ease; }
.bar.good > span { background: var(--green); }
.bar.warn > span { background: var(--amber); }
.bar.bad  > span { background: var(--crimson); }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row .bar { flex: 1; min-width: 60px; }
.bar-row b { font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; min-width: 38px; text-align: end; color: var(--ink-2); }

/* ---------- roll call ---------- */
.roll-list { display: flex; flex-direction: column; }
.roll-row {
  display: grid; gap: 14px; align-items: center;
  grid-template-columns: minmax(140px, 1fr) auto minmax(130px, .8fr);
  padding: 11px 2px; border-bottom: 1px solid var(--line);
}
.roll-row:last-child { border-bottom: 0; }
.roll-who { min-width: 0; display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.roll-who b { font-size: 14px; font-weight: 500; }
.roll-who span { font-size: 11.5px; color: var(--ink-3); }
.roll-note { border-color: transparent !important; background: var(--surface-2) !important; font-size: 13px !important; padding: 7px 10px !important; }
.roll-note:focus { border-color: var(--blue-bright) !important; background: var(--surface) !important; }

/* segmented status control */
.status-group {
  display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 9px; padding: 2px; gap: 2px;
}
.status-btn {
  cursor: pointer; border: 0; background: transparent; color: var(--ink-2);
  font: inherit; font-size: 12.5px; font-weight: 500; border-radius: 7px;
  padding: 7px 12px; min-height: 34px; white-space: nowrap;
  transition: background .12s, color .12s;
}
.status-btn:hover { color: var(--ink); }
.status-btn[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.status-btn[aria-pressed="true"][data-status="PRESENT"] { color: var(--green); }
.status-btn[aria-pressed="true"][data-status="ABSENT"]  { color: var(--crimson); }
.status-btn[aria-pressed="true"][data-status="LATE"]    { color: var(--amber); }
.status-btn[aria-pressed="true"][data-status="EXCUSED"] { color: var(--ink-2); }

/* ---------- group tiles ---------- */
.tile-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(256px, 1fr)); }
.tile {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.tile-top { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.tile-top h3 { font-size: 14.5px; }
.tile-top .meta { font-size: 12px; color: var(--ink-3); margin-top: 3px; }
.tile-body { padding: 14px 18px 16px; display: flex; flex-direction: column; gap: 9px; flex: 1; }
.tile-stat { display: flex; justify-content: space-between; font-size: 12.5px; }
.tile-stat span { color: var(--ink-3); }
.tile-stat b { font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- portal ---------- */
.portal-hero { text-align: center; padding: 44px 0 34px; }
.portal-hero h1 { font-size: 27px; font-weight: 600; }
.portal-hero p { color: var(--ink-2); font-size: 14px; margin: 9px 0 22px; }
.portal-search { display: flex; gap: 8px; max-width: 470px; margin: 0 auto; }
.portal-search input { flex: 1; padding: 11px 14px; }
.portal-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
.stat-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.stat-line:last-child { border-bottom: 0; }
.stat-line span { color: var(--ink-3); }
.stat-line b { font-weight: 500; font-variant-numeric: tabular-nums; text-align: end; }

.grade-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.grade-row:last-child { border-bottom: 0; }
.grade-top { display: flex; justify-content: space-between; align-items: baseline; gap: 14px; }
.grade-score {
  font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--ink); white-space: nowrap; letter-spacing: -.4px;
}
.grade-score small { font-size: 12px; font-weight: 400; color: var(--ink-3); letter-spacing: 0; }
.grade-score.is-low { color: var(--amber); }
.grade-fb { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; }

/* ---------- modal ---------- */
.modal-root { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal-root[hidden] { display: none !important; }
[hidden] { display: none !important; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(23, 32, 46, .28); backdrop-filter: blur(3px); }
.modal {
  position: relative; background: var(--surface); border-radius: 16px;
  box-shadow: 0 30px 70px -20px rgba(23, 32, 46, .35), 0 0 0 1px var(--line);
  width: 100%; max-width: 600px; max-height: calc(100vh - 36px); display: flex; flex-direction: column;
  animation: pop .15s ease-out;
}
.modal.narrow { max-width: 400px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } }
.modal-head {
  padding: 18px 20px 14px; border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
}
.modal-head h2 { font-size: 16px; }
.modal-head .sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close {
  background: transparent; border: 0; color: var(--ink-3); width: 30px; height: 30px;
  border-radius: 7px; cursor: pointer; font-size: 20px; line-height: 1; flex: none;
}
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-logo { display: block; margin: 0 auto 16px; }

/* ---------- toast ---------- */
.toast-root { position: fixed; z-index: 80; inset-block-end: 22px; inset-inline: 18px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px;
  box-shadow: 0 12px 30px -10px rgba(23, 32, 46, .5); font-size: 13.5px; max-width: 420px;
  animation: rise .17s ease-out;
}
.toast.ok  { background: var(--green); }
.toast.err { background: var(--crimson); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ---------- misc ---------- */
.empty { padding: 44px 16px; text-align: center; color: var(--ink-3); font-size: 13.5px; }
.empty .big { display: none; }
.spinner { width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--ink-3); border-radius: 50%; animation: spin .7s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; min-width: 170px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  cursor: pointer; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  font: inherit; font-size: 12.5px; font-weight: 500; padding: 6px 13px; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip .count { opacity: .6; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--line); overflow-x: auto; padding: 0 18px; }
.tab {
  cursor: pointer; border: 0; background: transparent; font: inherit; font-size: 13.5px; font-weight: 500;
  color: var(--ink-2); padding: 13px 0; border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--navy); font-weight: 600; border-bottom-color: var(--navy); }
/* kanji taught in a lesson is course content — always shown, in every language */
.kanji-strip { font-family: var(--jp); font-size: 15px; letter-spacing: 2px; color: var(--ink); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .lang-btn .lab { display: none; }
  .lang-btn { padding: 5px 6px; font-size: 15px; }
  .brand-text small { display: none; }
}
@media (max-width: 700px) {
  .shell { padding: 0 16px; }
  /* the brand keeps its line; the language row drops below it */
  .header-row { min-height: 0; flex-wrap: wrap; row-gap: 4px; padding-block: 8px; }
  .brand { flex: 1 1 auto; }
  .header-tools { flex: 0 0 auto; }
  .lang-switch { order: 3; width: 100%; justify-content: center; }
  .nav-toggle { display: inline-flex; }
  .app-nav { display: none; }
  .app-nav.open { display: block; }
  .nav-row { flex-direction: column; gap: 0; padding-block: 4px; }
  .nav-btn { border-bottom: 0; width: 100%; justify-content: flex-start; padding: 12px 0; }
  .nav-btn[aria-current="page"] { border-bottom-color: transparent; }
  .session-user { display: none; }
  .app-main { padding-top: 22px; }

  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi { border-top: 1px solid var(--line); }
  .kpi:nth-child(-n+2) { border-top: 0; }
  .kpi:nth-child(odd) { border-inline-start: 0; }
  .kpi-value { font-size: 22px; }

  .roll-row { grid-template-columns: 1fr; gap: 9px; padding: 14px 2px; }
  .status-group { display: grid; grid-template-columns: repeat(2, 1fr); width: 100%; }
  .status-btn { width: 100%; }
  h1 { font-size: 21px; }
  .portal-hero { padding: 30px 0 24px; }
  .portal-hero h1 { font-size: 22px; }
  .portal-search { flex-direction: column; }
  .modal-body { padding: 16px; }
  .tabs { padding: 0 14px; gap: 18px; }
  /* comfortable finger targets */
  .btn { min-height: 38px; }
  .btn-sm { min-height: 34px; }
  .chip { min-height: 34px; }
  .lang-btn { min-height: 34px; min-width: 34px; }
  .icon-btn { width: 36px; height: 36px; }
}
@media (max-width: 430px) {
  .brand-text strong { font-size: 13px; }
  .status-group { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- print ---------- */
@media print {
  body { background: #fff; }
  .app-header, .app-nav, .app-footer, .toast-root, .no-print, .btn { display: none !important; }
  .app-main { padding: 0; }
  .card { box-shadow: none; border-color: #ddd; break-inside: avoid; }
  .modal-root { position: static; padding: 0; }
  .modal-backdrop { display: none; }
  .modal { max-width: none; max-height: none; box-shadow: none; }
  .modal-foot { display: none; }
  table.data { min-width: 0; font-size: 11px; }
  .roll-row { break-inside: avoid; }
  @page { margin: 15mm; }
}
