/* Agenda — single stylesheet. No external fonts or assets: everything is
   same-origin so the CSP can stay locked down and nothing phones home. */

:root {
  --bg: #0e1116;
  --bg-soft: #151a21;
  --panel: #171d26;
  --panel-2: #1d242f;
  --line: #262f3d;
  --line-soft: #1f2733;
  --text: #e6eaf2;
  --text-dim: #93a0b4;
  --text-faint: #64718a;
  --accent: #6366f1;
  --accent-soft: #6366f133;
  --danger: #f43f5e;
  --ok: #22c55e;
  --warn: #f59e0b;
  --gate-glow: #1b2434;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  --radius: 12px;
  --hour-h: 52px;
  --gutter-w: 58px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb;
    --bg-soft: #eef1f7;
    --panel: #ffffff;
    --panel-2: #f2f4f9;
    --line: #dde2ec;
    --line-soft: #e8ecf3;
    --text: #18202e;
    --text-dim: #5a6779;
    --text-faint: #8b96a8;
    --gate-glow: #e3e8f6;
    --shadow: 0 12px 32px rgba(20, 30, 55, .12);
  }
}

* { box-sizing: border-box; }

/* Every `display:` rule below would otherwise beat the `hidden` attribute,
   leaving the lock overlay sitting invisibly on top of the app. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
.spacer { flex: 1 1 auto; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------- buttons -- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
  white-space: nowrap;
}
.btn:hover { background: var(--line-soft); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: #f43f5e66; color: var(--danger); }
.btn-danger:hover { background: #f43f5e1a; }
.btn-block { width: 100%; padding: 11px; margin-top: 4px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 9px;
  border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text-dim);
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm .ic { width: 16px; height: 16px; }
.icon-btn.danger:hover { color: var(--danger); background: #f43f5e1a; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* -------------------------------------------------------------- fields -- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; letter-spacing: .01em; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); outline: none; }
.field.compact { margin-bottom: 8px; }
.field textarea { resize: vertical; }
.checkline { display: flex; align-items: center; gap: 9px; margin: 6px 0 14px; cursor: pointer; font-size: 14px; }
.checkline input { width: 17px; height: 17px; accent-color: var(--accent); }
.row { display: grid; grid-template-columns: 1fr 130px; gap: 10px; }
.hint { font-size: 12.5px; color: var(--text-dim); margin: 0 0 10px; }
hr { border: none; border-top: 1px solid var(--line); margin: 20px 0 16px; }

/* ---------------------------------------------------------------- gate -- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1100px 600px at 50% -10%, var(--gate-glow) 0%, var(--bg) 60%);
}
.gate-card {
  width: 100%; max-width: 390px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 18px; padding: 30px 26px 22px;
  box-shadow: var(--shadow); text-align: left;
}
.gate-logo { color: var(--accent); display: flex; justify-content: center; margin-bottom: 10px; }
.gate-card h1 { margin: 0 0 6px; font-size: 23px; text-align: center; letter-spacing: -.01em; }
.gate-sub { margin: 0 0 20px; color: var(--text-dim); font-size: 13.5px; text-align: center; }
.gate-error { color: var(--danger); font-size: 13px; margin: 4px 0 10px; }
.gate-ok { color: var(--ok); font-size: 13px; margin: 4px 0 10px; }
.gate-warn {
  font-size: 12px; color: var(--warn); background: #f59e0b12;
  border: 1px solid #f59e0b33; border-radius: 9px; padding: 9px 11px; margin: 14px 0 0;
}
.gate-foot { font-size: 11px; color: var(--text-faint); text-align: center; margin: 16px 0 0; }
.gate.busy { pointer-events: none; }
.gate.busy .gate-card { opacity: .6; }

.strength { display: flex; align-items: center; gap: 9px; margin: -4px 0 12px; }
.strength-bar { flex: 1; height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.strength-bar i { display: block; height: 100%; width: 0; background: var(--danger); transition: width .2s, background .2s; }
.strength span { font-size: 11.5px; color: var(--text-dim); min-width: 56px; }

/* ----------------------------------------------------------------- app -- */
.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  height: var(--topbar-h); padding: 0 12px; flex: 0 0 auto;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -.01em; }
.brand-ic { color: var(--accent); }
.nav-group { display: flex; align-items: center; gap: 4px; margin-left: 10px; }
.range-label { font-size: 15px; font-weight: 550; margin: 0 0 0 8px; color: var(--text); white-space: nowrap; }

.seg { display: flex; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg-btn { border: none; background: transparent; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--text-dim); }
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

.save-status { font-size: 11.5px; color: var(--text-faint); min-width: 62px; text-align: right; }
.save-status.err { color: var(--danger); }
.save-status.ok { color: var(--text-faint); }

.body { display: flex; flex: 1 1 auto; min-height: 0; }

/* ------------------------------------------------------------- sidebar -- */
.sidebar {
  width: 252px; flex: 0 0 auto; border-right: 1px solid var(--line);
  background: var(--panel); padding: 14px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
}
.side-block { display: flex; flex-direction: column; gap: 6px; }
.side-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); margin: 0 0 6px; font-weight: 600; }
.side-foot { margin-top: auto; font-size: 11px; color: var(--text-faint); }

.mini-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.mini-head span { font-size: 13px; font-weight: 600; text-transform: capitalize; }
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.mini-dow { font-size: 10px; color: var(--text-faint); text-align: center; padding: 3px 0; text-transform: uppercase; }
.mini-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 12px; border-radius: 7px; cursor: pointer; border: none; background: transparent; color: var(--text);
  position: relative;
}
.mini-day:hover { background: var(--panel-2); }
.mini-day.out { color: var(--text-faint); opacity: .55; }
.mini-day.today { color: var(--accent); font-weight: 700; }
.mini-day.sel { background: var(--accent); color: #fff; font-weight: 600; }
.mini-day.has::after {
  content: ''; position: absolute; bottom: 3px; width: 3px; height: 3px;
  border-radius: 50%; background: var(--accent);
}
.mini-day.sel.has::after { background: #fff; }

.search-results, .upcoming { display: flex; flex-direction: column; gap: 4px; }
.res-item {
  text-align: left; border: none; background: transparent; cursor: pointer;
  padding: 6px 8px; border-radius: 8px; border-left: 3px solid var(--accent);
  display: flex; flex-direction: column; gap: 1px;
}
.res-item:hover { background: var(--panel-2); }
.res-title { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-when { font-size: 11px; color: var(--text-dim); }
.res-empty { font-size: 12px; color: var(--text-faint); padding: 4px 2px; }

/* -------------------------------------------------------------- grid ---- */
.cal { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

.cal-head {
  display: grid; flex: 0 0 auto; border-bottom: 1px solid var(--line);
  background: var(--panel); padding-right: var(--sbw, 0px);
}
.day-head { padding: 7px 4px 6px; text-align: center; border-left: 1px solid var(--line-soft); }
.day-head:first-child { border-left: none; }
.dh-dow { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.dh-num {
  font-size: 20px; font-weight: 600; margin-top: 1px; line-height: 1.25;
  width: 32px; height: 32px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; cursor: pointer;
}
.day-head.today .dh-dow { color: var(--accent); }
.day-head.today .dh-num { background: var(--accent); color: #fff; }

.allday {
  display: grid; flex: 0 0 auto; border-bottom: 1px solid var(--line);
  background: var(--panel); min-height: 26px; max-height: 92px; overflow-y: auto;
  padding-right: var(--sbw, 0px);
}
.allday-gutter { font-size: 10px; color: var(--text-faint); text-align: right; padding: 5px 6px 0 0; }
.allday-col { border-left: 1px solid var(--line-soft); padding: 3px; display: flex; flex-direction: column; gap: 2px; min-height: 26px; }
.ad-chip {
  font-size: 11.5px; padding: 2px 7px; border-radius: 6px; cursor: pointer;
  color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.cal-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; position: relative; }
.cal-body { display: grid; position: relative; }

.time-gutter { position: relative; }
.time-label {
  position: absolute; right: 7px; font-size: 10.5px; color: var(--text-faint);
  transform: translateY(-50%); user-select: none;
}
.day-col { position: relative; border-left: 1px solid var(--line-soft); }
.day-col.weekend { background: rgba(127, 140, 170, .035); }
.hour-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line-soft); pointer-events: none; }
.hour-line.half { border-top-style: dotted; opacity: .5; }

.now-line { position: absolute; left: 0; right: 0; height: 0; border-top: 2px solid var(--danger); z-index: 6; pointer-events: none; }
.now-line::before {
  content: ''; position: absolute; left: -5px; top: -5px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--danger);
}

.ev {
  position: absolute; border-radius: 7px; padding: 3px 7px; overflow: hidden;
  color: #fff; cursor: grab; font-size: 12px; line-height: 1.3; z-index: 3;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25); touch-action: none;
  border: 1px solid rgba(255, 255, 255, .14);
}
.ev:hover { filter: brightness(1.1); z-index: 5; }
.ev.dragging { opacity: .85; cursor: grabbing; z-index: 20; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); }
.ev-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-time { font-size: 10.5px; opacity: .88; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Sub-hour blocks have no room for two stacked lines. */
.ev.short { padding: 1px 6px; display: flex; gap: 6px; align-items: baseline; line-height: 1.15; }
.ev.short .ev-title { font-size: 11px; flex: 0 1 auto; }
.ev.short .ev-time { font-size: 10px; flex: 0 0 auto; white-space: nowrap; }
.ev.tiny { padding: 0 6px; font-size: 10px; align-items: center; }
.ev.tiny .ev-time { display: none; }
.ev-handle { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; cursor: ns-resize; }
.ev-rec { position: absolute; right: 4px; top: 3px; opacity: .75; font-size: 10px; }

.ghost {
  position: absolute; border-radius: 7px; background: var(--accent-soft);
  border: 1.5px dashed var(--accent); z-index: 4; pointer-events: none;
  font-size: 11px; color: var(--text); padding: 2px 6px;
}

/* ------------------------------------------------------------- dialogs -- */
.dlg {
  border: 1px solid var(--line); border-radius: 16px; background: var(--panel);
  color: var(--text); padding: 0; width: min(520px, calc(100vw - 24px));
  box-shadow: var(--shadow); max-height: min(88vh, 860px);
}
.dlg::backdrop { background: rgba(5, 8, 14, .6); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dlg-head h3 { margin: 0; font-size: 16px; flex: 1; }
.dlg-body { padding: 16px; overflow-y: auto; max-height: calc(88vh - 128px); }
.dlg-foot { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.sel { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 200;
  font-size: 13.5px; max-width: min(92vw, 460px);
}
.toast.err { border-color: #f43f5e66; color: #ffdfe5; background: #4c1020; }
.toast.warn { border-color: #f59e0b66; background: #3d2c08; color: #ffeccd; }

.only-mobile { display: none; }

/* -------------------------------------------------------------- mobile -- */
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .brand span, .range-label { display: none; }
  .sidebar {
    position: fixed; z-index: 50; top: var(--topbar-h); bottom: 0; left: 0; width: 264px;
    transform: translateX(-100%); transition: transform .18s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .topbar { gap: 4px; padding: 0 6px; }
  .nav-group { margin-left: 0; }
  .save-status { display: none; }
  :root { --gutter-w: 46px; --hour-h: 48px; }
}

@media (max-width: 560px) {
  .row { grid-template-columns: 1fr 110px; }
  .seg-btn { padding: 6px 10px; font-size: 14px; }
}

@media print { body { display: none; } }
