:root {
  --bg: #0b1120;
  --bg-elevated: #111827;
  --surface: #162032;
  --surface-hover: #1d2a40;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-soft: #64748b;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --rose: #f43f5e;
  --rose-soft: rgba(244, 63, 94, 0.14);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.14);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.35);
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

body.light-theme {
  --bg: #f4f7fb;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f1f5f9;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --text-muted: #475569;
  --text-soft: #64748b;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --accent-soft: rgba(2, 132, 199, 0.1);
  --emerald: #059669;
  --emerald-soft: rgba(5, 150, 105, 0.1);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.1);
  --rose: #e11d48;
  --rose-soft: rgba(225, 29, 72, 0.1);
  --violet: #7c3aed;
  --violet-soft: rgba(124, 58, 237, 0.1);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

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

/* Desktop Sidebar */
.sidebar {
  display: none;
  width: 248px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 2px 6px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--emerald));
  display: grid;
  place-items: center;
  color: #0b1120;
  font-weight: 800;
  font-size: 17px;
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-text span {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.side-nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.16s ease;
  text-align: left;
}

.side-nav-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.side-nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.24);
}

.side-nav-btn svg {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Main Column */
.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: 92px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 17, 32, 0.84);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

body.light-theme .topbar {
  background: rgba(244, 247, 251, 0.88);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.mobile-brand .brand-mark {
  width: 34px;
  height: 34px;
  font-size: 15px;
  border-radius: 10px;
}

.date-clock {
  display: flex;
  flex-direction: column;
}

.date-clock .today-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.date-clock .live-clock {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Active Alarm Banner */
.alarm-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: linear-gradient(90deg, rgba(244, 63, 94, 0.22), rgba(245, 158, 11, 0.22));
  border-bottom: 1px solid rgba(244, 63, 94, 0.45);
  animation: pulseBanner 1.4s ease-in-out infinite alternate;
}

.alarm-banner.show {
  display: flex;
}

@keyframes pulseBanner {
  from { background-color: rgba(244, 63, 94, 0.14); }
  to { background-color: rgba(245, 158, 11, 0.22); }
}

.alarm-banner-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.alarm-banner-title {
  font-weight: 800;
  font-size: 15px;
}

.alarm-banner-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Content Container */
.content-wrap {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 18px 28px;
}

/* Section Views */
.section-view {
  display: none;
  animation: fadeUp 0.2s ease;
}

.section-view.active {
  display: block;
}

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

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.section-header h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.section-header p {
  margin: 3px 0 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 15px 16px;
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  margin: 5px 0 2px;
  letter-spacing: -0.02em;
}

.stat-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #04131f;
  border-color: transparent;
  font-weight: 700;
}

.btn-primary:hover {
  filter: brightness(1.06);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.btn-emerald {
  background: var(--emerald-soft);
  color: var(--emerald);
  border-color: rgba(16, 185, 129, 0.35);
}

.btn-emerald:hover {
  background: rgba(16, 185, 129, 0.24);
}

.btn-amber {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.35);
}

.btn-amber:hover {
  background: rgba(245, 158, 11, 0.24);
}

.btn-danger {
  background: var(--rose-soft);
  color: var(--rose);
  border-color: rgba(244, 63, 94, 0.35);
}

.btn-danger:hover {
  background: rgba(244, 63, 94, 0.24);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
  border-radius: 9px;
}

.btn-icon {
  padding: 8px 10px;
}

/* Pills & Badges */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.pill-emerald {
  background: var(--emerald-soft);
  color: var(--emerald);
  border-color: rgba(16, 185, 129, 0.25);
}

.pill-amber {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.25);
}

.pill-rose {
  background: var(--rose-soft);
  color: var(--rose);
  border-color: rgba(244, 63, 94, 0.25);
}

.pill-muted {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border-color: var(--border);
}

/* Form Elements */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.input, .select, .textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  padding: 9px 13px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
}

.input-grow {
  flex: 1 1 180px;
  min-width: 140px;
}

.textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
}

/* Progress Bar */
.progress-track {
  width: 100%;
  height: 10px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--emerald));
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* Lists (Routine, Habits, Tasks) */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 13px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.list-row:hover {
  border-color: var(--border-strong);
}

.list-row.done {
  opacity: 0.65;
}

.list-row.done .row-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.list-row.next-up {
  border-color: rgba(56, 189, 248, 0.5);
  background: linear-gradient(90deg, rgba(56, 189, 248, 0.08), var(--bg-elevated));
}

.row-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.row-content {
  min-width: 0;
  flex: 1;
}

.row-title {
  font-weight: 600;
  font-size: 14.5px;
  word-break: break-word;
}

.row-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-muted);
}

.time-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.25);
  flex-shrink: 0;
}

.check-box {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 2px solid var(--border-strong);
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  color: #04131f;
  transition: all 0.15s ease;
}

.check-box.checked {
  background: var(--emerald);
  border-color: var(--emerald);
}

/* Toggle Switches */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.toggle-label {
  font-size: 13.5px;
  font-weight: 600;
}

.toggle-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: var(--surface-hover);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: 0.2s;
}

.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  background: var(--text);
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background: var(--emerald);
  border-color: var(--emerald);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
  background: #04131f;
}

/* Focus Timer */
.timer-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 12px 0 6px;
}

.timer-ring-wrap {
  position: relative;
  width: 236px;
  height: 236px;
  display: grid;
  place-items: center;
  margin: 14px 0 18px;
}

.timer-ring-svg {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

.timer-ring-bg {
  fill: none;
  stroke: var(--bg-elevated);
  stroke-width: 10;
}

.timer-ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s linear, stroke 0.25s ease;
}

.timer-digits {
  font-family: var(--font-mono);
  font-size: 46px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.timer-mode-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 8px;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

/* Filter & Subtabs */
.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.subtab-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.subtab-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.35);
}

/* Info Tip Box */
.tip-box {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.24);
  border-radius: 13px;
  padding: 13px 15px;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 12px;
}

.tip-box strong {
  color: var(--accent);
}

/* Charts & Heatmap */
.chart-box {
  position: relative;
  height: 230px;
  width: 100%;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 6px;
}

.heat-cell {
  aspect-ratio: 1;
  border-radius: 7px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-soft);
}

.heat-cell.l1 { background: rgba(16, 185, 129, 0.22); color: var(--text); }
.heat-cell.l2 { background: rgba(16, 185, 129, 0.45); color: #fff; }
.heat-cell.l3 { background: rgba(16, 185, 129, 0.78); color: #04131f; font-weight: 700; }

/* Subject Chips */
.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.subject-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  font-size: 13.5px;
  font-weight: 600;
}

.subject-chip button {
  background: none;
  border: none;
  color: var(--rose);
  cursor: pointer;
  font-weight: 700;
  padding: 0 2px;
}

/* Mobile Bottom Nav */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: rgba(17, 24, 39, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  gap: 2px;
}

body.light-theme .bottom-nav {
  background: rgba(255, 255, 255, 0.95);
}

.bottom-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.bottom-nav-btn svg {
  width: 20px;
  height: 20px;
}

.bottom-nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.68);
  backdrop-filter: blur(6px);
  z-index: 80;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  max-height: 88vh;
  overflow-y: auto;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%) translateY(18px);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--accent);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 90;
  max-width: 92vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.empty-state {
  text-align: center;
  padding: 26px 14px;
  color: var(--text-muted);
  font-size: 13.5px;
  border: 1px dashed var(--border-strong);
  border-radius: 13px;
}

/* Responsive Breakpoints */
@media (min-width: 720px) {
  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .two-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .heatmap-grid {
    grid-template-columns: repeat(15, minmax(0, 1fr));
  }
}

@media (min-width: 960px) {
  .sidebar {
    display: flex;
  }
  .mobile-brand, .bottom-nav {
    display: none;
  }
  .main-col {
    padding-bottom: 24px;
  }
  .toast {
    bottom: 26px;
  }
}
