:root {
  --accent: #2aabee;
  --accent-strong: #1c93d1;
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #17212b;
  --muted: #6b7785;
  --border: #e1e6ec;
  --hover: #f0f4f8;
  --danger: #e5484d;
  --ok: #30a46c;
  --warn: #d6930b;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 5%), 0 4px 16px rgb(16 24 40 / 6%);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1621;
    --card: #17212b;
    --text: #e9eef3;
    --muted: #8796a5;
    --border: #253241;
    --hover: #1f2b38;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

.muted { color: var(--muted); }

/* --- top bar --------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 17px;
}
.brand svg { width: 28px; height: 28px; }
.brand circle { fill: var(--accent); }
.brand path { stroke: #fff; stroke-width: 3; fill: none; stroke-linecap: round; }

.clock {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
#clock-time { font-size: 16px; font-weight: 600; }
.clock-offset { font-size: 11px; color: var(--muted); }
.clock-offset.warn { color: var(--warn); }

.account { position: relative; }
.account-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}
.account-btn:hover { background: var(--hover); }

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  background: var(--accent);
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 240px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.menu-info { padding: 8px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu button, .menu a {
  display: block;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.menu button:hover, .menu a:hover { background: var(--hover); }
.menu a { color: inherit; text-decoration: none; font-size: 15px; }
.menu .danger { color: var(--danger); }

/* --- layout ---------------------------------------------------------- */

main { padding: 24px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 1fr);
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .topbar { padding: 10px 12px; }
}

h1, h2 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; margin-bottom: 16px; }

/* --- forms ----------------------------------------------------------- */

.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }

label { display: block; font-weight: 550; font-size: 13px; margin: 14px 0 6px; }
.stack label { margin: 0; }
.stack label input { margin-top: 6px; }

input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(42 171 238 / 20%);
}
textarea { resize: vertical; min-height: 110px; }

button.primary {
  width: 100%;
  margin-top: 18px;
  padding: 11px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s;
}
.stack button.primary { margin-top: 4px; }
button.primary:hover { background: var(--accent-strong); }
button.primary:disabled { opacity: .6; cursor: progress; }

button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  align-self: center;
}

.error {
  margin: 14px 0 0;
  padding: 10px 12px;
  color: var(--danger);
  background: rgb(229 72 77 / 10%);
  border-radius: 10px;
  font-size: 14px;
}

/* --- login ----------------------------------------------------------- */

.login { display: grid; place-items: center; min-height: calc(100vh - 140px); }
.login-card { width: min(440px, 100%); padding: 32px; }
.fineprint { font-size: 12px; color: var(--muted); margin: 24px 0 0; }

/* --- timetable ------------------------------------------------------ */

.timetable { padding: 20px 22px 12px; }
.timetable-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.timetable-head h2 { margin: 0; }
.timetable-head select { width: auto; min-width: 190px; font-weight: 600; }
.timetable-status { font-size: 12px; margin-top: 10px; }
.timetable-status button.link { font-size: 12px; }
.timetable-status .err, .err { color: var(--danger); }
.rule { font-size: 13px; margin: 8px 0 4px; }

.day h3 {
  margin: 18px 0 6px;
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.lessons { list-style: none; margin: 0; padding: 0; }
.lesson {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.lesson.past { opacity: .55; }
.pair {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--hover);
  font-weight: 650;
  font-size: 13px;
}
.lesson-title { font-weight: 600; overflow-wrap: anywhere; }
.lesson-meta { font-size: 13px; color: var(--muted); }
.lesson-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: baseline;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}
.lesson-line .countdown { font-size: 12px; }
.place {
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 600;
  color: var(--accent);
  background: rgb(42 171 238 / 12%);
}
.place.sent { color: var(--ok); background: rgb(48 164 108 / 12%); }
button.take {
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: 1px solid var(--accent);
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
button.take:hover { background: var(--accent); color: #fff; }

.join {
  grid-column: 1 / -1;
  margin-top: 8px;
  padding: 4px 14px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.join input:not([type="checkbox"]):not([type="radio"]), .join select { background: var(--card); }
.join-preview { font-size: 13px; margin: 12px 0 0; }
.join-preview code { font-family: var(--mono); padding: 1px 5px; border-radius: 6px; background: var(--card); border: 1px solid var(--border); }
.join-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.join-actions button.primary { width: auto; margin: 0; padding: 8px 16px; }
button.ghost {
  padding: 8px 14px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
button.ghost:hover { background: var(--card); }

.combo { position: relative; }
.combo-list {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 300px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.combo-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.combo-list li[aria-selected="true"], .combo-list li:hover { background: var(--hover); }
.combo-list .avatar { width: 28px; height: 28px; font-size: 12px; }
.combo-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-list .kind { font-size: 11px; color: var(--muted); }
.combo-list .hint { color: var(--muted); font-size: 13px; cursor: default; }

/* --- queue ----------------------------------------------------------- */

.queue { min-height: 300px; }
.queue-head { padding: 12px 16px 0; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; }
.tabs button {
  padding: 10px 14px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-weight: 550;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  margin-left: 4px;
  font-size: 12px;
  border-radius: 999px;
  background: var(--hover);
}

.queue-list { list-style: none; margin: 0; padding: 0; }
.item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 4px 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: 0; }
.item .avatar { grid-row: span 4; width: 40px; height: 40px; font-size: 15px; }
.item-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-width: 0; }
.item-name { font-weight: 650; font-family: var(--mono); overflow-wrap: anywhere; }
.item-head .chat { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.item-sub { grid-column: 2 / 4; display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; font-size: 13px; color: var(--muted); }
.item-meta { grid-column: 2 / 4; font-size: 12px; color: var(--muted); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.item-meta .err { color: var(--danger); font-family: inherit; }
.item-actions { display: flex; gap: 6px; align-items: flex-start; }
.item-actions button {
  padding: 4px 10px;
  font-size: 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.item-actions button:hover { border-color: var(--danger); color: var(--danger); }

.when { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); white-space: nowrap; }
.countdown { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }

.badge {
  justify-self: end;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-radius: 999px;
  background: var(--hover);
  color: var(--muted);
}
.badge.pending { color: var(--accent); background: rgb(42 171 238 / 12%); }
.badge.sending { color: #fff; background: var(--accent); }
.badge.sent { color: var(--ok); background: rgb(48 164 108 / 12%); }
.badge.failed, .badge.missed { color: var(--danger); background: rgb(229 72 77 / 12%); }

.empty { padding: 48px 24px; text-align: center; margin: 0; }

@media (max-width: 560px) {
  #account-name { display: none; }
  .account-btn { padding: 4px; }
  .item { grid-template-columns: auto minmax(0, 1fr); padding: 14px; }
  .item .avatar { grid-row: span 5; }
  .item-sub, .item-meta { grid-column: 2; }
  .item-actions { grid-column: 2; grid-row: 5; margin-top: 6px; }
  .lesson { grid-template-columns: auto minmax(0, 1fr); }
  button.take { grid-column: 2; justify-self: start; }
  .timetable-head select { min-width: 0; }
}

/* --- toast ----------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--text);
  color: var(--card);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 50;
}

/* --- forms (admin: schedule a message) --------------------------------- */

.row-label { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-label select { width: auto; padding: 4px 8px; font-size: 13px; font-weight: 400; }
.counter { text-align: right; font-size: 12px; margin-top: 4px; }
.counter.over { color: var(--danger); }
#when-input { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips button {
  padding: 4px 10px;
  font-size: 12px;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.when-preview { font-size: 12px; margin-top: 6px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.options { border: 0; padding: 0; margin: 16px 0 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: 14px; margin: 8px 0; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }

/* --- admin ----------------------------------------------------------- */

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  vertical-align: middle;
  border-radius: 999px;
  color: var(--accent);
  background: rgb(42 171 238 / 12%);
}
a.account-btn.back { margin-left: 0; padding: 6px 12px; font-size: 14px; color: inherit; text-decoration: none; }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

.admin { display: flex; flex-direction: column; gap: 24px; max-width: 1280px; margin: 0 auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat { padding: 14px 18px; min-width: 0; }
.stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat-value { margin-top: 4px; font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value .countdown { font-size: 22px; }
.stat-sub { margin-top: 2px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.admin-cols { display: grid; grid-template-columns: minmax(320px, 440px) minmax(0, 1fr); gap: 24px; align-items: start; }
.admin-col { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
@media (max-width: 960px) { .admin-cols { grid-template-columns: 1fr; } }
.compose, .settings, .timetable-admin, .users { padding: 20px 22px 22px; }
.compose h2, .settings h2, .users h2 { margin-bottom: 4px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2 { margin: 0; }
.settings .check { margin: 12px 0 0; }

.queue-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.queue-head select { width: auto; margin-bottom: 8px; padding: 4px 8px; font-size: 13px; }
.item-user { font-weight: 600; }
.item-text {
  grid-column: 2 / 4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.table { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: 14px; }
.table th { padding: 6px 8px; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }
.table td { padding: 8px; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; }
.table a { color: inherit; }
.user-cell { display: flex; gap: 10px; align-items: center; }
.user-cell .avatar { width: 30px; height: 30px; font-size: 12px; }
button.small { padding: 4px 10px; font-size: 12px; border-radius: 8px; }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); background: rgb(229 72 77 / 8%); }

.denied { max-width: 520px; margin: 60px auto; padding: 28px; }
.primary-link { color: var(--accent); font-weight: 600; }

@media (max-width: 560px) {
  .item-text { grid-column: 2; }
  .table th:nth-child(4), .table td:nth-child(4) { display: none; }
}
