/* KLM Command Center 3 — glassmorphism over AMOLED black.
   Every color is a token below; Settings › Appearance rewrites them at runtime (cc-settings.js applyTheme). */
:root {
  --bg: #000000;
  --text: #f2f4f8;
  --accent-h: 255;
  --glass-rgb: 255 255 255;
  --glass-a: 0.07;
  --blur: 16px;
  --radius: 14px;
  --danger: #ff4d5e;
  --ok: #3ddc97;
  --cold: #4cb8ff;
  --warm: #ff9a3d;

  --accent: hsl(var(--accent-h) 95% 68%);
  --accent-soft: hsl(var(--accent-h) 95% 68% / 0.18);
  --accent-ink: hsl(var(--accent-h) 60% 12%);
  --glass: rgb(var(--glass-rgb) / var(--glass-a));
  --glass-hi: rgb(var(--glass-rgb) / calc(var(--glass-a) * 1.8));
  --glass-border: rgb(var(--glass-rgb) / calc(var(--glass-a) * 1.6 + 0.04));
  --muted: color-mix(in srgb, var(--text) 58%, transparent);
  --shadow: 0 8px 28px rgb(0 0 0 / 0.45);
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.4 'Roboto Flex', system-ui, -apple-system, 'Segoe UI', sans-serif;
  overscroll-behavior-y: contain;
  display: flex; justify-content: center;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Ambient glow so the glass has something to refract on pure black */
body::before {
  content: ''; position: fixed; inset: -20vmax; z-index: -2; pointer-events: none;
  background:
    radial-gradient(40vmax 40vmax at 15% 10%, hsl(var(--accent-h) 90% 50% / 0.16), transparent 60%),
    radial-gradient(35vmax 35vmax at 90% 80%, hsl(calc(var(--accent-h) + 60) 90% 50% / 0.12), transparent 60%);
}
#animCanvas { position: fixed; inset: 0; z-index: -1; pointer-events: none; width: 100vw; height: 100vh; }

/* ---------- Glass primitive ---------- */
.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(var(--blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(140%);
  box-shadow: var(--shadow);
}

/* ---------- Layout ---------- */
.app {
  width: 100%; max-width: 1180px; min-width: 0;
  display: flex; flex-direction: column; gap: 10px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 80px max(10px, env(safe-area-inset-left));
}
.topbar { position: sticky; top: 6px; z-index: 20; padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.topbar-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.brand img { width: 32px; height: 32px; border-radius: 9px; }
.brand h1 { margin: 0; font-size: 1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { color: var(--muted); font-size: .72rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Segmented control groups — contrasted background per AGENTS.md */
.seg { display: flex; gap: 2px; padding: 3px; border-radius: calc(var(--radius) - 2px); background: var(--glass-hi); border: 1px solid var(--glass-border); }
.seg .btn { border: 0; background: transparent; }
.seg .btn:hover { background: var(--glass-hi); }

/* ---------- Buttons (CodeShack-style: soft, rounded, quick lift) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 0 12px; border-radius: calc(var(--radius) - 4px);
  border: 1px solid var(--glass-border); background: var(--glass);
  cursor: pointer; font-weight: 600; font-size: .82rem; white-space: nowrap;
  transition: background .2s var(--ease), transform .15s var(--ease), border-color .2s, box-shadow .2s;
}
.btn:hover { background: var(--glass-hi); border-color: var(--accent-soft); }
.btn:active { transform: scale(.96); }
.btn:focus-visible, .chip:focus-visible, .input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { box-shadow: 0 4px 18px var(--accent-soft); }
.btn.danger { color: var(--danger); }
.btn.icon { width: 36px; padding: 0; }
.btn.round { border-radius: 50%; }
.btn.is-error { background: var(--danger); color: var(--bg); border-color: transparent; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 25%, transparent); } }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; min-height: 28px;
  border-radius: 999px; border: 1px solid var(--glass-border); background: var(--glass);
  font-size: .76rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .2s var(--ease), color .2s;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.tag { font-size: .66rem; padding: 2px 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.tag.alt { background: var(--glass-hi); color: var(--muted); }

/* ---------- Inputs ---------- */
.input {
  width: 100%; min-height: 36px; padding: 7px 11px; border-radius: calc(var(--radius) - 4px);
  border: 1px solid var(--glass-border); background: rgb(var(--glass-rgb) / 0.04);
  transition: border-color .2s, box-shadow .2s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 180px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .82rem; }
input[type=color].input { padding: 2px; width: 46px; min-height: 30px; cursor: pointer; }

/* Toggle switch */
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--glass-hi); border: 1px solid var(--glass-border); transition: background .25s var(--ease); cursor: pointer; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--text); transition: transform .25s var(--ease); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--accent-ink); }

/* Range slider */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 999px; background: var(--glass-hi); accent-color: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }

/* ---------- Bookmarks bar ---------- */
.bookmarks { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.bookmarks::-webkit-scrollbar { display: none; }
.bm { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 5px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-border); font-size: .78rem; white-space: nowrap; transition: background .2s; }
.bm:hover { background: var(--glass-hi); }
.bm img { width: 18px; height: 18px; border-radius: 50%; }

/* ---------- Widgets ---------- */
.widgets { display: flex; gap: 8px; flex-wrap: wrap; }
.widget { flex: 1 1 140px; padding: 9px 12px; min-width: 0; }
.widget .label { font-size: .66rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.widget .value { font-size: 1.25rem; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.widget .sub { font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 8px; }
.toolbar .meta { margin: 0 4px 0 2px; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--glass-border); margin: 2px 4px; }

/* ---------- Project grid ---------- */
.proj-grid { display: flex; flex-wrap: wrap; gap: 10px; } /* not ".grid": Tailwind CDN owns that utility */
.card {
  flex: 1 1 260px; max-width: 100%; min-width: 0; display: flex; flex-direction: column; overflow: hidden;
  transition: transform .25s var(--ease), border-color .25s, box-shadow .25s;
  --hue: var(--accent-h);
}
@media (min-width: 900px) { .card { max-width: calc((100% - 20px) / 3); } }
.card:hover { transform: translateY(-3px); border-color: hsl(var(--hue) 90% 65% / 0.5); box-shadow: 0 12px 34px hsl(var(--hue) 90% 40% / 0.25); }
.card .shot { position: relative; aspect-ratio: 16/8; background: linear-gradient(135deg, hsl(var(--hue) 80% 30% / .6), hsl(calc(var(--hue) + 40) 80% 15% / .6)); overflow: hidden; }
.card .shot img.snap { width: 100%; height: 100%; object-fit: cover; object-position: top; opacity: .9; transition: transform .4s var(--ease); }
.card:hover .shot img.snap { transform: scale(1.04); }
.card .shot .ico { position: absolute; left: 10px; bottom: -16px; width: 40px; height: 40px; border-radius: 11px; background: var(--bg); border: 1px solid var(--glass-border); padding: 4px; }
.card .status { position: absolute; top: 8px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 2px rgb(0 0 0 / .5); }
.card .status.up { background: var(--ok); }
.card .status.down { background: var(--danger); }
.card .body { padding: 20px 12px 10px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.card .title { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.card .title b { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .ver { font-size: .72rem; color: hsl(var(--hue) 90% 72%); font-weight: 700; }
.card .desc { font-size: .8rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .tags { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.card .foot { display: flex; gap: 6px; align-items: center; padding: 0 12px 10px; }
.card .foot .upd { flex: 1; font-size: .72rem; color: var(--muted); }
.card .open { background: hsl(var(--hue) 90% 62%); color: hsl(var(--hue) 60% 10%); border-color: transparent; }
.empty { width: 100%; text-align: center; padding: 30px; color: var(--muted); }

/* ---------- Overlay / sheet (modal) ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 12px; background: rgb(0 0 0 / .55); opacity: 0; pointer-events: none; transition: opacity .2s var(--ease); }
.overlay.open { opacity: 1; pointer-events: auto; }
.sheet { width: 100%; max-width: 620px; max-height: min(86vh, 860px); display: flex; flex-direction: column; transform: translateY(14px) scale(.98); transition: transform .25s var(--ease); background: color-mix(in srgb, var(--bg) 70%, transparent); }
.overlay.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--glass-border); }
.sheet-head h2 { margin: 0; flex: 1; font-size: 1rem; }
.sheet-body { padding: 10px 12px 14px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.sheet-body > * { flex-shrink: 0; } /* scroll the body; never squash sections */
.sheet-foot { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--glass-border); }
@media (max-width: 640px) {
  .overlay { align-items: flex-end; padding: 0; }
  .sheet { max-width: none; border-radius: var(--radius) var(--radius) 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
}

/* ---------- Accordion (settings categories) ---------- */
.acc { border: 1px solid var(--glass-border); border-radius: calc(var(--radius) - 2px); background: var(--glass); overflow: hidden; }
.acc > summary { list-style: none; cursor: pointer; padding: 10px 12px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::after { content: '▸'; margin-left: auto; color: var(--muted); transition: transform .2s var(--ease); }
.acc[open] > summary::after { transform: rotate(90deg); }
.acc[open] > summary { border-bottom: 1px solid var(--glass-border); }
.acc .rows { padding: 6px 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; min-height: 32px; }
.row > label, .row > .lbl { flex: 1; font-size: .84rem; }
.row .hint { color: var(--muted); font-size: .72rem; display: block; }
.row .val { min-width: 38px; text-align: right; font-size: .76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.row input[type=range] { flex: 1.3; }

/* ---------- Weather ---------- */
.widget.clickable { cursor: pointer; transition: transform .2s var(--ease), border-color .2s; }
.widget.clickable:hover { border-color: var(--accent-soft); transform: translateY(-2px); }
.widget.clickable .label::after { content: ' ›'; }
.sheet.wide { max-width: 980px; }
.wx-card { display: flex; flex-direction: column; gap: 8px; }
.wx-now { display: flex; align-items: center; gap: 14px; }
.wx-big { display: flex; align-items: center; gap: 6px; font-size: 2.4rem; line-height: 1; }
.wx-big b { font-size: 2.6rem; font-weight: 800; }
.wx-cond { font-size: 1.05rem; font-weight: 700; }
.wx-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.wx-stat { flex: 1 1 110px; padding: 6px 9px; border-radius: calc(var(--radius) - 4px); background: var(--glass); border: 1px solid var(--glass-border); display: flex; flex-direction: column; }
.wx-stat span { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.wx-stat b { font-size: .9rem; }
.wx-hours { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 4px; }
.wx-hour { flex: 0 0 54px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border-radius: 10px; background: var(--glass); font-size: .78rem; }
.wx-hour small { color: var(--muted); font-size: .68rem; }
.wx-hour .wx-pp { color: var(--cold); min-height: 1em; }
.wx-days { display: flex; flex-direction: column; gap: 2px; }
.wx-day { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--glass-border); }
.wx-day:last-child { border-bottom: 0; }
.wx-dn { width: 46px; flex: none; }
.wx-di { font-size: 1.3rem; width: 28px; flex: none; text-align: center; }
.wx-dl { flex: 1 1 auto; min-width: 0; font-size: .82rem; display: flex; flex-direction: column; }
.wx-dl small { color: var(--muted); font-size: .7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wx-t { width: 34px; flex: none; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.wx-t.lo { color: var(--muted); }
.wx-bar { position: relative; flex: 0 1 140px; min-width: 50px; height: 6px; border-radius: 999px; background: var(--glass-hi); }
.wx-bar i { position: absolute; top: 0; bottom: 0; border-radius: 999px; background: linear-gradient(90deg, var(--cold), var(--warm)); }
.wx-map { width: 100%; height: min(60vh, 460px); border: 0; border-radius: calc(var(--radius) - 4px); background: var(--glass); }
@media (max-width: 640px) { .wx-bar { flex-basis: 60px; } .wx-map { height: 50vh; } }

/* Changelog list */
.cl { border-left: 2px solid var(--accent-soft); padding: 2px 0 2px 10px; }
.cl b { color: var(--accent); }
.cl small { color: var(--muted); margin-left: 6px; }
.cl ul { margin: 4px 0 0; padding-left: 18px; font-size: .82rem; }
.kv { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8rem; }
.kv span { color: var(--muted); }
.files { font: .76rem ui-monospace, Consolas, monospace; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }

/* Console */
.log { font: .74rem/1.45 ui-monospace, Consolas, monospace; display: flex; flex-direction: column; gap: 2px; }
.log div { padding: 3px 6px; border-radius: 6px; word-break: break-word; }
.log .error { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.log .warn { background: rgb(var(--glass-rgb) / .06); }
.log .action { color: var(--accent); }
.log time { color: var(--muted); margin-right: 6px; }

/* Command palette */
.palette-list { display: flex; flex-direction: column; gap: 2px; }
.palette-item { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 9px; cursor: pointer; border: 0; background: transparent; text-align: left; width: 100%; }
.palette-item.sel, .palette-item:hover { background: var(--accent-soft); }
.palette-item img { width: 20px; height: 20px; border-radius: 5px; }
.palette-item small { margin-left: auto; color: var(--muted); }

/* ---------- Badges ---------- */
.sync-badge, .offline-badge { display: inline-flex; align-items: center; gap: 5px; font-size: .7rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--glass-hi); border: 1px solid var(--glass-border); white-space: nowrap; }
.sync-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.sync-badge.ok .dot { background: var(--ok); }
.sync-badge.busy .dot { background: var(--accent); animation: pulse 1s infinite; }
.sync-badge.err .dot { background: var(--danger); }
.offline-badge { color: var(--danger); }
.avatar { width: 30px; height: 30px; border-radius: 50%; }

/* ---------- Toast / tooltip ---------- */
.toast-wrap { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; padding: 9px 14px; font-size: .84rem; display: flex; gap: 10px; align-items: center; animation: toastIn .25s var(--ease); background: color-mix(in srgb, var(--bg) 70%, transparent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }
[data-tip] { position: relative; }
@media (hover: hover) {
  [data-tip]:hover::after { content: attr(data-tip); position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); padding: 4px 8px; border-radius: 6px; font-size: .7rem; white-space: nowrap; background: var(--text); color: var(--bg); z-index: 90; pointer-events: none; }
}

/* ---------- Pull to refresh ---------- */
.pull-indicator { position: fixed; top: 0; left: 50%; z-index: 60; transform: translate(-50%, -48px); width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; transition: transform .15s; }
.pull-indicator.ready { color: var(--accent); }

/* ---------- Overflow menu + responsive ---------- */
.more-menu { margin: 0; inset: auto; position: fixed; top: 56px; right: 10px; padding: 6px; min-width: 190px; color: var(--text); background: color-mix(in srgb, var(--bg) 75%, transparent); }
.more-menu:popover-open { display: flex; flex-direction: column; gap: 2px; }
.menu-item { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; text-align: left; font-weight: 600; }
.menu-item:hover { background: var(--glass-hi); }
.menu-item.is-error { color: var(--danger); }
.mob-only { display: none !important; }
.fab-search { position: fixed; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 30; width: 52px; height: 52px; border-radius: 50%; display: none; font-weight: 800; }
@media (max-width: 760px) {
  .desk-only { display: none !important; }
  .mob-only { display: inline-flex !important; }
  .fab-search { display: inline-flex; }
  .brand small { display: none; }
  .topbar-row { gap: 6px; }
  .widget, .toolbar, .card .body, .card .foot { min-width: 0; }
  .widget { flex-basis: calc(50% - 4px); }
  .card { flex-basis: 100%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; } }
