:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --line: #d9dde3;
  --text: #171a20;
  --muted: #5e6672;
  --primary: #2459d6;
  --on-primary: #ffffff;
  --danger: #c5362a;
  --ok: #17794f;
  --no: #bd3a2c;
  --warn-bg: #fff2d6;
  --warn-text: #7a5200;
  --free-line: #9aa3ae;
  --free-bg: rgba(120, 130, 145, .1);
  --meal-bg: rgba(209, 138, 0, .22);
  --meal-line: rgba(209, 138, 0, .6);
  --today: rgba(36, 89, 214, .08);
  --past: rgba(120, 130, 145, .1);
  --radius: 12px;
  --tabbar: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1e2229;
    --surface-2: #2a2f38;
    --line: #363c47;
    --text: #eef0f3;
    --muted: #a3acb8;
    --primary: #6d9bff;
    --on-primary: #0d1320;
    --danger: #ff7a6b;
    --ok: #4bcf94;
    --no: #ff8f80;
    --warn-bg: #3d2f12;
    --warn-text: #ffd27d;
    --free-line: #6b7480;
    --free-bg: rgba(160, 170, 185, .1);
    --meal-bg: rgba(226, 165, 45, .25);
    --meal-line: rgba(226, 165, 45, .6);
    --today: rgba(109, 155, 255, .13);
    --past: rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .35; cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.topbar {
  flex: none; height: 48px; display: flex; align-items: center; gap: 2px; padding: 0 6px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.title { flex: 1; margin: 0 0 0 10px; font-size: 18px; }
.icon-btn { flex: none; width: 40px; height: 40px; border-radius: 10px; font-size: 21px; line-height: 1; }
.icon-btn:active { background: var(--surface-2); }
.week-title { flex: 1; min-width: 0; height: 40px; display: flex; align-items: center; justify-content: center; font-weight: 650; font-size: 14.5px; white-space: nowrap; }
.wt { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.week-title .tag { flex: none; }
.tag { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.tag.warn { background: var(--warn-bg); color: var(--warn-text); }
.tag.ok { color: var(--ok); }
.tag-line { margin: 0; }

#main { flex: 1; min-height: 0; position: relative; }
.tab-root { position: absolute; inset: 0; display: flex; flex-direction: column; }
.page { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 16px 24px; }

.tabbar {
  flex: none; display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button { flex: 1; height: var(--tabbar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 11px; color: var(--muted); }
.tabbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--primary); font-weight: 650; }

/* Dosya seçici sayfa yenilense de yerinde kalsın diye ekranların dışındadır; düğmeler label ile açar. */
.file-input { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
label.btn, label.link-btn { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; text-align: center; }
label.link-btn { display: flex; justify-content: flex-start; }

/* Hafta */
.backup-warn { flex: none; padding: 7px 12px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; font-weight: 600; text-align: center; }
.week { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.head-row { flex: none; display: flex; background: var(--surface); border-bottom: 1px solid var(--line); }
.axis-head { flex: none; width: 15px; }
.day-head { flex: 1 1 0; min-width: 0; height: 40px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); line-height: 1.15; }
.day-head b { font-size: 14px; color: var(--text); }
.day-head.today b { color: var(--on-primary); background: var(--primary); border-radius: 999px; min-width: 22px; padding: 0 4px; }
.grid { flex: 1; min-height: 0; display: flex; position: relative; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.axis { flex: none; width: 15px; position: relative; font-size: 9px; color: var(--muted); }
.axis span { position: absolute; right: 2px; transform: translateY(-50%); }
.col { flex: 1 1 0; min-width: 0; position: relative; border-left: 1px solid var(--line); }
.col.today { background: var(--today); }
.col.past { background: var(--past); }
.line { position: absolute; left: 0; right: 0; height: 1px; background: var(--line); opacity: .45; pointer-events: none; }
.block {
  position: absolute; left: 1px; right: 1px; display: block; overflow: hidden; text-align: left;
  padding: 1px 2px; border-radius: 5px; font-size: 10px; line-height: 1.12; -webkit-touch-callout: none;
}
.block span { display: block; white-space: nowrap; overflow: hidden; text-overflow: clip; pointer-events: none; }
.block .t, .block .e { font-size: 9.5px; font-variant-numeric: tabular-nums; opacity: .92; }
.block .n { font-weight: 650; font-size: 10.5px; }
.block .in { display: flex; flex-direction: column; justify-content: space-between; height: 100%; }
.block .r { display: none; font-size: 8px; font-variant-numeric: tabular-nums; letter-spacing: -.25px; }
.block.lesson { padding: 1px 1px 1px 2px; }
.block.compact .in { justify-content: center; }
.block.compact .t, .block.compact .e, .block.mini .t, .block.mini .e { display: none; }
.block.compact .r { display: block; }
.block.compact .n, .block.mini .n { font-size: 10px; line-height: 1.05; }
.lesson.custom::after { content: ""; position: absolute; top: 0; right: 0; border: 4px solid; border-color: currentColor currentColor transparent transparent; border-top-right-radius: 5px; opacity: .9; }
.lesson.off { opacity: .55; }
.lesson.off .n { text-decoration: line-through; }
.block.free { border: 1px dashed var(--free-line); background: var(--free-bg); color: var(--muted); }
.block.free.saved { border-style: solid; }
.block.free.saved.custom .n { font-weight: 500; }
/* Mola: küçük aralıklarda da dokunulabilsin diye en az 14 piksel, aralığın ortasına oturur. */
.gap {
  position: absolute; left: 1px; right: 1px; z-index: 2; min-height: 14px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; overflow: hidden; border-radius: 4px;
  font-size: 9px; line-height: 1.05; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap;
}
.gap b { font-weight: 700; font-size: 9px; }
.gap.short b { display: none; }
.gap.short.normal span { background: var(--bg); border-radius: 3px; padding: 0 3px; }
.gap.meal { background: var(--meal-bg); color: var(--warn-text); box-shadow: inset 0 0 0 1px var(--meal-line); font-weight: 600; }
.gap.long { border: 1px dashed var(--line); }
.block.dragging { opacity: .25; }
.block.ghost { z-index: 50; box-shadow: 0 6px 18px rgba(0, 0, 0, .35); pointer-events: none; transform: scale(1.05); }
.drag-pill { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 40; padding: 5px 12px; border-radius: 999px; background: var(--text); color: var(--bg); font-weight: 650; font-size: 13px; pointer-events: none; }
.scope-bar { flex: none; display: flex; gap: 8px; padding: 8px; background: var(--surface); border-top: 1px solid var(--line); }
.scope-bar .btn { flex: 1; padding: 0 6px; font-size: 13.5px; }

/* Genel */
.btn { min-height: 44px; padding: 0 16px; border-radius: 10px; background: var(--surface-2); font-weight: 600; }
.btn:active { filter: brightness(.94); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1.5px var(--danger); }
.btn.on { box-shadow: inset 0 0 0 2px var(--primary); color: var(--primary); }
.btn.wide { width: 100%; }
.btn.self-end { align-self: end; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; }
.btn-row > .btn { flex: 1; }
.btn-row.wrap { flex-wrap: wrap; }
.link-btn { min-height: 40px; color: var(--primary); font-weight: 600; text-align: left; }
.section { margin: 22px 0 8px; font-size: 13px; text-transform: none; color: var(--muted); font-weight: 650; }
.list { list-style: none; margin: 8px 0 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.list > li + li { border-top: 1px solid var(--line); }
.list.inner { margin: 0 0 8px 12px; background: var(--surface-2); }
.row-btn { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 50px; padding: 8px 12px; text-align: left; }
.row-btn:active { background: var(--surface-2); }
.row-btn small, .pay-row small { display: block; color: var(--muted); font-size: 12px; }
.sheet-body > .row-btn { background: var(--surface-2); border-radius: 10px; margin-bottom: 8px; justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.dot { flex: none; width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-style: normal; font-weight: 700; }
.dot.small { width: 12px; height: 12px; }
.money { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.money small { display: block; font-size: 12px; }
.ok { color: var(--ok); }
.no { color: var(--no); }
.sub { margin: 0 0 10px; color: var(--muted); font-size: 13.5px; }
.msg { margin: 0 0 4px; color: var(--muted); }
.kv { display: flex; justify-content: space-between; margin: 6px 0; }
.warn-line { color: var(--warn-text); background: var(--warn-bg); padding: 6px 10px; border-radius: 8px; font-weight: 600; font-size: 13px; }
.version { color: var(--muted); font-size: 12px; text-align: center; margin-top: 18px; }
.fatal { padding: 24px; color: var(--danger); }

.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; font-size: 16px; min-width: 0;
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 0; }
.sheet-body > .two { margin-top: 12px; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 7px; }
.swatch { aspect-ratio: 1; border-radius: 50%; }
.swatch.on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { min-height: 36px; padding: 0 12px; border-radius: 999px; background: var(--surface-2); font-size: 13.5px; font-weight: 600; }
.chip.on { background: var(--primary); color: var(--on-primary); }
.seg { flex: 1; display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin: 0 4px; }
.seg button { flex: 1; height: 32px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); }
.pager { display: flex; align-items: center; justify-content: space-between; }
.totals { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.totals > div { background: var(--surface); border-radius: 10px; padding: 8px 12px; min-width: 0; }
.totals small { display: block; color: var(--muted); font-size: 12px; }
.totals b { font-size: 18px; font-variant-numeric: tabular-nums; }
.totals.small b { font-size: 15px; }
.totals .late { background: var(--warn-bg); color: var(--warn-text); }
.totals .late small { color: inherit; }
.month-body { padding: 0 8px 8px; }
.help { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13.5px; }
.help li { margin: 5px 0; }
.check-row { gap: 12px; }
.check-row input, .check input { width: 22px; height: 22px; accent-color: var(--primary); }

/* Alt sayfa */
.sheet-wrap { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-back { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sheet { position: relative; max-height: 92%; display: flex; flex-direction: column; background: var(--surface); border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
.sheet-wrap.full .sheet { height: 100%; max-height: 100%; border-radius: 0; padding-top: env(safe-area-inset-top); }
.sheet-head { flex: none; display: flex; align-items: center; padding: 6px 6px 2px 16px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px 18px; min-height: 0; flex: 1; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stat-row > div { background: var(--surface-2); border-radius: 10px; padding: 8px; min-width: 0; }
.stat-row small { display: block; color: var(--muted); font-size: 11.5px; }
.stat-row b { font-variant-numeric: tabular-nums; }

/* Ödeme listesi */
.pay-list { list-style: none; margin: 12px 0 0; padding: 0; }
.pay-list li { display: flex; align-items: center; gap: 6px; border-top: 1px solid var(--line); }
.pay-list li.future { background: var(--surface-2); border-radius: 6px; }
.check { flex: none; display: flex; padding: 12px 4px; }
.pay-row { flex: 1; min-width: 0; display: flex; justify-content: space-between; gap: 8px; align-items: center; text-align: left; min-height: 50px; padding: 6px 2px; }
.state { text-align: right; font-size: 12.5px; font-weight: 600; flex: none; max-width: 45%; }
.state small { display: block; font-weight: 500; }
.s-ok { color: var(--ok); }
.s-no { color: var(--no); }
.s-late { color: var(--warn-text); }
.s-wait { color: var(--muted); }
.tick { flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-weight: 800; }
.tick.on { background: var(--ok); color: #fff; }
.tick.none { background: transparent; }
.bulk { position: sticky; bottom: 0; display: flex; gap: 6px; align-items: center; padding: 8px; margin-top: 10px; background: var(--surface); border-top: 1px solid var(--line); }
.bulk span { flex: 1; font-weight: 650; }
.bulk .btn { padding: 0 10px; }

.expect { margin: 14px 0; padding: 10px 12px 12px; background: var(--surface-2); border-radius: 12px; }
.expect h3 { margin: 0 0 8px; font-size: 14px; }
.expect .field input { background: var(--surface); }
.expect .btn { background: var(--surface); }
.expect .btn.primary { background: var(--primary); }
.expect .btn.danger { background: transparent; }
.empty-note { margin-top: 12px; }
.pick-list { background: var(--surface-2); }
.bulk { flex-wrap: wrap; }

/* Öğrenci özeti: ekran görüntüsü olarak gönderilir */
.sum-head { position: sticky; top: -4px; z-index: 2; background: var(--surface); padding: 4px 0 8px; }
.summary h2 { margin: 2px 0 0; font-size: 22px; }
.sum-range { margin: 2px 0 0; font-weight: 600; color: var(--muted); }
.sum-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; }
.sum-grid > div { background: var(--surface-2); padding: 8px; border-radius: 10px; min-width: 0; }
.sum-grid .hi { background: var(--warn-bg); color: var(--warn-text); }
.sum-grid dt { font-size: 11.5px; opacity: .8; }
.sum-grid dd { margin: 2px 0 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.sum-days { width: 100%; margin-top: 12px; border-collapse: collapse; font-size: 13.5px; }
.sum-days td { padding: 7px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.sum-days td:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }
.sum-days td:last-child { text-align: right; font-weight: 600; }
.sum-days .future td { color: var(--muted); font-style: italic; }
.sum-days small { font-weight: 500; }

.toast {
  position: fixed; left: 16px; right: 16px; top: calc(54px + env(safe-area-inset-top)); z-index: 300;
  padding: 11px 14px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 600; text-align: center;
  opacity: 0; transform: translateY(8px); transition: opacity .15s, transform .15s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); color: #fff; }

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
