/* ===== PerTamo — mobile-first TAMO viewer ===== */
:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e3e8f0;
  --text: #1a1f2b;
  --muted: #667085;
  --primary: #0b57d0;
  --primary-weak: #e8f0fe;
  --danger: #d33831;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 16px;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);

  --g-bad: #d33831;   --g-bad-bg: #fdecea;
  --g-mid: #c77700;   --g-mid-bg: #fff4e0;
  --g-ok:  #1a7f5a;   --g-ok-bg:  #e5f5ee;
  --g-top: #0b7a3b;   --g-top-bg: #e2f5e6;
  --g-neu: #667085;   --g-neu-bg: #eef1f6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0f1a;
    --surface: #141a26;
    --surface-2: #1b2333;
    --border: #263141;
    --text: #e7ecf4;
    --muted: #93a1b5;
    --primary: #7aa7ff;
    --primary-weak: #17233d;
    --danger: #ff6b63;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --g-bad-bg: #3a1c1b; --g-mid-bg: #35291259; --g-mid: #e0a53d;
    --g-ok-bg: #12312559; --g-top-bg: #103322; --g-neu-bg: #222b3a;
    --g-bad: #ff7b73; --g-ok: #4fd6a0; --g-top: #58e08a; --g-neu: #93a1b5;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
svg { width: 1.25em; height: 1.25em; display: block; }

/* ---------- shell ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-main { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 750; letter-spacing: -.02em; }
.topbar-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.content {
  flex: 1;
  padding: 14px 16px calc(var(--tab-h) + var(--safe-b) + 20px);
  max-width: 680px; width: 100%; margin: 0 auto;
}

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 600;
}
.tab svg { width: 23px; height: 23px; }
.tab.is-active { color: var(--primary); }
.tab-label { line-height: 1; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-title { margin: 0 0 10px; font-size: 15px; font-weight: 700; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* ---------- alerts / empty ---------- */
.alert {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: 14px;
}
.alert svg { flex: none; }
.alert-error { background: var(--g-bad-bg); color: var(--g-bad); }
.empty {
  text-align: center; color: var(--muted); padding: 48px 20px;
}
.empty svg { width: 40px; height: 40px; margin: 0 auto 10px; opacity: .5; }
.empty p { margin: 0; }

/* ---------- pagers ---------- */
.pager { display: flex; align-items: center; gap: 6px; }
.pager-label { font-size: 13px; font-weight: 600; min-width: 92px; text-align: center; }
.pager-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 10px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
}
.pager-wide { justify-content: space-between; margin-top: 8px; }

/* ---------- schedule ---------- */
.day { margin-bottom: 16px; }
.day-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 2px 8px; font-size: 15px; font-weight: 700;
}
.day-date { font-size: 12px; font-weight: 600; color: var(--muted); }
.day-today .day-date { color: var(--primary); }
.day-today .day-head span:first-child { color: var(--primary); }
.day-empty { color: var(--muted); font-size: 13px; margin: 0 2px; }
.lessons { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.lesson {
  display: flex; gap: 12px; align-items: stretch;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow);
}
.lesson-no {
  flex: none; width: 30px; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; color: var(--primary);
  background: var(--primary-weak); border-radius: 9px;
}
.lesson-body { flex: 1; min-width: 0; }
.lesson-top { display: flex; justify-content: space-between; gap: 8px; }
.lesson-name { font-weight: 650; }
.lesson-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.lesson-teacher { font-size: 12.5px; color: var(--muted); }

/* ---------- segmented control ---------- */
.segmented {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.seg {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 650; font-size: 13.5px; padding: 8px 6px;
  border-radius: 9px; cursor: pointer; text-align: center;
}
.seg.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- grades ---------- */
.grade-row { display: flex; flex-wrap: wrap; gap: 7px; }
.grade {
  display: inline-flex; flex-direction: column; align-items: center;
  min-width: 40px; padding: 5px 8px; border-radius: 11px;
  font-weight: 800; font-size: 17px; line-height: 1.1;
}
.grade small { font-size: 9.5px; font-weight: 600; opacity: .8; margin-top: 1px; }
.g-bad { background: var(--g-bad-bg); color: var(--g-bad); }
.g-mid { background: var(--g-mid-bg); color: var(--g-mid); }
.g-ok  { background: var(--g-ok-bg);  color: var(--g-ok); }
.g-top { background: var(--g-top-bg); color: var(--g-top); }
.g-neutral { background: var(--g-neu-bg); color: var(--g-neu); }

/* ---------- attendance ---------- */
.att-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.att-item {
  display: flex; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow);
}
.att-badge {
  flex: none; width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 10px; font-weight: 800; font-size: 14px;
}
.att-n { background: var(--g-bad-bg); color: var(--g-bad); }
.att-p { background: var(--g-mid-bg); color: var(--g-mid); }
.att-a { background: var(--g-ok-bg); color: var(--g-ok); }
.att-other { background: var(--g-neu-bg); color: var(--g-neu); }
.att-body { display: flex; flex-direction: column; }
.att-subject { font-weight: 650; }
.att-meta { font-size: 12.5px; color: var(--muted); }

/* ---------- homework ---------- */
.filterbar { display: flex; gap: 8px; margin-bottom: 14px; }
.filterbar input { flex: 1; min-width: 0; }
.hw-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.hw-subject { font-weight: 700; }
.hw-due {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.hw-due svg { width: 14px; height: 14px; }
.hw-due.is-over { color: var(--danger); }
.hw-due.is-today { color: var(--primary); }
.hw-over { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.hw-today { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.hw-text { margin: 0 0 8px; font-size: 14.5px; }
.hw-meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); }
.hw-files { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--primary-weak); color: var(--primary);
}
.file-chip svg { width: 15px; height: 15px; }

/* ---------- tests ---------- */
.test { display: flex; gap: 14px; align-items: flex-start; }
.test.is-past { opacity: .55; }
.test-date {
  flex: none; width: 52px; text-align: center; padding: 6px 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
}
.test-day { display: block; font-size: 22px; font-weight: 800; line-height: 1; }
.test-mon { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; }
.test-body { flex: 1; min-width: 0; }
.test-subject { font-weight: 700; display: block; }
.test-group { font-size: 12.5px; color: var(--muted); }
.test-types { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.type-chip {
  font-size: 12px; font-weight: 600; padding: 4px 9px; border-radius: 8px;
  background: var(--g-mid-bg); color: var(--g-mid);
}

/* ---------- averages / semester ---------- */
.avg-summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px;
}
.avg-cell {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 6px; text-align: center; box-shadow: var(--shadow);
}
.avg-val { display: block; font-size: 22px; font-weight: 800; line-height: 1.1; border-radius: 8px; }
.avg-lbl { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }
.subj-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.subj-name { font-weight: 700; }
.subj-final { font-weight: 800; font-size: 18px; padding: 2px 10px; border-radius: 10px; }
.subj-avg { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.subj-teachers { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.term-grades { display: flex; gap: 8px; margin-top: 10px; }
.term {
  flex: 1; text-align: center; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 12px; padding: 8px 4px;
}
.term small { display: block; font-size: 10.5px; color: var(--muted); margin-bottom: 3px; }
.term b { font-size: 18px; padding: 1px 8px; border-radius: 8px; }
.subj .grade-row { margin-top: 10px; }

/* ---------- messages ---------- */
.msg-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.msg {
  display: flex; gap: 10px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); color: var(--text);
}
.msg-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: transparent; }
.msg.is-unread .msg-dot { background: var(--primary); }
.msg.is-unread .msg-subject { font-weight: 700; }
.msg-main { flex: 1; min-width: 0; }
.msg-top { display: flex; justify-content: space-between; gap: 8px; }
.msg-sender { font-weight: 650; font-size: 14px; }
.msg-date { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.msg-subject { display: block; font-size: 14px; margin: 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-sub { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; }
.msg-sub svg { width: 13px; height: 13px; display: inline; }

.msg-view { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.msg-body { font-size: 15px; overflow-wrap: anywhere; }
.msg-body img { max-width: 100%; height: auto; border-radius: 8px; }
.msg-body table { max-width: 100%; display: block; overflow-x: auto; }
.msg-body a { word-break: break-all; }
.attachments { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.attachments h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.attachments .file-chip { margin: 0 8px 8px 0; }

/* ---------- notes ---------- */
.note-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.note-type { font-weight: 700; font-size: 14px; }
.note-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.note-text { margin: 0 0 8px; font-size: 14.5px; }
.note-meta { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); }

/* ---------- "more" menu ---------- */
.menu-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.menu-item {
  display: flex; align-items: center; gap: 14px; padding: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); color: var(--text);
}
.menu-ico { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: var(--primary-weak); color: var(--primary); }
.menu-txt { flex: 1; display: flex; flex-direction: column; }
.menu-txt small { color: var(--muted); font-size: 12.5px; }
.menu-arw { color: var(--muted); }
.about { font-size: 12.5px; color: var(--muted); margin-top: 20px; }
.logout-form { margin-top: 6px; }

/* ---------- buttons / inputs ---------- */
.btn-primary, .btn-danger, .btn-sm, .btn-ghost {
  font: inherit; font-weight: 650; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.btn-primary { width: 100%; padding: 14px; border: 0; background: var(--primary); color: #fff; font-size: 16px; }
.btn-danger { width: 100%; padding: 13px; border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border)); background: transparent; color: var(--danger); }
.btn-sm { padding: 0 16px; border: 1px solid var(--border); background: var(--primary); color: #fff; }
.btn-ghost { padding: 8px 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; }
input[type="text"], input[type="password"], input[type="date"] {
  width: 100%; padding: 13px 14px; font: inherit; font-size: 16px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; -webkit-appearance: none;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---------- login ---------- */
.auth {
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
  padding: 24px 18px calc(24px + var(--safe-b)); max-width: 440px; margin: 0 auto;
}
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 24px 20px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.brand-mark { width: 52px; height: 52px; border-radius: 14px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 26px; font-weight: 800; }
.brand h1 { margin: 0; font-size: 22px; }
.brand p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle { position: absolute; right: 4px; top: 0; bottom: 0; width: 42px; border: 0; background: transparent; font-size: 18px; cursor: pointer; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.auth-note { margin: 16px 0 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.auth-foot { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 18px; }
