:root {
  --bg-0: #f7f3ee;
  --bg-1: #efe6db;
  --bg-2: #e4d5c6;
  --panel: rgba(255, 250, 244, 0.86);
  --cream: #fffaf4;
  --ink: #2a231c;
  --muted: #7a6e64;
  --mist: #8a7a6c;
  --sage: #9eb3a8;
  --warm: #c08a72;
  --line: rgba(42, 35, 28, 0.1);
  --user-tint: rgba(192, 138, 114, 0.16);
  --ok: #5f7d6c;
  --bad: #a35a4a;
  --shadow: 0 22px 48px rgba(90, 60, 40, 0.08);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Manrope", system-ui, sans-serif;
  --radius: 1.25rem;
  --touch: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--bg-1);
  -webkit-font-smoothing: antialiased;
}

body { position: relative; }

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 65% 55% at 8% 12%, rgba(210, 180, 150, 0.45), transparent 58%),
    radial-gradient(ellipse 50% 45% at 92% 18%, rgba(160, 180, 160, 0.18), transparent 52%),
    radial-gradient(ellipse 70% 55% at 55% 100%, rgba(232, 210, 190, 0.5), transparent 55%),
    linear-gradient(168deg, var(--bg-0) 0%, var(--bg-1) 48%, var(--bg-2) 100%);
}

.stipple {
  position: absolute;
  inset: 0;
  opacity: 0.26;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='3' cy='4' r='0.7' fill='%237a6550'/%3E%3Ccircle cx='12' cy='9' r='0.55' fill='%237a6550'/%3E%3Ccircle cx='17' cy='15' r='0.65' fill='%237a6550'/%3E%3Ccircle cx='8' cy='16' r='0.45' fill='%237a6550'/%3E%3C/svg%3E");
  background-size: 20px 20px;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: calc(24px + var(--safe-top)) 20px calc(40px + var(--safe-bottom));
  animation: rise 0.55s var(--ease) both;
}

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

@keyframes grow {
  from { transform: scaleY(0); }
  to { transform: scaleY(1); }
}

@keyframes draw {
  from { stroke-dashoffset: 120; }
  to { stroke-dashoffset: 0; }
}

.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.7rem, 3vw, 2.05rem);
  letter-spacing: -0.03em;
  margin: 0;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--mist);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  padding: 22px;
}

.panel + .panel { margin-top: 14px; }

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

.presence {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 8px;
  color: var(--mist);
  font-size: 0.82rem;
  font-weight: 500;
}

.presence i {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: var(--sage);
  box-shadow: 0 0 0 4px rgba(158, 179, 168, 0.22);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.nav button,
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.7);
  color: var(--ink);
  border-radius: 999px;
  min-height: var(--touch);
  padding: 0 16px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}

.nav button.active,
.btn.primary {
  background: var(--mist);
  border-color: transparent;
  color: #fffaf4;
}

.nav button:hover,
.btn:hover {
  border-color: rgba(138, 122, 108, 0.45);
}

.btn.ghost {
  background: transparent;
}

.btn:focus-visible,
.nav button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--mist);
  outline-offset: 2px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 12px;
  letter-spacing: -0.02em;
}

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

.kpi {
  padding: 16px;
  border-radius: 1rem;
  background: rgba(255, 250, 244, 0.72);
  border: 1px solid var(--line);
}

.kpi .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 8px;
}

.kpi .value {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}

.kpi .hint {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.charts {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.chart-card {
  padding: 16px;
  border-radius: 1rem;
  background: rgba(255, 250, 244, 0.65);
  border: 1px solid var(--line);
}

.chart-card h3 {
  margin: 0 0 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.bars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  align-items: end;
  height: 140px;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}

.bar-stack {
  width: 100%;
  max-width: 28px;
  height: 110px;
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-start;
  gap: 2px;
}

.bar {
  width: 100%;
  border-radius: 6px 6px 4px 4px;
  transform-origin: bottom;
  animation: grow 0.7s var(--ease) both;
  min-height: 0;
}

.bar.user { background: var(--warm); }
.bar.miya { background: var(--sage); }

.bar-day {
  font-size: 0.68rem;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot.user { background: var(--warm); }
.dot.miya { background: var(--sage); }
.dot.mist { background: var(--mist); }

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mode-row {
  display: grid;
  grid-template-columns: 88px 1fr 36px;
  gap: 10px;
  align-items: center;
  font-size: 0.85rem;
}

.mode-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(42, 35, 28, 0.06);
  overflow: hidden;
}

.mode-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mist), var(--sage));
  transform-origin: left;
  animation: grow 0.75s var(--ease) both;
}

.mode-row strong {
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.spark {
  width: 100%;
  height: 56px;
  display: block;
}

.spark path {
  fill: none;
  stroke: var(--mist);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 200;
  animation: draw 1s var(--ease) both;
}

.spark area {
  fill: rgba(138, 122, 108, 0.12);
  stroke: none;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 6px;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  background: rgba(255, 250, 244, 0.85);
  color: var(--ink);
  margin-bottom: 14px;
}

.login-wrap {
  max-width: 420px;
  margin: 12vh auto 0;
}

.login-wrap .brand {
  margin-bottom: 4px;
}

.login-wrap .btn.primary {
  width: 100%;
  margin-top: 4px;
}

.err {
  color: var(--bad);
  font-size: 0.9rem;
  margin: 8px 0 0;
  min-height: 1.2em;
}

.muted { color: var(--muted); }

.meta-line {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

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

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 62vh;
  overflow: auto;
}

.bubble {
  max-width: 720px;
  padding: 12px 14px;
  border-radius: 1.05rem;
  border: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.92);
  white-space: pre-wrap;
  line-height: 1.45;
}

.bubble.user { background: var(--user-tint); }
.bubble .meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.people-filter {
  margin: 0 0 12px;
  flex-wrap: wrap;
}
.people-filter .nav-btn {
  font-size: 0.85rem;
}
.meta-line.muted,
.muted.meta-line {
  color: var(--muted);
}
.pick-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 14px;
}

.pick-label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.user-pick {
  min-height: var(--touch);
  border-radius: 0.85rem;
  border: 1px solid var(--line);
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  padding: 0 12px;
  max-width: 100%;
}

.people {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.person {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  padding: 14px 16px;
  border-radius: 1rem;
  border: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.7);
}

.person .name {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(138, 122, 108, 0.12);
  color: var(--mist);
  font-size: 0.78rem;
  font-weight: 600;
}

.chip-ok {
  background: rgba(95, 125, 108, 0.16);
  color: var(--ok);
}

.chip-bad {
  background: rgba(163, 90, 74, 0.14);
  color: var(--bad);
}

@media (max-width: 720px) {
  .charts { grid-template-columns: 1fr; }
  .shell { padding-left: 14px; padding-right: 14px; }
  .person { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .shell, .bar, .mode-fill, .spark path { animation: none; }
}


/* Staff HQ + Agents */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--mist, #d9d2c5) 35%, transparent);
  font-size: 13px;
}
.chip.warn { background: color-mix(in srgb, #c45c26 18%, transparent); }
.staff-thread {
  max-height: min(52vh, 520px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0 16px;
}
.staff-bubble {
  max-width: min(640px, 92%);
  padding: 10px 12px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--paper, #f7f3ea) 80%, #fff);
  border: 1px solid color-mix(in srgb, var(--ink, #2a241c) 8%, transparent);
}
.staff-bubble.staff-me { align-self: flex-end; background: color-mix(in srgb, #c45c26 10%, #fff); }
.staff-bubble.staff-lead { align-self: flex-start; }
.staff-who { font-size: 12px; opacity: 0.7; margin-bottom: 4px; }
.staff-text { white-space: pre-wrap; line-height: 1.45; }
.staff-form textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--ink, #2a241c) 14%, transparent);
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}
.staff-actions { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.agents-layout { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; margin-top: 14px; }
@media (max-width: 900px) { .agents-layout { grid-template-columns: 1fr; } }
.agents-list { display: flex; flex-direction: column; gap: 8px; }
.agent-row {
  text-align: left;
  border: 1px solid color-mix(in srgb, var(--ink, #2a241c) 10%, transparent);
  background: #fff;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
}
.agent-row.active-row { outline: 2px solid color-mix(in srgb, #c45c26 45%, transparent); }
.agent-title { font-weight: 600; }
.agent-meta { font-size: 13px; margin-top: 2px; }
.agent-sum, .agent-when { font-size: 12px; margin-top: 4px; }
.check-list { margin: 10px 0 0; padding-left: 18px; }
.assign-box {
  margin: 0 0 14px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--ink, #2a241c) 10%, transparent);
  background: color-mix(in srgb, #fff 70%, var(--paper, #f7f3ea));
}
.assign-title { margin: 0 0 8px; font-size: 15px; }
.assign-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-top: 1px solid color-mix(in srgb, var(--ink, #2a241c) 8%, transparent);
  font-size: 14px;
}
.assign-row:first-of-type { border-top: 0; }
