/* Lowertown Pulse — "operations terminal" theme.
   Dark-first (a back-of-house instrument read in a dim bar), monospace-forward for
   all data/labels/status so numbers and columns align like a departure board; a
   clean sans is reserved for human prose (event titles, post copy, track names).
   Strong semantic status colour is the backbone of the honest-freshness design. */

:root {
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Menlo", "Consolas", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* dark (default) */
  --bg: #0c0e12;
  --bg-glow: #141a26;
  --panel: #14171e;
  --panel-2: #1a1f29;
  --line: #262d3a;
  --line-soft: #1e2530;
  --ink: #e8edf4;
  --ink-dim: #8a97a8;
  --ink-faint: #5a6473;
  --ok: #3fd07a;
  --stale: #eab029;
  --error: #ff5d4d;
  --inactive: #5a6577;
  --accent: #5cb2ff;
  --ok-bg: rgba(63, 208, 122, 0.13);
  --stale-bg: rgba(234, 176, 41, 0.14);
  --error-bg: rgba(255, 93, 77, 0.13);
  --inactive-bg: rgba(90, 101, 119, 0.16);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.02) inset, 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f5;
    --bg-glow: #e2e8f1;
    --panel: #ffffff;
    --panel-2: #f4f6fa;
    --line: #dce1ea;
    --line-soft: #e7ebf1;
    --ink: #10151d;
    --ink-dim: #55606f;
    --ink-faint: #8a94a3;
    --ok: #1a9e51;
    --stale: #b07d09;
    --error: #d33a2c;
    --inactive: #8894a5;
    --accent: #1f7fd6;
    --ok-bg: rgba(26, 158, 81, 0.10);
    --stale-bg: rgba(176, 125, 9, 0.12);
    --error-bg: rgba(211, 58, 44, 0.10);
    --inactive-bg: rgba(136, 148, 165, 0.14);
    --shadow: 0 1px 2px rgba(16, 21, 29, 0.06), 0 6px 18px rgba(16, 21, 29, 0.08);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }

body {
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(1100px 460px at 82% -8%, var(--bg-glow), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

.ico {
  width: 1em; height: 1em; flex: none;
  vertical-align: -0.14em;
}

/* ---- shell + header ---- */

.app-shell { max-width: 1400px; margin: 0 auto; padding: clamp(14px, 3vw, 30px); }

.app-header {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding-bottom: 16px; margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.app-header h1 {
  margin: 0; font-size: clamp(15px, 2.4vw, 19px);
  font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase;
  display: inline-flex; align-items: center; gap: 12px;
}
.app-header h1::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 0 0 var(--ok);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(63, 208, 122, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(63, 208, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(63, 208, 122, 0); }
}
.conn-status { color: var(--ink-faint); font-size: 12px; letter-spacing: 0.04em; }

/* ---- tile grid ---- */

.tiles { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.tile {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 15px 16px 16px;
  box-shadow: var(--shadow);
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
}
.tile-display { animation-delay: 0.02s; }
.tile-pipelines { animation-delay: 0.06s; }
.tile-events { animation-delay: 0.10s; }
.tile-social { animation-delay: 0.14s; }
.tile-music { animation-delay: 0.18s; }
.tile-sales { animation-delay: 0.22s; }
.tile-actions { animation-delay: 0.26s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .tile { animation: none; } .app-header h1::before { animation: none; } }

.tile-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.tile-title { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.tile-title h2 {
  margin: 0; font-size: 12px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-ico { width: 15px; height: 15px; color: var(--ink-faint); }
.status-line { display: inline-flex; align-items: center; gap: 7px; flex: none; }
.age { color: var(--ink-faint); font-size: 11.5px; letter-spacing: 0.03em; }

/* ---- status dots ---- */

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.dot-ok { background: var(--ok); box-shadow: 0 0 7px -1px var(--ok); }
.dot-stale { background: var(--stale); box-shadow: 0 0 7px -1px var(--stale); }
.dot-error { background: var(--error); box-shadow: 0 0 7px -1px var(--error); }
.dot-missing { background: var(--error); box-shadow: 0 0 8px 0 var(--error); }
.dot-inactive { background: var(--inactive); }

.status-ok { color: var(--ok); }
.status-stale { color: var(--stale); }
.status-error, .status-missing { color: var(--error); }
.status-inactive { color: var(--inactive); }

/* ---- error inset + banner ---- */

.inset {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 11px 12px; border-radius: 9px; margin-bottom: 4px;
  background: var(--stale-bg); border: 1px solid transparent;
}
.inset-ico { width: 15px; height: 15px; margin-top: 2px; flex: none; }
.inset-error { background: var(--error-bg); color: var(--error); }
.inset-stale, .inset-missing { background: var(--stale-bg); color: var(--stale); }
.inset-inactive { background: var(--inactive-bg); color: var(--ink-dim); }
.inset p { margin: 0; }
.inset-reason { font-size: 13px; }
.inset-lastgood { font-size: 11.5px; opacity: 0.8; margin-top: 2px; }

.banner {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 11px; border-radius: 8px; margin: 0 0 11px;
  font-size: 12.5px; background: var(--stale-bg); color: var(--stale);
}

/* ---- key/value + prose helpers ---- */

.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0 0; }
.kv dt { color: var(--ink-faint); font-size: 11.5px; letter-spacing: 0.05em; text-transform: uppercase; }
.kv dd { margin: 0; color: var(--ink); }
.empty { color: var(--ink-faint); font-size: 13px; padding: 6px 0; }

/* ---- 1. display ---- */

.display-box { position: relative; }
.display-thumb {
  width: 100%; aspect-ratio: 9 / 16; max-height: 340px; object-fit: contain;
  border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line-soft);
  display: block; margin: 0 auto;
}
.display-thumb-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--ink-faint); aspect-ratio: auto; min-height: 90px; padding: 20px;
  text-align: center; font-size: 12.5px;
}
.display-thumb-empty .ico { width: 26px; height: 26px; }
.ovr-badge {
  position: absolute; top: 8px; left: 8px;
  background: var(--stale); color: #1a1206; font-weight: 700;
  font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 5px;
}
.pi-line { display: flex; align-items: center; gap: 8px; margin: 12px 0 0; }
.run-errors { display: flex; gap: 6px; color: var(--error); font-size: 12px; margin: 8px 0 0; }

/* ---- 2. pipelines: departure-board grid ---- */

.check-list { list-style: none; margin: 0; padding: 0; }
.check-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas: "dot name status age" ".   sch  sch    sch";
  align-items: center; column-gap: 10px; row-gap: 1px;
  padding: 8px 0; border-bottom: 1px solid var(--line-soft);
}
.check-row:last-child { border-bottom: 0; }
.check-row .dot { grid-area: dot; }
.check-name { grid-area: name; text-align: left; color: var(--ink); }
.check-status { grid-area: status; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.check-age { grid-area: age; color: var(--ink-dim); text-align: right; min-width: 3.2em; }
.check-schedule { grid-area: sch; color: var(--ink-faint); font-size: 11px; }

/* ---- 3. today ---- */

.event-group + .event-group { margin-top: 12px; }
.event-day {
  margin: 0 0 7px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent);
}
.event-list { list-style: none; margin: 0; padding: 0; }
.event-row {
  display: grid; grid-template-columns: minmax(72px, auto) 1fr; gap: 4px 12px;
  padding: 9px 0; border-bottom: 1px solid var(--line-soft);
}
.event-row:last-child { border-bottom: 0; }
.event-when { color: var(--ink-dim); font-size: 12px; padding-top: 1px; }
.event-title { font-family: var(--sans); font-weight: 600; color: var(--ink); line-height: 1.35; }
.event-cal { color: var(--ink-faint); font-size: 11px; letter-spacing: 0.04em; margin-top: 1px; }
.event-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }

/* promo pills — status-tinted, icon + label, deliberately NOT button-shaped */
.promo {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; letter-spacing: 0.02em; line-height: 1;
  padding: 4px 8px; border-radius: 6px; white-space: nowrap;
  background: var(--inactive-bg); color: var(--ink-dim);
}
.promo .ico { width: 12px; height: 12px; }
.promo-ok { background: var(--ok-bg); color: var(--ok); }
.promo-stale { background: var(--stale-bg); color: var(--stale); }
.promo-error { background: var(--error-bg); color: var(--error); }
.promo-dim { background: var(--inactive-bg); color: var(--ink-dim); }

/* social pill is a tap-to-reveal disclosure; keep it pill-shaped, hide the marker */
.social-badge-details { display: inline-block; }
.social-badge-details summary {
  list-style: none; cursor: pointer; min-height: 44px;
  display: inline-flex; align-items: center;
}
.social-badge-details summary::-webkit-details-marker { display: none; }
.social-badge-details .matched-post-title {
  display: block; margin-top: 5px; padding: 6px 8px;
  font-family: var(--sans); font-size: 12px; color: var(--ink-dim);
  background: var(--panel-2); border-radius: 6px; border: 1px solid var(--line-soft);
}
/* the 44px tap target must not visually inflate the pill row */
.event-badges .social-badge-details summary { min-height: 0; }
.event-badges .social-badge-details { position: relative; }
.event-badges .social-badge-details summary::before {
  content: ""; position: absolute; inset: -11px -4px; /* invisible ~44px-tall hit area */
}

/* ---- 4. social ---- */

.stat-row { display: flex; flex-wrap: wrap; gap: 16px; margin: 0 0 12px; }
.stat { color: var(--ink-dim); font-size: 12px; }
.stat b { color: var(--ink); font-size: 16px; font-weight: 700; margin-right: 3px; }
.stat-ok { color: var(--ok); }
.stat-error { color: var(--error); }

.post-list { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; }
.post-row {
  display: grid; grid-template-columns: auto 1fr; gap: 9px;
  padding: 10px 0; border-bottom: 1px solid var(--line-soft);
}
.post-row:last-child { border-bottom: 0; }
.post-row .dot { margin-top: 5px; }
.post-body { min-width: 0; }
.post-meta { display: flex; align-items: center; gap: 8px; }
.post-channel { font-weight: 600; color: var(--ink); font-size: 12.5px; }
.post-date { color: var(--ink-faint); font-size: 11.5px; }
.post-link {
  min-height: 44px; margin-left: auto;
  display: inline-flex; align-items: center; color: var(--accent); text-decoration: none;
}
.post-link .ico { width: 14px; height: 14px; }
.post-content {
  font-family: var(--sans); font-size: 12.5px; color: var(--ink-dim);
  line-height: 1.4; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.post-error { display: block; margin-top: 4px; color: var(--error); font-size: 12px; }

/* ---- 5. music ---- */

.now-playing {
  display: flex; align-items: center; gap: 10px; margin: 0;
  font-family: var(--sans);
}
.now-playing .np-ico { width: 18px; height: 18px; color: var(--ok); flex: none; }
.now-playing b { font-size: 15.5px; display: block; color: var(--ink); }
.np-artist { color: var(--ink-dim); font-size: 13px; }
.now-playing-empty { color: var(--ink-faint); font-family: var(--mono); font-size: 13px; }
.playback-state {
  margin: 8px 0 0; color: var(--ok); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.1em;
}
.schedule-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0 0; color: var(--ink-dim); font-size: 12.5px; }
.playlist-sync { display: flex; align-items: center; gap: 8px; margin: 10px 0 0; color: var(--ink-dim); font-size: 12.5px; }

/* ---- 6. sales ---- */

.sales-big { margin: 0; font-size: clamp(30px, 6vw, 40px); font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.sales-big.sales-empty { font-size: 18px; color: var(--ink-faint); font-weight: 500; }
.sales-sub { display: block; font-size: 12px; font-weight: 400; color: var(--ink-faint); letter-spacing: 0.03em; margin-top: 6px; }
.sales-delta { margin: 12px 0 0; color: var(--ink-dim); font-size: 12.5px; }
.delta-chip { font-weight: 700; padding: 1px 6px; border-radius: 5px; margin-left: 2px; }
.delta-up { color: var(--ok); background: var(--ok-bg); }
.delta-down { color: var(--error); background: var(--error-bg); }

.mini-bars { display: flex; align-items: flex-end; gap: 6px; height: 82px; margin: 16px 0 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%; border-radius: 4px 4px 2px 2px;
  height: calc(6px + var(--v, 0) * 62px);
  background: linear-gradient(to top, var(--accent), color-mix(in srgb, var(--accent) 60%, transparent));
}
.bar-empty { height: 6px; background: repeating-linear-gradient(45deg, var(--line), var(--line) 3px, transparent 3px, transparent 6px); border: 1px dashed var(--line); }
.bar-label { color: var(--ink-faint); font-size: 10.5px; }
.sales-caption { margin: 6px 0 0; color: var(--ink-faint); font-size: 11px; line-height: 1.4; }

/* ---- actions ---- */

.tile-actions { grid-column: 1 / -1; margin-top: 4px; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 9px; }
.action-btn {
  display: inline-flex; align-items: center; gap: 7px; min-height: 44px;
  font-family: var(--mono); font-size: 12.5px; color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 0 14px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.action-btn::before { content: ""; width: 14px; height: 14px; flex: none;
  background: var(--accent);
  -webkit-mask: no-repeat center / contain; mask: no-repeat center / contain;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13 2 3 14h7l-1 8 10-12h-7l1-8Z'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M13 2 3 14h7l-1 8 10-12h-7l1-8Z'/%3E%3C/svg%3E"); }
.action-btn:hover { border-color: var(--accent); background: var(--panel); }
.action-btn:active { transform: translateY(1px); }
.action-btn:disabled { opacity: 0.5; cursor: default; }
.action-result {
  font-family: var(--mono); font-size: 12px; color: var(--ink-dim);
  white-space: pre-wrap; word-break: break-word; margin: 12px 0 0;
  max-height: 220px; overflow: auto;
}
.action-result:empty { display: none; }
.quick-links { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.quick-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px;
  font-size: 12.5px; color: var(--ink-dim); text-decoration: none;
  padding: 0 12px; border-radius: 8px; border: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.quick-link .ico { width: 13px; height: 13px; }
.quick-link:hover { color: var(--accent); border-color: var(--line); }

/* ---- login ---- */

.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 30px 26px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 {
  margin: 0 0 6px; font-size: 15px; letter-spacing: 0.2em; text-transform: uppercase;
  text-align: center; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.login-card h1::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.login-card label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.login-card input {
  font-family: var(--mono); font-size: 15px; color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 13px; min-height: 44px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-submit {
  min-height: 44px; font-family: var(--mono); font-size: 13px; letter-spacing: 0.06em;
  color: #05130a; background: var(--ok); border: 0; border-radius: 9px;
  cursor: pointer; font-weight: 700; margin-top: 4px;
}
.login-submit:hover { filter: brightness(1.06); }
.login-error { color: var(--error); font-size: 12.5px; margin: 2px 0 0; min-height: 1em; text-align: center; }
