:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --sidebar: #eceef2;
  --text: #15171a;
  --muted: #6b7280;
  --border: #e3e5ea;
  --accent: #2f6fed;
  --accent-soft: rgba(47, 111, 237, 0.12);
  --green: #16a34a;
  --orange: #ea8a0c;
  --red: #dc2626;
  --purple: #7c3aed;
  --indigo: #4f46e5;
  --teal: #0d9488;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 14px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121316;
    --surface: #1c1d21;
    --surface-2: #26272c;
    --sidebar: #17181b;
    --text: #f2f3f5;
    --muted: #9a9ea8;
    --border: #2d2f35;
    --accent: #5b8dff;
    --accent-soft: rgba(91, 141, 255, 0.16);
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121316;
  --surface: #1c1d21;
  --surface-2: #26272c;
  --sidebar: #17181b;
  --text: #f2f3f5;
  --muted: #9a9ea8;
  --border: #2d2f35;
  --accent: #5b8dff;
  --accent-soft: rgba(91, 141, 255, 0.16);
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }

/* ---------- shell ---------- */

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; font-size: 18px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.nav-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 6px 10px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent); color: #fff; }
.nav a .icon { width: 20px; text-align: center; }
.nav a .badge { margin-left: auto; font-size: 12px; background: var(--red); color: #fff; border-radius: 10px; padding: 0 7px; }
.sidebar-foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.sidebar-foot strong { color: var(--text); display: block; font-size: 12px; }

.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 28px; padding-top: max(14px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view { padding: 24px 28px 48px; max-width: 1180px; }

.tabbar { display: none; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding-left: 16px; padding-right: 16px; }
  .view { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    padding: 8px 0 6px; font-size: 11px; color: var(--muted); text-decoration: none;
  }
  .tabbar a .icon { font-size: 20px; line-height: 1.1; }
  .tabbar a.active { color: var(--accent); font-weight: 600; }
}

/* ---------- building blocks ---------- */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.card + .card, .stack > * + * { margin-top: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .spacer { flex: 1; }

.grid { display: grid; gap: 14px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.two-col { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

.tile { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.tile .glyph {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 19px; flex: none;
}
.tile .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tile .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .value.small { font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; font-weight: 550; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.icon-only { padding: 7px 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row .grow { flex: 1; }

input[type=text], input[type=password], input[type=search], input[type=email], select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
label.check input { margin-top: 3px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.green { background: color-mix(in srgb, var(--green) 14%, transparent); color: var(--green); }
.pill.orange { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); }
.pill.red { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.pill.indigo { background: color-mix(in srgb, var(--indigo) 14%, transparent); color: var(--indigo); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 20px; padding: 5px 12px; cursor: pointer; font-size: 13px; font-weight: 550; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.list > * { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--border); }
.list > *:first-child { border-top: 0; padding-top: 2px; }
.list .main-text { flex: 1; min-width: 0; }
.list .title { font-weight: 560; overflow-wrap: anywhere; }
.list .sub { font-size: 13px; color: var(--muted); }
.list a { color: inherit; text-decoration: none; }
.clickable { cursor: pointer; border-radius: 10px; }
.clickable:hover { background: var(--surface-2); }

.course-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; flex: none; }
.letter { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 750; font-size: 16px; flex: none; }
.bar { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.error-box { background: color-mix(in srgb, var(--red) 10%, transparent); color: var(--red); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.note-box { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: var(--muted); }

/* ---------- today ---------- */

.day-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin: 10px 0 18px; }
.day-head .letter-day { font-size: 36px; font-weight: 750; color: var(--accent); letter-spacing: -.01em; }
.day-head .date { font-size: 20px; font-weight: 600; color: var(--muted); }
.day-head .clock { margin-left: auto; font-size: 18px; color: var(--muted); font-variant-numeric: tabular-nums; }
.now { display: flex; gap: 16px; align-items: center; }
.now .glyph { width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; font-size: 28px; flex: none; }
.now .kicker { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.now .big { font-size: 26px; font-weight: 700; line-height: 1.2; }
.now .count { margin-left: auto; text-align: right; }
.now .count .num { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
@media (max-width: 560px) {
  .now { flex-wrap: wrap; }
  .now .count { margin-left: 0; text-align: left; width: 100%; }
  .day-head .letter-day { font-size: 30px; }
  .day-head .date { font-size: 17px; }
}
.block-row { display: flex; gap: 14px; align-items: center; padding: 10px 6px; border-top: 1px solid var(--border); }
.block-row:first-child { border-top: 0; }
.block-row .when { width: 132px; flex: none; }
.block-row .when b { display: block; }
.block-row.current { background: var(--accent-soft); border-radius: 10px; border-top-color: transparent; }
.block-row.current + .block-row { border-top-color: transparent; }
.block-row.past { opacity: .55; }
.block-row.lunch { background: color-mix(in srgb, var(--green) 10%, transparent); border-radius: 10px; color: var(--green); font-weight: 600; border-top-color: transparent; }
.block-row.lunch + .block-row { border-top-color: transparent; }
@media (max-width: 560px) { .block-row .when { width: 98px; font-size: 13px; } }

/* ---------- privacy cover ---------- */

.covered { position: relative; }
.covered > .content { filter: blur(18px); pointer-events: none; user-select: none; }
.covered > .cover { position: absolute; inset: 0; display: grid; place-items: start center; padding-top: 80px; }
.cover .card { text-align: center; }

/* ---------- chat ---------- */

.ask { display: grid; grid-template-columns: 250px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .ask { grid-template-columns: 1fr; } .chat-list { max-height: 210px; overflow: auto; } }
.chat-list { background: var(--sidebar); }
.chat-list .item { padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.chat-list .item:hover { background: var(--surface-2); }
.chat-list .item.active { background: var(--accent-soft); }
.chat-list .item .t { font-weight: 560; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat { display: flex; flex-direction: column; min-height: 60vh; }
.messages { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 4px 0 12px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.bubble.model { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 5px; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble img { max-width: 160px; border-radius: 8px; display: block; margin-bottom: 6px; }
.composer { display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--border); padding-top: 12px; }
.composer textarea { resize: none; min-height: 44px; max-height: 160px; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.thumbs img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; }
.status-line { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.dots::after { content: "…"; animation: dots 1.2s steps(3) infinite; }
@keyframes dots { 0% { content: "."; } 33% { content: ".."; } 66% { content: "..."; } }

/* ---------- sign in ---------- */

.signin { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.signin .card { width: 100%; max-width: 420px; padding: 28px; }
.signin .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin: 0 auto 12px; }
.signin h1 { text-align: center; margin: 0 0 4px; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 22px; max-width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 50; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px);
}
@media (max-width: 760px) { .toast { bottom: calc(84px + env(safe-area-inset-bottom)); } }

.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin, .dots::after { animation: none; } }
