:root {
  --bg: #edf2f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #111827;
  --muted: #64748b;
  --line: #d9e2ec;
  --sidebar: #101827;
  --sidebar-soft: #182238;
  --blue: #2563eb;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --teal: #0f766e;
  --radius: 8px;
  --shadow: 0 16px 36px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
button.active {
  border-color: var(--blue);
  color: var(--blue);
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
}

textarea {
  min-height: 112px;
  padding: 10px;
  resize: vertical;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: var(--surface-soft);
}

td span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 300px;
  min-height: 100vh;
}

.sidebar,
.right-rail {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.sidebar {
  background: var(--sidebar);
  color: #e2e8f0;
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 800;
}

.brand-block strong,
.rail-panel strong {
  display: block;
}

.brand-block span:not(.brand-mark),
.sidebar-panel span,
.rail-panel p {
  color: #a8b5c8;
  font-size: 13px;
  line-height: 1.45;
}

.primary-nav {
  display: grid;
  gap: 7px;
}

.primary-nav button {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  background: transparent;
  color: #dbeafe;
  border-color: rgba(255, 255, 255, 0.12);
}

.primary-nav button span {
  color: #93c5fd;
  font-size: 11px;
  width: 22px;
}

.primary-nav button:hover,
.primary-nav button.active {
  background: #1d4ed8;
  border-color: #60a5fa;
  color: #ffffff;
}

.sidebar-panel,
.rail-panel {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 12px;
}

.sidebar-panel {
  background: var(--sidebar-soft);
}

.sidebar-label,
.eyebrow {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.sidebar-label {
  color: #93a4ba;
  margin-bottom: 5px;
}

.stacked-actions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.stacked-actions button {
  width: 100%;
  justify-content: flex-start;
}

.workspace {
  min-width: 0;
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

h1,
h2 {
  margin: 0;
  font-weight: 750;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
}

h2 {
  font-size: 18px;
}

.topbar-tools,
.inline-controls,
.rail-actions,
.table-actions,
.detail-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-tools {
  justify-content: flex-end;
}

.search-box {
  display: grid;
  grid-template-columns: auto minmax(180px, 280px);
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0 10px;
}

.search-box span {
  color: var(--muted);
  font-size: 12px;
}

.search-box input {
  border: 0;
  padding: 0;
  min-height: 34px;
}

.ghost-button {
  background: transparent;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.badge.healthy,
.badge.active,
.badge.standard,
.metric-card.good {
  border-color: rgba(22, 163, 74, 0.32);
  color: var(--green);
}

.badge.watch,
.badge.read-only,
.badge.monitoring,
.metric-card.warning {
  border-color: rgba(217, 119, 6, 0.34);
  color: var(--amber);
}

.badge.hold,
.badge.suspended,
.badge.sharp,
.metric-card.danger {
  border-color: rgba(220, 38, 38, 0.32);
  color: var(--red);
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card,
.panel,
.player-detail,
.bar-row,
.broadcast-preview article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-card {
  min-height: 124px;
  padding: 14px;
  display: grid;
  align-content: space-between;
  box-shadow: var(--shadow);
}

.metric-card strong {
  font-size: 26px;
  line-height: 1.15;
}

.metric-card em {
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
  line-height: 1.35;
}

.panel {
  min-width: 0;
  padding: 14px;
  box-shadow: var(--shadow);
}

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

.panel-header.compact {
  margin-bottom: 10px;
}

.two-column,
.message-layout,
.broadcast-layout,
.settings-grid,
.chart-row,
.audit-layout {
  display: grid;
  gap: 14px;
}

.two-column,
.message-layout,
.broadcast-layout,
.settings-grid,
.audit-layout {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.chart-row {
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.selected-row {
  background: #eff6ff;
}

.activity-list,
.message-list,
.thread-list,
.tree-list,
.bar-chart,
.detail-grid,
.structure-map,
.analytics-grid,
.mini-player-grid {
  display: grid;
  gap: 10px;
}

.activity-list.compact,
.message-list.compact {
  gap: 8px;
}

.activity-list article,
.message-list article,
.thread-list button,
.detail-grid article,
.structure-map article,
.analytics-grid article,
.mini-player-grid article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.activity-list strong,
.message-list strong,
.thread-list strong,
.structure-map strong,
.analytics-grid strong,
.mini-player-grid strong {
  display: block;
  margin-bottom: 4px;
}

.activity-list span,
.message-list span,
.thread-list span,
.thread-list em,
.detail-grid p,
.structure-map p,
.analytics-grid p,
.mini-player-grid span,
.broadcast-preview p,
.rail-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  font-style: normal;
}

.detail-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.structure-map,
.analytics-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.structure-map article {
  min-height: 112px;
}

.structure-map article span,
.analytics-grid article span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.analytics-grid {
  margin-bottom: 12px;
}

.analytics-grid article.good {
  border-color: rgba(22, 163, 74, 0.32);
}

.analytics-grid article.warning {
  border-color: rgba(217, 119, 6, 0.34);
}

.analytics-grid article.danger {
  border-color: rgba(220, 38, 38, 0.32);
}

.analytics-grid article strong {
  font-size: 20px;
}

.detail-grid article span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.detail-grid article strong {
  display: block;
  margin: 6px 0;
  font-size: 20px;
}

.expansion-row > td {
  background: #f8fafc;
  padding: 0;
}

.sub-agent-expansion {
  display: grid;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.expansion-summary,
.expansion-meter,
.mini-player-grid article {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.expansion-summary p,
.expansion-meter span {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.expansion-actions,
.mini-player-grid article > div:last-child {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.expansion-meter {
  align-items: stretch;
}

.expansion-meter .bar-track {
  flex: 1;
  min-width: 180px;
  align-self: center;
}

.mini-player-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tree-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(0, 1.15fr);
  gap: 14px;
  align-items: start;
}

.tree-branch {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  overflow: hidden;
}

.branch-button {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.branch-button span {
  color: var(--muted);
  font-size: 12px;
}

.player-nodes {
  display: grid;
  gap: 7px;
  padding: 10px;
}

.player-nodes button {
  min-height: 50px;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  grid-template-areas:
    "dot name"
    "dot meta";
  gap: 0 8px;
  text-align: left;
  white-space: normal;
}

.player-nodes button strong {
  grid-area: name;
}

.player-nodes button em {
  grid-area: meta;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.risk-dot {
  grid-area: dot;
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--green);
}

.risk-dot.watch {
  background: var(--amber);
}

.risk-dot.sharp {
  background: var(--red);
}

.player-detail {
  padding: 14px;
  position: sticky;
  top: 18px;
}

.detail-actions {
  margin-top: 12px;
}

.thread-list button {
  min-height: 82px;
  text-align: left;
  white-space: normal;
}

.thread-list button.active {
  background: #eff6ff;
}

.conversation {
  display: grid;
  gap: 10px;
  max-height: 460px;
  overflow: auto;
  padding-right: 2px;
}

.conversation article {
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 12px;
}

.conversation article div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.conversation span {
  color: var(--muted);
  font-size: 12px;
}

.conversation p {
  margin: 0;
  color: #243247;
  line-height: 1.45;
}

.reply-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.audit-readonly,
.dm-warning {
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  background: #eff6ff;
  color: #1e3a8a;
  padding: 12px;
}

.audit-readonly {
  margin-top: 12px;
}

.audit-readonly strong,
.dm-warning strong {
  display: block;
  margin-bottom: 4px;
}

.audit-readonly span,
.dm-warning span {
  display: block;
  color: #334155;
  font-size: 13px;
  line-height: 1.45;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.form-grid .wide,
.check-row {
  grid-column: 1 / -1;
}

.check-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 8px;
  color: var(--ink) !important;
  font-size: 14px !important;
}

.check-row input {
  width: auto;
  min-height: auto;
}

.message-list article.unread {
  border-color: rgba(37, 99, 235, 0.36);
  background: #eff6ff;
}

.message-list article div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.message-list p {
  margin: 6px 0 0;
  color: #334155;
  line-height: 1.45;
}

.broadcast-preview {
  min-height: 150px;
  margin-bottom: 12px;
}

.broadcast-preview > p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.broadcast-preview article {
  padding: 12px;
  background: var(--surface-soft);
}

.broadcast-preview strong {
  display: block;
  margin: 6px 0;
  font-size: 18px;
}

.broadcast-preview span,
.broadcast-preview em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.report-summary {
  margin-bottom: 12px;
}

.report-summary article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.report-summary strong {
  display: block;
  margin: 4px 0;
  font-size: 20px;
}

.report-summary p {
  margin: 0;
  color: var(--muted);
}

.bar-chart {
  align-content: start;
}

.bar-row {
  display: grid;
  grid-template-columns: 180px minmax(120px, 1fr) 48px;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  padding: 12px;
}

.bar-row span {
  color: var(--muted);
  font-size: 12px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.bar-track span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--blue));
}

.right-rail {
  border-left: 1px solid var(--line);
  background: #f8fafc;
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 14px;
}

.right-rail .rail-panel {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.rail-actions {
  margin-top: 12px;
}

.empty-state {
  margin: 0;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  z-index: 20;
}

.toast {
  width: min(360px, calc(100vw - 36px));
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .right-rail {
    display: none;
  }

  .metric-grid,
  .detail-grid,
  .structure-map,
  .analytics-grid,
  .mini-player-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .sidebar,
  .right-rail {
    position: static;
    height: auto;
  }

  .sidebar {
    padding: 14px;
  }

  .primary-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    padding: 14px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-tools,
  .inline-controls,
  .table-actions,
  .detail-actions {
    justify-content: flex-start;
  }

  .search-box {
    grid-template-columns: 1fr;
    padding: 8px 10px;
  }

  .two-column,
  .message-layout,
  .broadcast-layout,
  .settings-grid,
  .chart-row,
  .audit-layout,
  .tree-layout {
    grid-template-columns: 1fr;
  }

  .player-detail {
    position: static;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }

  .expansion-summary,
  .expansion-meter,
  .mini-player-grid article {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  button {
    width: 100%;
  }

  .primary-nav {
    grid-template-columns: 1fr;
  }

  .metric-grid,
  .detail-grid,
  .structure-map,
  .analytics-grid,
  .mini-player-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .reply-form {
    grid-template-columns: 1fr;
  }
}

/* Operational Agent Board / Sub-Agent Board. Every visible state is filled from the API. */
.app-shell[aria-hidden="true"] {
  display: none;
}

.auth-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(37, 99, 235, 0.17), transparent 32%),
    linear-gradient(145deg, #0f172a, #172554);
}

.auth-panel[hidden] {
  display: none;
}

.auth-card {
  width: min(460px, 100%);
  min-width: 0;
  grid-template-columns: minmax(0, 1fr);
  display: grid;
  gap: 16px;
  padding: 30px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 30px 80px rgba(2, 6, 23, 0.42);
}

.auth-card > *, .auth-card input, .auth-brand > div {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.auth-card button { white-space: normal; }
.auth-brand .brand-mark { flex-shrink: 0; }

.auth-brand {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.auth-brand span:not(.brand-mark) {
  color: var(--muted);
}

.auth-card label,
.form-grid label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}

.auth-card h1 {
  margin: 0;
}

.muted-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.form-error,
.surface-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-weight: 700;
}

.surface-error:empty {
  display: none;
}

.primary-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
  font-weight: 800;
}

.primary-button:hover {
  color: #ffffff;
  filter: brightness(0.94);
}

.primary-nav button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.office-link {
  display: block;
  padding: 11px 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  color: #dbeafe;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.office-link:hover,
.office-link:focus-visible {
  border-color: #93c5fd;
  outline: none;
}

.metric-card {
  min-height: 132px;
}

.metric-card > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card > strong {
  display: block;
  margin: 10px 0 6px;
  font-size: 25px;
}

.metric-card > p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.activity-row {
  width: 100%;
  min-height: 0;
  display: grid;
  gap: 4px;
  padding: 12px;
  text-align: left;
  white-space: normal;
}

.activity-row span {
  color: var(--muted);
  font-size: 12px;
}

.wide-field {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.form-actions span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.permission-form {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.compact-table {
  max-height: 360px;
  margin-top: 18px;
  overflow: auto;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

@media (max-width: 1080px) {
  .wide-field {
    grid-column: 1;
  }
}
