/*
 * Live-data layer.
 *
 * Extends the approved command-center design system with the states a real
 * dashboard needs and a prototype does not: loading, not-connected, upstream
 * error, empty result, and data-freshness attribution. The visual language
 * (institutional black/gold, tight grid, data-dense) is unchanged.
 */

/* --- shell corrections for the live layout -------------------------------- */

body { overflow: hidden; }

/*
 * A class-level `display` beats the user-agent [hidden] rule on specificity,
 * so both the gate and the shell need an explicit [hidden] override or they
 * stay visible after sign-in.
 */
.app-shell[hidden],
.auth-gate[hidden] { display: none !important; }

.topbar {
  grid-template-columns: 208px minmax(220px, 1fr) auto auto;
}

.view-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.view-subtitle {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}

.brand-lockup { display: flex; flex-direction: column; gap: 2px; }
.brand-line { font-size: 9px; letter-spacing: 0.18em; color: var(--gold); font-weight: 600; }

.header-actions { display: flex; align-items: center; gap: 10px; }
.operator { font-size: 11px; color: var(--muted); max-width: 190px; overflow: hidden;
            text-overflow: ellipsis; white-space: nowrap; }

.main {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  min-width: 0;
}

.dashboard { display: flex; flex-direction: column; gap: 14px; max-width: 1600px; }

.statusbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 16px;
  border-top: 1px solid var(--line-soft);
  background: rgba(3, 4, 5, 0.9);
  font-size: 10px;
  color: var(--faint);
}
.statusbar-right { margin-left: auto; font-variant-numeric: tabular-nums; }

.nav-scroll { overflow-y: auto; height: 100%; padding: 10px 8px 20px; }
.nav-item { display: flex; align-items: center; gap: 6px; width: 100%; text-decoration: none; }
.nav-item.nav-planned { opacity: 0.45; }
.nav-flag { margin-left: auto; font-size: 10px; color: var(--faint); }

/* --- sign-in gate ---------------------------------------------------------
 * Moved to auth.css, which styles it in Dynamic Peptides' own brand rather
 * than the console's. Left as a pointer so nobody re-adds it here.
 */

/* --- state blocks --------------------------------------------------------- */

.state-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  padding: 22px;
  border-radius: 10px;
  border: 1px dashed var(--line-soft);
  background: rgba(255, 255, 255, 0.012);
  font-size: 12px;
}

.state-title { font-weight: 650; color: var(--text); display: flex; align-items: center; gap: 8px; }
.state-hint { color: var(--muted); line-height: 1.5; max-width: 62ch; }

.state-remedy {
  padding: 7px 10px;
  border-left: 2px solid var(--gold-deep);
  background: rgba(217, 175, 87, 0.06);
  color: var(--gold-pale);
  font-size: 11px;
  line-height: 1.5;
  max-width: 62ch;
}

.state-link { color: var(--gold-bright); font-size: 11px; text-decoration: none; font-weight: 600; }
.state-link:hover { text-decoration: underline; }

.state-code {
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 102, 120, 0.16);
  color: #ff97a5;
  font-size: 10px;
  font-weight: 700;
}

.state-loading { flex-direction: row; align-items: center; color: var(--muted); border-style: solid; }

.state-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid var(--line);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: dp-spin 0.8s linear infinite;
  flex: 0 0 auto;
}
@keyframes dp-spin { to { transform: rotate(360deg); } }

.state-unconfigured { border-color: rgba(240, 169, 66, 0.3); background: rgba(240, 169, 66, 0.04); }
.state-error { border-color: rgba(255, 102, 120, 0.34); background: rgba(255, 102, 120, 0.05); border-style: solid; }
.state-empty { align-items: center; text-align: center; color: var(--muted); }
.state-success { border-color: rgba(88, 207, 145, 0.36); background: rgba(88, 207, 145, 0.06); border-style: solid; }

/* --- metric cards --------------------------------------------------------- */

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 13px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--surface);
  min-height: 92px;
}

.metric-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.metric-source { font-size: 9px; color: var(--faint); text-transform: none; letter-spacing: 0; }

.metric-value {
  font-size: 25px;
  font-weight: 640;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.metric-foot { min-height: 15px; font-size: 10px; }

/* A tile whose source did not answer is visibly inert, not quietly zero. */
.metric-unavailable { border-style: dashed; opacity: 0.66; }
.metric-unavailable .metric-value { color: var(--faint); }
.metric-reason { color: var(--faint); font-size: 10px; }

.metric-delta { font-size: 10px; font-weight: 650; }
.metric-delta.up { color: var(--green); }
.metric-delta.down { color: var(--red); }
.metric-delta.neutral { color: var(--faint); }

/* --- freshness & attribution ---------------------------------------------- */

.freshness {
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.07em;
}
.freshness.live { background: rgba(88, 207, 145, 0.14); color: var(--green); }
.freshness.cached { background: rgba(217, 175, 87, 0.13); color: var(--gold); }

.source-chip {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 9px;
  font-weight: 650;
}

.status.live { background: rgba(88, 207, 145, 0.14); color: var(--green); }
.status.warn { background: rgba(240, 169, 66, 0.14); color: var(--amber); }
.status.bad  { background: rgba(255, 102, 120, 0.14); color: var(--red); }
.status.review { background: rgba(255, 255, 255, 0.06); color: var(--muted); }

/* --- panels & tables ------------------------------------------------------ */

.panel { padding: 14px; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--surface); }

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-header-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.panel-title { margin: 0; font-size: 13px; font-weight: 680; }
.panel-subtitle { margin: 3px 0 0; font-size: 10.5px; color: var(--muted); }

.panel-foot-note {
  margin-top: 11px;
  padding-top: 9px;
  border-top: 1px solid var(--line-soft);
  font-size: 10px;
  color: var(--faint);
  line-height: 1.55;
}
.panel-foot-note code {
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 9.5px;
}

.lower-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }

.table-scroll { overflow-x: auto; margin: 0 -4px; }

.sync-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.sync-table th {
  padding: 7px 9px;
  text-align: left;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.sync-table td { padding: 9px; border-bottom: 1px solid rgba(255, 255, 255, 0.03); vertical-align: top; }
.sync-table tbody tr:hover { background: rgba(217, 175, 87, 0.035); }

.cell-sub { margin-top: 2px; font-size: 10px; color: var(--faint); }
.cell-sub a { color: var(--gold); text-decoration: none; }
.cell-sub a:hover { text-decoration: underline; }
.muted { color: var(--faint); }

.row-critical { background: rgba(255, 102, 120, 0.045); }
.row-warning  { background: rgba(240, 169, 66, 0.035); }
.row-muted    { opacity: 0.55; }

/* --- key/value lists ------------------------------------------------------ */

.kv-list { display: flex; flex-direction: column; }
.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 11.5px;
}
.kv-label { color: var(--muted); }
.kv-value { font-weight: 600; text-align: right; }
.kv-note { font-size: 9.5px; font-weight: 400; color: var(--faint); }
.kv-warn .kv-value { color: var(--amber); }
.kv-bad .kv-value  { color: var(--red); }
.kv-ok .kv-value   { color: var(--text); }

/* --- charts & bars -------------------------------------------------------- */

.live-chart { width: 100%; height: 180px; display: block; }

.live-bars { display: flex; flex-direction: column; gap: 6px; }
.live-bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 1.4fr) 3fr auto 52px;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
}
.live-bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-bar-track { height: 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.05); overflow: hidden; }
.live-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold-bright));
}
.live-bar-value { font-weight: 650; font-variant-numeric: tabular-nums; }
.live-bar-share { text-align: right; color: var(--faint); font-variant-numeric: tabular-nums; }

/* --- attention queue ------------------------------------------------------ */

.task-list { display: flex; flex-direction: column; }
.task-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.task-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.task-copy strong { font-size: 11.5px; font-weight: 640; }
.task-copy span { font-size: 10px; color: var(--muted); }
.task-meta { display: flex; align-items: center; gap: 7px; font-size: 10px; }
.task-meta a { color: var(--gold); text-decoration: none; }

.task-icon { width: 8px; height: 8px; border-radius: 50%; justify-self: center; }
.severity-icon-critical { background: var(--red);   box-shadow: 0 0 8px rgba(255, 102, 120, 0.5); }
.severity-icon-warning  { background: var(--amber); }
.severity-icon-info     { background: var(--gold);  }

.compact-list { display: flex; flex-direction: column; }
.source-row {
  display: grid;
  grid-template-columns: minmax(96px, auto) auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 11px;
}
.source-title { font-weight: 640; }
.source-line { color: var(--faint); font-size: 10px; overflow: hidden; text-overflow: ellipsis; }

.flow-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.flow-index { color: var(--gold); font-size: 11px; text-align: center; }

/* --- integration control -------------------------------------------------- */

.connector-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }

.connector-card { display: flex; flex-direction: column; gap: 10px; }
.connector-card.attention { border-color: rgba(240, 169, 66, 0.28); }

.connector-top { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 10px; }
.connector-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: rgba(217, 175, 87, 0.12);
  color: var(--gold-bright);
  font-weight: 750; font-size: 14px;
}
.connector-name { font-size: 12px; font-weight: 680; }
.connector-role { font-size: 10px; color: var(--muted); }

.connector-detail {
  padding: 7px 9px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.025);
  font-size: 10.5px;
  color: var(--muted);
  line-height: 1.5;
}
.connector-detail.detail-warn { background: rgba(240, 169, 66, 0.07); color: var(--amber); }

.connector-caps { display: flex; flex-wrap: wrap; gap: 5px; }
.cap-chip {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 9.5px;
  color: var(--muted);
}

.connector-foot { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line-soft); }
.connector-secrets { font-size: 9.5px; color: var(--faint); }

.coverage-chip { padding: 2px 7px; border-radius: 999px; font-size: 9.5px; font-weight: 650; }
.coverage-connected      { background: rgba(88, 207, 145, 0.14); color: var(--green); }
.coverage-via-woocommerce{ background: rgba(217, 175, 87, 0.13); color: var(--gold); }
.coverage-no-api         { background: rgba(255, 255, 255, 0.05); color: var(--muted); }
.coverage-not-wired      { background: rgba(240, 169, 66, 0.12); color: var(--amber); }

/* --- support inbox -------------------------------------------------------- */

.inbox-shell { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.15fr); gap: 14px; }

.inbox-list { display: flex; flex-direction: column; max-height: 62vh; overflow-y: auto; }

.inbox-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  cursor: pointer;
  border-left: 2px solid transparent;
}
.inbox-item:hover { background: rgba(217, 175, 87, 0.035); }
.inbox-item.unread { border-left-color: var(--gold); }
.inbox-item.unread .inbox-subject { font-weight: 680; }

.inbox-item-main { min-width: 0; }
.inbox-item-head { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; }
.inbox-time { color: var(--faint); font-size: 10px; flex: 0 0 auto; }
.inbox-subject { margin-top: 2px; font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-snippet { margin-top: 2px; font-size: 10px; color: var(--faint);
                 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.starred { color: var(--gold); }
.attach { font-size: 9px; }

.inbox-actions { display: flex; align-items: center; gap: 3px; }
.icon-btn {
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.icon-btn:disabled { opacity: 0.5; cursor: wait; }
.icon-btn.action-failed { border-color: var(--red); color: var(--red); }

.inbox-thread { display: flex; flex-direction: column; gap: 10px; max-height: 44vh; overflow-y: auto; }

.message-bubble {
  padding: 11px 13px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: var(--surface-2);
}
.message-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 11px; margin-bottom: 6px; }
.message-body { font-size: 11.5px; line-height: 1.6; color: var(--muted); word-break: break-word; }

.reply-composer { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.section-label {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--faint); margin-bottom: 7px;
}
.reply-text {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  line-height: 1.55;
  resize: vertical;
}
.reply-text:focus { border-color: var(--gold); outline: none; }
.reply-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 9px; }
.reply-note { font-size: 10px; color: var(--faint); line-height: 1.45; }

/* --- buttons -------------------------------------------------------------- */

.primary-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 15px;
  border: 1px solid var(--gold-deep);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(217, 175, 87, 0.22), rgba(217, 175, 87, 0.09));
  color: var(--gold-pale);
  font-size: 11.5px; font-weight: 650;
  cursor: pointer;
}
.primary-btn:hover { background: linear-gradient(180deg, rgba(217, 175, 87, 0.3), rgba(217, 175, 87, 0.14)); }
.primary-btn:disabled { opacity: 0.55; cursor: wait; }

.ghost-btn {
  padding: 6px 11px;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 10.5px; font-weight: 600;
  cursor: pointer;
}
.ghost-btn:hover { border-color: var(--line); color: var(--text); }
.ghost-btn:disabled { opacity: 0.55; cursor: wait; }

.select-compact {
  padding: 5px 9px;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 10.5px;
}

.range-toggle { display: flex; gap: 3px; }
.range-toggle[hidden] { display: none; }
.range-btn {
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 10px; font-weight: 650; letter-spacing: 0.04em;
  cursor: pointer;
}
.range-btn:hover { color: var(--text); }
.range-btn.active { border-color: var(--line); background: rgba(217, 175, 87, 0.1); color: var(--gold-bright); }

/* --- responsive ----------------------------------------------------------- */

@media (max-width: 1100px) {
  .inbox-shell { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto auto minmax(0, 1fr) 32px; }
  .topbar { grid-template-columns: 1fr auto; row-gap: 8px; height: auto; padding: 10px 12px; }
  .header-context { grid-column: 1 / -1; order: 3; }
  .range-toggle { grid-column: 1 / -1; order: 4; flex-wrap: wrap; }
  .sidebar { grid-column: 1 / -1; max-height: 150px; border-right: none; border-bottom: 1px solid var(--line); }
  .nav-scroll { display: flex; gap: 14px; overflow-x: auto; padding: 8px 12px; }
  .nav-group { flex: 0 0 auto; }
  .main { padding: 12px; }
  .lower-grid, .connector-grid, .metrics-grid { grid-template-columns: 1fr; }
}

/* Source did not answer — must never read as fresh data. */
.freshness.stale { background: rgba(255, 102, 120, 0.13); color: var(--red); }

/* One-line state for a secondary panel whose source already failed above. */
.state-block.state-compact {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  font-size: 11.5px;
}
.state-compact .state-title { font-weight: 600; color: var(--muted); }
