/* =========================================
   THORP COMMAND CENTER — Stylesheet
   Dark mode, light-blue accent, clean futurism.
   ========================================= */

:root {
  /* Palette */
  --bg:           #06090f;
  --bg-2:         #080c14;
  --surface:      #0e1422;
  --surface-elev: #131b2e;
  --border:       rgba(96, 165, 250, 0.12);
  --border-strong:rgba(96, 165, 250, 0.28);

  /* Text */
  --text:         #e7ecf5;
  --text-mute:    #8794ad;
  --text-dim:     #5a6680;

  /* Accent */
  --accent:       #60a5fa;
  --accent-soft:  #93c5fd;
  --accent-deep:  #3b82f6;
  --accent-glow:  rgba(96, 165, 250, 0.35);

  /* Semantic */
  --ok:           #34d399;
  --warn:         #fbbf24;
  --err:          #f87171;

  /* Fonts */
  --font-ui:      'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:    'JetBrains Mono', 'SF Mono', Consolas, monospace;

  /* Rhythm */
  --radius:       12px;
  --radius-sm:    6px;
  --pad:          24px;

  /* Motion */
  --ease:         cubic-bezier(0.22, 1, 0.36, 1);
}

/* ------------ Reset / Base ------------ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  position: relative;

  /* Disable selection & long-press highlight everywhere by default. */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;

  /* Whole site renders uppercase. Letters only; numbers / punctuation
     / emoji are unaffected. */
  text-transform: uppercase;
}

/* Inputs show typed letters as uppercase too (purely visual; the
   underlying value is whatever was typed — JS lowercases for compare). */
input { text-transform: uppercase; }
input::placeholder { text-transform: uppercase; }

/* Inputs / textareas still need to accept text for typing. */
input, textarea, [contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
}

button { font-family: inherit; cursor: pointer; border: 0; background: transparent; color: inherit; }
input { font-family: inherit; color: inherit; background: transparent; border: 0; outline: 0; }
ul { list-style: none; }

/* ------------ Background ambience ------------ */
.bg-grid {
  position: fixed; inset: 0;
  background-image:
    linear-gradient(to right, rgba(96,165,250,0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(96,165,250,0.04) 1px, transparent 1px);
  background-size: 80px 80px;
  pointer-events: none;
  mask-image: radial-gradient(ellipse at center, black 40%, transparent 85%);
  z-index: 0;
}
.bg-glow {
  position: fixed;
  width: 60vw; height: 60vw;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(96,165,250,0.10) 0%, transparent 65%);
  pointer-events: none;
  filter: blur(40px);
  z-index: 0;
}

/* ------------ App / screens ------------ */
.app { position: relative; z-index: 1; height: 100vh; width: 100vw; overflow: hidden; }

.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.45s var(--ease);
}
.screen.is-active { opacity: 1; pointer-events: auto; }

/* ===========================================================
   SCREEN 1 — LANDING
   =========================================================== */
.screen--landing { padding: 24px; }
.landing-content {
  display: flex; flex-direction: column; align-items: center; gap: 32px;
  text-align: center;
}

.prelude {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--text-mute);
  background: rgba(14,20,34,0.6);
  backdrop-filter: blur(8px);
}
.prelude-text { line-height: 1; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok), 0 0 16px rgba(52,211,153,0.4);
  animation: pulse-dot 2.4s ease-in-out infinite;
}
.status-dot--live {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent), 0 0 18px var(--accent-glow);
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.85); }
}

.title {
  display: flex; flex-direction: column; gap: 6px;
  font-weight: 700;
  font-size: clamp(48px, 11vw, 152px);
  line-height: 0.95;
  letter-spacing: -0.04em;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  text-shadow: 0 0 60px var(--accent-glow);
  transition: text-shadow 0.4s var(--ease), transform 0.4s var(--ease), color 0.4s var(--ease);
}
.title:hover, .title:focus-visible {
  outline: none;
  color: var(--accent-soft);
  text-shadow: 0 0 80px rgba(96,165,250,0.6);
}
.title span {
  display: block;
  animation: title-stagger 0.9s var(--ease) backwards;
}
.title span:nth-child(1) { animation-delay: 0.05s; }
.title span:nth-child(2) { animation-delay: 0.18s; }
.title span:nth-child(3) { animation-delay: 0.31s; }
@keyframes title-stagger {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* title-hint and hint-arrow removed — landing no longer shows "click to engage";
   the SYSTEM ONLINE pill moved below the title now serves as the only sub-text. */

/* ===========================================================
   SCREEN 2 — LOGIN
   =========================================================== */
.screen--login { padding: 24px; }
.login-wrap {
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 24px;
  padding: 40px 36px;
  background: linear-gradient(180deg, rgba(19,27,46,0.85), rgba(14,20,34,0.7));
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  backdrop-filter: blur(12px);
  box-shadow: 0 0 80px rgba(96,165,250,0.08), inset 0 1px 0 rgba(255,255,255,0.03);
  transform: translateY(20px); opacity: 0;
  transition: transform 0.55s var(--ease), opacity 0.55s var(--ease);
}
.screen--login.is-active .login-wrap { transform: translateY(0); opacity: 1; }

.login-brand {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--accent); letter-spacing: 0.32em;
}
.brand-mark {
  width: 22px; height: 22px;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  position: relative;
}
.brand-mark::after {
  content: ''; position: absolute; inset: 4px;
  background: var(--accent);
  border-radius: 1px;
  box-shadow: 0 0 10px var(--accent-glow);
}

.login-heading {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.login-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--text-mute);
  text-transform: uppercase;
  margin-top: -16px;
}

.login-form { display: flex; flex-direction: column; gap: 22px; margin-top: 8px; }

.field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.field-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.28em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.field input {
  padding: 10px 0;
  font-size: 16px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.3s var(--ease);
}
.field input::placeholder { color: var(--text-dim); }
.field-underline {
  position: absolute; bottom: 0; left: 0; right: 0; height: 1px;
  background: var(--accent);
  transform: scaleX(0); transform-origin: left;
  transition: transform 0.4s var(--ease);
}
.field input:focus ~ .field-underline { transform: scaleX(1); }

.btn-engage {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.28em;
  color: var(--bg);
  background: var(--accent);
  border-radius: 8px;
  margin-top: 6px;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease), box-shadow 0.3s var(--ease);
  box-shadow: 0 0 24px rgba(96,165,250,0.25);
}
.btn-engage:hover { background: var(--accent-soft); box-shadow: 0 0 32px var(--accent-glow); }
.btn-engage:active { transform: translateY(1px); }
/* .btn-engage-arrow removed — arrow icons stripped per keeper preference. */

.login-error {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--err);
  min-height: 16px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ===========================================================
   SCREEN 3 — BOOT
   =========================================================== */
.boot-stack {
  display: flex; flex-direction: column; align-items: center; gap: 36px;
}
.boot-ring {
  width: 96px; height: 96px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: boot-spin 1.2s linear infinite;
  box-shadow: 0 0 32px var(--accent-glow);
  position: relative;
}
.boot-ring-inner {
  position: absolute; inset: 18px;
  border: 1px solid var(--border-strong);
  border-bottom-color: var(--accent-soft);
  border-radius: 50%;
  animation: boot-spin 2.4s linear infinite reverse;
}
@keyframes boot-spin { to { transform: rotate(360deg); } }

.boot-log {
  display: flex; flex-direction: column; gap: 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-mute);
  width: 360px;
  text-align: left;
}
.boot-log li {
  opacity: 0;
  animation: boot-line-in 0.35s var(--ease) forwards;
  letter-spacing: 0.05em;
}
.boot-log .boot-ok { color: var(--accent); }
@keyframes boot-line-in { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }

/* ===========================================================
   SCREEN 4 — DASHBOARD
   Full-viewport layout: edge-to-edge topbar + 2x2 grid that
   fills the remaining height (no scroll on desktop/tablet).
   =========================================================== */
.screen--dashboard {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
}
.screen--dashboard.is-active { overflow: hidden; pointer-events: auto; }

.topbar {
  flex: 0 0 auto;
  width: 100%;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 28px;
  background: linear-gradient(180deg, rgba(8,12,20,0.92), rgba(8,12,20,0.65));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-left { flex: 1 1 auto; min-width: 0; overflow: hidden; }
.topbar-brand { white-space: nowrap; }

.topbar-brand {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.32em;
  color: var(--accent-soft);
}
.topbar-sep { color: var(--text-dim); }
.topbar-user { font-size: 13px; color: var(--text-mute); }
.topbar-user span { color: var(--text); font-weight: 500; }

.topbar-stat { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.stat-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.28em;
  color: var(--text-dim);
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
}

.btn-logout {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.24em;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-mute);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.btn-logout:hover { color: var(--accent); border-color: var(--accent); background: rgba(96,165,250,0.06); }

/* ----- Dashboard content (flex column filling remaining vh) ----- */
.dashboard-content {
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px;
  min-height: 0;
  overflow: hidden;
}

/* 2x2 grid fills the remaining viewport. min-height:0 lets grid rows
   honor 1fr instead of expanding to content. */
.module-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 14px;
  min-height: 0;
}

.module {
  background: linear-gradient(180deg, var(--surface-elev), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 14px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  opacity: 0; transform: translateY(20px);
  animation: tile-in 0.65s var(--ease) forwards;
  transition: border-color 0.3s var(--ease), transform 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.module:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.4), 0 0 24px rgba(96,165,250,0.06);
}
#module-finance     { animation-delay: 0.12s; }
#module-smart-home  { animation-delay: 0.22s; }
#module-calendar    { animation-delay: 0.32s; }
#module-system      { animation-delay: 0.42s; }
@keyframes tile-in {
  to { opacity: 1; transform: translateY(0); }
}

.module-head {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.module-head > div { display: flex; align-items: baseline; gap: 10px; }
.module-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.16em;
}
.module-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text);
}

.module-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-mute);
  display: inline-flex; align-items: center; gap: 6px;
}
.module-pill--live { color: var(--accent); border-color: rgba(96,165,250,0.35); background: rgba(96,165,250,0.08); }
.module-pill--ok { color: var(--ok); border-color: rgba(52,211,153,0.35); background: rgba(52,211,153,0.08); }
.module-pill--idle { color: var(--text-dim); }

.module-body {
  display: flex; flex-direction: column; gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* KPIs */
.kpi-primary {
  display: flex; flex-direction: column; gap: 6px;
}
.kpi-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.24em;
  color: var(--text-dim);
  text-transform: uppercase;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 500;
  color: var(--text);
  letter-spacing: -0.01em;
}
.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding-top: 6px; border-top: 1px dashed var(--border); }
.kpi-mini { display: flex; flex-direction: column; gap: 3px; }
.kpi-mini .kpi-value { font-size: 14px; }

/* Chart — fills the remaining tile space; Chart.js (responsive,
   maintainAspectRatio:false) scales to whatever this resolves to. */
.chart-wrap {
  flex: 1 1 auto;
  min-height: 60px;
  position: relative;
}
.chart-wrap canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.chart-wrap--system { margin-top: 2px; }

/* Smart-home rooms */
.room-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.room {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(96,165,250,0.02);
}
.room-icon { font-size: 14px; color: var(--accent); }
.room:nth-child(3) .room-icon,
.room:nth-child(4) .room-icon { color: var(--text-dim); }
.room-name { font-size: 13px; color: var(--text); }
.room-state { font-family: var(--font-mono); font-size: 12px; color: var(--text-mute); }

.module-footer {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-mute);
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.module-link { color: var(--accent); cursor: pointer; }

/* Agenda */
.agenda { display: flex; flex-direction: column; gap: 8px; }
.agenda li {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.agenda-time { font-family: var(--font-mono); font-size: 12px; color: var(--accent); letter-spacing: 0.05em; }
.agenda-item { color: var(--text); }
.agenda-flag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  min-width: 12px; min-height: 12px;
}
.agenda-flag--done { color: var(--text-dim); background: rgba(120,128,148,0.10); }
.agenda-flag--active { color: var(--accent); background: rgba(96,165,250,0.10); border: 1px solid rgba(96,165,250,0.3); }

/* System metrics */
.system-body { gap: 18px; }
.sysmetric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.sysmetric { display: flex; flex-direction: column; gap: 6px; }
.bar {
  height: 6px;
  background: rgba(96,165,250,0.08);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.bar-fill {
  height: 100%;
  width: var(--pct, 0%);
  background: linear-gradient(90deg, var(--accent-deep), var(--accent-soft));
  border-radius: 999px;
  box-shadow: 0 0 12px var(--accent-glow);
}

/* Footer / greeting styles removed — those elements no longer in DOM. */

/* ===========================================================
   Responsive — mobile / narrow screens
   =========================================================== */

/* Tablet portrait & smaller: tighter spacing, still 2x2 if room. */
@media (max-width: 900px) {
  .module-grid { gap: 10px; }
  .module { padding: 14px 16px; gap: 10px; }
  .module-title { font-size: 12px; }
  .kpi-value { font-size: 22px; }
  .kpi-mini .kpi-value { font-size: 13px; }
  .topbar { padding: 12px 18px; }
}

/* Mobile: single column. Allow vertical scroll on the dashboard
   so each tile has room to breathe; topbar stays sticky-feeling. */
@media (max-width: 720px) {
  .topbar {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px 12px;
  }
  .topbar-brand { font-size: 11px; letter-spacing: 0.24em; }
  .topbar-user { font-size: 12px; }
  .topbar-sep { display: none; }
  .topbar-right { gap: 10px; }

  .screen--dashboard.is-active { overflow-y: auto; }
  .dashboard-content {
    padding: 12px;
    overflow: visible;
    height: auto;
  }
  /* Mobile: one card per row, vertical scroll, each tile gets
     comfortable height for full-width content. */
  .module-grid {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-rows: minmax(280px, auto);
    flex: 0 0 auto;
    gap: 12px;
  }
  .module { min-height: 280px; padding: 18px 18px; }
  .kpi-row { grid-template-columns: 1fr 1fr 1fr; }
  .sysmetric-row { grid-template-columns: 1fr; }
  .room-grid { grid-template-columns: 1fr 1fr; }
  .chart-wrap { min-height: 130px; }
}

/* Login form: ensure it fits in viewport on mobile. */
@media (max-width: 720px) {
  .login-wrap { padding: 28px 22px; gap: 18px; }
  .login-heading { font-size: 18px; }
  .field input { font-size: 16px; /* >=16 prevents iOS zoom */ }
}

/* Landing: keep readable on short screens. */
@media (max-height: 520px) {
  .landing-content { gap: 18px; }
  .title { font-size: clamp(40px, 13vh, 96px); }
}

/* ===========================================================
   CALENDAR module
   =========================================================== */
.cal-body { gap: 10px; }

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.cal-nav-btn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  color: var(--text-mute);
  font-size: 18px;
  line-height: 1;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.cal-nav-btn:hover { color: var(--accent); border-color: var(--accent); background: rgba(96,165,250,0.06); }
.cal-today-btn {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  padding: 6px 14px;
  color: var(--text-mute);
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.cal-today-btn:hover { color: var(--accent); border-color: var(--accent); background: rgba(96,165,250,0.06); }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-align: center;
  padding: 2px 0;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.cal-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease), color 0.18s var(--ease);
  min-height: 26px;
  padding: 0;
}
.cal-cell:hover { background: rgba(96,165,250,0.06); border-color: var(--border); }
.cal-cell--other { color: var(--text-dim); opacity: 0.32; cursor: default; }
.cal-cell--other:hover { background: transparent; border-color: transparent; }
.cal-cell.is-today { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.cal-cell.is-selected {
  background: var(--accent); color: var(--bg);
  border-color: var(--accent); font-weight: 600;
  box-shadow: 0 0 14px var(--accent-glow);
}
.cal-cell.is-selected:hover { background: var(--accent-soft); }
.cal-cell-num { line-height: 1; }
.cal-cell-dots {
  position: absolute;
  bottom: 3px;
  left: 50%; transform: translateX(-50%);
  display: flex; gap: 2px;
}
.cal-cell-dot {
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--accent);
}
.cal-cell-dot--task { background: var(--ok); }
.cal-cell.is-selected .cal-cell-dot { background: var(--bg); }

.cal-events {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 0;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}
.cal-events-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}
.btn-add {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--accent);
  transition: background 0.2s, border-color 0.2s;
  cursor: pointer;
}
.btn-add:hover { background: rgba(96,165,250,0.08); border-color: var(--accent); }

.cal-events-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  padding-right: 2px;
}
.cal-events-list::-webkit-scrollbar { width: 4px; }
.cal-events-list::-webkit-scrollbar-track { background: transparent; }
.cal-events-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.cal-event {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-left: 2px solid var(--ev-color, var(--accent));
  background: rgba(96,165,250,0.03);
  border-radius: 0 4px 4px 0;
  font-size: 12px;
  min-width: 0;
}
.cal-event-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ev-color, var(--accent));
  letter-spacing: 0.04em;
}
.cal-event-title {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-event-edit {
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  padding: 0 6px;
  cursor: pointer;
}
.cal-event-edit:hover { color: var(--accent); }
.cal-events-empty {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  padding: 10px 0;
  text-align: center;
}

/* ===========================================================
   TASKS module
   =========================================================== */
.tasks-body { gap: 8px; }

.task-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  padding-right: 2px;
}
.task-list::-webkit-scrollbar { width: 4px; }
.task-list::-webkit-scrollbar-track { background: transparent; }
.task-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.task {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(96,165,250,0.02);
  font-size: 13px;
  transition: background 0.2s, border-color 0.2s;
  min-width: 0;
}
.task:hover { border-color: var(--border-strong); background: rgba(96,165,250,0.05); }
.task input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  position: relative;
  flex-shrink: 0;
  background: transparent;
}
.task input[type="checkbox"]:hover { border-color: var(--accent); }
.task input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.task input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 5px; height: 9px;
  border-right: 2px solid var(--bg);
  border-bottom: 2px solid var(--bg);
  transform: rotate(45deg);
}
.task-title {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.task.is-done .task-title {
  color: var(--text-dim);
  text-decoration: line-through;
  text-decoration-color: var(--text-dim);
}
.task-del {
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  padding: 0 6px;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.2s var(--ease), color 0.2s;
}
.task:hover .task-del { opacity: 1; }
.task-del:hover { color: var(--err); }
.task-empty {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  padding: 16px 0;
  text-align: center;
}

.task-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  flex-shrink: 0;
}
.task-add input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: rgba(8,12,20,0.5);
  font-family: var(--font-ui);
}
.task-add input:focus { border-color: var(--accent); }
.task-add input::placeholder { color: var(--text-dim); letter-spacing: 0.04em; }
.btn-add-icon {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
  transition: background 0.2s, border-color 0.2s;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.btn-add-icon:hover { background: rgba(96,165,250,0.08); border-color: var(--accent); }

/* ===========================================================
   MODAL (event editor)
   =========================================================== */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  z-index: 100;
  padding: 20px;
}
.modal.is-open { pointer-events: auto; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(6,9,15,0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.28s var(--ease);
  cursor: pointer;
}
.modal.is-open .modal-backdrop { opacity: 1; }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: linear-gradient(180deg, var(--surface-elev), var(--surface));
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 26px 28px;
  display: flex; flex-direction: column; gap: 16px;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  transition: transform 0.32s var(--ease), opacity 0.32s var(--ease);
  box-shadow: 0 20px 80px rgba(0,0,0,0.55), 0 0 60px rgba(96,165,250,0.08);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.modal.is-open .modal-card { transform: translateY(0) scale(1); opacity: 1; }
.modal-card::-webkit-scrollbar { width: 4px; }
.modal-card::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.modal-title {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: var(--accent);
}
.modal-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--text-mute);
  margin-top: -10px;
}

.modal-form { display: flex; flex-direction: column; gap: 14px; }
.modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.modal-field input[type="text"],
.modal-field input[type="time"],
.modal-field textarea {
  padding: 9px 12px;
  background: rgba(8,12,20,0.55);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  transition: border-color 0.2s, background 0.2s;
  width: 100%;
}
.modal-field input[type="time"] { font-family: var(--font-mono); }
.modal-field input:focus,
.modal-field textarea:focus { border-color: var(--accent); outline: 0; background: rgba(8,12,20,0.7); }
.modal-field textarea {
  resize: vertical;
  min-height: 56px;
  max-height: 200px;
  font-size: 13px;
}
.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.color-swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--c);
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), transform 0.18s var(--ease), box-shadow 0.18s var(--ease);
  padding: 0;
  position: relative;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.is-selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg), 0 0 14px var(--c);
}

.modal-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  flex-wrap: wrap;
}
.modal-actions-spacer { flex: 1 1 auto; }
.btn-ghost {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-mute);
  background: transparent;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--accent); border-color: var(--accent); background: rgba(96,165,250,0.06); }
.btn-ghost--danger:hover { color: var(--err); border-color: var(--err); background: rgba(248,113,113,0.06); }

.btn-engage--compact { padding: 9px 16px; font-size: 11px; }

/* ===========================================================
   Tile-density tuning so calendar/tasks fit at 2x2
   =========================================================== */
@media (min-width: 901px) {
  /* Compress header padding inside calendar/tasks so the grid + lists
     have more vertical room when 4 tiles share viewport height. */
  #module-calendar .module-head,
  #module-tasks .module-head { padding-bottom: 8px; }
  #module-calendar { padding: 14px 16px; gap: 8px; }
  #module-tasks { padding: 14px 16px; gap: 8px; }
}

/* Modal & calendar adjustments for narrow screens */
@media (max-width: 720px) {
  .modal-card { padding: 22px 20px; }
  .modal-row { grid-template-columns: 1fr 1fr; }
  .cal-cell { font-size: 13px; }
}

/* ===========================================================
   Dashboard calendar tile — DAY VIEW
   =========================================================== */
.cal-day-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.cal-day-display {
  flex: 1 1 auto;
  min-width: 0;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--text);
  background: rgba(8,12,20,0.4);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-day-display:hover { border-color: var(--accent); color: var(--accent); background: rgba(96,165,250,0.06); }
.cal-day-input-hidden {
  position: absolute;
  width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  opacity: 0;
  pointer-events: none;
}

/* Action-pill variant: clickable like a button */
.module-pill--action {
  cursor: pointer;
  color: var(--accent);
  border-color: rgba(96,165,250,0.35);
  background: rgba(96,165,250,0.08);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.module-pill--action:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ===========================================================
   STANDALONE CALENDAR PAGE
   =========================================================== */
.screen--calendar {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
}
.screen--calendar.is-active { overflow: hidden; pointer-events: auto; }

.topbar--page { flex-wrap: wrap; gap: 12px; }
.topbar--page .topbar-left,
.topbar--page .topbar-right { min-width: 0; flex: 0 1 auto; }

.btn-back {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-mute);
  background: transparent;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.btn-back:hover { color: var(--accent); border-color: var(--accent); background: rgba(96,165,250,0.06); }

.cal-view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(8,12,20,0.4);
}
.cal-view-btn {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  padding: 7px 14px;
  color: var(--text-mute);
  background: transparent;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  border: 0;
  border-right: 1px solid var(--border);
}
.cal-view-btn:last-child { border-right: 0; }
.cal-view-btn:hover { color: var(--accent); background: rgba(96,165,250,0.06); }
.cal-view-btn.is-active {
  color: var(--bg);
  background: var(--accent);
  font-weight: 600;
}

.cal-page-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(8,12,20,0.5);
  flex-wrap: wrap;
}
.cal-page-title {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text);
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  min-width: 220px;
  text-align: center;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.cal-page-title:hover { border-color: var(--border); color: var(--accent); background: rgba(96,165,250,0.04); }
.cal-page-spacer { flex: 1 1 auto; }

.cal-page-content {
  flex: 1 1 auto;
  width: 100%;
  padding: 18px 28px 28px;
  overflow: auto;
  min-height: 0;
}

/* ----- Month view ----- */
.cal-view-month {
  display: flex;
  flex-direction: column;
  gap: 6px;
  height: 100%;
  min-height: 0;
}
.cal-view-month .cal-weekdays {
  font-size: 11px;
  letter-spacing: 0.14em;
  padding: 6px 0;
}
.cal-view-month .cal-grid {
  flex: 1 1 auto;
  grid-auto-rows: minmax(0, 1fr);
  min-height: 0;
}
.cal-view-month .cal-cell {
  aspect-ratio: auto;
  min-height: 80px;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 6px;
  gap: 4px;
}
.cal-view-month .cal-cell-num {
  font-size: 12px;
  text-align: right;
  padding: 0 2px;
}
.cal-view-month .cal-cell-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  min-height: 0;
  flex: 1 1 auto;
}
.cal-view-month .cal-cell-chip {
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--bg);
  background: var(--ev-color, var(--accent));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-view-month .cal-cell-more {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  letter-spacing: 0.05em;
}
.cal-view-month .cal-cell.is-selected .cal-cell-num { color: var(--bg); }

/* ----- Week view ----- */
.cal-view-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  height: 100%;
  min-height: 0;
}
.cal-week-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(8,12,20,0.3);
  overflow: hidden;
  min-height: 0;
}
.cal-week-col-head {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: center;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background 0.2s;
}
.cal-week-col-head:hover { background: rgba(96,165,250,0.05); }
.cal-week-col-day { display: block; font-size: 10px; letter-spacing: 0.18em; color: var(--text-dim); }
.cal-week-col-date { display: block; font-size: 18px; color: var(--text); margin-top: 2px; }
.cal-week-col.is-today .cal-week-col-date { color: var(--accent); }
.cal-week-col.is-selected { border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }
.cal-week-col.is-other .cal-week-col-day,
.cal-week-col.is-other .cal-week-col-date { color: var(--text-dim); opacity: 0.5; }
.cal-week-col-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 6px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}
.cal-week-col-list::-webkit-scrollbar { width: 4px; }
.cal-week-col-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }
.cal-week-event {
  font-size: 11px;
  padding: 5px 8px;
  border-left: 2px solid var(--ev-color, var(--accent));
  background: rgba(96,165,250,0.05);
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  transition: background 0.2s;
}
.cal-week-event:hover { background: rgba(96,165,250,0.12); }
.cal-week-event-time { display: block; font-family: var(--font-mono); font-size: 10px; color: var(--ev-color, var(--accent)); }
.cal-week-event-title { display: block; color: var(--text); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-week-empty { color: var(--text-dim); font-family: var(--font-mono); font-size: 10px; text-align: center; padding: 12px 0; opacity: 0.6; }

/* ----- Day view (standalone) ----- */
.cal-view-day {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}
.cal-day-header { display: flex; flex-direction: column; gap: 6px; }
.cal-day-header-name {
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.cal-day-header-sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-mute);
  letter-spacing: 0.16em;
}
.cal-day-event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cal-day-event {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: start;
  gap: 14px;
  padding: 12px 16px;
  border-left: 3px solid var(--ev-color, var(--accent));
  background: rgba(96,165,250,0.04);
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  transition: background 0.2s;
}
.cal-day-event:hover { background: rgba(96,165,250,0.10); }
.cal-day-event-time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ev-color, var(--accent));
  letter-spacing: 0.04em;
}
.cal-day-event-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-day-event-title { font-size: 14px; color: var(--text); }
.cal-day-event-note {
  font-size: 12px;
  color: var(--text-mute);
  line-height: 1.4;
  white-space: pre-wrap;
}
.cal-day-event-edit { color: var(--text-dim); font-size: 18px; line-height: 1; padding: 0 6px; cursor: pointer; }
.cal-day-event-edit:hover { color: var(--accent); }
.cal-day-empty {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  padding: 40px 0;
  text-align: center;
}

/* ===========================================================
   Standalone calendar mobile
   =========================================================== */
@media (max-width: 720px) {
  .topbar--page { padding: 10px 14px; }
  .cal-page-controls { padding: 12px 14px; gap: 6px; }
  .cal-page-title { font-size: 13px; min-width: 0; flex: 1 1 auto; padding: 6px 10px; }
  .cal-page-content { padding: 12px 14px 20px; }
  .cal-view-btn { padding: 6px 10px; font-size: 9px; letter-spacing: 0.16em; }

  /* Month: shrink cells */
  .cal-view-month .cal-cell { min-height: 56px; padding: 4px; }
  .cal-view-month .cal-cell-num { font-size: 11px; }
  .cal-view-month .cal-cell-chip { font-size: 9px; padding: 1px 4px; }

  /* Week: stack 7 days vertically as rows */
  .cal-view-week {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .cal-week-col-head { padding: 8px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
  .cal-week-col-day { font-size: 11px; letter-spacing: 0.12em; }
  .cal-week-col-date { font-size: 14px; margin-top: 0; }
  .cal-week-col-list { max-height: 160px; }

  /* Day view tight */
  .cal-view-day { max-width: none; gap: 12px; }
  .cal-day-event { grid-template-columns: 80px 1fr auto; gap: 10px; padding: 10px 12px; }
  .cal-day-header-name { font-size: 20px; }
}
