/* D-Relay dashboard — violet theme, distinct from the desktop tool's dark
   cyan, per DROPLET_MIGRATION.md's own design decision. Mobile-first: this
   is read on a phone in a pocket as often as a monitor. */

:root {
  --bg: #121016;
  --surface-0: #1a1720;
  --surface-1: #221e2b;
  --surface-2: #2a2536;
  --border: #38324424;
  --border-strong: #4a4260;
  --text: #ece8f5;
  --text-secondary: #a89ec2;
  --text-muted: #6f6584;
  --cyan: #b48cff;
  --cyan-dim: #b48cff33;
  --success: #6fe3a1;
  --success-bg: #6fe3a11a;
  --warning: #f0c05a;
  --warning-bg: #f0c05a1a;
  --danger: #f0708a;
  --danger-bg: #f0708a1a;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 48px; /* room for the fixed statusbar */
}

/* ---- topbar ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface-0);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-name { font-weight: 600; font-size: 16px; letter-spacing: 0.02em; }
.mode-tag {
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 2px 8px;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
  display: inline-block;
}
.dot.ok { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot.bad { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

.icon-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 8px;
  width: 34px; height: 34px;
  font-size: 16px;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.spin { animation: spin 0.6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- bulk selection bar ---- */

.bulk-bar {
  position: sticky;
  bottom: 40px; /* sits above the fixed statusbar */
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--cyan);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 12px auto 0;
  max-width: 720px;
  box-shadow: 0 4px 16px #00000066;
}
.bulk-bar span { font-size: 13px; color: var(--text-secondary); flex: 1; }
.bulk-btn { width: auto; margin-top: 0; padding: 8px 14px; font-size: 13px; }

/* ---- tabs ---- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  background: var(--surface-0);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 10px 0;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tab.active { color: var(--cyan); border-bottom-color: var(--cyan); font-weight: 600; }

/* ---- auth gate ---- */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}

.auth-box {
  width: 100%;
  max-width: 380px;
}

.auth-brand {
  font-size: 22px;
  font-weight: 700;
  color: var(--cyan);
  text-align: center;
  margin-bottom: 24px;
}

/* ---- OM current-task banner ---- */

.om-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface-0);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.om-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-muted);
}
.om-status-dot.idle { background: var(--text-muted); }
.om-status-dot.running {
  background: var(--cyan);
  box-shadow: 0 0 6px var(--cyan);
  animation: om-pulse 1.6s ease-in-out infinite;
}
.om-status-dot.stale { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.om-status-dot.unknown { background: var(--text-muted); }

@keyframes om-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#om-status-text { color: var(--text-secondary); }

/* ---- layout ---- */

main { padding: 12px; max-width: 720px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

/* ---- summary cards ---- */

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 6px;
  text-align: center;
}
.card .num { font-size: 20px; font-weight: 700; line-height: 1.1; }
.card .label { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.card.warn .num { color: var(--warning); }
.card.bad .num { color: var(--danger); }
.card.good .num { color: var(--success); }

/* ---- filter chips ---- */

.filter-row { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }
.chip {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.chip.active { background: var(--cyan-dim); border-color: var(--cyan); color: var(--cyan); }

/* ---- task list ---- */

.task-list { display: flex; flex-direction: column; gap: 8px; }

.task-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
}
.task-row:active { background: var(--surface-2); }

.task-checkbox {
  width: 18px; height: 18px;
  flex-shrink: 0;
  accent-color: var(--cyan);
  cursor: pointer;
}

.identity-badge {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 3px 7px;
  color: var(--cyan);
  flex-shrink: 0;
  white-space: nowrap;
}

.task-info { flex: 1; min-width: 0; }
.task-desc {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 999px;
  flex-shrink: 0;
  white-space: nowrap;
}
.status-pill.AWAITING_REPORT { background: var(--surface-2); color: var(--text-secondary); }
.status-pill.STALE { background: var(--danger-bg); color: var(--danger); }
.status-pill.DONE { background: var(--success-bg); color: var(--success); }

/* A stale LEGACY task predates the file-based report convention entirely —
   likely already resolved with no artifact, not a live problem. Muted
   amber rather than alarm red, so it doesn't compete for attention with a
   genuinely stale NEW-scheme task, which is a real, fresh thing to check
   since that whole pipeline has only existed for one day. */
.status-pill.STALE.legacy-stale { background: var(--warning-bg); color: var(--warning); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 14px;
}

/* ---- counters ---- */

.hint { color: var(--text-muted); font-size: 13px; margin: 0 0 14px; }
.counters-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.counter-cell {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.counter-cell .author { font-size: 13px; color: var(--text-secondary); }
.counter-cell .next {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 18px;
  color: var(--cyan);
  margin-top: 2px;
}

/* ---- issues ---- */

.issue-group { margin-bottom: 18px; }
.issue-group h3 {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
}
.issue-row {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  word-break: break-all;
}
.issue-row .reason {
  display: block;
  font-family: -apple-system, sans-serif;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ---- detail sheet ---- */

.sheet {
  position: fixed; inset: 0; z-index: 50;
  display: none;
}
.sheet.open { display: block; }
.sheet-backdrop {
  position: absolute; inset: 0;
  background: #00000099;
}
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface-0);
  border-top: 1px solid var(--border-strong);
  border-radius: 16px 16px 0 0;
  padding: 20px 16px 24px;
}
.sheet-close {
  position: absolute; top: 10px; right: 14px;
  background: none; border: none; color: var(--text-muted);
  font-size: 24px; cursor: pointer;
}
.detail-row { margin-bottom: 12px; }
.detail-row .k { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.detail-row .v { font-size: 14px; margin-top: 2px; word-break: break-all; }
.detail-row .v.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.detail-row .v a { color: var(--cyan); text-decoration: underline; }

/* ---- command centre ---- */

.cc-alerts { margin-bottom: 16px; }
.cc-alert {
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 6px;
}
.cc-alert.ok { background: var(--success-bg); color: var(--success); }
.cc-alert.warn { background: var(--warning-bg); color: var(--warning); }
.cc-alert.crit { background: var(--danger-bg); color: var(--danger); }
.cc-alert-since { display: block; font-size: 11px; opacity: 0.75; margin-top: 2px; }

.cc-group { margin-bottom: 16px; }
.cc-group h3 {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
}
.cc-metric {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  font-size: 14px;
}
.cc-metric-label { color: var(--text-secondary); }
.cc-metric-value {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 600;
}
.cc-metric.warn { border-color: var(--warning); }
.cc-metric.warn .cc-metric-value { color: var(--warning); }

/* ---- compose ---- */

.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 16px 0 6px;
}
.field-label:first-child { margin-top: 0; }

.field-select, .field-input, .field-textarea {
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
}
.field-select:focus, .field-input:focus, .field-textarea:focus {
  outline: none;
  border-color: var(--cyan);
}
.field-textarea { resize: vertical; min-height: 140px; }

.template-btn {
  width: auto;
  margin: 0 0 10px;
  padding: 8px 14px;
  font-size: 13px;
}

.compose-preview {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--cyan);
  margin-top: 6px;
  padding: 2px 2px;
}
.compose-preview.invalid { color: var(--text-muted); }

.btn-primary {
  width: 100%;
  background: var(--cyan);
  color: #1a0f2e;
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  margin-top: 18px;
  cursor: pointer;
}
.btn-primary:disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  background: var(--surface-1);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 14px;
  margin-top: 10px;
  cursor: pointer;
}

.compose-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}

.compose-result-badge {
  display: inline-block;
  background: var(--success-bg);
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.v.copyable {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px;
}

/* ---- statusbar ---- */

.statusbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface-0);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

@media (min-width: 640px) {
  .cards { grid-template-columns: repeat(6, 1fr); }
}
