/* ---------------------------------------------------------------
   Design tokens — ShowRun brand palette (Primary / Secondary / Accent)
   Light surface. Primary (navy-teal) carries chrome and text. Accent
   (teal-green) reads as "go/running" — Secondary (terracotta) reads as
   "stop/attention" — matching the intuitive cool=go, warm=stop mapping
   without needing a color outside the given system.
------------------------------------------------------------------ */
:root {
  /* Primary */
  --p50: #e6ebed;
  --p75: #97adb4;
  --p100: #6c8b94;
  --p200: #2d5966;
  --p300: #023747;
  --p400: #012732;
  --p500: #01222b;

  /* Secondary */
  --s50: #fdf3f0;
  --s75: #f8cfc3;
  --s100: #f6bcaa;
  --s200: #f29f86;
  --s300: #ef8b6d;
  --s400: #a7614c;
  --s500: #925542;

  /* Accent */
  --a50: #eef8f8;
  --a75: #bae1e4;
  --a100: #9dd4d8;
  --a200: #73c2c7;
  --a300: #56b5bc;
  --a400: #3c7f84;
  --a500: #346e73;

  --bg: var(--p50);
  --surface: #ffffff;
  --surface-alt: var(--a50);
  --border: #d3dde0;

  --text-primary: var(--p500);
  --text-secondary: var(--p300);
  --text-muted: var(--p100);

  --status-running: var(--a400);
  --status-running-bg: var(--a50);
  --status-running-border: var(--a75);

  --status-stopped: var(--p100);
  --status-stopped-bg: var(--p50);
  --status-stopped-border: var(--p75);

  --status-pending: var(--s300);
  --status-pending-bg: var(--s50);
  --status-pending-border: var(--s75);

  --status-partial: var(--s400);
  --status-partial-bg: var(--s50);
  --status-partial-border: var(--s100);

  --status-error: var(--s500);
  --status-error-bg: var(--s50);
  --status-error-border: var(--s200);

  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(1, 34, 43, 0.06);
  --shadow-md: 0 4px 16px rgba(1, 34, 43, 0.08);

  --font-ui: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

/* The browser's built-in "[hidden] { display: none }" rule has the same
   CSS specificity as a single class selector. Any element below that also
   sets its own "display" property (flex/grid/block) will silently defeat
   the hidden attribute, because this stylesheet loads after the browser's
   defaults. This one rule guarantees [hidden] always wins, everywhere in
   this app, regardless of what any other rule sets — so `el.hidden = true`
   in JS can never be silently ignored again. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
}

button { font-family: inherit; font-size: inherit; }

/* ---------------------------------------------------------------
   Buttons
------------------------------------------------------------------ */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  padding: 9px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn:focus-visible { outline: 2px solid var(--a400); outline-offset: 2px; }

.btn-primary {
  background: var(--p300);
  border-color: var(--p300);
  color: #ffffff;
}
.btn-primary:hover:not(:disabled) { background: var(--p400); }

.btn-full { width: 100%; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) { color: var(--text-primary); background: var(--surface-alt); box-shadow: none; transform: none; }

.btn-start {
  background: var(--a300);
  border-color: var(--a300);
  color: #ffffff;
  padding: 7px 14px;
  font-size: 13.5px;
}
.btn-start:hover:not(:disabled) { background: var(--a400); }

.btn-stop {
  background: var(--s300);
  border-color: var(--s300);
  color: #ffffff;
  padding: 7px 14px;
  font-size: 13.5px;
}
.btn-stop:hover:not(:disabled) { background: var(--s400); }

.btn-icon-sm {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-muted);
}
.btn-icon-sm:hover:not(:disabled) { background: var(--surface-alt); color: var(--text-primary); }
.btn-icon-sm:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-icon-sm.start { color: var(--a400); }
.btn-icon-sm.stop { color: var(--s400); }

/* ---------------------------------------------------------------
   Auth page
------------------------------------------------------------------ */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
}

.auth-mark-wrap { display: flex; justify-content: center; }
.auth-mark {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  line-height: 1;
  overflow: hidden;
}
.auth-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }

.auth-title { font-size: 21px; margin: 0 0 4px; font-weight: 700; }
.auth-subtitle { color: var(--text-muted); margin: 0 0 26px; font-size: 14px; }

.auth-form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--text-muted); font-weight: 500; }

.field input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--a300); box-shadow: 0 0 0 3px rgba(86, 181, 188, 0.15); }

.auth-error { color: var(--status-error); font-size: 13px; margin: 0; }

/* ---------------------------------------------------------------
   Top bar
------------------------------------------------------------------ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
  overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 600; font-size: 19px; color: var(--text-primary); letter-spacing: 0.2px; }
.brand-tagline { font-size: 13px; color: var(--text-muted); font-weight: 500; }

.topbar-user { display: flex; align-items: center; gap: 16px; }
.signed-in-as { color: var(--text-muted); font-size: 13px; }

.online-users { display: flex; align-items: center; }
.online-avatars { display: flex; }
.online-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--a300);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
  margin-left: -8px;
  position: relative;
  cursor: default;
}
.online-avatar:first-child { margin-left: 0; }
.online-avatar::after {
  content: "";
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-running);
  border: 2px solid var(--surface);
}

/* Styled hover tooltip showing the full email, rather than relying on the
   browser's native (often slow/inconsistent) title attribute tooltip. */
.online-avatar[data-tooltip] { z-index: 1; }
.online-avatar[data-tooltip]:hover { z-index: 2; }
.online-avatar[data-tooltip]::before {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--p400);
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  box-shadow: var(--shadow-md);
}
.online-avatar[data-tooltip]:hover::before { opacity: 1; }

/* ---------------------------------------------------------------
   Toast (fun messages)
------------------------------------------------------------------ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--p400);
  color: #ffffff;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: 14px;
  font-weight: 500;
  max-width: min(90vw, 460px);
  text-align: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* ---------------------------------------------------------------
   Page / environment panels
------------------------------------------------------------------ */
.page { max-width: 820px; margin: 0 auto; padding: 32px 24px 80px; }
.page-head { margin-bottom: 24px; }
.page-head h1 { font-size: 23px; margin: 0 0 6px; font-weight: 700; }
.page-sub { color: var(--text-muted); margin: 0; font-size: 14px; }

.empty-state {
  color: var(--text-muted);
  padding: 32px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.env-list { display: flex; flex-direction: column; gap: 14px; }

.env-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--status-stopped);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: border-left-color 0.2s ease;
}
.env-panel[data-status="running"] { border-left-color: var(--status-running); }
.env-panel[data-status="stopped"] { border-left-color: var(--status-stopped); }
.env-panel[data-status="pending"] { border-left-color: var(--status-pending); }
.env-panel[data-status="partial"] { border-left-color: var(--status-partial); }
.env-panel[data-status="error"]   { border-left-color: var(--status-error); }

.env-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
}

.env-panel-heading { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; min-width: 0; }
.env-name { font-size: 17px; margin: 0; font-weight: 700; white-space: nowrap; }
.btn-refresh { flex-shrink: 0; }

.env-meta {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

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

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status-stopped);
  flex-shrink: 0;
}
[data-status="running"] .env-panel-heading .status-dot { background: var(--status-running); }
[data-status="pending"] .env-panel-heading .status-dot,
.app-row[data-status="pending"] .status-dot {
  background: var(--status-pending);
  animation: pulse 1.1s ease-in-out infinite;
}
[data-status="partial"] .env-panel-heading .status-dot { background: var(--status-partial); }
.app-row[data-status="error"] .status-dot,
.app-row[data-status="unknown"] .status-dot { background: var(--status-error); }
.app-row[data-status="running"] .status-dot { background: var(--status-running); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.status-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  background: var(--status-stopped-bg);
  color: var(--status-stopped);
  border: 1px solid var(--status-stopped-border);
}
[data-status="running"] .status-badge { color: var(--status-running); background: var(--status-running-bg); border-color: var(--status-running-border); }
[data-status="pending"] .status-badge { color: var(--status-pending); background: var(--status-pending-bg); border-color: var(--status-pending-border); }
[data-status="partial"] .status-badge { color: var(--status-partial); background: var(--status-partial-bg); border-color: var(--status-partial-border); }

/* Auto-off row: its own line below the header, only shown while running */
.autooff-row {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--a75);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.autooff-picker { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.autooff-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--p300);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.autooff-chips { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--a75);
  background: var(--surface);
  color: var(--a400);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
.chip:hover:not(:disabled) { background: var(--a75); transform: translateY(-1px); }
.chip:active:not(:disabled) { transform: translateY(0); }
.chip:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.chip.chip-custom { color: var(--text-muted); border-color: var(--border); }
.chip.chip-custom:hover:not(:disabled) { background: var(--surface-alt); }
.chip.chip-custom.active {
  background: var(--p300);
  border-color: var(--p300);
  color: #ffffff;
  opacity: 1;
}
/* Without this, the plain ".chip-custom:hover" rule above (light
   background) still wins on hover even while .active is set, leaving
   white text on a near-white background — unreadable. This rule has to
   come after and be at least as specific to correctly take over. */
.chip.chip-custom.active:hover {
  background: var(--p400);
  border-color: var(--p400);
  color: #ffffff;
}

/* Custom timer: its own small centered card, only shown once "Custom" is
   selected — a distinct, modern-looking cluster rather than a bare inline row. */
.autooff-custom-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 2px auto 0;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--a75);
  border-radius: 10px;
  width: fit-content;
  box-shadow: var(--shadow-sm);
}
.autooff-custom-row input {
  width: 56px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 7px;
  font-size: 13px;
  color: var(--text-primary);
  text-align: center;
}
.autooff-custom-row select {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 7px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text-primary);
}
.btn-apply-sm {
  padding: 6px 16px;
  font-size: 12.5px;
  background: var(--a300);
  border-color: var(--a300);
  color: #ffffff;
  margin-left: 4px;
}
.btn-apply-sm:hover:not(:disabled) { background: var(--a400); }

.autooff-active-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; width: 100%; }
.autooff-active-info { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }

/* Countdown reads like a small stopwatch: monospace, tabular figures so
   the digits don't jitter side to side as they tick down. */
.autooff-countdown {
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  font-weight: 600;
  color: var(--a400);
  letter-spacing: normal;
}
.autooff-countdown.applying {
  color: var(--s400);
  animation: pulse 1s ease-in-out infinite;
}
.autooff-active {
  font-size: 11.5px;
  color: var(--text-muted);
}

.autooff-cancel {
  border: 1px solid var(--s200);
  background: var(--surface);
  color: var(--s400);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 100px;
  cursor: pointer;
  flex-shrink: 0;
}
.autooff-cancel:hover { background: var(--s50); }
.autooff-cancel:disabled { opacity: 0.5; cursor: not-allowed; }

.env-toggle-apps {
  margin-top: 10px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
}
.env-toggle-apps:hover { color: var(--p400); }
.env-toggle-apps .chevron {
  transition: transform 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  transform-origin: center;
}
.env-toggle-apps.expanded .chevron { transform: rotate(180deg); }

.app-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 8px 0 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
/* This explicit rule is required: [hidden] and .app-list have equal CSS
   specificity, so without this, the "display: flex" above silently wins
   over the browser's built-in "[hidden] { display: none }" and the list
   never actually collapses back after expanding once. */
.app-list[hidden] { display: none; }

.app-row {
  display: grid;
  grid-template-columns: 10px 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  padding: 5px 4px;
  border-radius: 6px;
}
.app-row:hover { background: var(--surface-alt); }

.app-name { font-family: var(--font-mono); color: var(--text-primary); }
.app-type {
  color: var(--text-muted);
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  flex-shrink: 0;
}
.app-status-text { color: var(--text-muted); font-size: 12px; margin-left: auto; }
.app-row-actions { display: flex; gap: 4px; }

.env-error {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--status-error);
  background: var(--status-error-bg);
  border: 1px solid var(--status-error-border);
  border-radius: 7px;
  padding: 8px 10px;
}

/* ---------------------------------------------------------------
   Responsive
------------------------------------------------------------------ */
@media (max-width: 560px) {
  .env-panel-header { flex-direction: column; align-items: flex-start; }
  .env-panel-actions { width: 100%; }
  .env-panel-actions .btn { flex: 1; }
  .app-row { flex-wrap: wrap; }
}