:root {
  color-scheme: light;
  --bg: #f6f5ef;
  --surface: #fffefa;
  --surface-raised: #fbfaf5;
  --text: #14272d;
  --muted: #627176;
  --accent: #0b514a;
  --accent-strong: #073d38;
  --accent-soft: rgb(11 81 74 / 9%);
  --line: rgb(20 39 45 / 14%);
  --line-light: rgb(20 39 45 / 8%);
  --danger: #9f2f2f;
  --danger-soft: rgb(159 47 47 / 8%);
  --warning: #885b08;
  --warning-soft: rgb(136 91 8 / 10%);
  --success: #116149;
  --success-soft: rgb(17 97 73 / 9%);
  --shadow: 0 8px 24px rgb(20 39 45 / 7%);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1214;
  --surface: #111a1d;
  --surface-raised: #172226;
  --text: #f2f4f1;
  --muted: #a5b0ae;
  --accent: #68cfb2;
  --accent-strong: #8cddc6;
  --accent-soft: rgb(104 207 178 / 11%);
  --line: rgb(242 244 241 / 14%);
  --line-light: rgb(242 244 241 / 8%);
  --danger: #ff9696;
  --danger-soft: rgb(255 150 150 / 10%);
  --warning: #e6bd68;
  --warning-soft: rgb(230 189 104 / 11%);
  --success: #75d7b4;
  --success-soft: rgb(117 215 180 / 10%);
  --shadow: 0 8px 24px rgb(0 0 0 / 24%);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button,
a,
input,
select,
textarea {
  outline-offset: 3px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 0 20px 48px;
}

.app-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-title {
  font-size: 18px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.brand-subtitle,
.caller-name {
  color: var(--muted);
  font-size: 13px;
}

.header-actions,
.call-actions,
.outcome-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.header-signout {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.header-signout:hover {
  background: var(--surface);
  color: var(--text);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

[data-theme="light"] .sun-icon,
[data-theme="dark"] .moon-icon {
  display: none;
}

.simulation-banner {
  margin: 16px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--warning);
  background: var(--warning-soft);
  color: var(--text);
  font-size: 13px;
}

.outcome-reminder {
  width: 100%;
  margin: 0 0 16px;
  padding: 11px 14px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  border: 1px solid color-mix(in srgb, var(--danger) 32%, transparent);
  border-left: 4px solid var(--danger);
  background: var(--danger-soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.outcome-reminder[hidden] {
  display: none;
}

.outcome-reminder strong {
  color: var(--danger);
  white-space: nowrap;
}

.outcome-reminder span {
  color: var(--muted);
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(116px, 1fr));
  border: 1px solid var(--line);
  background: var(--surface);
  margin-bottom: 16px;
  overflow-x: auto;
}

.summary-item {
  min-height: 70px;
  padding: 12px 16px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.summary-item:last-child {
  border-right: 0;
}

.summary-item:hover,
.summary-item.active {
  background: var(--accent-soft);
}

.summary-item.active {
  box-shadow: inset 0 -3px 0 var(--accent);
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 2px;
  white-space: nowrap;
}

.summary-item strong {
  font-size: 21px;
}

.summary-item[data-tone="accent"] strong {
  color: var(--accent-strong);
}

.summary-item[data-tone="warning"] strong {
  color: var(--warning);
}

.summary-item[data-tone="success"] strong {
  color: var(--success);
}

.summary-item[data-tone="danger"] strong {
  color: var(--danger);
}

.work-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(0, 1.65fr);
  gap: 16px;
  align-items: start;
}

.queue-panel,
.workspace-panel {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface);
}

.queue-panel {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.queue-heading,
.lead-heading,
.section-heading,
.call-bar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.queue-heading {
  padding: 18px 18px 12px;
}

.eyebrow,
.field-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: 20px;
  letter-spacing: -0.02em;
}

h2 {
  margin: 3px 0 4px;
  font-size: clamp(22px, 3vw, 30px);
  letter-spacing: -0.025em;
  line-height: 1.15;
}

h3 {
  margin: 3px 0 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.queue-count,
.status-badge,
.miko-note,
.required-call {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.search-field {
  position: relative;
  display: block;
  margin: 0;
}

.search-field svg {
  position: absolute;
  top: 13px;
  left: 12px;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
}

.search-field input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px 8px 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.queue-tools {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
}

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

.queue-control {
  min-width: 0;
}

.queue-control span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.queue-control select {
  min-width: 0;
  padding-inline: 9px 30px;
  background-color: var(--bg);
}

.sort-control {
  grid-column: 1 / -1;
}

.queue-filter-summary {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.queue-filter-summary[hidden] {
  display: none;
}

.queue-filter-summary button {
  min-width: 44px;
  min-height: 44px;
  margin-block: -8px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 700;
  cursor: pointer;
}

.queue-list {
  overflow: auto;
  border-top: 1px solid var(--line);
}

.queue-lead {
  width: 100%;
  min-height: 92px;
  padding: 14px 16px;
  display: block;
  border: 0;
  border-bottom: 1px solid var(--line-light);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.queue-lead:hover,
.queue-lead.active {
  background: var(--accent-soft);
}

.queue-lead.active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.queue-lead.outcome-needed,
.queue-lead.outcome-needed:hover,
.queue-lead.outcome-needed.active {
  background: var(--danger-soft);
  box-shadow: inset 3px 0 0 var(--danger);
}

.queue-lead-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 3px;
}

.queue-status,
.status-badge {
  border-color: transparent;
  font-weight: 700;
}

.queue-status {
  flex: 0 0 auto;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  white-space: nowrap;
}

.queue-status[data-tone="accent"],
.status-badge[data-tone="accent"] {
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.queue-status[data-tone="warning"],
.status-badge[data-tone="warning"] {
  border-color: color-mix(in srgb, var(--warning) 28%, transparent);
  background: var(--warning-soft);
  color: var(--warning);
}

.queue-status[data-tone="success"],
.status-badge[data-tone="success"] {
  border-color: color-mix(in srgb, var(--success) 28%, transparent);
  background: var(--success-soft);
  color: var(--success);
}

.queue-status[data-tone="danger"],
.status-badge[data-tone="danger"] {
  border-color: color-mix(in srgb, var(--danger) 28%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

.queue-status[data-tone="neutral"],
.status-badge[data-tone="neutral"] {
  border-color: var(--line);
  background: var(--surface-raised);
  color: var(--muted);
}

.queue-lead strong {
  line-height: 1.3;
}

.queue-lead small,
.queue-lead-meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.queue-lead-meta {
  margin-top: 8px;
}

.queue-lead-bottom {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  justify-content: space-between;
  margin-top: 8px;
}

.queue-lead-bottom .queue-lead-meta {
  margin-top: 0;
}

.queue-ranking {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.01em;
}

.queue-empty {
  padding: 26px 18px;
  color: var(--muted);
}

.workspace-panel {
  min-height: 660px;
}

.empty-state {
  max-width: 500px;
  padding: clamp(40px, 8vw, 100px) clamp(22px, 6vw, 72px);
}

.empty-state p,
.reward-panel > p {
  color: var(--muted);
  max-width: 60ch;
}

.lead-workspace > section,
.lead-heading,
.reward-panel {
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.lead-heading p {
  margin-bottom: 0;
  color: var(--muted);
}

.call-blocked-notice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--danger-soft);
  border-left: 4px solid var(--danger);
}

.call-blocked-notice[hidden] {
  display: none;
}

.call-blocked-notice strong {
  font-weight: 700;
  color: var(--danger);
}

.call-blocked-notice span {
  color: var(--muted);
  font-size: 13px;
}

.call-bar {
  align-items: center;
}

.copy-value {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
}

.copy-hint {
  margin-left: 7px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.call-timer {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 700;
}

.button {
  min-height: 44px;
  padding: 9px 15px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 650;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button-primary {
  background: var(--accent);
  color: var(--surface);
}

[data-theme="dark"] .button-primary {
  color: var(--bg);
}

.button-secondary {
  border-color: var(--line);
  background: transparent;
  color: var(--text);
}

.button-danger {
  border-color: var(--danger);
  background: transparent;
  color: var(--danger);
}

.opportunity-section p {
  margin: 6px 0 0;
  font-size: 17px;
}

.section-heading {
  align-items: center;
  margin-bottom: 16px;
}

.section-heading.compact {
  margin-bottom: 10px;
}

.script-tabs {
  display: flex;
  gap: 6px;
  padding-bottom: 4px;
  overflow-x: auto;
}

.script-tab {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
}

.script-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.script-content {
  margin-top: 12px;
  padding: 18px;
  border-left: 3px solid var(--accent);
  background: var(--surface-raised);
  font-size: 17px;
}

.script-content p:last-child,
.script-content ol:last-child {
  margin-bottom: 0;
}

.script-content ol {
  padding-left: 20px;
}

.script-content li + li {
  margin-top: 8px;
}

.diary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 2px 0 4px;
  text-decoration: none;
}

.booking-reference-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin: 10px 0 14px;
}

.booking-reference-row code {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  overflow-wrap: anywhere;
  font: inherit;
}

.booking-reference-row .button {
  flex: 0 0 auto;
}

.outcome-section.disabled {
  opacity: 0.74;
}

.followup-section { padding: 24px 0; border-top: 1px solid var(--line); }
.followup-section [hidden] { display: none; }
.followup-section summary { min-height: 44px; padding: 10px 0; cursor: pointer; font-weight: 650; }
.followup-notice { color: var(--muted); font-size: 13px; margin: 10px 0; overflow-wrap: anywhere; }
.permission-fields { margin: 8px 0 20px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.permission-fields legend { padding: 0 6px; font-size: 14px; font-weight: 650; }
.confirmation-label { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.confirmation-label input { width: 22px; min-height: 22px; height: 22px; flex: 0 0 22px; accent-color: var(--accent); }
.confirmation-label > span { margin: 0; font-weight: 400; }
.message-history-heading { margin: 26px 0 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; }
.message-history-item { border-top: 1px solid var(--line-light); padding: 4px 0; overflow-wrap: anywhere; }
.message-history-item summary { font-size: 14px; }
.message-history-item pre, #messagePreviewBody { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; }
.message-history-item pre { font-size: 14px; }
.message-history-reply { border-left: 3px solid var(--accent); padding-left: 14px; }
#messagePreviewDialog { width: min(620px, calc(100% - 24px)); max-height: calc(100dvh - 32px); padding: 24px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 10px; overflow: auto; }
#messagePreviewDialog::backdrop { background: rgb(0 0 0 / 55%); }
#messagePreviewDialog h2 { font-size: 22px; }
#messagePreviewAddresses { margin: 20px 0; overflow-wrap: anywhere; }
#messagePreviewAddresses dt { color: var(--muted); font-size: 13px; }
#messagePreviewAddresses dd { margin: 0 0 10px; }
.message-preview-notice { padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-raised); font-size: 14px; }
.message-preview-notice[data-state="error"] { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); font-weight: 700; }
.message-preview-notice[data-state="unknown"] { color: var(--warning); border-color: var(--warning); background: var(--warning-soft); font-weight: 700; }
.message-preview-notice[data-state="pending"] { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.message-preview-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.message-preview-actions .button { flex: 1 1 150px; }

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

form label {
  display: block;
  margin-bottom: 12px;
}

form label > span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 650;
}

select,
input,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

textarea {
  resize: vertical;
}

.history-list,
.reward-list {
  display: grid;
  gap: 8px;
}

.history-item,
.reward-item {
  padding: 12px 0;
  border-top: 1px solid var(--line-light);
}

.history-item:first-child,
.reward-item:first-child {
  border-top: 0;
}

.history-top,
.reward-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.history-item p,
.reward-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.reward-amount {
  color: var(--accent);
  font-size: 18px;
  font-weight: 750;
}

.reward-panel {
  border-bottom: 0;
}

.toast {
  position: fixed;
  z-index: 20;
  right: 20px;
  bottom: 20px;
  max-width: min(360px, calc(100vw - 40px));
  padding: 11px 14px;
  border: 1px solid var(--line);
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(460px, 100%);
}

.login-card {
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 34px;
}

.login-card h1 {
  margin: 6px 0 10px;
  font-size: clamp(26px, 6vw, 34px);
  line-height: 1.12;
  letter-spacing: -0.035em;
}

.login-intro,
.login-footnote {
  color: var(--muted);
}

.login-card form {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.login-card label {
  display: grid;
  gap: 7px;
  font-weight: 650;
}

.login-card input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--text);
}

.login-card .button {
  min-height: 48px;
}

.login-message {
  margin-top: 18px;
  padding: 10px 12px;
  border-left: 3px solid var(--success);
  background: var(--success-soft);
}

.login-message.error {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}

.login-footnote {
  margin: 24px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line-light);
  font-size: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .app-shell {
    padding-inline: 14px;
  }

  .work-layout {
    grid-template-columns: 1fr;
  }

  .queue-panel {
    position: static;
    max-height: 420px;
  }

  .workspace-panel {
    min-height: 500px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding-inline: 10px;
  }

  .app-header {
    min-height: 64px;
  }

  .brand-subtitle,
  .caller-name {
    display: none;
  }

  .summary-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-inline: -10px;
    border-left: 0;
    border-right: 0;
    overflow: visible;
  }

  .summary-item {
    min-width: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary-item:nth-child(even) {
    border-right: 0;
  }

  .outcome-reminder {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .lead-workspace > section,
  .lead-heading,
  .reward-panel {
    padding: 18px 16px;
  }

  .lead-heading,
  .call-bar,
  .section-heading,
  .call-blocked-notice {
    align-items: flex-start;
    flex-direction: column;
  }

  .call-bar > div:first-child {
    min-width: 0;
    width: 100%;
  }

  .copy-value {
    max-width: 100%;
    overflow-wrap: anywhere;
    text-align: left;
  }

  .call-actions,
  .outcome-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .call-actions .button,
  .outcome-actions .button {
    flex: 1 1 150px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .script-tabs {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .script-tab {
    flex: 1 1 calc(50% - 6px);
  }

  .miko-note {
    white-space: normal;
  }
}

@media (max-width: 420px) {
  .queue-control-grid {
    grid-template-columns: 1fr;
  }

  .sort-control {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

.business-number-control {
  display: grid;
  gap: 8px;
  min-width: min(100%, 360px);
}

.business-number-control select,
.add-phone-form input {
  width: 100%;
  min-height: 44px;
}

.phone-status {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.phone-status[data-tone="success"] { color: var(--accent); }
.phone-status[data-tone="warning"] { color: var(--warning); }

.add-phone-details summary,
#callKeypad summary {
  min-height: 44px;
  padding: 10px 0;
  cursor: pointer;
}

.add-phone-form {
  display: grid;
  gap: 12px;
  max-width: 520px;
  padding: 10px 0 4px;
}

.add-phone-form label {
  display: grid;
  gap: 6px;
}
.dtmf-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(48px, 1fr));
  gap: 8px;
  max-width: 260px;
  margin-top: 12px;
}
#savedOutcomeNotice { margin-bottom: 16px; }
