:root {
  --paper: #f0eadc;
  --paper-deep: #ded4c0;
  --ink: #152433;
  --ink-soft: #52606a;
  --signal: #d5482d;
  --signal-dark: #9d2b1b;
  --green: #11634f;
  --line: rgba(21, 36, 51, 0.22);
  --shadow: 0 18px 50px rgba(31, 37, 40, 0.13);
  font-family: "Archivo Narrow", sans-serif;
  color: var(--ink);
  background: var(--paper-deep);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, transparent 49.8%, rgba(21, 36, 51, 0.035) 50%, transparent 50.2%),
    radial-gradient(circle at 8% 12%, rgba(255,255,255,.85), transparent 27%),
    var(--paper-deep);
}

button, textarea { font: inherit; }
button { color: inherit; }

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

.masthead {
  min-height: 132px;
  padding: 26px clamp(22px, 4vw, 64px);
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(240, 234, 220, .82);
  backdrop-filter: blur(10px);
}

.eyebrow, .kicker {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: .16em;
  font-weight: 700;
  font-size: .75rem;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-family: "Fraunces", serif;
  font-size: clamp(2.4rem, 5vw, 4.8rem);
  line-height: .86;
  letter-spacing: -.045em;
}

.masthead__actions { display: flex; align-items: center; gap: 18px; }
.system-state { display: inline-flex; align-items: center; gap: 8px; text-transform: uppercase; letter-spacing: .1em; font-size: .72rem; font-weight: 700; }
.system-state i { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(17, 99, 79, .12); }
.text-button { border: 0; border-bottom: 1px solid currentColor; padding: 3px 0; background: transparent; cursor: pointer; font-weight: 700; }

.workbench-nav { display: flex; gap: 7px; margin-top: 18px; }
.workbench-nav__button { padding: 7px 12px; border: 1px solid var(--line); background: rgba(255,255,255,.28); cursor: pointer; text-transform: uppercase; letter-spacing: .1em; font-size: .7rem; font-weight: 700; }
.workbench-nav__button.is-active { border-color: var(--ink); background: var(--ink); color: var(--paper); }

.desk {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  width: min(1540px, calc(100% - 42px));
  min-height: calc(100vh - 174px);
  margin: 20px auto 22px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: var(--paper);
}

.queue { border-right: 1px solid var(--line); min-width: 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; padding: 24px 26px 20px; border-bottom: 1px solid var(--line); }
.section-heading h2 { margin: 0; font-family: "Fraunces", serif; font-size: 1.7rem; }
.count { display: grid; place-items: center; min-width: 42px; height: 42px; border: 1px solid var(--ink); border-radius: 50%; font-family: "Fraunces", serif; font-weight: 800; }
.queue__items { max-height: calc(100vh - 238px); overflow: auto; }
.loading-card, .queue-empty { padding: 30px 26px; color: var(--ink-soft); }

.handoff-card {
  width: 100%;
  padding: 22px 26px;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .18s ease, padding-left .18s ease;
}
.handoff-card:hover { background: rgba(255,255,255,.5); padding-left: 31px; }
.handoff-card.is-active { background: var(--ink); color: var(--paper); }
.handoff-card__top { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.handoff-card strong { font-family: "Fraunces", serif; font-size: 1.14rem; }
.handoff-card time { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; opacity: .72; }
.handoff-card p { margin: 0 0 7px; font-weight: 600; }
.handoff-card small { display: block; opacity: .7; }

.case-file { min-width: 0; position: relative; }
.empty-state { min-height: 610px; display: grid; align-content: center; justify-items: center; text-align: center; padding: 60px; }
.empty-state__number { font-family: "Fraunces", serif; font-size: clamp(6rem, 15vw, 14rem); font-weight: 800; line-height: .75; color: rgba(21,36,51,.055); }
.empty-state h2 { margin: -20px 0 12px; font-family: "Fraunces", serif; font-size: 2.2rem; }
.empty-state p { max-width: 440px; color: var(--ink-soft); font-size: 1.08rem; }

.case-file__content { animation: reveal .35s ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(7px); } }
.case-header { display: flex; align-items: start; justify-content: space-between; gap: 28px; padding: 30px clamp(24px, 4vw, 52px) 26px; }
.case-header h2 { margin: 0; font-family: "Fraunces", serif; font-size: clamp(2rem, 4vw, 3.5rem); line-height: .95; }
.case-meta { margin: 9px 0 0; color: var(--ink-soft); }
.reason-stamp { max-width: 230px; padding: 10px 13px; border: 2px solid var(--signal); color: var(--signal-dark); transform: rotate(1.5deg); text-transform: uppercase; letter-spacing: .08em; text-align: center; font-weight: 700; font-size: .78rem; }
.summary-strip { padding: 15px clamp(24px, 4vw, 52px); border-block: 1px solid var(--line); background: rgba(255,255,255,.35); font-size: 1.02rem; }

.conversation { display: flex; flex-direction: column; gap: 14px; padding: 30px clamp(24px, 4vw, 52px); max-height: 470px; overflow-y: auto; scroll-behavior: smooth; }
.message { max-width: min(76%, 680px); padding: 13px 16px 11px; border: 1px solid var(--line); background: rgba(255,255,255,.5); }
.message--inbound { align-self: flex-start; border-radius: 2px 17px 17px 17px; }
.message--outbound { align-self: flex-end; border-radius: 17px 2px 17px 17px; background: var(--ink); color: var(--paper); }
.message--human { background: var(--green); }
.message__meta { display: flex; justify-content: space-between; gap: 18px; margin-bottom: 5px; font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; opacity: .68; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-family: "Archivo Narrow", sans-serif; font-size: 1.02rem; line-height: 1.45; }

.reply-box { margin: 0 clamp(24px, 4vw, 52px) 24px; padding: 18px; border: 2px solid var(--ink); background: rgba(255,255,255,.32); }
.reply-box label { display: block; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .12em; font-weight: 700; font-size: .76rem; }
.reply-box textarea { width: 100%; resize: vertical; border: 0; border-bottom: 1px solid var(--line); outline: 0; padding: 8px 2px 13px; background: transparent; color: var(--ink); font-size: 1.12rem; line-height: 1.45; }
.reply-box textarea:focus { border-color: var(--signal); }
.reply-box__footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-top: 14px; }
.reply-box__footer p { margin: 0; color: var(--ink-soft); font-size: .85rem; }
.primary-button, .close-button { border: 0; padding: 12px 18px; cursor: pointer; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; transition: transform .16s ease, background .16s ease; }
.primary-button { background: var(--signal); color: white; }
.primary-button:hover, .close-button:hover { transform: translateY(-2px); }
.primary-button:disabled, .close-button:disabled { opacity: .45; cursor: wait; transform: none; }

.resolution-bar { display: flex; justify-content: space-between; align-items: center; gap: 24px; padding: 22px clamp(24px, 4vw, 52px); border-top: 1px solid var(--line); background: var(--paper-deep); }
.resolution-bar strong, .resolution-bar span { display: block; }
.resolution-bar span { margin-top: 3px; color: var(--ink-soft); font-size: .85rem; }
.close-button { border: 1px solid var(--ink); background: transparent; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: 420px; padding: 15px 18px; background: var(--ink); color: white; box-shadow: var(--shadow); font-weight: 600; }
.toast.is-error { background: var(--signal-dark); }

.quality-room {
  width: min(1540px, calc(100% - 42px));
  margin: 20px auto 22px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: var(--paper);
}
.quality-room__header { display: flex; align-items: end; justify-content: space-between; gap: 40px; padding: 34px clamp(24px, 4vw, 54px) 29px; border-bottom: 1px solid var(--line); }
.quality-room__header h2 { margin: 0 0 10px; font: 800 clamp(2.4rem, 5vw, 5.1rem)/.88 "Fraunces", serif; letter-spacing: -.045em; }
.quality-room__header p:last-child { max-width: 680px; margin: 0; color: var(--ink-soft); font-size: 1.04rem; }
.period-switcher { display: flex; flex: 0 0 auto; border: 1px solid var(--ink); }
.period-button { min-width: 66px; padding: 10px 12px; border: 0; border-right: 1px solid var(--ink); background: transparent; cursor: pointer; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.period-button:last-child { border-right: 0; }
.period-button.is-active { background: var(--ink); color: var(--paper); }

.metric-ledger { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.metric-ticket { min-height: 166px; padding: 22px 24px; border-right: 1px solid var(--line); background: rgba(255,255,255,.16); }
.metric-ticket:last-child { border-right: 0; }
.metric-ticket > span { display: block; text-transform: uppercase; letter-spacing: .11em; font-size: .72rem; font-weight: 700; }
.metric-ticket strong { display: block; margin: 12px 0 8px; font: 800 clamp(2rem, 4vw, 3.7rem)/1 "Fraunces", serif; letter-spacing: -.04em; }
.metric-ticket small { color: var(--ink-soft); font-size: .82rem; }
.metric-ticket--signal { background: var(--signal); color: white; }
.metric-ticket--signal small { color: rgba(255,255,255,.78); }
.metric-ticket--unmeasured { background: repeating-linear-gradient(-45deg, transparent, transparent 8px, rgba(21,36,51,.035) 8px, rgba(21,36,51,.035) 10px); }
.metric-ticket--unmeasured strong { font-size: clamp(1.45rem, 2.5vw, 2.25rem); }
.coverage-warning { padding: 12px 24px; border-bottom: 1px solid var(--line); background: #f7d9a9; color: var(--signal-dark); font-weight: 700; }

.quality-workbench { display: grid; grid-template-columns: minmax(330px, 430px) minmax(0, 1fr); min-height: 620px; }
.quality-index { border-right: 1px solid var(--line); min-width: 0; }
.quality-index__legend { padding: 12px 26px; border-bottom: 1px solid var(--line); color: var(--ink-soft); background: var(--paper-deep); font-size: .82rem; }
.quality-conversations { max-height: 680px; overflow-y: auto; }
.quality-card { width: 100%; padding: 20px 24px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; transition: background .18s ease, padding-left .18s ease; }
.quality-card:hover { padding-left: 29px; background: rgba(255,255,255,.52); }
.quality-card.is-active { background: var(--ink); color: var(--paper); }
.quality-card__top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.quality-card__top strong { font: 700 1.08rem "Fraunces", serif; }
.quality-card time { opacity: .66; font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; }
.quality-card p { margin: 8px 0 11px; font-weight: 600; }
.quality-card__signals, .signal-cluster { display: flex; flex-wrap: wrap; gap: 6px; }
.quality-card__signals small { opacity: .62; }
.quality-signal { display: inline-flex; padding: 4px 7px 3px; border: 1px solid currentColor; color: var(--signal-dark); text-transform: uppercase; letter-spacing: .07em; font-size: .62rem; font-weight: 700; }
.quality-card.is-active .quality-signal { color: #ef9b87; }

.quality-transcript { position: relative; min-width: 0; }
.quality-empty { min-height: 620px; display: grid; align-content: center; justify-items: center; padding: 50px; text-align: center; }
.quality-empty > span { color: rgba(21,36,51,.08); font: 800 10rem/.7 "Fraunces", serif; }
.quality-empty h2 { margin: -8px 0 10px; font: 800 2.2rem "Fraunces", serif; }
.quality-empty p { max-width: 520px; color: var(--ink-soft); }
.quality-detail__header { display: flex; align-items: start; justify-content: space-between; gap: 30px; padding: 30px clamp(24px, 4vw, 50px) 24px; }
.quality-detail__header h2 { margin: 0; font: 800 clamp(2rem, 4vw, 3.4rem)/.95 "Fraunces", serif; }
.quality-detail__header p:last-child { margin: 8px 0 0; color: var(--ink-soft); }
.quality-detail__header .signal-cluster { max-width: 320px; justify-content: flex-end; }
.truth-note { padding: 14px clamp(24px, 4vw, 50px); border-block: 1px solid var(--line); background: #f7d9a9; font-weight: 600; }
.quality-conversation { max-height: 520px; }

@media (max-width: 860px) {
  .masthead { min-height: 0; padding: 22px; align-items: flex-start; flex-direction: column; }
  .masthead__actions { width: 100%; justify-content: space-between; flex-wrap: wrap; }
  .desk { width: 100%; min-height: 0; margin: 0; grid-template-columns: 1fr; border-inline: 0; }
  .queue { border-right: 0; border-bottom: 1px solid var(--line); }
  .queue__items { max-height: 300px; }
  .empty-state { min-height: 470px; padding: 52px 28px; }
  .empty-state__number { font-size: 7.5rem; }
  .case-header { flex-direction: column; }
  .reason-stamp { align-self: flex-start; }
  .message { max-width: 90%; }
  .reply-box__footer, .resolution-bar { align-items: stretch; flex-direction: column; }
  .primary-button, .close-button { width: 100%; }
  .quality-room { width: 100%; margin: 0; border-inline: 0; }
  .quality-room__header { align-items: stretch; flex-direction: column; }
  .period-switcher { width: 100%; }
  .period-button { flex: 1; }
  .metric-ledger { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-ticket { border-bottom: 1px solid var(--line); }
  .metric-ticket:nth-child(2n) { border-right: 0; }
  .metric-ticket:last-child { grid-column: 1 / -1; }
  .quality-workbench { grid-template-columns: 1fr; }
  .quality-index { border-right: 0; border-bottom: 1px solid var(--line); }
  .quality-conversations { max-height: 360px; }
  .quality-detail__header { flex-direction: column; }
  .quality-detail__header .signal-cluster { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
