:root {
  --bg: #f3efe6;
  --ink: #16313b;
  --muted: #5c6d73;
  --line: rgba(22, 49, 59, 0.12);
  --surface: rgba(255, 250, 242, 0.92);
  --surface-strong: #fff9f1;
  --accent: #0f8d78;
  --accent-strong: #0a6d5d;
  --sun: #f2a93b;
  --danger: #b53d3d;
  --warning: #c57d1d;
  --shadow: 0 14px 42px rgba(22, 49, 59, 0.11);
  --radius: 28px;
  --radius-sm: 20px;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-body: "Avenir Next", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(242, 169, 59, 0.14), transparent 22%),
    linear-gradient(180deg, #f4f1e8 0%, #efe5d6 100%);
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
}

p {
  margin: 0;
}

.eyebrow {
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.lead {
  max-width: 32rem;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.6;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.login-shell {
  width: min(1080px, 100%);
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
  gap: 1.5rem;
}

.login-poster,
.login-card,
.surface,
.agent-card {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.login-poster {
  min-height: 420px;
  padding: 3rem;
  border-radius: 36px;
  background: linear-gradient(145deg, rgba(18, 58, 72, 0.96), rgba(15, 141, 120, 0.88));
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.login-poster h1 {
  font-size: clamp(3rem, 6vw, 5rem);
  max-width: 9ch;
  line-height: 0.92;
}

.login-card,
.surface,
.agent-card {
  background: var(--surface);
  backdrop-filter: blur(12px);
}

.login-card {
  padding: 2rem;
  border-radius: var(--radius);
  align-self: center;
}

.stack-sm > * + * {
  margin-top: 0.45rem;
}

.stack-md > * + * {
  margin-top: 1rem;
}

.stack-lg > * + * {
  margin-top: 1.25rem;
}

.min-w-0 {
  min-width: 0;
}

.field span,
.surface h3,
.panel-header h2 {
  display: block;
  margin-bottom: 0.55rem;
}

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

.input,
.textarea,
.small-input,
.field input {
  width: 100%;
  border: 1px solid rgba(22, 49, 59, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  padding: 0.9rem 1rem;
  color: var(--ink);
}

.textarea {
  min-height: 148px;
  resize: vertical;
}

.textarea-strong {
  min-height: 188px;
  background: rgba(255, 255, 255, 0.95);
}

.button {
  border: none;
  border-radius: 999px;
  cursor: pointer;
  padding: 0.85rem 1.2rem;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, opacity 180ms ease;
}

.button:focus-visible,
.input:focus-visible,
.textarea:focus-visible,
select:focus-visible,
.workspace-nav-item:focus-visible,
.chat-open-button:focus-visible,
.chat-selector:focus-within,
.quiet-toggle:focus-visible,
.analytics-tab:focus-visible,
.ranking-item:focus-visible {
  outline: 3px solid rgba(15, 141, 120, 0.32);
  outline-offset: 3px;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.button-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  box-shadow: 0 12px 28px rgba(15, 141, 120, 0.28);
}

.button-secondary {
  background: rgba(15, 141, 120, 0.12);
  color: var(--ink);
}

.button-compact {
  padding: 0.6rem 0.85rem;
}

.status {
  min-height: 1.25rem;
  color: var(--muted);
  min-width: 0;
}

.status-error {
  color: var(--danger);
}

.status-hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.app-shell {
  min-height: 100vh;
  padding: 1.5rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.topbar h1 {
  font-size: clamp(2.2rem, 4vw, 3.8rem);
}

.topbar-actions {
  display: flex;
  gap: 0.75rem;
}

.workspace-shell {
  display: grid;
  grid-template-columns: minmax(190px, 220px) minmax(560px, 1fr) minmax(340px, 400px);
  gap: 1rem;
  align-items: start;
}

.workspace-sidebar,
.action-panel {
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 3rem);
  overflow: auto;
}

.workspace-sidebar {
  padding: 1rem;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.workspace-nav {
  display: grid;
  gap: 0.55rem;
}

.workspace-nav-item {
  width: 100%;
  border: 1px solid rgba(22, 49, 59, 0.08);
  background: rgba(255, 255, 255, 0.62);
  border-radius: 14px;
  padding: 0.78rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  text-align: left;
}

.workspace-nav-item-active {
  background: rgba(15, 141, 120, 0.16);
  border-color: rgba(15, 141, 120, 0.24);
}

.workspace-nav-copy {
  display: grid;
  gap: 0.18rem;
  min-width: 0;
}

.workspace-nav-copy strong,
.workspace-nav-copy small {
  display: block;
}

.workspace-nav-copy small {
  color: var(--muted);
}

.workspace-nav-badge {
  min-width: 1.9rem;
  min-height: 1.9rem;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  background: rgba(15, 141, 120, 0.18);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
}

.workspace-center {
  min-width: 0;
  display: grid;
}

.view-panel > .surface {
  padding: 1rem;
  border-radius: 18px;
}

.view-panel {
  min-width: 0;
}

.view-panel[hidden],
.analytics-tab-panel[hidden] {
  display: none !important;
}

.panel-header-grid,
.history-filters,
.section-row,
.composer-head,
.composer-actions,
.chat-summary-card-head,
.summary-card-footer,
.detail-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.85rem;
  min-width: 0;
}

.panel-header-grid {
  flex-wrap: wrap;
}

.panel-header-grid .eyebrow {
  margin-bottom: 0.25rem;
}

.header-copy {
  min-width: 0;
  flex: 1 1 260px;
}

.action-panel-head {
  gap: 0.55rem;
}

.action-panel-head .header-copy {
  flex: 1 1 auto;
}

.action-panel-head .status {
  flex: 0 1 100%;
}

.history-filters {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.small-input {
  width: auto;
  min-width: 160px;
}

.action-panel {
  padding: 1rem;
  border-radius: 20px;
  display: grid;
  gap: 0.8rem;
}

.action-panel-body {
  min-width: 0;
  display: grid;
  gap: 1rem;
}

.detail-card,
.detail-empty,
.analytics-card,
.chat-group,
.inbox-card,
.learning-card,
.history-item,
.chat-summary-card,
.kpi-card,
.summary-box {
  border: 1px solid rgba(22, 49, 59, 0.1);
  background: rgba(255, 255, 255, 0.66);
  border-radius: 14px;
  padding: 0.85rem;
}

.detail-empty {
  display: grid;
  gap: 0.55rem;
}

.detail-summary,
.chat-summary-text,
.learning-pair,
.analytics-bullets,
.summary-wide {
  line-height: 1.55;
}

.detail-block {
  padding-top: 0.2rem;
}

.badges,
.summary-badges {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  background: rgba(22, 49, 59, 0.08);
  font-size: 0.8rem;
}

.badge-summary {
  background: rgba(15, 141, 120, 0.14);
}

.badge-danger {
  background: rgba(181, 61, 61, 0.16);
}

.badge-warning {
  background: rgba(197, 125, 29, 0.16);
}

.badge-alert {
  background: rgba(242, 169, 59, 0.18);
}

.chat-tree,
.inbox-list,
.learning-list,
.history-list {
  display: grid;
  gap: 0.65rem;
}

.inbox-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.chat-group {
  display: grid;
  gap: 0.55rem;
}

.thread-list {
  display: grid;
  gap: 0.6rem;
  padding-left: 1rem;
  border-left: 2px solid rgba(22, 49, 59, 0.1);
}

.chat-node-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

.chat-node-row-thread {
  align-items: flex-start;
}

.chat-node-copy-shell {
  flex: 1 1 auto;
  min-width: 0;
}

.chat-open-button,
.chat-selector {
  width: 100%;
  border: 1px solid rgba(22, 49, 59, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  padding: 0.68rem 0.8rem;
  min-width: 0;
}

.chat-open-button {
  display: grid;
  gap: 0.15rem;
  text-align: left;
}

.chat-open-button-active {
  border-color: rgba(15, 141, 120, 0.28);
  background: rgba(15, 141, 120, 0.14);
}

.chat-open-title {
  font-weight: 700;
}

.chat-selector {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.chat-selector-thread {
  padding-left: 1.1rem;
}

.chat-node-actions,
.composer-actions-left,
.composer-actions-right {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.quiet-toggle {
  border: 1px solid rgba(22, 49, 59, 0.1);
  background: rgba(255, 255, 255, 0.52);
  color: var(--ink);
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
}

.quiet-toggle-active {
  background: rgba(15, 141, 120, 0.18);
}

.inbox-card,
.learning-card {
  cursor: pointer;
}

.inbox-card {
  display: grid;
  gap: 0.55rem;
  padding: 0.78rem;
}

.inbox-card-topline {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.inbox-card-critical {
  border-color: rgba(181, 61, 61, 0.24);
  background: linear-gradient(180deg, rgba(181, 61, 61, 0.06), rgba(255, 255, 255, 0.68));
}

.inbox-card-warning {
  border-color: rgba(197, 125, 29, 0.24);
  background: linear-gradient(180deg, rgba(242, 169, 59, 0.08), rgba(255, 255, 255, 0.68));
}

.inbox-card-attention {
  border-color: rgba(15, 141, 120, 0.2);
  background: linear-gradient(180deg, rgba(15, 141, 120, 0.06), rgba(255, 255, 255, 0.68));
}

.inbox-card-actions .button {
  padding: 0.62rem 0.82rem;
}

.inbox-severity-badge {
  font-weight: 700;
}

.inbox-severity-badge-critical {
  background: rgba(181, 61, 61, 0.16);
}

.inbox-severity-badge-warning {
  background: rgba(197, 125, 29, 0.16);
}

.inbox-severity-badge-attention {
  background: rgba(242, 169, 59, 0.18);
}

.inbox-severity-badge-calm {
  background: rgba(22, 49, 59, 0.08);
}

.inbox-card-active,
.learning-card-active,
.ranking-item-active {
  border-color: rgba(15, 141, 120, 0.25);
  background: rgba(15, 141, 120, 0.12);
}

.ranking-item {
  width: 100%;
  border: 1px solid rgba(22, 49, 59, 0.08);
  background: rgba(255, 255, 255, 0.56);
  border-radius: 14px;
  padding: 0.72rem 0.82rem;
  display: grid;
  gap: 0.2rem;
  text-align: left;
}

.draft-preview {
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  padding: 0.9rem;
  line-height: 1.5;
}

.draft-preview-compact {
  padding: 0.7rem 0.85rem;
  font-size: 0.92rem;
}

.wrap-actions {
  flex-wrap: wrap;
}

.message-chip {
  padding: 0.8rem 0.9rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
  display: grid;
  gap: 0.35rem;
}

.message-chip-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.timeline-list {
  display: grid;
  gap: 0.85rem;
}

.timeline-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 0.8rem;
}

.timeline-rail {
  position: relative;
  display: grid;
  justify-items: center;
}

.timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: rgba(22, 49, 59, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 16px rgba(22, 49, 59, 0.1);
  z-index: 1;
}

.timeline-line {
  position: absolute;
  top: 12px;
  bottom: -14px;
  width: 2px;
  background: rgba(22, 49, 59, 0.12);
}

.timeline-card {
  border-radius: 14px;
  padding: 0.72rem 0.82rem;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(22, 49, 59, 0.08);
  display: grid;
  gap: 0.35rem;
  line-height: 1.5;
}

.timeline-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
  align-items: baseline;
}

.timeline-item-self .timeline-card {
  background: rgba(15, 141, 120, 0.12);
}

.timeline-item-self .timeline-dot {
  background: rgba(15, 141, 120, 0.8);
}

.timeline-item-alert .timeline-card {
  background: rgba(242, 169, 59, 0.12);
}

.timeline-item-alert .timeline-dot {
  background: rgba(197, 125, 29, 0.85);
}

.composer-panel {
  border-top: 1px solid rgba(22, 49, 59, 0.08);
  padding-top: 0.25rem;
}

.composer-panel-dragover {
  outline: 2px dashed rgba(15, 141, 120, 0.45);
  outline-offset: 6px;
}

.composer-fields {
  display: grid;
  gap: 0.9rem;
}

.attachment-inline-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-radius: 18px;
  padding: 0.75rem 0.85rem;
  background: rgba(255, 255, 255, 0.66);
  border: 1px solid rgba(22, 49, 59, 0.08);
}

.attachment-copy {
  display: grid;
  gap: 0.1rem;
}

.attachment-remove {
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

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

.email-form {
  display: grid;
  gap: 1rem;
}

.email-recipients-textarea {
  min-height: 116px;
}

.email-status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
}

.email-actions {
  border-top: 1px solid rgba(22, 49, 59, 0.08);
  padding-top: 1rem;
}

.email-validation {
  margin-top: -0.35rem;
  min-height: 1.2rem;
}

.email-result-root,
.email-result-list {
  display: grid;
  gap: 0.75rem;
}

.email-result-summary,
.email-recipient-result {
  border: 1px solid rgba(22, 49, 59, 0.1);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.66);
  padding: 0.82rem;
}

.email-recipient-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.email-recipient-result small {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
}

.email-recipient-ok {
  border-color: rgba(15, 141, 120, 0.2);
}

.email-recipient-error {
  border-color: rgba(181, 61, 61, 0.24);
}

.analytics-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.8rem;
}

.analytics-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.analytics-tab {
  border: 1px solid rgba(22, 49, 59, 0.08);
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.75rem 1rem;
}

.analytics-tab-active {
  background: rgba(15, 141, 120, 0.16);
  border-color: rgba(15, 141, 120, 0.28);
}

.analytics-tab-panel {
  display: grid;
  gap: 1rem;
}

.analytics-digest-panel {
  background: linear-gradient(180deg, rgba(15, 141, 120, 0.08), rgba(255, 255, 255, 0.7));
}

.kpi-card {
  display: grid;
  gap: 0.2rem;
  text-align: left;
}

.kpi-card strong {
  font-size: 1.5rem;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.analytics-card-wide {
  grid-column: 1 / -1;
}

.analytics-ranking,
.analytics-bullets,
.faq-clusters {
  display: grid;
  gap: 0.7rem;
}

.faq-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
}

.analytics-heatmap {
  display: grid;
  gap: 0.65rem;
}

.heatmap-header,
.heatmap-row {
  display: grid;
  grid-template-columns: minmax(140px, 1.4fr) repeat(7, minmax(32px, 1fr));
  gap: 0.4rem;
  align-items: center;
}

.heatmap-cell {
  min-height: 2rem;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(22, 49, 59, 0.08);
  font-size: 0.82rem;
}

.heatmap-level-1 { background: rgba(15, 141, 120, 0.12); }
.heatmap-level-2 { background: rgba(15, 141, 120, 0.2); }
.heatmap-level-3 { background: rgba(15, 141, 120, 0.28); }
.heatmap-level-4 { background: rgba(15, 141, 120, 0.38); color: white; }

.summary-empty,
.chat-empty {
  padding: 0.85rem;
  border-radius: 14px;
  border: 1px dashed rgba(22, 49, 59, 0.16);
  color: var(--muted);
}

.history-meta {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
}

.agent-card-compact {
  padding: 0.72rem 0.82rem;
  border-radius: 16px;
}

.agent-card-compact-body {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 0.75rem;
  align-items: center;
}

.agent-portrait-compact {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
}

@media (max-width: 1260px) {
  .workspace-shell {
    grid-template-columns: minmax(180px, 210px) minmax(500px, 1fr) minmax(300px, 360px);
  }

  .workspace-sidebar-copy .status-hint {
    display: none;
  }

  .workspace-nav-copy small {
    display: none;
  }
}

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

  .workspace-sidebar,
  .action-panel {
    position: static;
    max-height: none;
  }

  .workspace-sidebar {
    order: -2;
    padding: 0.85rem;
  }

  .workspace-center {
    order: -1;
  }

  .workspace-sidebar-copy {
    display: none;
  }

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

  .workspace-nav-item {
    padding: 0.8rem;
  }

  .workspace-nav-copy small {
    display: none;
  }

  .action-panel {
    order: 0;
  }

  .action-panel-head .header-copy {
    flex-basis: auto;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 1rem;
  }

  .login-shell {
    grid-template-columns: 1fr;
  }

  .workspace-nav {
    display: flex;
    overflow: auto;
  }

  .workspace-nav-item {
    min-width: 138px;
    flex: 0 0 auto;
  }

  .workspace-nav-copy strong {
    font-size: 0.95rem;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 2rem;
  }

  .panel-header-grid,
  .history-filters,
  .section-row,
  .composer-head,
  .composer-actions,
  .chat-summary-card-head,
  .summary-card-footer,
  .detail-actions,
  .message-chip-meta,
  .timeline-meta,
  .inbox-card-topline {
    flex-direction: column;
    align-items: stretch;
  }

  .small-input {
    width: 100%;
  }

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

  .analytics-tabs {
    flex-direction: column;
  }

  .analytics-card-wide {
    grid-column: auto;
  }

  .summary-grid,
  .heatmap-header,
  .heatmap-row,
  .agent-card-compact-body {
    grid-template-columns: 1fr;
  }

  .email-status-pills,
  .email-recipient-result {
    align-items: stretch;
  }

  .chat-node-row {
    flex-direction: column;
    align-items: stretch;
  }
}
