@import url('https://fonts.googleapis.com/css2?family=Eczar:wght@400;600;700&family=Work+Sans:wght@400;500;600&display=swap');

:root {
  --bg: #0f1115;
  --ink: #f3efe7;
  --muted: #9f988b;
  --accent: #c8792b;
  --panel: #171b22;
  --border: #2a3039;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --shell-bg: rgba(17, 21, 27, 0.94);
  --note-bg: rgba(255, 255, 255, 0.02);
  --nav-bg: #131820;
  --nav-active-bg: linear-gradient(135deg, #232b36 0%, #1a2029 100%);
  --nav-active-border: #394252;
  --column-bg: #151a22;
  --field-bg: #11161d;
  --field-placeholder: #7f8896;
  --card-bg: #121720;
  --card-active-shadow: 0 12px 30px rgba(200,121,43,0.18);
  --badge-bg: #222933;
  --divider: #323947;
  --pane-bg: rgba(255,255,255,0.015);
  --bubble-bg: #11161c;
  --thread-base-bg: #11161d;
  --email-bg: #10151b;
}

body.theme-light {
  --bg: #eef2f7;
  --ink: #19212b;
  --muted: #6f7b89;
  --accent: #b76a2b;
  --panel: #ffffff;
  --border: #dbe3ec;
  --shadow: 0 18px 36px rgba(27, 39, 53, 0.08);
  --shell-bg: rgba(248, 251, 255, 0.92);
  --note-bg: rgba(255, 255, 255, 0.9);
  --nav-bg: #f6f9fc;
  --nav-active-bg: linear-gradient(135deg, #b76a2b 0%, #c98542 100%);
  --nav-active-border: #b76a2b;
  --column-bg: #ffffff;
  --field-bg: #ffffff;
  --field-placeholder: #90a0b2;
  --card-bg: #ffffff;
  --card-active-shadow: 0 14px 28px rgba(33, 49, 66, 0.12);
  --badge-bg: #eef3f8;
  --divider: #e3eaf2;
  --pane-bg: #f9fbfd;
  --bubble-bg: #f4f7fb;
  --thread-base-bg: #ffffff;
  --email-bg: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Work Sans", system-ui, sans-serif;
  background:
    radial-gradient(900px 540px at 8% -10%, rgba(200, 121, 43, 0.18) 0%, transparent 60%),
    radial-gradient(900px 540px at 110% 0%, rgba(60, 74, 108, 0.28) 0%, transparent 60%),
    var(--bg);
  color: var(--ink);
}

body.theme-light {
  background:
    radial-gradient(900px 540px at 8% -10%, rgba(183, 106, 43, 0.10) 0%, transparent 60%),
    radial-gradient(900px 540px at 110% 0%, rgba(119, 150, 188, 0.12) 0%, transparent 60%),
    var(--bg);
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220' viewBox='0 0 220 220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  width: min(1440px, calc(100% - 40px));
  margin: 22px auto;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
}

.sidebar,
.workspace {
  background: var(--shell-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.sidebar {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: calc(100vh - 44px);
}

.workspace {
  padding: 20px;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.monogram {
  font-family: "Eczar", serif;
  background: var(--ink);
  color: #11151b;
  padding: 10px 12px;
  border-radius: 12px;
  letter-spacing: 0.05em;
}

body.theme-light .monogram {
  background: linear-gradient(135deg, #b76a2b 0%, #d89a5a 100%);
  color: #fffaf3;
}

h1 {
  margin: 0 0 4px;
  font-family: "Eczar", serif;
  font-weight: 700;
}

.workspace-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}

h2 {
  margin: 0;
  font-family: "Eczar", serif;
  font-size: 28px;
}

.toggle-card,
.sidebar-note {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--note-bg);
}

.label { font-weight: 600; }
.muted { color: var(--muted); font-size: 12px; }

.sidebar-note p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 13px;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: auto;
  padding: 14px 16px;
  background: var(--nav-bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: none;
}

.nav-btn.active {
  background: var(--nav-active-bg);
  color: #fff8ef;
  border-color: var(--nav-active-border);
}

.nav-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  font-size: 12px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 54px;
  height: 30px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  inset: 0;
  background: #2f3642;
  border-radius: 999px;
  transition: .2s;
}

.slider:before {
  content: "";
  position: absolute;
  height: 22px;
  width: 22px;
  left: 4px;
  top: 4px;
  background: #f4ede2;
  border-radius: 50%;
  transition: .2s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(24px); }

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
}

.column {
  background: var(--column-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
  min-height: 520px;
}

.list-header {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

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

.section-title {
  font-weight: 700;
  font-size: 16px;
}

input, button, textarea {
  font-family: inherit;
}

input, textarea, select, button {
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--field-bg);
  color: var(--ink);
}

input::placeholder,
textarea::placeholder {
  color: var(--field-placeholder);
}

button {
  background: var(--accent);
  border: none;
  color: white;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(225,121,45,0.25);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: none;
  cursor: pointer;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 280px);
  overflow: auto;
  padding-right: 4px;
}

.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 6px;
  cursor: pointer;
  background: var(--card-bg);
}

.card.active { border-color: var(--accent); box-shadow: var(--card-active-shadow); }

.card-title { font-weight: 600; }
.card-preview {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--muted);
}

.urgent { background: rgba(154, 67, 40, 0.22); color: #ffb090; }
.sending { background: rgba(61, 101, 184, 0.24); color: #a9c7ff; }

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--divider);
  margin-bottom: 12px;
}

.detail-title { font-weight: 700; font-size: 18px; }
.detail-sub { color: var(--muted); font-size: 13px; }
.detail-note { margin-top: 6px; max-width: 70ch; line-height: 1.4; }

.actions { display: flex; gap: 8px; }

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

.pane {
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  min-height: 320px;
  background: var(--pane-bg);
}

.pane-title { font-weight: 600; margin-bottom: 10px; }
.pane-title.small { font-size: 12px; color: var(--muted); }

.bubble {
  background: var(--bubble-bg);
  padding: 12px;
  border-radius: 12px;
  line-height: 1.5;
}

.history {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.ai-context {
  margin-top: 10px;
}

.ai-context-box {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bubble-bg);
  font-size: 13px;
  line-height: 1.45;
}

.ai-fallback-banner {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(200, 121, 43, 0.18);
  border: 1px solid rgba(200, 121, 43, 0.28);
  color: var(--ink);
  font-weight: 700;
}

body.theme-light .ai-fallback-banner {
  background: rgba(183, 106, 43, 0.12);
  border-color: rgba(183, 106, 43, 0.22);
}

.ai-line {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
}

.ai-label {
  color: var(--muted);
  font-weight: 700;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding-right: 4px;
}

.thread-item {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--thread-base-bg);
  border-left-width: 4px;
}

.thread-item.agent {
  background: rgba(200, 121, 43, 0.16);
  border-color: rgba(200, 121, 43, 0.28);
  border-left-color: #c8792b;
}

.thread-item.client {
  background: rgba(72, 112, 186, 0.18);
  border-color: rgba(72, 112, 186, 0.30);
  border-left-color: #5f8ef2;
}

body.theme-light .thread-item.agent {
  background: rgba(183, 106, 43, 0.10);
  border-color: rgba(183, 106, 43, 0.20);
  border-left-color: #b76a2b;
}

body.theme-light .thread-item.client {
  background: rgba(95, 142, 242, 0.10);
  border-color: rgba(95, 142, 242, 0.20);
  border-left-color: #5f8ef2;
}

.thread-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.thread-author {
  font-weight: 700;
  color: var(--ink);
}

.thread-item.agent .thread-author {
  color: #f2bf86;
}

.thread-item.client .thread-author {
  color: #b8ceff;
}

body.theme-light .thread-item.agent .thread-author {
  color: #9f5e27;
}

body.theme-light .thread-item.client .thread-author {
  color: #3d6fd2;
}

.email {
  background: var(--email-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  min-height: 200px;
}

.email-subject { font-weight: 700; margin-bottom: 8px; }

.email-body { white-space: pre-wrap; line-height: 1.6; }

.email-sign { margin-top: 12px; color: var(--muted); font-size: 13px; }

.manual-composer {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.manual-input {
  width: 100%;
}

.manual-textarea {
  min-height: 180px;
  height: auto;
  padding: 12px;
  resize: vertical;
}

.hidden { display: none; }

.status-line {
  margin-bottom: 10px;
}

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

.pager .ghost {
  min-width: 42px;
}

.upload {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
  background: var(--note-bg);
}

.theme-toggle {
  width: 100%;
  margin-top: auto;
}

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; width: min(100%, calc(100% - 24px)); }
  .sidebar { min-height: auto; }
  .layout { grid-template-columns: 1fr; }
  .preview { grid-template-columns: 1fr; }
}


.history-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 2px;
}

.badge.milestone {
  background: rgba(200, 121, 43, 0.18);
  border-color: rgba(200, 121, 43, 0.30);
  color: var(--ink);
}

.badge.milestone.subtle {
  background: rgba(95, 142, 242, 0.16);
  border-color: rgba(95, 142, 242, 0.26);
  color: var(--ink);
}

.thread-label {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.thread-label.outbound,
.thread-label.reply-sent {
  background: rgba(200, 121, 43, 0.18);
  color: #f2bf86;
}

.thread-label.reply-received {
  background: rgba(95, 142, 242, 0.18);
  color: #b8ceff;
}

body.theme-light .thread-label.outbound,
body.theme-light .thread-label.reply-sent {
  background: rgba(183, 106, 43, 0.12);
  color: #9f5e27;
}

body.theme-light .thread-label.reply-received {
  background: rgba(95, 142, 242, 0.12);
  color: #3d6fd2;
}

.thread-item.milestone-outbound,
.thread-item.milestone-sent {
  box-shadow: inset 0 0 0 1px rgba(200, 121, 43, 0.14);
}

.thread-item.milestone-reply {
  box-shadow: inset 0 0 0 1px rgba(95, 142, 242, 0.14);
}
