:root {
  --ink: #171216;
  --muted: #6f626a;
  --pink: #970747;
  --pink-dark: #6e0636;
  --pink-soft: #fff3f8;
  --line: #e6d9df;
  --surface: #ffffff;
  --success: #176447;
  --warning: #8a4a04;
  --danger: #a32323;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #faf7f8;
}

* { box-sizing: border-box; }

body { margin: 0; min-height: 100vh; background: #faf7f8; }
body.portal-theme-clinic {
  --ink: #171216;
  --muted: #6f626a;
  --pink: #970747;
  --pink-dark: #6e0636;
  --pink-soft: #fff3f8;
  --line: #e6d9df;
  --surface: #ffffff;
  background: #faf7f8;
}
body.portal-theme-night {
  --ink: #eef5ef;
  --muted: #a8b7b0;
  --pink: #6bd1a6;
  --pink-dark: #4aa982;
  --pink-soft: #182621;
  --line: #334043;
  --surface: #182021;
  --success: #6bd1a6;
  --warning: #ffc16b;
  --danger: #ff8c80;
  background: #0f1516;
}
body.portal-theme-executive {
  --ink: #211a14;
  --muted: #786d61;
  --pink: #6f4b2b;
  --pink-dark: #4d321c;
  --pink-soft: #f8f1e7;
  --line: #e3d5c5;
  --surface: #fffdfa;
  background: #f4efe8;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }

.portal-header {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px clamp(18px, 5vw, 68px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.portal-brand { display: flex; align-items: center; gap: 13px; }
.portal-brand img { width: 82px; height: 48px; object-fit: contain; }
.portal-brand span { display: grid; gap: 3px; }
.portal-brand strong { color: var(--pink); font-size: 1rem; text-transform: uppercase; }
.portal-brand small { color: var(--muted); font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }
.portal-user { display: flex; align-items: center; gap: 14px; }
.portal-user span { color: var(--muted); font-size: 0.9rem; font-weight: 700; }

main { min-height: calc(100vh - 78px); }

.auth-view {
  min-height: calc(100vh - 78px);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  align-items: center;
  gap: clamp(36px, 8vw, 110px);
  padding: 64px clamp(22px, 8vw, 120px);
  background:
    linear-gradient(90deg, rgba(255,255,255,.92), rgba(255,255,255,.76)),
    url("https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?auto=format&fit=crop&w=1800&q=80") center / cover;
}

.auth-copy { max-width: 650px; }
.auth-copy h1, .dashboard-title h1 { margin: 10px 0 16px; font-size: clamp(2.7rem, 6vw, 5.5rem); line-height: .94; }
.auth-copy > p:last-child { max-width: 520px; color: var(--muted); font-size: 1.08rem; line-height: 1.6; }
.eyebrow { margin: 0; color: var(--pink); font-size: .74rem; font-weight: 900; text-transform: uppercase; }

.auth-form, dialog form {
  display: grid;
  gap: 18px;
  padding: clamp(24px, 4vw, 42px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 22px 70px rgba(49, 18, 33, .14);
}

h2 { margin: 7px 0 0; font-size: clamp(1.55rem, 3vw, 2.15rem); }
label { display: grid; gap: 7px; color: #3b3036; font-size: .78rem; font-weight: 850; text-transform: uppercase; }
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: -6px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 800;
  text-transform: none;
}
.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--pink);
}
input, select, textarea {
  width: 100%;
  border: 1px solid #d9cbd2;
  border-radius: 4px;
  padding: 12px 13px;
  background: #fff;
  color: var(--ink);
  outline: none;
  text-transform: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--pink); box-shadow: 0 0 0 3px rgba(151, 7, 71, .1); }
textarea { resize: vertical; }

.button {
  min-height: 43px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 10px 17px;
  font-weight: 850;
  cursor: pointer;
}
.button:disabled { cursor: wait; opacity: .6; }
.button-primary { background: var(--pink); color: #fff; }
.button-primary:hover { background: var(--pink-dark); }
.button-secondary { border-color: var(--pink); background: #fff; color: var(--pink); }
.button-quiet { border-color: var(--line); background: #fff; color: var(--ink); }
.form-message { min-height: 20px; margin: 0; color: #a32323; font-size: .86rem; line-height: 1.4; }
.form-message.success { color: var(--success); }

.dashboard { padding: 48px clamp(18px, 5vw, 72px) 80px; }
.dashboard-title, .section-heading { display: flex; align-items: end; justify-content: space-between; gap: 22px; }
.dashboard-title h1 { max-width: 760px; margin-bottom: 0; font-size: clamp(2.5rem, 5vw, 4.6rem); }
.command-title {
  align-items: start;
  margin-bottom: 30px;
}
.dashboard-intro {
  max-width: 720px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.theme-desk {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, .8fr);
  gap: 18px;
  align-items: stretch;
  margin: 0 0 30px;
  padding: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.theme-desk h2 { margin: 5px 0 8px; }
.theme-desk p { margin: 0; color: var(--muted); line-height: 1.5; }

.theme-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.theme-buttons button {
  display: grid;
  gap: 5px;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.theme-buttons button.selected {
  border-color: var(--pink);
  background: var(--pink-soft);
  box-shadow: inset 0 0 0 1px rgba(151, 7, 71, .18);
}

.theme-buttons span { color: var(--muted); font-size: .78rem; line-height: 1.35; }
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 42px 0 64px;
  border-block: 1px solid var(--line);
}
.support-metrics { margin: 64px 0 0; }
.metrics div { display: grid; gap: 6px; padding: 24px clamp(12px, 3vw, 32px); border-right: 1px solid var(--line); }
.metrics div:last-child { border-right: 0; }
.metrics strong { color: var(--pink); font-size: clamp(2rem, 5vw, 3.5rem); }
.metrics span { color: var(--muted); font-size: .78rem; font-weight: 850; text-transform: uppercase; }

.operations-section {
  margin: 0 0 64px;
  padding-top: 4px;
}

.ops-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  background: #fff;
}

.ops-metrics div {
  display: grid;
  gap: 6px;
  min-height: 112px;
  padding: 22px;
  border-right: 1px solid var(--line);
}

.ops-metrics div:last-child { border-right: 0; }
.ops-metrics strong { color: var(--pink); font-size: clamp(1.8rem, 3.5vw, 2.8rem); }
.ops-metrics span { color: var(--muted); font-size: .72rem; font-weight: 900; text-transform: uppercase; }

.team-routing {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 18px 0;
  border: 1px solid var(--line);
  background: #fff;
}

.team-card {
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 116px;
  padding: 18px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  text-align: left;
}

button.team-card { cursor: pointer; }
button.team-card:hover, .team-card.selected { background: var(--pink-soft); }
.team-card.selected { box-shadow: inset 0 0 0 2px rgba(151, 7, 71, .24); }
.team-card:last-child { border-right: 0; }
.team-card strong { font-size: 1rem; }
.team-card span { color: var(--muted); font-size: .75rem; font-weight: 850; text-transform: uppercase; }
.team-card small { color: var(--pink); font-weight: 900; }
.team-card.owner-card { background: var(--pink-soft); }

.module-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.module-strip article {
  display: grid;
  gap: 10px;
  min-height: 104px;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.module-strip article > div {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

.module-strip strong { font-size: .98rem; }
.module-strip span {
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--pink-soft);
  color: var(--pink);
  font-size: .68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.module-strip p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.42; }

.agent-focus {
  margin: 18px 0;
  border: 1px solid var(--line);
  background: #fff;
}

.agent-focus-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.agent-focus-header h3 { margin: 5px 0 2px; font-size: clamp(1.35rem, 2.4vw, 1.85rem); }
.agent-focus-header small { color: var(--muted); font-weight: 750; }

.agent-focus-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.agent-focus-metrics div {
  display: grid;
  gap: 5px;
  padding: 18px 24px;
  border-right: 1px solid var(--line);
}

.agent-focus-metrics div:last-child { border-right: 0; }
.agent-focus-metrics strong { color: var(--pink); font-size: 1.7rem; }
.agent-focus-metrics span { color: var(--muted); font-size: .72rem; font-weight: 900; text-transform: uppercase; }

.agent-focus-list {
  display: grid;
  max-height: 430px;
  overflow: auto;
}

.agent-focus-item {
  display: grid;
  gap: 9px;
  padding: 18px 24px;
  border-bottom: 1px solid #eee6ea;
}

.agent-focus-item:last-child { border-bottom: 0; }
.agent-focus-item p { margin: 0; color: #473b41; line-height: 1.5; }
.agent-focus-item small { color: var(--muted); font-weight: 700; }
.route-note { margin: 8px 0 0; color: var(--muted); font-size: .86rem; line-height: 1.45; }

.workflow-note {
  margin-top: 18px;
  padding: 13px;
  border: 1px solid color-mix(in srgb, var(--pink) 20%, var(--line));
  border-radius: 6px;
  background: var(--pink-soft);
}

.workflow-note strong { display: block; margin-bottom: 5px; }
.workflow-note p { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.45; }

.ops-layout {
  display: grid;
  grid-template-columns: minmax(320px, .9fr) minmax(0, 1.35fr);
  gap: 18px;
}

.command-panel, .queue-panel {
  border: 1px solid var(--line);
  background: #fff;
}

.command-panel { padding: 24px; }
.panel-heading h3, .queue-heading h3 { margin: 5px 0 0; font-size: clamp(1.35rem, 2.4vw, 1.9rem); }
.command-panel form { display: grid; gap: 16px; margin-top: 20px; }
.compact-grid { gap: 12px; }

.queue-panel { min-width: 0; }
.queue-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 24px 18px;
  border-bottom: 1px solid var(--line);
}

.queue-controls { display: flex; gap: 8px; }
.queue-controls .selected { border-color: var(--pink); color: var(--pink); background: var(--pink-soft); }
.work-search { display: block; width: auto; margin: 18px 24px; }

.work-list {
  display: grid;
  max-height: 660px;
  overflow: auto;
  border-top: 1px solid #eee6ea;
}

.work-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, .42fr);
  gap: 18px;
  padding: 20px 24px;
  border-bottom: 1px solid #eee6ea;
}

.work-item h4 { margin: 9px 0 8px; font-size: 1.05rem; }
.work-item p { margin: 0; color: #473b41; line-height: 1.5; }
.work-meta, .work-proof {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 750;
}

.work-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fcfafb;
  color: #443840;
  font-size: .72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.work-pill.urgent { border-color: #f0c48d; background: #fff7eb; color: var(--warning); }
.work-pill.completed { border-color: #aad9c6; background: #effaf5; color: var(--success); }
.work-pill.needs_review { border-color: #f0c48d; background: #fff7eb; color: var(--warning); }
.work-pill.blocked { border-color: #e8b2b2; background: #fff2f2; color: var(--danger); }

.work-actions {
  display: grid;
  align-content: start;
  gap: 8px;
}

.work-actions .button { min-height: 36px; padding: 8px 11px; font-size: .78rem; }
.work-proof { display: grid; gap: 5px; }
.work-proof small { color: var(--muted); font-weight: 650; line-height: 1.45; }

.daily-board {
  margin-top: 34px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.daily-board-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

.daily-board-header h2 { margin: 5px 0 7px; }
.daily-board-header p { margin: 0; max-width: 760px; color: var(--muted); line-height: 1.5; }

.ops-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.ops-tabs button {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 900;
  text-transform: uppercase;
}

.ops-tabs button.selected {
  border-color: var(--pink);
  background: var(--pink-soft);
  color: var(--pink);
}

.ops-grid {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.ops-card {
  display: grid;
  grid-template-columns: minmax(220px, .78fr) minmax(180px, .55fr) minmax(260px, 1fr) minmax(250px, .8fr);
  gap: 13px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--pink);
  background: #fff;
}

.ops-card.urgent { border-left-color: var(--danger); }
.ops-missed_checkin { border-left-color: var(--warning); }
.ops-message { border-left-color: #315f78; }

.ops-card-head {
  display: grid;
  gap: 5px;
}

.ops-card-head strong { font-size: .98rem; }
.ops-card-head small { color: var(--muted); font-size: .78rem; line-height: 1.35; }
.ops-card h3 { margin: 0; font-size: 1rem; }
.ops-card > p, .agent-action p, .contact-actions p { margin: 0; color: #473b41; font-size: .84rem; line-height: 1.45; }

.ops-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.ops-meta span {
  min-height: 26px;
  padding: 5px 8px;
  border-radius: 7px;
  background: #fcfafb;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 850;
}

.ops-meta .urgent-meta { background: #fff2f2; color: var(--danger); }

.agent-action, .contact-actions {
  display: grid;
  gap: 7px;
  padding: 11px;
  border-radius: 6px;
  background: #fcfafb;
}

.agent-action span, .contact-actions span {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.contact-actions {
  border: 1px solid var(--line);
  background: #fff;
}

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

.contact-buttons button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: .74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.contact-buttons button:hover { border-color: var(--pink); color: var(--pink); background: var(--pink-soft); }

.improvement-band {
  display: grid;
  grid-template-columns: minmax(280px, .65fr) minmax(0, 1.35fr);
  gap: 18px;
  margin-top: 60px;
  padding: 24px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.improvement-band h2 { margin: 5px 0 7px; }
.improvement-band p { margin: 0; color: var(--muted); line-height: 1.5; }

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

.idea-grid span {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fcfafb;
  color: #473b41;
  font-size: .86rem;
  font-weight: 750;
  line-height: 1.35;
}

body.portal-theme-night .auth-form,
body.portal-theme-night dialog form,
body.portal-theme-night .portal-header,
body.portal-theme-night .theme-buttons button,
body.portal-theme-night .ops-metrics,
body.portal-theme-night .team-card,
body.portal-theme-night .agent-focus,
body.portal-theme-night .command-panel,
body.portal-theme-night .queue-panel,
body.portal-theme-night .work-pill,
body.portal-theme-night .ops-tabs button,
body.portal-theme-night .ops-card,
body.portal-theme-night .contact-actions,
body.portal-theme-night .contact-buttons button,
body.portal-theme-night .idea-grid span,
body.portal-theme-night .table-wrap,
body.portal-theme-night .agent-item,
body.portal-theme-night input,
body.portal-theme-night select,
body.portal-theme-night textarea {
  background: var(--surface);
  color: var(--ink);
}

body.portal-theme-night .ops-card > p,
body.portal-theme-night .agent-action p,
body.portal-theme-night .contact-actions p,
body.portal-theme-night .work-item p,
body.portal-theme-night .idea-grid span {
  color: var(--ink);
}

.owner-tools, .client-section { margin-top: 60px; }
.section-heading { margin-bottom: 22px; }
.section-heading h2 { margin-top: 6px; }
.client-tools {
  display: flex;
  align-items: end;
  gap: 12px;
}
.agent-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); border: 1px solid var(--line); }
.agent-item { display: grid; gap: 5px; min-height: 102px; padding: 20px; border: 0; border-right: 1px solid var(--line); background: #fff; text-align: left; cursor: pointer; }
.agent-item:hover { background: var(--pink-soft); }
.agent-item strong { font-size: 1.05rem; }
.agent-item span { color: var(--muted); font-size: .84rem; }

.search-field { width: min(310px, 100%); }
.search-field input { margin-top: 1px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 850px; }
th, td { padding: 16px 18px; border-bottom: 1px solid #eee6ea; text-align: left; vertical-align: top; }
th { color: var(--muted); background: #fcfafb; font-size: .72rem; text-transform: uppercase; }
td { font-size: .9rem; }
td strong { display: block; margin-bottom: 4px; }
td small { color: var(--muted); }
.progress-value { color: var(--pink); font-weight: 850; }
.empty-state { margin: 0; padding: 36px; color: var(--muted); text-align: center; }

dialog { width: min(680px, calc(100% - 28px)); max-height: calc(100vh - 36px); padding: 0; border: 0; border-radius: 8px; background: transparent; }
dialog::backdrop { background: rgba(25, 13, 19, .62); backdrop-filter: blur(4px); }
dialog form { max-height: calc(100vh - 36px); overflow-y: auto; }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; }
.close-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 4px; background: #fff; font-size: 1.5rem; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.full-field { grid-column: 1 / -1; }
.field-note { margin: -7px 0 0; color: var(--muted); font-size: .82rem; line-height: 1.4; }

[hidden] { display: none !important; }

@media (max-width: 760px) {
  .portal-header { min-height: 68px; padding: 9px 14px; }
  .portal-brand img { width: 62px; height: 40px; }
  .portal-user span { display: none; }
  .auth-view { min-height: calc(100vh - 68px); grid-template-columns: 1fr; gap: 26px; padding: 36px 18px; background-position: 60% center; }
  .auth-copy h1 { font-size: clamp(2.7rem, 14vw, 4rem); }
  .auth-form { padding: 24px 20px; }
  .dashboard { padding: 32px 16px 70px; }
  .dashboard-title, .section-heading { align-items: stretch; flex-direction: column; }
  .dashboard-title .button, .section-heading .button { width: 100%; }
  .metrics { margin: 32px 0 48px; }
  .metrics div { padding: 18px 10px; }
  .metrics strong { font-size: 2rem; }
  .metrics span { font-size: .62rem; }
  .ops-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ops-metrics div { min-height: 96px; padding: 16px; }
  .ops-metrics div:nth-child(2) { border-right: 0; }
  .theme-desk, .daily-board-header, .improvement-band { grid-template-columns: 1fr; }
  .theme-buttons { grid-template-columns: 1fr; }
  .module-strip { grid-template-columns: 1fr; }
  .ops-tabs { justify-content: flex-start; }
  .ops-card { grid-template-columns: 1fr; align-items: stretch; }
  .idea-grid { grid-template-columns: 1fr; }
  .team-routing { grid-template-columns: 1fr; }
  .team-card { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .team-card:last-child { border-bottom: 0; }
  .agent-focus-header { align-items: stretch; flex-direction: column; padding: 20px; }
  .agent-focus-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .agent-focus-metrics div:nth-child(2) { border-right: 0; }
  .agent-focus-item { padding: 18px 20px; }
  .ops-layout { grid-template-columns: 1fr; }
  .queue-heading { align-items: stretch; flex-direction: column; padding: 20px; }
  .queue-controls { width: 100%; }
  .queue-controls .button { flex: 1; }
  .work-search { margin: 16px 20px; }
  .work-item { grid-template-columns: 1fr; padding: 18px 20px; }
  .search-field { width: 100%; }
  .client-tools { align-items: stretch; flex-direction: column; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .full-field { grid-column: auto; }
}
