:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #6b7280; --line: #e5e7eb;
  --primary: #2563eb; --primary-text: #fff; --ok: #15803d; --ok-bg: #dcfce7; --err: #b91c1c; --err-bg: #fee2e2;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1218; --card: #181c25; --text: #e7e9ee; --muted: #9aa1ad; --line: #2a303c;
    --primary: #3b82f6; --ok: #4ade80; --ok-bg: #14321f; --err: #f87171; --err-bg: #3a1717; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 640px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 380px; }
.center { text-align: center; padding-top: 12vh; }
h1 { font-size: 1.7rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: .9rem; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.who { color: var(--muted); font-size: .9rem; }
.inline { display: inline; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin: 16px 0; }
.credit { background: var(--primary); color: var(--primary-text); border-radius: 14px; padding: 18px; text-align: center; }
.credit.low { background: var(--err); }
.credit-num { font-size: 3rem; font-weight: 700; line-height: 1; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row.small { font-size: .9rem; }
.when { font-weight: 600; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 10px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 1rem; }
input, select { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); }
input[type=checkbox] { width: 22px; height: 22px; margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2.add { margin-top: 12px; grid-template-columns: 1fr 1fr auto; align-items: end; }
.grid2.add input { margin: 0; }
@media (max-width: 480px) { .grid2.add { grid-template-columns: 1fr; } }
button, .btn { font: inherit; cursor: pointer; }
.btn { display: inline-block; border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 600;
  background: var(--primary); color: var(--primary-text); text-decoration: none; white-space: nowrap; }
.btn-big { display: block; width: 100%; padding: 14px; font-size: 1.05rem; text-align: center; margin-top: 8px; }
.btn-ghost { background: transparent; color: var(--err); border: 1px solid var(--line); }
.link { background: none; border: 0; color: var(--primary); padding: 0 0 0 6px; }
.flash { padding: 12px 14px; border-radius: 10px; margin: 0 0 12px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.tag { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); font-weight: 500; }
.tag.completed, .tag.sent { background: var(--ok-bg); color: var(--ok); }
.tag.cancelled, .tag.failed { background: var(--err-bg); color: var(--err); }
form.card { margin-top: 24px; }

/* Week calendar */
:root { --row: 22px; --mine: #2563eb; --mine-bg: #dbeafe; --other: #94a3b8; --other-bg: #f1f5f9; --done: #15803d; --done-bg: #dcfce7; --today: #fff7ed; }
@media (prefers-color-scheme: dark) {
  :root { --mine: #60a5fa; --mine-bg: #1e3a5f; --other: #94a3b8; --other-bg: #263041; --done: #4ade80; --done-bg: #14321f; --today: #2a2216; }
}
main { max-width: 860px; }
.cal-card { padding: 12px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.cal-nav .btn { font-size: 1.4rem; padding: 4px 14px; line-height: 1.2; }
.cal-title { text-align: center; }
.small-link { font-size: .85rem; color: var(--primary); }
.cal { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.cal-head, .cal-body { display: grid; grid-template-columns: 40px repeat(7, minmax(0, 1fr)); }
.cal-head { border-bottom: 1px solid var(--line); background: var(--card); }
.dh { text-align: center; font-size: .75rem; font-weight: 600; padding: 6px 0; color: var(--muted); }
.dh.today { color: var(--primary); }
.cal-body { max-height: 62vh; overflow-y: auto; position: relative; }
.times div { height: calc(var(--row) * 2); font-size: .65rem; color: var(--muted); text-align: right; padding-right: 4px; transform: translateY(-6px); }
.times div:first-child { transform: none; }
.day { position: relative; border-left: 1px solid var(--line); }
.day.today { background: var(--today); }
.slot { display: block; width: 100%; height: var(--row); border: 0; border-top: 1px solid transparent; background: transparent; padding: 0; margin: 0; }
.slot:nth-child(odd) { border-top-color: var(--line); }
.slot.free { cursor: pointer; }
.slot.free:hover, .slot.free:focus-visible { background: var(--mine-bg); outline: none; }
.lesson { position: absolute; left: 2px; right: 2px; border: 0; border-left: 3px solid var(--other); border-radius: 5px;
  background: var(--other-bg); color: var(--text); font: inherit; font-size: .68rem; line-height: 1.15; padding: 2px 3px;
  text-align: left; overflow: hidden; cursor: pointer; z-index: 1; }
.lesson.mine { border-left-color: var(--mine); background: var(--mine-bg); }
.lesson.completed { border-left-color: var(--done); background: var(--done-bg); }
.lesson .lt { font-weight: 700; display: block; }
.lesson .ln { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 8px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sw.mine { background: var(--mine); } .sw.other { background: var(--other); } .sw.done { background: var(--done); }
.btn-ghost.neutral { color: var(--text); }

dialog { border: 0; border-radius: 16px; padding: 20px; width: min(92vw, 380px); background: var(--card); color: var(--text);
  box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin: 0 0 4px; }
dialog .when { font-weight: 600; margin: 0 0 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.dlg-stack { display: grid; gap: 8px; }
.dlg-stack .btn-big { margin: 0; }
[hidden] { display: none !important; }
@media (max-width: 480px) {
  main { padding: 10px; }
  .cal-head, .cal-body { grid-template-columns: 32px repeat(7, minmax(0, 1fr)); }
  .lesson .ln { display: none; }
  .dh { font-size: .68rem; }
}
