/* ============================================================
   THATCHER CONTROL — styles.css
   Dark by default, deliberately distinct from the other 4 apps' light
   "paper" system — this is a control surface, not a family-facing app.
   Palette: near-black base, mint/teal accent, glass cards. Per-app tag
   colours below are Thatcher Control's own scannable palette (not each
   app's own light-mode accent, which wouldn't read well on a dark
   background).
   ============================================================ */

:root {
  --bg: #0B0F0D;
  --bg-2: #0F1512;
  --panel: #121815;
  --card: rgba(255,255,255,0.035);
  --card-border: rgba(255,255,255,0.08);
  --card-hover: rgba(255,255,255,0.06);

  --text: #F2F4F2;
  --text-soft: rgba(242,244,242,0.62);
  --text-faint: rgba(242,244,242,0.38);

  --mint: #7FBFA0;
  --mint-dark: #5A9A7C;
  --mint-soft: rgba(127,191,160,0.14);

  --danger: #E0776B;
  --danger-soft: rgba(224,119,107,0.14);
  --warning: #E0B36B;
  --warning-soft: rgba(224,179,107,0.14);
  --info: #6B9FE0;
  --info-soft: rgba(107,159,224,0.14);

  /* Per-app tag colours - Thatcher Control's own scannable palette */
  --tag-food: #D98A5E;
  --tag-food-soft: rgba(217,138,94,0.16);
  --tag-garden: #8FBF8A;
  --tag-garden-soft: rgba(143,191,138,0.16);
  --tag-edu: #7C93D9;
  --tag-edu-soft: rgba(124,147,217,0.16);
  --tag-hq: #C9A96B;
  --tag-hq-soft: rgba(201,169,107,0.16);
  --tag-overview: #B57EC9;
  --tag-overview-soft: rgba(181,126,201,0.16);
  /* Thatcher Control's own tag reuses --mint (its own accent, defined
     below) rather than a new colour, since a self-filed ticket is
     naturally "home turf" in its own scannable palette. */

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  --shadow-md: 0 8px 30px rgba(0,0,0,0.35);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.45);

  --font: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;

  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; min-height: 100%;
  background: radial-gradient(ellipse 900px 500px at 85% -10%, rgba(127,191,160,0.10), transparent 55%), var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, h4 { margin: 0; font-family: var(--font); font-weight: 800; }
a { color: var(--mint); }
::selection { background: var(--mint-soft); }

:focus-visible {
  outline: 2.5px solid var(--mint);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.hidden { display: none !important; }

#loadingGate {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.12); border-top-color: var(--mint);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth screen ---------- */
#authScreen {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.auth-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--mint), var(--mint-dark));
  color: #0B0F0D;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 18px;
}
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -0.01em; }
.brand-name span { color: var(--mint); }
.auth-tagline { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--text-soft); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--card-border); background: rgba(255,255,255,0.03);
  color: var(--text); font-size: 15px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--mint); }
.field textarea { min-height: 90px; resize: vertical; }
.auth-error { color: var(--danger); font-size: 12.5px; font-weight: 700; min-height: 16px; margin: -4px 0 12px; }
.auth-note { text-align: center; font-size: 12px; color: var(--text-faint); margin: 14px 0 0; }

.btn {
  border: none; border-radius: var(--radius-pill);
  font-weight: 800; font-size: 14px; padding: 12px 20px;
  cursor: pointer; transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.12s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--mint); color: #0B0F0D; }
.btn-primary:hover { background: #93cbb0; }
.btn-ghost { background: rgba(255,255,255,0.06); color: var(--text); border: 1px solid var(--card-border); }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 12.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- App shell ---------- */
#app { display: flex; min-height: 100dvh; }

.sidebar {
  width: 220px; flex-shrink: 0;
  display: flex; flex-direction: column;
  padding: 24px 16px calc(20px + var(--safe-bottom));
  border-right: 1px solid var(--card-border);
  background: var(--bg-2);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 24px;
  font-weight: 800; font-size: 15px;
}
.sidebar-brand .brand-mark { width: 32px; height: 32px; border-radius: 10px; font-size: 14px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  border: none; background: none; text-align: left;
  padding: 11px 12px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 700; font-size: 13.5px;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active { background: var(--mint-soft); color: var(--mint); }
.nav-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: 0.5; flex-shrink: 0;
}
.nav-item.active .nav-dot { opacity: 1; }
.sidebar-signout {
  border: none; background: none; text-align: left;
  padding: 11px 12px; color: var(--text-faint); font-weight: 700; font-size: 13px;
}
.sidebar-signout:hover { color: var(--text-soft); }
.sidebar-version { text-align: left; font-size: 11.5px; font-weight: 700; color: var(--text-faint); padding: 4px 12px 0; }

.main { flex: 1; min-width: 0; overflow-y: auto; }
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: calc(28px + var(--safe-top)) 32px 8px;
  gap: 16px; flex-wrap: wrap;
}
.topbar-date { font-size: 11.5px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); }
.topbar-greeting { font-size: 26px; margin-top: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.filter-wrap { position: relative; }
.filter-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--panel); border: 1px solid var(--card-border);
  border-radius: var(--radius-md); padding: 8px; min-width: 200px;
  box-shadow: var(--shadow-lg); z-index: 30;
}
.filter-menu label {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; font-size: 13px; font-weight: 600; border-radius: var(--radius-sm); cursor: pointer;
}
.filter-menu label:hover { background: rgba(255,255,255,0.05); }

.view-content { padding: 20px 32px calc(48px + var(--safe-bottom)); }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
  margin-bottom: 22px;
}
.card {
  background: var(--card); border: 1px solid var(--card-border);
  border-radius: var(--radius-lg); padding: 18px;
}
.stat-card .stat-label { font-size: 12px; color: var(--text-soft); font-weight: 700; }
.stat-card .stat-row { display: flex; align-items: baseline; justify-content: space-between; margin-top: 10px; }
.stat-card .stat-value { font-size: 30px; font-weight: 800; }
.stat-card .stat-delta { font-size: 12px; color: var(--mint); font-weight: 700; }

/* ---------- Two-column layout: priority queue + agent panel ---------- */
.dashboard-grid { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.panel-header h2 { font-size: 15px; }
.panel-header .view-all { font-size: 12.5px; color: var(--text-soft); font-weight: 700; background: none; border: none; }
.panel-header .view-all:hover { color: var(--mint); }

.ticket-table { width: 100%; border-collapse: collapse; }
.ticket-table th {
  text-align: left; font-size: 10.5px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-faint); padding: 0 10px 10px;
}
.ticket-table td { padding: 12px 10px; border-top: 1px solid var(--card-border); vertical-align: middle; }
.ticket-table tr { cursor: pointer; }
.ticket-table tr:hover td { background: rgba(255,255,255,0.02); }
.ticket-title { font-weight: 700; font-size: 13.5px; }
.ticket-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.ticket-status { font-size: 12.5px; color: var(--text-soft); font-weight: 600; }
.ticket-owner {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--mint-soft); color: var(--mint);
  display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 800;
}

.app-tag {
  display: inline-block; padding: 4px 10px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 800;
}
.app-tag.thatcherFood { background: var(--tag-food-soft); color: var(--tag-food); }
.app-tag.thatcherGarden { background: var(--tag-garden-soft); color: var(--tag-garden); }
.app-tag.thatcherEdu { background: var(--tag-edu-soft); color: var(--tag-edu); }
.app-tag.thatcherHQ { background: var(--tag-hq-soft); color: var(--tag-hq); }
.app-tag.thatcherHQCentral { background: var(--mint-soft); color: var(--mint); }
.app-tag.thatcherOverview { background: var(--tag-overview-soft); color: var(--tag-overview); }

.severity-tag { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; }
.severity-tag.critical, .severity-tag.high { color: var(--danger); }
.severity-tag.medium { color: var(--warning); }
.severity-tag.low { color: var(--text-faint); }

/* ---------- Agent status card ---------- */
.agent-card {
  background: linear-gradient(160deg, rgba(127,191,160,0.10), rgba(127,191,160,0.02));
  border: 1px solid rgba(127,191,160,0.25);
}
.agent-online {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 800; color: var(--mint);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.agent-online::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--mint);
  box-shadow: 0 0 0 3px var(--mint-soft);
}
/* Architecture audit Phase 2: real agent-run status variants, replacing
   the always-green hardcoded indicator. */
.agent-online.is-idle { color: var(--text-faint); }
.agent-online.is-idle::before { background: var(--text-faint); box-shadow: 0 0 0 3px rgba(242,244,242,0.1); }
.agent-online.is-stalled { color: var(--warning); }
.agent-online.is-stalled::before { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }

.run-status { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; }
.run-status.running { color: var(--mint); }
.run-status.completed { color: var(--text-soft); }
.run-status.failed { color: var(--danger); }
.run-status.stalled { color: var(--warning); }
.agent-orb {
  width: 56px; height: 56px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #A8DFC4, var(--mint) 70%);
  margin-bottom: 14px;
}
.agent-card h3 { font-size: 17px; margin: 4px 0 6px; }
.agent-card p { font-size: 13px; color: var(--text-soft); margin: 0 0 16px; line-height: 1.5; }

.activity-feed { display: flex; flex-direction: column; gap: 14px; }
.activity-item { display: flex; gap: 10px; font-size: 12.5px; }
.activity-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); margin-top: 5px; flex-shrink: 0; }
.activity-message { font-weight: 600; }
.activity-time { color: var(--text-faint); font-size: 11px; margin-top: 1px; }

/* ---------- Needs-attention list (Inbox-style) ---------- */
.attention-list { display: flex; flex-direction: column; }
.attention-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 4px; border-bottom: 1px solid var(--card-border);
  cursor: pointer;
}
.attention-row:last-child { border-bottom: none; }
.attention-avatar {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 12px;
}
.attention-body { flex: 1; min-width: 0; }
.attention-title { font-weight: 700; font-size: 14px; }
.attention-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.attention-badge { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em; flex-shrink: 0; }
.attention-badge.high, .attention-badge.critical { color: var(--danger); }
.attention-badge.new { color: var(--info); }
.attention-badge.medium { color: var(--warning); }
.attention-badge.low { color: var(--text-faint); }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-faint); }
.empty-state h3 { color: var(--text-soft); font-size: 15px; margin-bottom: 6px; }
.empty-state p { font-size: 13px; margin: 0; }

/* ---------- Full tickets table view ---------- */
.tickets-toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip {
  padding: 7px 14px; border-radius: var(--radius-pill);
  background: rgba(255,255,255,0.04); border: 1px solid var(--card-border);
  font-size: 12.5px; font-weight: 700; color: var(--text-soft);
}
.chip.active { background: var(--mint-soft); border-color: rgba(127,191,160,0.4); color: var(--mint); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--card-border);
  border-radius: var(--radius-lg); padding: 26px;
  box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h2 { font-size: 19px; }
.modal-close {
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.06); color: var(--text);
  font-size: 18px; display: flex; align-items: center; justify-content: center;
}
.detail-row { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.detail-label { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); margin: 18px 0 8px; }
.detail-desc { font-size: 14px; line-height: 1.6; color: var(--text-soft); white-space: pre-wrap; }
.status-select-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.status-pill-btn {
  padding: 8px 14px; border-radius: var(--radius-pill);
  background: rgba(255,255,255,0.04); border: 1px solid var(--card-border);
  font-size: 12px; font-weight: 700; color: var(--text-soft);
}
.status-pill-btn.active { background: var(--mint-soft); border-color: rgba(127,191,160,0.4); color: var(--mint); }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.type-btn {
  text-align: left; border: 1.5px solid var(--card-border); background: rgba(255,255,255,0.02);
  border-radius: var(--radius-md); padding: 14px; cursor: pointer;
}
.type-btn strong { display: block; font-size: 14px; }
.type-btn span { display: block; font-size: 11px; color: var(--text-faint); margin-top: 3px; }
.type-btn.active { border-color: var(--mint); background: var(--mint-soft); }

.toast-wrap {
  position: fixed; top: calc(var(--safe-top) + 16px); left: 0; right: 0; z-index: 150;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--panel); border: 1px solid var(--card-border); color: var(--text);
  padding: 12px 20px; border-radius: var(--radius-pill); font-weight: 700; font-size: 13px;
  box-shadow: var(--shadow-lg); animation: toastin 0.25s ease;
}
.toast.error { border-color: rgba(224,119,107,0.4); color: var(--danger); }
@keyframes toastin { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: column; align-items: stretch;
    padding: calc(12px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
    overflow-x: visible;
  }
  .sidebar-brand { padding: 0 0 10px; }
  .sidebar-nav { flex-direction: row; flex: none; flex-wrap: wrap; gap: 4px; }
  .nav-item span.label-text { display: none; }
  .sidebar-signout { display: none; }
  .topbar { padding: 20px 18px 8px; }
  .view-content { padding: 16px 18px 40px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}
