/* Captain Cal — shadcn/ui-flavored tokens, light + dark */

:root {
  --background: #ffffff;
  --foreground: #0a0a0a;
  --card: #ffffff;
  --muted: #f5f5f5;
  --muted-foreground: #6b7280;
  --border: #e5e7eb;
  --primary: #0a0a0a;
  --primary-foreground: #fafafa;
  --accent: #2563eb;
  --ring: #2563eb;
  --danger: #dc2626;
  --radius: 0.5rem;
  --grid-line: #ececec;
  --now-line: #ea4335;
  --hour-h: 3rem; /* height of one hour row */
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: #0a0a0a;
    --foreground: #e5e7eb;
    --card: #111214;
    --muted: #16181c;
    --muted-foreground: #9ca3af;
    --border: #262626;
    --primary: #e5e7eb;
    --primary-foreground: #0a0a0a;
    --accent: #60a5fa;
    --ring: #60a5fa;
    --grid-line: #1f2023;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* our display:flex rules must not defeat the hidden attribute */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--background);
  color: var(--foreground);
  overscroll-behavior: none;
}
button { font: inherit; }
.muted { color: var(--muted-foreground); }

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

#app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; letter-spacing: -0.02em; }
.brand-icon { font-size: 1.2rem; }
.nav-controls { display: flex; align-items: center; gap: 0.25rem; }
.range-label { font-size: 1.05rem; font-weight: 600; margin-left: 0.5rem; white-space: nowrap; text-transform: capitalize; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
.tabs { display: flex; gap: 0.25rem; background: var(--muted); border-radius: var(--radius); padding: 0.2rem; }
.tab {
  border: 0; background: transparent; color: var(--muted-foreground);
  padding: 0.3rem 0.7rem; border-radius: calc(var(--radius) - 0.15rem); cursor: pointer;
  min-height: 2rem;
}
.tab.active { background: var(--card); color: var(--foreground); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.user-chip { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }
.avatar { width: 1.75rem; height: 1.75rem; border-radius: 50%; }

/* ---------- buttons / inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius); border: 1px solid transparent;
  padding: 0.4rem 0.9rem; min-height: 2.5rem; min-width: 2.5rem;
  background: transparent; color: var(--foreground); cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { opacity: 0.9; }
.btn-outline { border-color: var(--border); }
.btn-outline:hover { background: var(--muted); }
.btn-ghost:hover { background: var(--muted); }
.btn-icon { font-size: 1.3rem; padding: 0.2rem 0.6rem; }
.btn-sm { min-height: 2rem; padding: 0.2rem 0.6rem; font-size: 0.85rem; }
.btn-danger { color: var(--danger); }

.input {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--foreground);
  padding: 0.4rem 0.6rem; min-height: 2.5rem; font: inherit;
}
.input:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }

/* ---------- calendar grid ---------- */

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.cal-scroll { flex: 1; overflow: auto; }
.cal-inner { min-width: 100%; width: fit-content; display: flex; flex-direction: column; }

.cal-head {
  position: sticky; top: 0; z-index: 20;
  display: flex; background: var(--background);
  border-bottom: 1px solid var(--border);
}
.cal-gutter-head {
  width: 3.5rem; flex: none;
  position: sticky; left: 0; z-index: 21; background: var(--background);
}
.day-heads { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); flex: 1; min-width: 38.5rem; }
.day-head {
  text-align: center; padding: 0.4rem 0 0.5rem; user-select: none;
  border-left: 1px solid var(--grid-line);
  min-width: 0; overflow: hidden;
}
.day-head .dow { font-size: 0.68rem; letter-spacing: 0.08em; color: var(--muted-foreground); text-transform: uppercase; }
.day-head .num {
  font-size: 1.35rem; font-weight: 500; line-height: 1.6;
  width: 2.4rem; height: 2.4rem; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.day-head.today .num { background: var(--accent); color: #fff; }

/* per-day color summary chips under the date */
.day-chips {
  display: flex; flex-direction: column; align-items: stretch; gap: 0.15rem;
  padding: 0.25rem 0.3rem 0.1rem; min-height: 0.2rem;
}
.chip {
  display: flex; align-items: center; gap: 0.3rem;
  min-width: 0; max-width: 100%;
  border: 0; background: transparent; color: var(--muted-foreground);
  font-size: 0.68rem; line-height: 1.2; padding: 0.1rem 0.25rem;
  border-radius: 0.3rem; cursor: pointer; text-align: left;
}
.chip:hover { background: var(--muted); }
.chip:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.chip .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; flex: none; }
.day-total {
  font-size: 0.7rem; font-weight: 700; color: var(--foreground);
  padding: 0.1rem 0.25rem; text-align: left;
}
.chip .chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot-lg { display: inline-block; width: 0.9rem; height: 0.9rem; border-radius: 50%; vertical-align: -0.1rem; }
.label-hint { font-size: 0.8rem; margin: 0.2rem 0 0.6rem; }
.label-input { width: 100%; }

.cal-body { display: flex; }
.time-gutter {
  width: 3.5rem; flex: none;
  position: sticky; left: 0; z-index: 12; background: var(--background);
  height: calc(24 * var(--hour-h));
}
.time-label {
  position: absolute; right: 0.5rem; transform: translateY(-50%);
  font-size: 0.68rem; color: var(--muted-foreground); user-select: none;
}
.day-cols { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); flex: 1; min-width: 38.5rem; }
.day-col {
  position: relative; border-left: 1px solid var(--grid-line);
  height: calc(24 * var(--hour-h));
}
.day-col.today { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.hour-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--grid-line); pointer-events: none; }

.now-line {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 2px solid var(--now-line); z-index: 5; pointer-events: none;
}
.now-line::before {
  content: ""; position: absolute; left: -0.3rem; top: -0.35rem;
  width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--now-line);
}

/* ---------- events ---------- */

.event {
  position: absolute; z-index: 2;
  border-radius: 0.375rem;
  color: #fff; font-size: 0.78rem; line-height: 1.25;
  padding: 0.2rem 0.45rem;
  overflow: hidden; cursor: grab; user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  touch-action: none;
}
.event .ev-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event .ev-time { opacity: 0.9; font-size: 0.7rem; white-space: nowrap; }
.event.short { padding-top: 0.05rem; }
.event.short .ev-time { display: none; }
.event.recurring .ev-title::after { content: " ⟳"; opacity: 0.8; font-weight: 400; }
.event.dragging { opacity: 0.75; z-index: 10; cursor: grabbing; box-shadow: 0 6px 16px rgba(0,0,0,0.3); }
.event.ghost { opacity: 0.6; pointer-events: none; z-index: 9; border-style: dashed; }

.resize-handle {
  position: absolute; left: 0; right: 0; height: 0.45rem; cursor: ns-resize; z-index: 3;
}
.resize-handle.top { top: -0.1rem; }
.resize-handle.bottom { bottom: -0.1rem; }

/* ---------- dialogs ---------- */

.backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.dialog {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 0.75rem; box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  padding: 1.1rem 1.2rem; width: 100%; max-width: 26rem;
  max-height: 90dvh; overflow: auto;
}
.dialog-sm { max-width: 20rem; }
.dialog h3 { margin: 0 0 0.8rem; font-size: 1.05rem; }
.ed-title {
  width: 100%; border: 0; border-bottom: 2px solid var(--border);
  background: transparent; color: var(--foreground);
  font-size: 1.25rem; font-weight: 600; padding: 0.3rem 0.1rem; margin-bottom: 0.9rem;
}
.ed-title:focus { outline: none; border-bottom-color: var(--ring); }
.ed-row { display: flex; align-items: center; gap: 0.5rem; margin: 0.55rem 0; flex-wrap: wrap; }
.ed-label { width: 3.6rem; flex: none; font-size: 0.85rem; color: var(--muted-foreground); }
.ed-dash { color: var(--muted-foreground); }
.ed-hint { font-size: 0.75rem; }
.input-time { min-width: 6rem; }
.ed-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 1rem; }
.ed-actions .spacer { flex: 1; }
.ed-actions-col { flex-direction: column; align-items: stretch; }

.color-swatches { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.swatch {
  width: 1.6rem; height: 1.6rem; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; padding: 0;
}
.swatch.selected { border-color: var(--foreground); box-shadow: 0 0 0 2px var(--card) inset; }
.swatch:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ---------- access view ---------- */

.access-wrap { max-width: 46rem; margin: 0 auto; padding: 1.5rem 1rem; width: 100%; overflow-y: auto; }
.access-wrap h2 { margin: 0 0 0.3rem; }
.users-h { margin: 1.6rem 0 0.2rem; }
.grant-form {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.7rem 0.8rem; margin: 1rem 0; background: var(--card);
}
.grant-form .input { max-width: 14rem; }
.users-list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.user-row {
  display: flex; align-items: center; gap: 0.7rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.6rem 0.8rem; background: var(--card); flex-wrap: wrap;
}
.user-row .avatar { width: 2.2rem; height: 2.2rem; }
.user-row .u-info { display: flex; flex-direction: column; min-width: 0; }
.user-row .u-name { font-weight: 600; }
.user-row .u-email { font-size: 0.82rem; color: var(--muted-foreground); word-break: break-all; }
.user-row .u-actions { margin-left: auto; display: flex; gap: 0.4rem; flex-wrap: wrap; }
.badge {
  font-size: 0.7rem; font-weight: 600; padding: 0.12rem 0.5rem; border-radius: 999px;
  border: 1px solid var(--border); color: var(--muted-foreground);
}
.badge.granted { color: #16a34a; border-color: #16a34a55; }
.badge.pending { color: #d97706; border-color: #d9770655; }
.badge.revoked { color: var(--danger); border-color: #dc262655; }
.badge.role { color: var(--accent); border-color: transparent; background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ---------- misc ---------- */

.center-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--background); padding: 1rem; z-index: 40;
}
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 0.75rem;
  padding: 1.5rem; max-width: 24rem; text-align: center;
}
.card h2 { margin-top: 0; }

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: var(--primary-foreground);
  padding: 0.6rem 1rem; border-radius: var(--radius); font-size: 0.9rem;
  z-index: 100; box-shadow: 0 4px 14px rgba(0,0,0,0.25); max-width: 90vw;
}

/* ---------- mobile ---------- */

@media (max-width: 700px) {
  .topbar { gap: 0.5rem; padding: 0.4rem 0.6rem; }
  .range-label { font-size: 0.9rem; }
  .brand-name { display: none; }
  #user-name { display: none; }
}
