:root {
  --bg: #f6f7f9; --card: #fff; --text: #1d2330; --muted: #667085; --line: #e3e6eb;
  --accent: #1f6feb; --accent-text: #fff; --soft: #eaf1fe;
  --sub: #b45309; --sub-bg: #fff7ed; --off-bg: #f2f4f7; --err: #c62828; --ok: #2e7d32;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1b2029; --text: #e6e9ef; --muted: #98a2b3; --line: #2c3340;
    --accent: #4c8dff; --soft: #1d2a40; --sub: #f5a524; --sub-bg: #2b2215; --off-bg: #232831;
    --err: #ff6b6b; --ok: #5bd17a; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--card); padding: 7px 12px; border-radius: 8px; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.link { border: 0; background: none; padding: 4px 6px; color: var(--accent); }
button.danger { color: var(--err); }
input, select { border: 1px solid var(--line); background: var(--card); padding: 8px 10px; border-radius: 8px; min-width: 0; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; margin: 10px 0 4px; font-weight: 600; font-size: 14px; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 19px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); margin: 8px 0; min-height: 0; }
.error:empty, .ok:empty { display: none; }
.ok { color: var(--ok); margin: 8px 0; }
.warn { color: var(--sub); }
.loading, .empty { padding: 24px 16px; color: var(--muted); }

.center { display: flex; justify-content: center; padding: 48px 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.narrow { width: 100%; max-width: 380px; }
.narrow input { width: 100%; }
.narrow button[type=submit] { width: 100%; margin-top: 14px; padding: 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; }
.who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { background: var(--soft); color: var(--accent); border-radius: 99px; padding: 1px 8px; font-size: 12px; font-weight: 600; }
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--card); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; white-space: nowrap; }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.notice { margin: 12px 16px 0; padding: 8px 12px; border-radius: 8px; background: var(--sub-bg); color: var(--sub); }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }

.bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.bar input[type=search] { flex: 1 1 220px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; }
.seg button:first-child { border-radius: 8px 0 0 8px; }
.seg button:last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.seg button.on { background: var(--soft); color: var(--accent); border-color: var(--accent); position: relative; }
.title { margin-bottom: 12px; }
.title p { margin: 2px 0 0; }

.weeknav { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; min-height: 120px; }
.day.today { border-color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.day h3 { margin: 0 0 8px; font-size: 14px; display: flex; justify-content: space-between; gap: 4px; }
.day h3 span { color: var(--muted); font-weight: 400; }
.slot { border-left: 4px solid var(--accent); background: var(--soft); border-radius: 6px; padding: 6px 8px; margin-bottom: 6px; font-size: 13px; overflow-wrap: anywhere; }
.slot .time { font-weight: 700; display: flex; justify-content: space-between; gap: 4px; flex-wrap: wrap; }
.slot .time span { font-weight: 400; color: var(--muted); }
.slot .subj { font-weight: 600; }
.slot.thay { border-left-color: var(--sub); background: var(--sub-bg); }
.slot.nghi { border-left-color: var(--line); background: var(--off-bg); color: var(--muted); }
.slot.nghi > :not(.tag) { text-decoration: line-through; }
.tag { color: var(--sub); font-weight: 600; font-size: 12px; margin-top: 2px; }

.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.list ul { margin: 6px 0; padding-left: 18px; }
.list .subs { color: var(--sub); }
.row-head { display: flex; justify-content: space-between; gap: 8px; }

.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr:focus { background: var(--soft); outline: none; }

.dlg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 16px; }
.dlg::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.dlg input, .dlg select { width: 100%; }
.dlg fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 12px 0; padding: 4px 12px 12px; }
.dlg legend { font-weight: 700; padding: 0 4px; }
.dlg fieldset > button.primary { margin-top: 10px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hist { padding-left: 18px; }

@media (max-width: 900px) {
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; }
  .day.empty-day { display: none; }
  .weeknav strong { order: -1; width: 100%; }
}
@media print {
  .no-print, .tabs, .top, .notice { display: none !important; }
  body { background: #fff; color: #000; }
  main { padding: 0; max-width: none; }
  .week { grid-template-columns: repeat(7, 1fr); gap: 4px; }
  .day { min-height: 0; border-color: #999; }
  .day.empty-day { display: block; }
  .slot { background: none; border: 1px solid #999; border-left-width: 4px; }
}
