:root {
  --bg: #080a0f;
  --bg-card: rgba(18, 22, 32, 0.72);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f2f4f8;
  --muted: #8b95a8;
  --accent: #ff7a2f;
  --accent-2: #ff5c7a;
  --ok: #4ade9b;
  --radius: 16px;
  --nav-w: 220px;
  --font: "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 70% 50% at 10% -20%, rgba(255, 122, 47, 0.18), transparent 50%),
    radial-gradient(ellipse 50% 40% at 90% 10%, rgba(74, 222, 155, 0.08), transparent 45%),
    radial-gradient(ellipse 80% 60% at 50% 100%, rgba(255, 92, 122, 0.06), transparent 50%);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* Login */
.login-screen {
  position: relative;
  z-index: 400;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card {
  width: min(400px, 100%);
  padding: 2rem;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.login-card__logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #ffb347);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.4rem;
  color: #fff;
}

.login-card h1 { margin: 0 0 0.35rem; font-size: 1.35rem; }
.login-card__sub { margin: 0 0 1.5rem; color: var(--muted); font-size: 0.9rem; }

.login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  text-align: left;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.login-form input {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 1rem;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
}

.login-form input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-warn {
  text-align: left;
  font-size: 0.85rem;
  line-height: 1.45;
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  border-radius: 10px;
  background: rgba(255, 92, 122, 0.12);
  border: 1px solid rgba(255, 92, 122, 0.35);
  color: #ffb8c8;
}

.login-warn code {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.login-error {
  min-height: 1.25rem;
  color: var(--accent-2);
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
}

/* Shell layout */
.shell {
  display: flex;
  min-height: 100vh;
}

.nav {
  width: var(--nav-w);
  flex-shrink: 0;
  padding: 1.25rem 0.75rem;
  border-right: 1px solid var(--border);
  background: rgba(12, 14, 20, 0.6);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.nav__brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 0.5rem 1.25rem;
}

.nav__logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #ffb347);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
}

.nav__title { font-weight: 700; font-size: 0.95rem; }

.nav__links { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }

.nav__link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav__link:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }

.nav__link--active {
  background: rgba(255, 122, 47, 0.12);
  color: var(--accent);
  border: 1px solid rgba(255, 122, 47, 0.2);
}

.nav__icon { opacity: 0.7; font-size: 0.75rem; }

.nav__foot { padding: 0.5rem; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem 1.5rem;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toolbar__left, .toolbar__right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.toolbar__studio {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.toolbar__studio select {
  min-width: 160px;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  font-size: 0.88rem;
}

.range-pills {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
}

.pill {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.4rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
}

.pill--active { background: var(--accent); color: #fff; }

.chip {
  font-size: 0.72rem;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--muted);
}

.chip--accent { color: var(--accent); border-color: rgba(255, 122, 47, 0.3); }

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.status-chip__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.status-chip--ok .status-chip__dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.status-chip--ok { color: var(--ok); }
.status-chip--err .status-chip__dot { background: var(--accent-2); }
.status-chip--err { color: var(--accent-2); }

.toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
}

.toggle input { accent-color: var(--accent); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, filter 0.15s;
}

.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn--ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn--ghost:hover { color: var(--text); }
.btn--sm { padding: 0.35rem 0.6rem; font-size: 0.78rem; }
.btn--lg { width: 100%; padding: 0.75rem; }

/* Toast */
.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  border: 1px solid;
}

.toast--error { background: rgba(255, 92, 122, 0.1); border-color: rgba(255, 92, 122, 0.35); color: #ffb8c8; }
.toast--info { background: rgba(255, 122, 47, 0.1); border-color: rgba(255, 122, 47, 0.3); color: #ffd0b0; }
.toast__x { background: none; border: none; color: inherit; font-size: 1.2rem; cursor: pointer; }

/* Pages */
.pages { flex: 1; }

.page { display: none; animation: fadeIn 0.25s ease; }
.page--active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.page-intro {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.page-intro code {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

/* Hero */
.hero-card {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  padding: 1.5rem;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  margin-bottom: 1rem;
}

.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom));
  background: rgba(12, 14, 20, 0.92);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  justify-content: space-around;
  z-index: 50;
}

.mobile-nav__link {
  color: var(--muted);
  text-decoration: none;
  font-size: 1.1rem;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
}

.mobile-nav__link--active { color: var(--accent); background: rgba(255, 122, 47, 0.12); }

@media (max-width: 640px) {
  .hero-card { flex-direction: column; text-align: center; }
  .nav { display: none; }
  .shell { flex-direction: column; }
  .mobile-nav { display: flex; }
  .main { padding-bottom: 4rem; }
}

.hero-card__gauge { position: relative; width: 140px; height: 140px; flex-shrink: 0; }

.gauge { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge__track { fill: none; stroke: rgba(255, 255, 255, 0.06); stroke-width: 10; }
.gauge__fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 327;
  stroke-dashoffset: 327;
  transition: stroke-dashoffset 0.6s ease, stroke 0.3s;
}

.gauge__label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gauge__value { font-size: 2rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; }
.gauge__status { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 0.15rem; }

.hero-card h2 { margin: 0; font-size: 1.2rem; }
.hero-card__time { margin: 0.25rem 0 1rem; font-size: 0.85rem; color: var(--muted); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem 1.25rem;
}

.stat-grid .lbl { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.stat-grid strong { font-size: 1.1rem; }

.tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  text-transform: uppercase;
}

.tag--db { background: rgba(74, 222, 155, 0.15); color: var(--ok); }
.tag--api { background: rgba(255, 122, 47, 0.15); color: var(--accent); }
.tag--active { border: 1px solid var(--accent); color: var(--accent); }

.tag-row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.5rem; }

.insight {
  margin-top: 1rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  font-size: 0.85rem;
  background: rgba(255, 122, 47, 0.08);
  border: 1px solid rgba(255, 122, 47, 0.2);
  color: #ffd4b8;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.mini {
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.mini span { display: block; font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.mini strong { font-size: 1rem; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.15rem;
  backdrop-filter: blur(12px);
  margin-bottom: 1rem;
}

.card__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.75rem;
}

.card__head h3 { margin: 0; font-size: 0.95rem; color: var(--muted); font-weight: 600; }

.link { color: var(--accent); font-size: 0.8rem; text-decoration: none; }
.link:hover { text-decoration: underline; }

.card__chart { height: 200px; position: relative; }
.card__chart--tall { height: 360px; }
.card__hint { margin: 0.75rem 0 0; font-size: 0.78rem; color: var(--muted); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 768px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.card__chart--md { height: 240px; }

.card--featured {
  margin-bottom: 0.25rem;
}

/* Stats table */
.stats-table-wrap { overflow-x: auto; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.stats-table th,
.stats-table td {
  padding: 0.5rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.stats-table th:first-child,
.stats-table td:first-child {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
}

.stats-table thead th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Heatmap */
.heatmap-wrap { overflow-x: auto; padding: 0.25rem 0; }

.heatmap {
  display: grid;
  grid-template-columns: 36px repeat(24, minmax(28px, 1fr));
  gap: 2px;
  min-width: 720px;
  font-size: 0.65rem;
}

.heatmap__corner { grid-column: 1; }
.heatmap__hour-label {
  text-align: center;
  color: var(--muted);
  padding: 0.2rem 0;
  font-weight: 600;
}

.heatmap__day-label {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.35rem;
  color: var(--muted);
  font-weight: 600;
}

.heatmap__cell {
  aspect-ratio: 1;
  min-height: 26px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  cursor: default;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.heatmap__cell--empty {
  background: rgba(255, 255, 255, 0.04) !important;
  color: var(--muted);
  font-weight: 400;
  text-shadow: none;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.65rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.heatmap-legend__bar {
  flex: 1;
  max-width: 200px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, #4ade9b, #ff7a2f, #ff5c7a);
}

/* Calendar */
.calendar-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  justify-content: flex-start;
}

.calendar-month {
  flex: 1 1 280px;
  max-width: 340px;
}

.calendar-month h4 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 600;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.calendar-dow {
  font-size: 0.65rem;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  padding: 0.2rem;
}

.calendar-day {
  aspect-ratio: 1;
  min-height: 36px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  line-height: 1.15;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.calendar-day__num { font-weight: 700; }
.calendar-day__val { font-size: 0.6rem; opacity: 0.95; }

.calendar-day--empty {
  background: transparent !important;
  border-color: transparent;
  visibility: hidden;
}

.calendar-day--nodata {
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.patterns-empty {
  color: var(--muted);
  font-size: 0.88rem;
  padding: 1rem 0;
}

/* Pattern insights */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.insight-card {
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.insight-card--accent {
  border-color: rgba(255, 122, 47, 0.35);
  background: linear-gradient(145deg, var(--bg-card), rgba(255, 122, 47, 0.06));
}

.insight-card__label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.insight-card__value {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
}

.insight-card__sub {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.compare-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 0.25rem 0;
}

.compare-hint {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.compare-pill {
  text-align: center;
  padding: 1rem 0.75rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.compare-pill__label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.compare-pill__value {
  font-size: 1.6rem;
  font-weight: 800;
}

.compare-pill__hint {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.hour-rank-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.hour-rank-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.hour-rank-item__pos {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.hour-rank-item__bar-wrap {
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  overflow: hidden;
}

.hour-rank-item__bar {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
}

.hour-rank-item--quiet .hour-rank-item__bar {
  background: var(--ok);
}

.hour-rank-item__meta {
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.card__chart--sm { height: 160px; }

#monthly-card.hidden { display: none; }

/* Meta panels */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.65rem;
}

.panel--wide { grid-column: 1 / -1; }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.panel__toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0.7rem 0.85rem;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.panel__toggle:hover { background: rgba(255, 255, 255, 0.03); }
.panel--collapsed .panel__body { display: none; }
.panel--collapsed .panel__chevron { transform: rotate(-90deg); }
.panel__chevron { transition: transform 0.2s; color: var(--muted); }
.panel__body { padding: 0 0.85rem 0.85rem; font-size: 0.8rem; }

.meta-list { margin: 0; display: grid; gap: 0.4rem; }
.meta-row { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; }
.meta-row dt { margin: 0; color: var(--muted); }
.meta-row dd { margin: 0; text-align: right; font-weight: 600; }
.meta-row dd.mono { font-family: var(--mono); font-size: 0.7rem; font-weight: 500; }

/* Footer */
.footer {
  margin-top: auto;
  padding-top: 1rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
}

.footer a { color: var(--accent); text-decoration: none; }

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(8, 10, 15, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.loading__ring {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
