:root {
  --bg: #f3f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #6d7688;
  --line: #dfe5ee;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #f59e0b;
  --ok: #16a34a;
  --warn: #facc15;
  --bad: #dc2626;
  --info: #38bdf8;
  --radius: 8px;
  --shadow: 0 16px 38px rgba(15, 23, 42, 0.09);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #eef6fb 0, var(--bg) 280px);
  color: var(--ink);
}

a { color: inherit; text-decoration: none; }
input, select, textarea, button { font: inherit; }

.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; transition: grid-template-columns .2s ease; }
.sidebar-collapsed .layout { grid-template-columns: 86px 1fr; }
.sidebar-backdrop { display: none; }
.sidebar {
  background: linear-gradient(180deg, #0b1f2a 0%, #10202c 100%);
  color: #edf6f9;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-x: hidden;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 28px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--brand);
  font-weight: 800;
}
.brand strong { display: block; font-size: 17px; }
.brand span { color: #aebecd; font-size: 12px; }
.sidebar-collapsed .brand { justify-content: center; }
.sidebar-collapsed .brand-text { display: none; }
.nav { display: grid; gap: 6px; }
.nav a {
  color: #dce7ef;
  padding: 11px 12px;
  border-radius: var(--radius);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav a.active, .nav a:hover { background: rgba(255,255,255,.11); }
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}
.nav-count {
  color: #b6c7d7;
  font-weight: 800;
}
.sidebar-collapsed .nav a {
  text-align: center;
  padding-left: 4px;
  padding-right: 4px;
  font-size: 0;
}
.sidebar-collapsed .nav a::first-letter { font-size: 16px; }
.main { padding: 28px; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}
.topbar-title {
  display: flex;
  align-items: center;
  gap: 14px;
}
.live-clock {
  font-variant-numeric: tabular-nums;
}
.sidebar-toggle {
  display: inline-grid;
  place-items: center;
  width: 58px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .06);
  font-weight: 900;
  font-size: 12px;
}
.topbar h1 { margin: 0; font-size: 26px; letter-spacing: 0; }
.topbar p { margin: 5px 0 0; color: var(--muted); }
.user-chip { display: flex; gap: 10px; align-items: center; }
.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: #d1fae5;
  color: #065f46;
  border-radius: 50%;
  font-weight: 800;
}
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-6 { grid-column: span 6; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.dashboard-hero {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  padding: 22px;
  border: 1px solid #bde8e1;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #0f766e 0%, #14532d 100%);
  color: #fff;
  box-shadow: var(--shadow);
}
.dashboard-hero span {
  color: #bff7ea;
  font-weight: 800;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: .08em;
}
.dashboard-hero h2 { margin: 6px 0; font-size: 28px; }
.dashboard-hero p { margin: 0; color: #d9fff7; }
.hero-stat {
  min-width: 150px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: var(--radius);
  background: rgba(255,255,255,.12);
}
.hero-stat small { color: #d9fff7; }
.hero-stat strong { display: block; font-size: 34px; }
.metric {
  position: relative;
  overflow: hidden;
  min-height: 112px;
}
.metric::after {
  content: "";
  position: absolute;
  right: -28px;
  top: -28px;
  width: 92px;
  height: 92px;
  border-radius: 999px;
  background: rgba(255,255,255,.55);
}
.metric strong { display: block; font-size: 34px; margin-top: 8px; position: relative; z-index: 1; }
.metric span { position: relative; z-index: 1; font-weight: 800; }
.metric span, .card small { color: var(--muted); }
.metric-accepted {
  background: #dcfce7;
  border-color: #86efac;
}
.metric-accepted span, .metric-accepted strong { color: #166534; }
.metric-rejected {
  background: #fee2e2;
  border-color: #fca5a5;
}
.metric-rejected span, .metric-rejected strong { color: #991b1b; }
.metric-inprocess {
  background: #fef9c3;
  border-color: #fde047;
}
.metric-inprocess span, .metric-inprocess strong { color: #854d0e; }
.metric-pending {
  background: #e0f2fe;
  border-color: #7dd3fc;
}
.metric-pending span, .metric-pending strong { color: #075985; }
.metric-submitted {
  background: #fff;
  border-color: #dfe5ee;
}
.metric-submitted span, .metric-submitted strong { color: #334155; }
.dashboard-stat-group .toolbar {
  margin-bottom: 12px;
}
.dashboard-metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.dashboard-metric-grid .metric {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}
.btn.secondary { background: #e8eef5; color: var(--ink); }
.btn.danger { background: var(--bad); }
.btn.small { padding: 7px 10px; font-size: 13px; }
.icon-btn {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #eef6ff;
  color: #075985;
  cursor: pointer;
  padding: 7px 10px;
  font-weight: 800;
}
.user-search {
  justify-content: flex-start;
}
.user-search input {
  max-width: 460px;
}
.sales-filter {
  align-items: end;
  justify-content: flex-start;
  flex-wrap: wrap;
}
.cell-accepted {
  background: #dcfce7;
  color: #166534;
  font-weight: 900;
}
.cell-rejected {
  background: #fee2e2;
  color: #991b1b;
  font-weight: 900;
}
.cell-inprocess {
  background: #fef9c3;
  color: #854d0e;
  font-weight: 900;
}
.pagination {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.pagination a {
  display: inline-flex;
  min-width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font-weight: 800;
}
.pagination a.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
th[data-sortable] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th[data-sortable]::after {
  content: "↕";
  display: inline-block;
  margin-left: 6px;
  color: #9aa6b7;
  font-size: 11px;
}
th[data-sort-direction="asc"]::after {
  content: "↑";
  color: var(--brand);
}
th[data-sort-direction="desc"]::after {
  content: "↓";
  color: var(--brand);
}
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 14px; }
.field { grid-column: span 6; display: grid; gap: 6px; }
.field.full { grid-column: span 12; }
label { color: #39465a; font-weight: 700; font-size: 13px; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
}
.toggle-row strong,
.toggle-row small {
  display: block;
}
.toggle-row small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 500;
}
.toggle-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.toggle-switch {
  position: relative;
  flex: 0 0 auto;
  width: 58px;
  height: 32px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background .18s ease;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .25);
  transition: transform .18s ease;
}
.toggle-row input:checked + .toggle-switch {
  background: var(--brand);
}
.toggle-row input:checked + .toggle-switch::after {
  transform: translateX(26px);
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}
textarea { min-height: 92px; resize: vertical; }
.rich-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  background: #f8fafc;
}
.rich-toolbar select {
  width: auto;
  min-width: 110px;
  padding: 6px 8px;
}
.rich-editor {
  min-height: 140px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  background: #fff;
  outline: 0;
  overflow-wrap: anywhere;
}
.rich-editor:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}
.announcement-body,
.announcement-preview {
  overflow-wrap: anywhere;
}
.announcement-body p,
.announcement-preview p {
  margin: 6px 0;
}
.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}
.input-action .btn {
  white-space: nowrap;
}
.duplicate-result {
  min-height: 18px;
  color: var(--muted);
  font-weight: 800;
}
.duplicate-result.success {
  color: #166534;
}
.duplicate-result.error {
  color: #991b1b;
}
.duplicate-details {
  margin: 8px 0 0;
  padding-left: 18px;
}
.duplicate-details small {
  display: block;
  color: var(--muted);
}
.status {
  display: inline-flex;
  min-width: 110px;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 800;
  font-size: 12px;
}
.password-hidden {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 9px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.accepted { background: #dcfce7; color: #166534; }
.pending { background: #e0f2fe; color: #075985; }
.inprocess { background: #fef9c3; color: #854d0e; }
.rejected { background: #fee2e2; color: #991b1b; }
.submitted { background: #fff; color: #334155; }
.flash {
  padding: 12px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: #fff;
}
.flash.error { border-color: #fecaca; background: #fff1f2; color: #9f1239; }
.flash.success { border-color: #bbf7d0; background: #f0fdf4; color: #166534; }
.lookup-result {
  border-width: 2px;
}
.lookup-result p {
  margin: 6px 0 0;
}
.lookup-result.duplicate {
  background: #fff7ed;
  border-color: #fb923c;
}
.lookup-result.unique {
  background: #f0fdf4;
  border-color: #22c55e;
}
.lookup-result.error {
  background: #fff1f2;
  border-color: #f87171;
}
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, .92), rgba(23, 32, 51, .94)),
    radial-gradient(circle at top left, #fbbf24, transparent 30%);
}
.login-card {
  width: min(440px, 100%);
  background: #fff;
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 24px 70px rgba(0,0,0,.2);
}
.login-card h1 { margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 18px; }
.announcement {
  border-left: 4px solid var(--accent);
  background: #fffbeb;
}
.did-list { display: grid; gap: 10px; }
.did-picker {
  display: grid;
  gap: 6px;
}
.did-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fbfdff;
}
.did-item header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.did-action-form {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(260px, 1fr);
  gap: 14px;
  align-items: end;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.did-action-form .field {
  grid-column: auto;
}
.did-action-form .field.full {
  grid-column: 1 / -1;
}
.did-action-form .btn {
  width: 100%;
}
.message-popup {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(360px, calc(100vw - 40px));
  background: #10202c;
  color: #fff;
  border-radius: var(--radius);
  box-shadow: 0 18px 44px rgba(0,0,0,.22);
  padding: 16px;
  z-index: 50;
}
.message-popup p { margin: 6px 0 12px; color: #dce7ef; }
#chat-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: flex;
  flex-direction: row-reverse;
  gap: 12px;
  align-items: flex-end;
  pointer-events: none;
}
.chat-box {
  width: min(340px, calc(100vw - 36px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(15, 23, 42, .22);
  overflow: hidden;
  pointer-events: auto;
}
.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #10202c;
  color: #fff;
}
.chat-head button {
  border: 0;
  background: rgba(255,255,255,.14);
  color: #fff;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  cursor: pointer;
}
.chat-messages {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
  padding: 12px;
  background: #f6f8fb;
}
.chat-message {
  max-width: 82%;
  padding: 8px 10px;
  border-radius: var(--radius);
}
.chat-message p { margin: 0; }
.chat-message small { display: block; margin-top: 4px; font-size: 10px; }
.chat-message.mine {
  justify-self: end;
  background: #0f766e;
  color: #fff;
}
.chat-message.mine small { color: #c7fff5; }
.chat-message.theirs {
  justify-self: start;
  background: #fff;
  border: 1px solid var(--line);
}
.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
  background: #fff;
  border-top: 1px solid var(--line);
}
.messages-layout .card {
  min-height: 520px;
}
.conversation-list {
  display: grid;
  gap: 8px;
}
.conversation-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.conversation-item.active,
.conversation-item:hover {
  border-color: #99f6e4;
  background: #ecfeff;
}
.conversation-item strong,
.conversation-item small {
  display: block;
}
.conversation-item small,
.muted-line {
  color: var(--muted);
}
.message-history {
  display: grid;
  gap: 10px;
  max-height: 430px;
  overflow: auto;
  padding: 14px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
}
.history-message {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.history-message p {
  margin: 5px 0;
  overflow-wrap: anywhere;
}
.history-message small {
  color: var(--muted);
}
.history-message.mine {
  justify-self: end;
  background: #0f766e;
  border-color: #0f766e;
  color: #fff;
}
.history-message.mine small {
  color: #c7fff5;
}
.history-message.theirs {
  justify-self: start;
  background: #fff;
}
.message-compose {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.copy-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
}
.leave-call-form {
  margin-top: 14px;
}
.copy-list.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.copy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.copy-row div { min-width: 0; }
.copy-row small {
  display: block;
  color: var(--muted);
  margin-bottom: 3px;
}
.copy-row strong {
  display: block;
  overflow-wrap: anywhere;
  line-height: 1.25;
}
.copy-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #e8eef5;
  color: var(--ink);
  cursor: pointer;
  padding: 6px 9px;
  font-weight: 800;
  font-size: 12px;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, .48);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgba(0,0,0,.24);
  padding: 18px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.modal-head h3 { margin: 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar-collapsed .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 70;
    width: min(310px, 86vw);
    height: 100vh;
    transform: translateX(-105%);
    transition: transform .22s ease;
    overflow-y: auto;
    box-shadow: 18px 0 45px rgba(15, 23, 42, .28);
  }
  .mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    background: rgba(15, 23, 42, .48);
  }
  .mobile-sidebar-open .sidebar-backdrop {
    display: block;
  }
  .sidebar-collapsed .brand-text { display: block; }
  .sidebar-collapsed .nav a { font-size: inherit; text-align: left; padding: 11px 12px; }
  .sidebar-collapsed .nav a::first-letter { font-size: inherit; }
  .main { padding: 18px; }
  .span-3, .span-4, .span-6, .span-8 { grid-column: span 12; }
  .field { grid-column: span 12; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .copy-list.compact { grid-template-columns: 1fr; }
  .did-action-form { grid-template-columns: 1fr; }
  .dashboard-hero { align-items: flex-start; flex-direction: column; }
}
