:root {
  --font-body: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  --font-display: "Space Grotesk", "Avenir Next", sans-serif;
  --bg: #ecf3f8;
  --ink: #0f2a3f;
  --ink-soft: #374c5e;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-border: rgba(30, 74, 106, 0.16);
  --line: rgba(30, 74, 106, 0.15);
  --accent: #0d7c7a;
  --accent-strong: #095b59;
  --accent-soft: rgba(13, 124, 122, 0.14);
  --warn: #c66f1a;
  --danger: #b73737;
  --ok: #1f7a53;
}

html.dark {
  --bg: #0f1419;
  --ink: #e4e8ec;
  --ink-soft: #94a3b3;
  --panel: rgba(22, 29, 38, 0.95);
  --panel-border: rgba(200, 220, 240, 0.12);
  --line: rgba(200, 220, 240, 0.14);
  --accent: #2ec4b6;
  --accent-strong: #20a99c;
  --accent-soft: rgba(46, 196, 182, 0.14);
  --warn: #e09f3e;
  --danger: #e05858;
  --ok: #34d399;
}

html.dark body {
  background:
    radial-gradient(1600px 1000px at 0% 0%, rgba(160, 50, 100, 0.55), transparent 70%),
    radial-gradient(1400px 900px at 55% 0%, rgba(200, 140, 40, 0.4), transparent 60%),
    radial-gradient(1600px 1000px at 100% 100%, rgba(30, 160, 150, 0.55), transparent 70%),
    #0f1419;
}

html.dark .ambient-top { background: #1a6e66; opacity: 0.2; }
html.dark .ambient-bottom { background: #7a5c2e; opacity: 0.15; }

html.dark .panel {
  background: rgba(22, 29, 38, 0.92);
  border-color: rgba(200, 220, 240, 0.1);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.4);
}

html.dark input,
html.dark select,
html.dark textarea {
  background: rgba(12, 18, 25, 0.9);
  color: var(--ink);
  border-color: rgba(200, 220, 240, 0.15);
}

html.dark .ghost-button {
  background: rgba(30, 40, 52, 0.9);
  color: var(--ink);
  border-color: rgba(200, 220, 240, 0.15);
}

html.dark .tiny-button {
  background: rgba(30, 40, 52, 0.9);
  color: var(--ink-soft);
  border-color: rgba(200, 220, 240, 0.15);
}

html.dark .pending-reply-toggle {
  background: rgba(46, 196, 182, 0.16);
  border-color: rgba(46, 196, 182, 0.3);
  color: #c6fff7;
}

html.dark .policy-step-index {
  border-color: rgba(46, 196, 182, 0.7);
  background: rgba(46, 196, 182, 0.16);
  color: #bffcf6;
}

html.dark .danger-button {
  border-color: rgba(224, 88, 88, 0.42);
  background: rgba(224, 88, 88, 0.18);
  color: #ffb4b4;
}

html.dark .danger-button:hover {
  background: rgba(224, 88, 88, 0.24);
}

html.dark .policy-modal {
  background: rgba(18, 25, 33, 0.98);
  border-color: rgba(200, 220, 240, 0.14);
  box-shadow: 0 24px 52px rgba(0, 0, 0, 0.45);
}

html.dark .policy-modal-rule {
  background: rgba(46, 196, 182, 0.12);
  border-color: rgba(200, 220, 240, 0.15);
}

html.dark .tabs,
html.dark .subtabs {
  background: rgba(18, 24, 32, 0.8);
  border-color: rgba(200, 220, 240, 0.1);
}

html.dark .tab {
  color: var(--ink-soft);
}

html.dark .tab.active {
  background: rgba(46, 196, 182, 0.15);
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

html.dark .topic-row {
  background: rgba(22, 29, 38, 0.8);
  border-color: rgba(200, 220, 240, 0.1);
  color: var(--ink);
}
html.dark .topic-row:hover {
  background: rgba(46, 196, 182, 0.12);
}

html.dark .chip {
  background: rgba(22, 29, 38, 0.8);
  border-color: rgba(200, 220, 240, 0.12);
  color: var(--ink-soft);
}

html.dark .token-row {
  background: rgba(22, 29, 38, 0.8);
  border-color: rgba(200, 220, 240, 0.1);
}

html.dark .error-banner {
  background: rgba(224, 88, 88, 0.12);
  border-color: rgba(224, 88, 88, 0.3);
  color: #f09090;
}

html.dark .error-text { color: #f09090; }

html.dark .toast {
  background: rgba(46, 196, 182, 0.95);
  color: #0f1419;
}

html.dark .toast.toast--error {
  background: rgba(183, 28, 28, 0.92);
  color: #fff;
}

html.dark .source-slack {
  color: #6cacff;
  background: rgba(34, 109, 255, 0.2);
  border-color: rgba(34, 109, 255, 0.3);
}

html.dark .source-instagram {
  color: #e88ac0;
  background: rgba(225, 76, 153, 0.2);
  border-color: rgba(225, 76, 153, 0.3);
}

html.dark .source-api,
html.dark .source-unknown {
  color: #94a3b3;
  background: rgba(139, 155, 171, 0.15);
  border-color: rgba(139, 155, 171, 0.22);
}

html.dark .status-sent,
html.dark .status-healthy {
  color: #34d399;
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.26);
}

html.dark .status-pending,
html.dark .status-expiring_soon,
html.dark .status-send_failed {
  color: #e09f3e;
  background: rgba(224, 159, 62, 0.16);
  border-color: rgba(224, 159, 62, 0.26);
}

html.dark .status-failed,
html.dark .status-dead_letter,
html.dark .status-expired {
  color: #e05858;
  background: rgba(224, 88, 88, 0.16);
  border-color: rgba(224, 88, 88, 0.26);
}

html.dark .category-fan_mail {
  color: #a78bfa;
  background: rgba(124, 58, 237, 0.2);
  border-color: rgba(124, 58, 237, 0.3);
}

html.dark .category-business {
  color: #e09f3e;
  background: rgba(224, 159, 62, 0.16);
  border-color: rgba(224, 159, 62, 0.26);
}

html.dark .category-meta_help {
  color: #5eead4;
  background: rgba(15, 118, 110, 0.24);
  border-color: rgba(45, 212, 191, 0.35);
}

html.dark .category-general_comments {
  color: #94a3b3;
  background: rgba(139, 155, 171, 0.15);
  border-color: rgba(139, 155, 171, 0.22);
}

html.dark .category-no_sources {
  color: #fbbf24;
  background: rgba(217, 119, 6, 0.2);
  border-color: rgba(217, 119, 6, 0.3);
}

html.dark .category-spam {
  color: #e05858;
  background: rgba(224, 88, 88, 0.16);
  border-color: rgba(224, 88, 88, 0.26);
}

html.dark .stat-card h3 {
  color: var(--ink-soft);
}

html.dark .login-panel {
  background: rgba(22, 29, 38, 0.95);
  border-color: rgba(200, 220, 240, 0.1);
}

html.dark th {
  color: var(--ink-soft);
}

html.dark td {
  border-color: rgba(200, 220, 240, 0.08);
}

html.dark th {
  border-color: rgba(200, 220, 240, 0.1);
}

.theme-toggle {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink-soft);
  border-radius: 11px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  transition: transform 0.15s ease;
}
.theme-toggle:hover { filter: brightness(0.97); }
.theme-toggle:active { transform: translateY(1px); }
html.dark .theme-toggle {
  background: rgba(28, 35, 43, 0.78);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  position: relative;
  background:
    radial-gradient(1600px 1000px at 0% 0%, rgba(180, 60, 120, 0.6), transparent 70%),
    radial-gradient(1400px 900px at 55% 0%, rgba(220, 150, 50, 0.45), transparent 60%),
    radial-gradient(1600px 1000px at 100% 100%, rgba(30, 180, 170, 0.6), transparent 70%),
    linear-gradient(165deg, #f8fbfd 0%, var(--bg) 56%, #e7eef4 100%);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app {
  position: relative;
  max-width: 1320px;
  margin: 0 auto;
  padding: 32px 24px 56px;
}

.ambient {
  position: fixed;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(72px);
  pointer-events: none;
  opacity: 0.45;
  z-index: -1;
}

.ambient-top {
  background: #8ad7ca;
  top: -220px;
  right: -120px;
}

.ambient-bottom {
  background: #ffcf9e;
  bottom: -220px;
  left: -120px;
}

.reveal {
  animation: rise 0.34s ease both;
}

@keyframes rise {
  from {
    transform: translateY(10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.app-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 2.8vw, 2.35rem);
  letter-spacing: -0.02em;
}

.app-header p {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 0.96rem;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.login-shell {
  min-height: 58vh;
  display: grid;
  place-items: center;
}

.panel {
  border: 1px solid var(--panel-border);
  background: linear-gradient(178deg, rgba(255, 255, 255, 0.88), var(--panel));
  border-radius: 20px;
  box-shadow: 0 18px 48px rgba(19, 57, 89, 0.08);
  backdrop-filter: blur(8px);
}

.login-panel {
  width: min(460px, 100%);
  padding: 22px;
  display: grid;
  gap: 12px;
}

.login-panel h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
}

.login-panel label {
  display: grid;
  gap: 7px;
}

.login-panel label span {
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-weight: 600;
}

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

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(13, 124, 122, 0.18);
  border-color: rgba(13, 124, 122, 0.55);
}

.primary-button,
.ghost-button,
.tiny-button {
  border: 0;
  border-radius: 11px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
  line-height: 1.2;
}

.primary-button {
  background: linear-gradient(140deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-size: 0.9rem;
}

.primary-button:hover,
.ghost-button:hover,
.tiny-button:hover {
  filter: brightness(0.97);
}

.primary-button:active,
.ghost-button:active,
.tiny-button:active {
  transform: translateY(1px);
}

.ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.9rem;
}

.tiny-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  font-size: 0.78rem;
  padding: 4px 9px;
}

button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.tabs,
.subtabs {
  display: inline-flex;
  gap: 8px;
  margin-bottom: 14px;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
}

.tab {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 700;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}

.tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 5px 16px rgba(17, 61, 96, 0.12);
}

.error-banner {
  border: 1px solid rgba(183, 55, 55, 0.3);
  background: rgba(183, 55, 55, 0.08);
  color: #7a1d1d;
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
}

.dashboard-shell {
  display: grid;
  gap: 10px;
}

.dashboard-view {
  display: grid;
  gap: 16px;
}

.policy-rules-view {
  display: grid;
  gap: 24px;
}

.policy-workflow {
  display: grid;
  gap: 22px;
}

.policy-step {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.policy-step-index {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 2px solid var(--accent);
  color: var(--accent-strong);
  background: rgba(13, 124, 122, 0.08);
  font-weight: 800;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
}

.policy-step-card {
  padding: 20px 22px;
  display: grid;
  gap: 14px;
  border: 1px solid rgba(30, 74, 106, 0.18);
  box-shadow: 0 10px 24px rgba(19, 57, 89, 0.06);
}

.policy-step-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.06rem;
  line-height: 1.25;
}

.policy-live-card,
.policy-compose-card,
.policy-test-card {
  padding: 20px 22px;
  display: grid;
  gap: 14px;
}

.policy-live-card {
  background: linear-gradient(135deg, rgba(17, 67, 56, 0.98), rgba(22, 95, 78, 0.94));
  color: #e7f4ef;
}

.policy-live-card .muted {
  color: rgba(231, 244, 239, 0.85);
}

.policy-live-list,
.policy-staged-list {
  display: grid;
  gap: 12px;
}

.policy-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.policy-rule-card {
  position: relative;
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  padding-right: 44px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 6px 14px rgba(19, 57, 89, 0.06);
}

.policy-rule-live {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(231, 244, 239, 0.22);
}

.policy-rule-live .policy-rule-label,
.policy-rule-live .policy-rule-text {
  color: #e7f4ef;
}

.policy-rule-live .policy-rule-tag {
  background: rgba(231, 244, 239, 0.16);
  border-color: rgba(231, 244, 239, 0.2);
  color: #d9efe8;
}

.policy-rule-label {
  margin: 0;
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}

.policy-rule-text {
  margin: 0;
  font-size: 0.96rem;
  line-height: 1.55;
}

.policy-rule-tag {
  justify-self: start;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid rgba(30, 74, 106, 0.2);
  background: rgba(255, 255, 255, 0.9);
  color: #244157;
}

.policy-rule-tag--forced_response {
  border-color: rgba(30, 98, 198, 0.28);
  background: rgba(53, 125, 230, 0.14);
  color: #1f4e8d;
}

.policy-rule-tag--topic_block {
  border-color: rgba(198, 111, 26, 0.3);
  background: rgba(198, 111, 26, 0.14);
  color: #8a4e10;
}

.policy-rule-tag--behavioral_modifier {
  border-color: rgba(31, 122, 83, 0.34);
  background: rgba(31, 122, 83, 0.14);
  color: #1d6647;
}

.policy-rule-tag--conditional_qa {
  border-color: rgba(24, 106, 147, 0.3);
  background: rgba(24, 106, 147, 0.14);
  color: #1a5878;
}

.policy-rule-tag--custom {
  border-color: rgba(54, 82, 107, 0.24);
  background: rgba(54, 82, 107, 0.12);
  color: #304a61;
}

.policy-rule-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  border: 1px solid rgba(30, 74, 106, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: inherit;
  cursor: pointer;
  opacity: 0.82;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.policy-rule-delete:hover {
  opacity: 1;
  filter: brightness(0.98);
}

html.dark .policy-rule-delete {
  border-color: rgba(200, 220, 240, 0.18);
  background: rgba(22, 29, 38, 0.92);
}

.policy-rule-input {
  min-height: 110px;
}

.policy-preview-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.82);
  display: grid;
  gap: 12px;
}

.policy-preview-title {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  font-weight: 700;
}

.policy-preview-text {
  margin: 0;
  line-height: 1.5;
}

.policy-preview-grid {
  display: grid;
  gap: 8px;
}

.policy-preview-row {
  display: grid;
  grid-template-columns: minmax(140px, 170px) minmax(0, 1fr);
  align-items: start;
  column-gap: 12px;
  row-gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(30, 74, 106, 0.12);
}

.policy-preview-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.policy-preview-label {
  margin: 2px 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}

.policy-preview-highlight {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.policy-guardrail-reason {
  margin: 0;
}

.policy-guardrail-error {
  color: #b73737;
  font-weight: 500;
}

.policy-staged-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.policy-staged-head h4 {
  margin: 0;
  font-size: 0.9rem;
}

.policy-go-live-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.policy-go-live-row .primary-button {
  min-width: 220px;
}

.policy-test-scope {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.84);
}

.policy-scope-label {
  margin: 0 0 8px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  font-weight: 700;
}

.policy-scope-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.policy-scope-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  column-gap: 10px;
  row-gap: 8px;
  font-size: 0.9rem;
  border: 1px solid rgba(30, 74, 106, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.82);
  padding: 10px 12px;
  line-height: 1.45;
}

.policy-scope-item-disabled {
  opacity: 0.68;
}

.policy-scope-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

.policy-scope-chip {
  white-space: nowrap;
}

.policy-scope-actions {
  margin-left: 0;
  justify-self: end;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.policy-scope-toggle {
  margin-left: 0;
}

.policy-scope-empty {
  grid-template-columns: 1fr !important;
}

.policy-scope-remove {
  border-color: rgba(183, 55, 55, 0.28);
  color: #9b2a2a;
}

.policy-scope-edit {
  border-color: rgba(30, 98, 198, 0.28);
  color: #1f4e8d;
}

html.dark .policy-scope-remove {
  border-color: rgba(224, 88, 88, 0.36);
  color: #f0a0a0;
}

html.dark .policy-editing-banner {
  border-color: rgba(96, 166, 255, 0.34);
  background: rgba(59, 130, 246, 0.2);
}

html.dark .policy-editing-title {
  color: #b8d8ff;
}

html.dark .policy-scope-edit {
  border-color: rgba(96, 166, 255, 0.34);
  color: #b8d8ff;
}

.scope-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  align-self: center;
}

.scope-live {
  background: #58c58a;
}

.scope-staged {
  background: #d9b84f;
}

.policy-config-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 10px;
}

.controls label {
  display: grid;
  gap: 5px;
  width: min(280px, 100%);
}

.controls label span {
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-weight: 700;
}

.inline-toggle {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.inline-toggle input {
  margin: 0;
}

.stamp {
  margin-left: auto;
  text-align: right;
}

.policy-settings-card {
  display: grid;
  gap: 14px;
  padding: 20px 22px;
}

.policy-side-stack {
  display: grid;
  gap: 14px;
}

.policy-help-text {
  margin: 0;
  line-height: 1.45;
}

.policy-editing-banner {
  border: 1px solid rgba(30, 98, 198, 0.26);
  background: rgba(53, 125, 230, 0.12);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
}

.policy-editing-title {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #1f4e8d;
}

.policy-editing-text {
  margin: 0;
}

.policy-textarea {
  width: 100%;
  resize: vertical;
  min-height: 120px;
  border-radius: 12px;
  border: 1px solid rgba(30, 74, 106, 0.24);
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  padding: 11px 12px;
  font: inherit;
  line-height: 1.45;
}

.policy-base-qa-input {
  min-height: 260px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.85rem;
}

.policy-action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.policy-settings-meta {
  display: grid;
  gap: 4px;
}

.policy-test-result {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  border-radius: 12px;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.policy-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.policy-test-answer {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  line-height: 1.5;
}

.policy-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}

.prompt-limit-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.override-chip-active {
  border-color: rgba(31, 122, 83, 0.3);
  color: var(--ok);
  background: rgba(31, 122, 83, 0.12);
}

.override-chip-inactive {
  border-color: rgba(183, 55, 55, 0.2);
  color: var(--ink-soft);
  background: rgba(183, 55, 55, 0.08);
}

.policy-scenario-input {
  min-height: 140px;
}

html.dark .policy-step-card,
html.dark .policy-settings-card {
  border-color: rgba(200, 220, 240, 0.18);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.26);
}

html.dark .policy-rule-card,
html.dark .policy-scope-list li,
html.dark .policy-preview-box,
html.dark .policy-test-scope,
html.dark .policy-test-result,
html.dark .policy-test-answer {
  border-color: rgba(200, 220, 240, 0.18);
  background: rgba(16, 23, 30, 0.86);
}

html.dark .policy-preview-row {
  border-bottom-color: rgba(200, 220, 240, 0.16);
}

html.dark .policy-rule-tag {
  border-color: rgba(200, 220, 240, 0.28);
  background: rgba(32, 43, 57, 0.9);
  color: #cbd8e6;
}

html.dark .policy-rule-tag--forced_response {
  border-color: rgba(96, 166, 255, 0.36);
  background: rgba(59, 130, 246, 0.2);
  color: #b8d8ff;
}

html.dark .policy-rule-tag--topic_block {
  border-color: rgba(238, 170, 89, 0.4);
  background: rgba(224, 159, 62, 0.2);
  color: #ffd79f;
}

html.dark .policy-rule-tag--behavioral_modifier {
  border-color: rgba(82, 207, 154, 0.4);
  background: rgba(52, 211, 153, 0.2);
  color: #b8f8dc;
}

html.dark .policy-rule-tag--conditional_qa {
  border-color: rgba(108, 208, 234, 0.4);
  background: rgba(34, 197, 246, 0.18);
  color: #b9eeff;
}

html.dark .policy-rule-tag--custom {
  border-color: rgba(166, 181, 199, 0.35);
  background: rgba(100, 116, 139, 0.2);
  color: #d2dceb;
}

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

.stat-card {
  padding: 18px;
}

.stat-card h3 {
  margin: 0;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.stat-card p {
  margin: 12px 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 2.1vw, 2rem);
}

.chart-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 12px;
}

.bottom-grid {
  grid-template-columns: 1.15fr 0.85fr;
}

.chart-card,
.topics-card,
.token-panel,
.queries-view,
.pending-card {
  padding: 16px;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.chart-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.02rem;
}

.cluster-head {
  flex-direction: column;
  align-items: stretch;
}

.chart-host {
  height: 280px;
  width: 100%;
}

.bottom-grid .chart-host {
  height: 250px;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
}

.topics-card {
  display: grid;
  align-content: start;
  gap: 9px;
}

.topic-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  border-radius: 12px;
  padding: 9px 11px;
  cursor: pointer;
}

.topic-row:hover {
  background: rgba(13, 124, 122, 0.08);
}

.queries-view {
  display: grid;
  gap: 12px;
}

.clusters-view {
  display: grid;
  gap: 10px;
}

.cluster-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.cluster-card {
  cursor: pointer;
  padding: 20px;
  border-left: 4px solid var(--card-accent, var(--accent));
  transition: transform 0.15s;
}

.cluster-card:hover {
  transform: translateY(-2px);
}

.cluster-card .card-label {
  font-weight: 700;
  font-size: 1.05rem;
  margin: 0;
}

.cluster-card .card-count {
  font-size: 1.6rem;
  font-weight: 800;
  font-family: var(--font-display);
  margin: 8px 0 0;
}

.cluster-card .card-pct {
  color: var(--ink-soft);
  font-size: 0.85rem;
  margin: 2px 0 0;
}

.cluster-card .card-action {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  margin: 10px 0 0;
}

.cluster-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.cluster-breadcrumb button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0;
}

.cluster-breadcrumb button:hover {
  text-decoration: underline;
}

.cluster-breadcrumb .breadcrumb-title {
  font-weight: 700;
  font-size: 1.02rem;
  font-family: var(--font-display);
}

.cluster-breadcrumb .breadcrumb-count {
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.cluster-bar-host {
  height: auto;
  min-height: 200px;
  width: 100%;
}

html.dark .cluster-card {
  border-left-color: var(--card-accent, var(--accent));
}

html.dark .cluster-breadcrumb button {
  color: var(--accent);
}

.cluster-stat-chips {
  display: inline-flex;
  gap: 8px;
}

.cluster-map-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
}

.cluster-map-selects {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
}

.cluster-map-selects label {
  display: grid;
  gap: 4px;
}

.cluster-map-selects label span {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cluster-map-selects select {
  min-width: 138px;
}

.cluster-map-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.clusters-hint {
  margin: 0;
}

.query-filters {
  display: grid;
  grid-template-columns: minmax(180px, 1.6fr) repeat(5, minmax(120px, 1fr)) auto;
  gap: 8px;
}

.active-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  vertical-align: top;
  text-align: left;
  font-size: 0.84rem;
  line-height: 1.35;
}

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  font-weight: 700;
}

.empty-cell {
  text-align: center;
  padding: 18px;
}

.source-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.source-slack {
  color: #18499f;
  background: rgba(34, 109, 255, 0.15);
  border-color: rgba(34, 109, 255, 0.22);
}

.source-instagram {
  color: #993568;
  background: rgba(225, 76, 153, 0.16);
  border-color: rgba(225, 76, 153, 0.22);
}

.source-api,
.source-unknown {
  color: #36526b;
  background: rgba(54, 82, 107, 0.12);
  border-color: rgba(54, 82, 107, 0.2);
}

.status-sent,
.status-healthy {
  color: #1d6a46;
  background: rgba(31, 122, 83, 0.14);
  border-color: rgba(31, 122, 83, 0.22);
}

.status-pending,
.status-expiring_soon,
.status-send_failed {
  color: #9c5b11;
  background: rgba(198, 111, 26, 0.16);
  border-color: rgba(198, 111, 26, 0.26);
}

.status-failed,
.status-dead_letter,
.status-expired {
  color: #8f2424;
  background: rgba(183, 55, 55, 0.14);
  border-color: rgba(183, 55, 55, 0.24);
}

.pill-button {
  font: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: filter 0.15s;
}
.pill-button:hover {
  filter: brightness(1.2);
}

.topic-pill-button {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #1e40af;
  background: rgba(37, 99, 235, 0.12);
  border: 1px solid rgba(37, 99, 235, 0.22);
}

.dark .topic-pill-button {
  color: #93bbfd;
  background: rgba(37, 99, 235, 0.22);
  border-color: rgba(37, 99, 235, 0.35);
}

.category-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.category-fan_mail {
  color: #5b21b6;
  background: rgba(124, 58, 237, 0.14);
  border-color: rgba(124, 58, 237, 0.24);
}

.category-business {
  color: #9c5b11;
  background: rgba(198, 111, 26, 0.16);
  border-color: rgba(198, 111, 26, 0.26);
}

.category-meta_help {
  color: #0f766e;
  background: rgba(15, 118, 110, 0.12);
  border-color: rgba(15, 118, 110, 0.2);
}

.category-general_comments {
  color: #36526b;
  background: rgba(54, 82, 107, 0.12);
  border-color: rgba(54, 82, 107, 0.2);
}

.category-no_sources {
  color: #92400e;
  background: rgba(217, 119, 6, 0.14);
  border-color: rgba(217, 119, 6, 0.24);
}

.category-spam {
  color: #8f2424;
  background: rgba(183, 55, 55, 0.14);
  border-color: rgba(183, 55, 55, 0.24);
}

/* Priority sections — Pending tab grouped inbox */
.priority-section {
  margin-bottom: 24px;
}

.priority-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--line);
  cursor: pointer;
  user-select: none;
}

.priority-section-title {
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.priority-badge {
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 20px;
  padding: 2px 8px;
}

.priority-collapse-btn {
  margin-left: auto;
  font-size: 0.72rem;
  color: #888;
  cursor: pointer;
  background: #f2f2f2;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 10px;
}

.priority-collapse-btn:hover {
  background: #e5e5e5;
}

.priority-section-body.collapsed {
  display: none;
}

.priority-info {
  font-size: 0.82rem;
  color: var(--ink-soft);
  font-style: italic;
  margin: 8px 0 4px;
}

/* Section color variants */
.section-nosources .priority-section-header {
  border-color: #d97706;
}

.section-nosources .priority-section-title {
  color: #d97706;
}

.section-nosources .priority-badge {
  background: #fef3c7;
  color: #d97706;
}

.section-business .priority-section-header {
  border-color: #0d9488;
}

.section-business .priority-section-title {
  color: #0d9488;
}

.section-business .priority-badge {
  background: #ccfbf1;
  color: #0d9488;
}

.section-fanmail .priority-section-header {
  border-color: #7c3aed;
}

.section-fanmail .priority-section-title {
  color: #7c3aed;
}

.section-fanmail .priority-badge {
  background: #ede9fe;
  color: #7c3aed;
}

.section-other .priority-section-header {
  border-color: #9ca3af;
}

.section-other .priority-section-title {
  color: #6b7280;
}

.section-other .priority-badge {
  background: #f3f4f6;
  color: #6b7280;
}

.priority-more-hint {
  font-size: 0.82rem;
  color: var(--ink-soft);
  padding: 4px 0 8px;
}

/* Dark mode for priority sections */
html.dark .section-nosources .priority-section-title {
  color: #fbbf24;
}

html.dark .section-nosources .priority-section-header {
  border-color: #fbbf24;
}

html.dark .section-nosources .priority-badge {
  background: rgba(217, 119, 6, 0.2);
  color: #fbbf24;
}

html.dark .priority-collapse-btn {
  background: rgba(30, 40, 52, 0.9);
  color: var(--ink-soft);
  border-color: rgba(200, 220, 240, 0.15);
}

html.dark .priority-collapse-btn:hover {
  background: rgba(46, 196, 182, 0.12);
}

html.dark .section-business .priority-section-title {
  color: #2dd4bf;
}

html.dark .section-business .priority-section-header {
  border-color: #2dd4bf;
}

html.dark .section-business .priority-badge {
  background: rgba(13, 148, 136, 0.2);
  color: #2dd4bf;
}

html.dark .section-fanmail .priority-section-title {
  color: #a78bfa;
}

html.dark .section-fanmail .priority-section-header {
  border-color: #a78bfa;
}

html.dark .section-fanmail .priority-badge {
  background: rgba(124, 58, 237, 0.2);
  color: #a78bfa;
}

html.dark .section-other .priority-section-title {
  color: #94a3b3;
}

html.dark .section-other .priority-section-header {
  border-color: rgba(200, 220, 240, 0.15);
}

html.dark .section-other .priority-badge {
  background: rgba(139, 155, 171, 0.15);
  color: #94a3b3;
}

html.dark .priority-info {
  color: var(--ink-soft);
}

.answer-text {
  white-space: pre-wrap;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  max-width: 420px;
}

.answer-text.expanded {
  display: block;
  -webkit-line-clamp: unset;
}

.answer-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}

.pending-view {
  display: grid;
  gap: 16px;
}

.pending-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  max-width: 1040px;
  width: 100%;
}

.pending-card {
  display: grid;
  gap: 12px;
  transition: box-shadow 0.15s ease;
}

.pending-card-header {
  cursor: pointer;
}

.pending-card:not(.pending-card-expanded):hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.pending-card-summary {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.pending-reply-toggle {
  flex-shrink: 0;
  border: 1px solid rgba(13, 124, 122, 0.3);
  background: rgba(13, 124, 122, 0.12);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}

.pending-reply-toggle:hover {
  background: rgba(13, 124, 122, 0.18);
  transform: translateY(-1px);
}

.pending-reply-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pending-card-expanded {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.pending-card-body {
  display: grid;
  gap: 12px;
}

.pending-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.76rem;
  color: var(--ink-soft);
}

.pending-time {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

.pending-prompt {
  margin: 0;
  font-weight: 700;
  line-height: 1.45;
}

.pending-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.pending-details p {
  margin: 0;
}

.detail-key {
  font-weight: 700;
}

.reply-box {
  width: 100%;
  min-height: 38px;
  resize: vertical;
  transition: min-height 0.15s ease;
}

.reply-box:focus {
  min-height: 100px;
}

.pending-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.token-panel {
  display: grid;
  gap: 8px;
}

.token-row {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.84);
}

.muted {
  color: var(--ink-soft);
  font-size: 0.86rem;
}

.error-text {
  margin: 0;
  color: #9b2a2a;
  font-size: 0.85rem;
}

.danger-button {
  border: 1px solid rgba(183, 55, 55, 0.35);
  background: rgba(183, 55, 55, 0.12);
  color: #8e2020;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}

.danger-button:hover {
  background: rgba(183, 55, 55, 0.2);
}

.danger-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.policy-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 18, 26, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 14px;
}

.policy-modal {
  width: min(480px, 100%);
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 20px 44px rgba(15, 31, 45, 0.22);
  padding: 16px;
  display: grid;
  gap: 10px;
}

.policy-modal h4 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.08rem;
}

.policy-modal-rule {
  margin: 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(13, 124, 122, 0.08);
  padding: 10px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.policy-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.sent-response-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.45;
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 12px;
}

.toast {
  position: fixed;
  top: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: rgba(16, 74, 73, 0.95);
  color: #fff;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 0.83rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 40;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast--error {
  background: rgba(183, 28, 28, 0.92);
}

.noscript {
  padding: 18px;
  margin: 24px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-family: var(--font-body);
}

@media (max-width: 1100px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-grid,
  .bottom-grid {
    grid-template-columns: 1fr;
  }

  .query-filters {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .pending-details {
    grid-template-columns: 1fr;
  }

  .policy-config-grid {
    grid-template-columns: 1fr;
  }

  .policy-grid {
    grid-template-columns: 1fr;
  }

  .policy-step {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .policy-step-index {
    margin-top: 0;
  }

  .policy-preview-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

}

@media (max-width: 760px) {
  #app {
    padding: 18px 14px 40px;
  }

  .app-header {
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button {
    flex: 1;
  }

  .tabs,
  .subtabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .query-filters {
    grid-template-columns: 1fr;
  }

  .cluster-cards-grid {
    grid-template-columns: 1fr;
  }

  .cluster-map-selects {
    width: 100%;
  }

  .cluster-map-selects label {
    width: 100%;
  }

  .cluster-map-selects select {
    min-width: 0;
    width: 100%;
  }

  .cluster-map-actions {
    width: 100%;
  }

  th,
  td {
    font-size: 0.78rem;
    padding: 8px;
  }

  .token-row {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .policy-step-card,
  .policy-live-card,
  .policy-settings-card {
    padding: 16px;
  }

  .policy-scope-list li {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
  }

  .policy-scope-chip {
    grid-column: 2;
    justify-self: start;
  }

  .policy-scope-actions {
    grid-column: 1 / -1;
    justify-self: start;
    padding-left: 18px;
  }
}
