:root {
  --bg: #0e1116;
  --bg-2: #161b23;
  --bg-3: #1e2530;
  --line: #2a3342;
  --text: #e8edf4;
  --text-dim: #8b97a8;
  --accent: #4f8cff;
  --green: #2ecc8f;
  --green-dim: #14342a;
  --red: #ff5d5d;
  --red-dim: #3a1d22;
  --gray: #5b6573;
  --gray-dim: #232a35;
  --amber: #ffb74d;
  --radius: 12px;
  --tabbar-h: 56px;
  --sa-b: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2332 0%, var(--bg) 60%);
  padding: 24px; z-index: 100;
}
.login-card { width: 100%; max-width: 360px; }
.logo {
  font-size: 34px; font-weight: 800; letter-spacing: 2px; text-align: center;
}
.logo span { color: var(--accent); }
.login-sub { text-align: center; color: var(--text-dim); margin: 6px 0 28px; font-size: 14px; }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; text-align: center; }

/* ── Fields & buttons ──────────────────────────── */
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; font-size: 16px;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  outline: none;
}
.field input:focus { border-color: var(--accent); }

.btn {
  padding: 12px 18px; font-size: 15px; font-weight: 600;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; transition: filter .15s;
}
.btn:active { filter: brightness(1.25); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-green { background: var(--green); border-color: var(--green); color: #06281c; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.hint { font-size: 12px; color: var(--text-dim); margin: 10px 0; line-height: 1.5; }

/* ── App layout ────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100dvh; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; gap: 8px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.week-nav { display: flex; align-items: center; gap: 2px; }
.week-label { font-size: 13px; font-weight: 700; min-width: 116px; text-align: center; }
.icon-btn {
  width: 34px; height: 34px; font-size: 18px; line-height: 1;
  background: transparent; color: var(--text);
  border: none; border-radius: 50%; cursor: pointer;
}
.icon-btn:active { background: var(--bg-3); }
.icon-btn:disabled { opacity: .3; pointer-events: none; }
.icon-btn.spinning { animation: spin 1s linear infinite; }

.top-actions { display: flex; align-items: center; gap: 6px; }
.chip {
  padding: 6px 12px; font-size: 12px; font-weight: 600;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.active { border-color: var(--accent); color: var(--accent); }

main { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#view-my, #view-settings { overflow-y: auto; padding: 14px 14px calc(var(--tabbar-h) + var(--sa-b) + 14px); display: block; }

/* ── Calendar ──────────────────────────────────── */
#view-calendar { padding-bottom: 0; }

.cal-head { display: flex; flex-shrink: 0; background: var(--bg-2); }
.cal-head-gutter { width: 28px; flex-shrink: 0; }
.cal-days { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-day-h {
  text-align: center; padding: 4px 0 5px; font-size: 11px; color: var(--text-dim);
  border-left: 1px solid var(--line);
}
.cal-day-h b { display: block; font-size: 13px; color: var(--text); font-weight: 700; }
.cal-day-h.today { color: var(--accent); }
.cal-day-h.today b {
  color: #fff; background: var(--accent); border-radius: 50%;
  width: 22px; height: 22px; line-height: 22px; margin: 0 auto;
}

.cal-body { flex: 1; min-height: 0; position: relative; display: flex; }
.cal-times { width: 28px; flex-shrink: 0; position: relative; }
.cal-time {
  position: absolute; right: 4px; transform: translateY(-50%);
  font-size: 9px; color: var(--text-dim);
}
.cal-cols { flex: 1; display: grid; grid-template-columns: repeat(7, 1fr); position: relative; }
.cal-col { position: relative; border-left: 1px solid var(--line); }
.cal-col.today { background: rgba(79, 140, 255, .05); }
.cal-hline {
  position: absolute; left: 0; right: 0; height: 1px;
  background: var(--line); opacity: .45; pointer-events: none;
}
.cal-now {
  position: absolute; left: 0; right: 0; height: 2px; background: var(--red);
  z-index: 5; pointer-events: none;
}
.cal-now::before {
  content: ''; position: absolute; left: -3px; top: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--red);
}

/* Event chips */
.ev {
  position: absolute; left: 1px; right: 1px;
  border-radius: 5px; padding: 2px 3px;
  font-size: 9px; line-height: 1.25; overflow: hidden; cursor: pointer;
  border: 1px solid transparent;
  display: flex; flex-direction: column;
}
.ev .ev-time { font-weight: 700; font-size: 8.5px; opacity: .9; white-space: nowrap; }
.ev .ev-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ev .ev-coach { opacity: .75; font-size: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.ev-free   { background: var(--green-dim); border-color: rgba(46, 204, 143, .55); color: #bfeedd; }
.ev-full   { background: var(--red-dim);   border-color: rgba(255, 93, 93, .4);   color: #f0b9bd; }
.ev-past   { background: var(--gray-dim);  border-color: var(--line);             color: var(--gray); }
.ev-reg    { outline: 2px solid var(--accent); outline-offset: -1px; }
.ev-badges { position: absolute; top: 1px; right: 2px; font-size: 8px; display: flex; gap: 1px; }
.ev-spark {
  position: absolute; left: 0; bottom: 0; width: 100%; height: 9px;
  opacity: .45; pointer-events: none;
}

/* Loading overlay */
.cal-loading {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(14, 17, 22, .8); backdrop-filter: blur(2px);
  font-size: 13px; color: var(--text-dim);
}
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Lists (Mano) ──────────────────────────────── */
.list-section { margin-bottom: 22px; }
.list-section h2 { font-size: 14px; color: var(--text-dim); font-weight: 700; margin-bottom: 10px; text-transform: uppercase; letter-spacing: .5px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 12px; display: flex; align-items: center; gap: 10px;
}
.list-item .li-main { flex: 1; min-width: 0; }
.li-title { font-size: 14px; font-weight: 700; }
.li-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.li-status { font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.st-pending { background: var(--gray-dim); color: var(--amber); }
.st-armed { background: var(--green-dim); color: var(--green); }
.st-success { background: var(--green-dim); color: var(--green); }
.st-failed, .st-session_expired { background: var(--red-dim); color: var(--red); }
.li-cancel {
  padding: 7px 12px; font-size: 12px; font-weight: 600;
  background: transparent; color: var(--red);
  border: 1px solid var(--red); border-radius: 8px; cursor: pointer; flex-shrink: 0;
}
.empty { color: var(--text-dim); font-size: 13px; padding: 14px 4px; }

/* ── Settings ──────────────────────────────────── */
.session-status { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot-unknown { background: var(--gray); }
.dot-ok { background: var(--green); }
.dot-bad { background: var(--red); }

.admin-tag {
  font-size: 9px; font-weight: 700; letter-spacing: .5px;
  background: var(--accent); color: #fff; padding: 2px 6px; border-radius: 4px;
  vertical-align: middle; margin-left: 6px;
}
#secrets-list { margin-top: 14px; }
.secret-item .li-title { font-family: ui-monospace, monospace; font-size: 13px; }
.secret-badge {
  font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
  background: var(--accent); color: #fff;
}
.secret-badge.has-session { background: var(--green); color: #06281c; }
.secret-badge.no-session { background: var(--gray-dim); color: var(--text-dim); }

/* ── Tabbar ────────────────────────────────────── */
#tabbar {
  display: flex; flex-shrink: 0;
  background: var(--bg-2); border-top: 1px solid var(--line);
  padding-bottom: var(--sa-b);
  height: calc(var(--tabbar-h) + var(--sa-b));
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--text-dim);
  font-size: 10px; font-weight: 600; cursor: pointer; position: relative;
}
.tab.active { color: var(--accent); }
.tab-icon { font-size: 17px; }
.badge {
  position: absolute; top: 6px; right: calc(50% - 22px);
  background: var(--accent); color: #fff; font-size: 9px; font-weight: 700;
  min-width: 15px; height: 15px; line-height: 15px; border-radius: 999px; text-align: center;
}

/* ── Bottom sheet ──────────────────────────────── */
#sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 200;
}
#sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 201;
  background: var(--bg-2); border-radius: 18px 18px 0 0;
  padding: 8px 18px calc(18px + var(--sa-b));
  max-height: 75dvh; overflow-y: auto;
  animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 38px; height: 4px; background: var(--line); border-radius: 2px; margin: 4px auto 14px; }
.sheet-title { font-size: 19px; font-weight: 800; margin-bottom: 2px; }
.sheet-coach { color: var(--text-dim); font-size: 14px; margin-bottom: 12px; }
.sheet-rows { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.sheet-row { display: flex; justify-content: space-between; font-size: 14px; }
.sheet-row .k { color: var(--text-dim); }
.sheet-row .v { font-weight: 600; text-align: right; }
.sheet-actions { display: flex; flex-direction: column; gap: 9px; }
.sheet-history { margin: 0 0 14px; }
.hist-title { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.sheet-history svg { width: 100%; height: 120px; display: block; background: var(--bg-3); border: 1px solid var(--line); border-radius: var(--radius); }
.v-free { color: var(--green); }
.v-full { color: var(--red); }
.v-past { color: var(--gray); }

/* ── Toast ─────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--sa-b) + 16px);
  transform: translateX(-50%); z-index: 300;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 18px; font-size: 13px; font-weight: 600;
  max-width: calc(100vw - 40px); text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
}
#toast.ok { border-color: var(--green); }
#toast.err { border-color: var(--red); }

/* Wider screens: cap width, center */
@media (min-width: 760px) {
  #app { max-width: 980px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .ev { font-size: 11px; padding: 3px 5px; }
  .ev .ev-time { font-size: 10px; }
  .ev .ev-coach { font-size: 10px; }
  .cal-times { width: 36px; }
  .cal-head-gutter { width: 36px; }
  #sheet { max-width: 520px; left: 50%; transform: translateX(-50%); border-radius: 18px 18px 0 0; }
}
