/* ── CSS variables ──────────────────────────────────────────────────────── */
:root {
  --bg:         #f4f5f7;
  --surface:    #ffffff;
  --surface2:   #f0f1f3;
  --border:     #e2e4e9;
  --text:       #1a1d23;
  --text2:      #6b7280;
  --text3:      #9ca3af;
  --accent:     #4f6ef7;
  --accent-dim: #eef0ff;
  --green:      #22c55e;
  --green-dim:  #dcfce7;
  --amber:      #f59e0b;
  --amber-dim:  #fef3c7;
  --red:        #ef4444;
  --red-dim:    #fee2e2;
  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 1px 4px rgba(0,0,0,.07);
  --topbar-h:   56px;
  --sidebar-w:  220px;
  --font:       'Inter', system-ui, sans-serif;
  --mono:       'JetBrains Mono', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #0f1117;
    --surface:    #1a1d27;
    --surface2:   #222535;
    --border:     #2d3148;
    --text:       #e8eaf0;
    --text2:      #9399a8;
    --text3:      #5c6278;
    --accent:     #6b82f8;
    --accent-dim: #1e2347;
    --green-dim:  #14322a;
    --amber-dim:  #332410;
    --red-dim:    #330f0f;
    --shadow:     0 1px 6px rgba(0,0,0,.35);
  }
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Layout shell ───────────────────────────────────────────────────────── */
.dash {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar content";
  min-height: 100vh;
}

/* ── Topbar ─────────────────────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  width: var(--sidebar-w);
  flex-shrink: 0;
}
.topbar-logomark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent) 0%, #8b5cf6 100%);
  display: inline-block;
  flex-shrink: 0;
}
.topbar-sitename {
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
  letter-spacing: -.3px;
}
.topbar-search {
  flex: 1;
  position: relative;
  max-width: 380px;
}
.topbar-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  font-size: 1rem;
  pointer-events: none;
}
.topbar-search-input {
  width: 100%;
  padding: 6px 12px 6px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: .875rem;
  outline: none;
  transition: border-color .15s;
}
.topbar-search-input:focus { border-color: var(--accent); }
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.topbar-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  font-size: 1.1rem;
  transition: background .15s, color .15s;
}
.topbar-icon-btn:hover { background: var(--surface2); color: var(--text); }
.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  color: var(--text2);
  width: 100%;
  text-align: left;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item i { font-size: 1.1rem; flex-shrink: 0; }

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}
.nav-section-label {
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 8px 10px 4px;
}

/* ── Content ────────────────────────────────────────────────────────────── */
.content {
  grid-area: content;
  padding: 28px 32px;
  overflow-y: auto;
}

/* ── Stats row ──────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 6px;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  font-family: var(--mono);
  line-height: 1.1;
}
.stat-sub {
  font-size: .75rem;
  color: var(--text2);
  margin-top: 4px;
}

/* ── Section title ──────────────────────────────────────────────────────── */
.section-title {
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text3);
  margin: 24px 0 12px;
}

/* ── Cards grid ─────────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .12s;
}
.card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 14px rgba(79,110,247,.12);
  transform: translateY(-1px);
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}
.card-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.card-title {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.card-desc {
  font-size: .8rem;
  color: var(--text2);
  line-height: 1.45;
}

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .03em;
  flex-shrink: 0;
}
.badge-green  { background: var(--green-dim);  color: var(--green); }
.badge-amber  { background: var(--amber-dim);  color: var(--amber); }
.badge-gray   { background: var(--surface2);   color: var(--text3); }
.badge-red    { background: var(--red-dim);    color: var(--red); }
.badge-blue   { background: var(--accent-dim); color: var(--accent); }

/* ── Panel header ───────────────────────────────────────────────────────── */
.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.panel-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  color: var(--text2);
  background: var(--surface2);
  transition: background .15s, color .15s;
}
.back-btn:hover { background: var(--border); color: var(--text); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { opacity: .88; }
.btn-dashed {
  border: 1.5px dashed var(--border);
  color: var(--text2);
}
.btn-dashed:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--red-dim); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }

/* ── Info card (service detail) ─────────────────────────────────────────── */
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 560px;
  box-shadow: var(--shadow);
}
.info-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 14px;
}
.info-note {
  font-size: .875rem;
  color: var(--text2);
  margin-bottom: 16px;
  line-height: 1.6;
}
.info-warn {
  background: var(--amber-dim);
  border: 1px solid var(--amber);
  color: var(--amber);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: .8rem;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.info-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.info-details {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 8px;
}
.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: .8rem;
  border-bottom: 1px solid var(--border);
}
.kv:last-child { border-bottom: none; }
.kv-key { color: var(--text2); }
.kv-val { font-family: var(--mono); color: var(--text); }

/* ── Settings ───────────────────────────────────────────────────────────── */
.settings-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  max-width: 600px;
  box-shadow: var(--shadow);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.settings-row:last-child { border-bottom: none; }
.settings-title {
  font-size: .875rem;
  font-weight: 500;
  color: var(--text);
}
.settings-sub {
  font-size: .75rem;
  color: var(--text2);
  margin-top: 2px;
}
.settings-warn .settings-title { color: var(--amber); }
.settings-danger .settings-title { color: var(--red); }

/* ── Weather widget ─────────────────────────────────────────────────────── */
.wx-card {
  background: linear-gradient(135deg, #1a3a6e 0%, #1e4080 60%, #2a5298 100%);
  border-radius: var(--radius);
  padding: 22px;
  color: #fff;
  box-shadow: 0 4px 20px rgba(26,58,110,.35);
  max-width: 420px;
}
.wx-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}
.wx-big {
  font-size: 3.2rem;
  font-weight: 700;
  font-family: var(--mono);
  line-height: 1;
}
.wx-cond {
  font-size: .95rem;
  opacity: .85;
  margin-top: 4px;
}
.wx-loc {
  font-size: .8rem;
  opacity: .7;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.wx-icon {
  font-size: 3rem;
  opacity: .9;
}
.forecast {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  border-top: 1px solid rgba(255,255,255,.2);
  padding-top: 14px;
  margin-top: 4px;
}
.fc-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.fc-label {
  font-size: .7rem;
  opacity: .7;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.fc-icon { font-size: 1.25rem; opacity: .85; }
.fc-temp {
  font-size: .8rem;
  font-weight: 600;
}
.fc-lo {
  font-size: .75rem;
  opacity: .6;
}

/* ── Pi-hole widget ─────────────────────────────────────────────────────── */
.ph-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.ph-numbers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.ph-stat { text-align: center; }
.ph-val {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--text);
}
.ph-label {
  font-size: .7rem;
  color: var(--text3);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.ph-chart-wrap {
  display: flex;
  justify-content: center;
  margin-top: 8px;
}

/* ── Spotify widget ─────────────────────────────────────────────────────── */
.sp-card {
  background: #191414;
  border-radius: var(--radius);
  padding: 20px;
  color: #fff;
  max-width: 340px;
  box-shadow: var(--shadow);
}
.sp-icon {
  color: #1db954;
  font-size: 2rem;
  margin-bottom: 10px;
}
.sp-title {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.sp-note {
  font-size: .8rem;
  color: rgba(255,255,255,.6);
  margin-bottom: 14px;
}
.sp-now {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.sp-art {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  background: #282828;
  flex-shrink: 0;
  object-fit: cover;
}
.sp-track {
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sp-artist {
  font-size: .8rem;
  color: rgba(255,255,255,.6);
  margin-top: 2px;
}
.sp-bar {
  height: 3px;
  background: rgba(255,255,255,.2);
  border-radius: 2px;
}
.sp-bar-fill {
  height: 100%;
  background: #1db954;
  border-radius: 2px;
  transition: width .5s linear;
}

/* ── Journal app ────────────────────────────────────────────────────────── */
.journal {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  max-width: 860px;
}
.journal-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.journal-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.journal-item:last-child { border-bottom: none; }
.journal-item:hover { background: var(--surface2); }
.journal-item.active { background: var(--accent-dim); }
.ji-date {
  font-size: .75rem;
  font-family: var(--mono);
  color: var(--text3);
  margin-bottom: 3px;
}
.ji-prev {
  font-size: .8rem;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.journal-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}
.journal-date {
  font-size: .8rem;
  font-family: var(--mono);
  color: var(--text3);
}
.journal-area {
  flex: 1;
  min-height: 280px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: .875rem;
  padding: 12px;
  line-height: 1.6;
  outline: none;
  transition: border-color .15s;
  font-family: var(--font);
}
.journal-area:focus { border-color: var(--accent); }
.journal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.journal-count {
  font-size: .75rem;
  color: var(--text3);
  font-family: var(--mono);
}

/* ── Games grid ─────────────────────────────────────────────────────────── */
.games-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.game-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: border-color .15s, transform .12s, box-shadow .15s;
  text-align: center;
  box-shadow: var(--shadow);
}
.game-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(79,110,247,.15);
}
.game-icon {
  font-size: 2.2rem;
  color: var(--accent);
  margin-bottom: 10px;
}
.game-name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.game-desc { font-size: .8rem; color: var(--text2); }
.game-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.game-playing {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
}

/* ── Sudoku ─────────────────────────────────────────────────────────────── */
.sudoku-top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.diff-group { display: flex; gap: 6px; }
.diff-btn {
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 500;
  border: 1.5px solid var(--border);
  color: var(--text2);
  background: var(--surface);
  transition: all .15s;
}
.diff-btn:hover, .diff-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
.sudoku-timer {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text2);
  min-width: 52px;
}
.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 1px;
  background: var(--border);
  border: 2px solid var(--text2);
  border-radius: 4px;
  width: fit-content;
  margin-bottom: 16px;
}
.s-cell {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-family: var(--mono);
  background: var(--surface);
  cursor: pointer;
  transition: background .1s;
  border: none;
  outline: none;
  color: var(--accent);
  user-select: none;
}
.s-cell.given { color: var(--text); font-weight: 600; cursor: default; }
.s-cell.selected { background: var(--accent-dim) !important; color: var(--accent); }
.s-cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--text2); }
.s-cell:nth-child(n+19):nth-child(-n+27) { border-bottom: 2px solid var(--text2); }
.s-cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--text2); }

.num-pad {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}
.num-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: .95rem;
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .12s;
}
.num-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.sudoku-controls { display: flex; gap: 8px; }

/* ── App iframe ─────────────────────────────────────────────────────────── */
.app-frame {
  width: 100%;
  height: calc(100vh - var(--topbar-h) - 90px);
  border: none;
  border-radius: var(--radius);
  background: var(--surface2);
}

/* ── Empty / loading states ─────────────────────────────────────────────── */
.empty {
  color: var(--text3);
  font-size: .875rem;
  padding: 32px 0;
  text-align: center;
}
.loading {
  color: var(--text3);
  font-size: .85rem;
  padding: 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Status helpers ─────────────────────────────────────────────────────── */
.status-running { color: var(--green); }
.status-deploy  { color: var(--amber); }

/* ── Screen reader only ─────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  :root { --sidebar-w: 60px; }
  .dash {
    grid-template-columns: var(--sidebar-w) 1fr;
  }
  .nav-item span { display: none; }
  .nav-section-label { display: none; }
  .topbar-sitename { display: none; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
  .games-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 16px; }
  .journal { grid-template-columns: 1fr; }
}
