:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --border: #dfe4ec;
  --text: #1c2434;
  --muted: #64748b;
  --primary: #0a5cff;
  --primary-dark: #084ad0;
  --primary-soft: #e8f0ff;
  --success: #0f9d58;
  --success-soft: #e6f6ee;
  --warn: #b7791f;
  --warn-soft: #fdf3e0;
  --danger: #d3455b;
  --danger-soft: #fbe9ec;
  --info-soft: #eef2f8;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 30, 54, 0.08), 0 4px 16px rgba(16, 30, 54, 0.06);
  font-size: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
h1, h2, h3 { line-height: 1.25; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.loading-screen { padding: 4rem; text-align: center; color: var(--muted); }

/* ---------- layout ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.65rem 1.4rem;
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand .sub { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
@media (max-width: 560px) { .brand .sub { display: none; } }
.topbar .actions { display: flex; align-items: center; gap: 0.9rem; }
.container { max-width: 1080px; margin: 0 auto; padding: 1.6rem 1.4rem 5rem; }

/* ---------- cards & badges ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.2rem;
}
.card h2 { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.badge {
  display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; white-space: nowrap;
}
.badge.not_started { background: var(--info-soft); color: var(--muted); }
.badge.in_progress { background: var(--warn-soft); color: var(--warn); }
.badge.submitted { background: var(--primary-soft); color: var(--primary-dark); }
.badge.approved, .badge.complete { background: var(--success-soft); color: var(--success); }
.badge.changes_requested, .badge.blocked { background: var(--danger-soft); color: var(--danger); }
.badge.pending { background: var(--info-soft); color: var(--muted); }
.badge.active { background: var(--success-soft); color: var(--success); }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text);
  padding: 0.5rem 1rem; font-size: 0.92rem; font-weight: 600;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--info-soft); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.82rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.icon-btn { background: none; border: none; font-size: 1rem; cursor: pointer; color: var(--muted); }

label.field { display: block; margin-bottom: 0.9rem; }
label.field > .lbl { display: block; font-weight: 600; font-size: 0.86rem; margin-bottom: 0.25rem; }
.req { color: var(--danger); }
.upload-current {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 0.6rem; padding: 0.6rem 0.8rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
label.field .hint { display: block; color: var(--muted); font-size: 0.78rem; font-weight: 400; margin-top: 0.2rem; }
input[type="text"], input[type="email"], input[type="date"], input[type="password"], select, textarea {
  width: 100%; padding: 0.5rem 0.65rem;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 0.92rem; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 92, 255, 0.15);
}
textarea { min-height: 84px; resize: vertical; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 1.2rem; }
.form-grid .span-2 { grid-column: 1 / -1; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: 100%; max-width: 400px; }
.login-card .brand { justify-content: center; margin-bottom: 1rem; flex-direction: column; text-align: center; }
.login-card .login-logo { height: 36px; max-width: 100%; margin-bottom: 0.4rem; }

/* ---------- progress ---------- */
.progress-wrap { display: flex; align-items: center; gap: 1.4rem; flex-wrap: wrap; }
.progress-ring { position: relative; width: 110px; height: 110px; flex-shrink: 0; }
.progress-ring svg { transform: rotate(-90deg); }
.progress-ring .pct {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.35rem;
}
.progress-bar { height: 8px; border-radius: 999px; background: var(--info-soft); overflow: hidden; }
.progress-bar > div { height: 100%; border-radius: 999px; background: var(--primary); transition: width 0.3s; }

/* ---------- section list ---------- */
.section-card {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.95rem 1.1rem; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.1s;
}
.section-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.section-card .icon { font-size: 1.5rem; }
.section-card .title { font-weight: 700; }
.section-card .meta { margin-left: auto; text-align: right; }

/* ---------- stage timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 0.9rem; position: relative; padding-bottom: 1.1rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline .dot-col { display: flex; flex-direction: column; align-items: center; width: 26px; flex-shrink: 0; }
.timeline .dot {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border); background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; color: #fff; z-index: 1;
}
.timeline .line { flex: 1; width: 2px; background: var(--border); margin-top: 2px; }
.timeline li:last-child .line { display: none; }
.timeline li.complete .dot { background: var(--success); border-color: var(--success); }
.timeline li.in_progress .dot { background: var(--primary); border-color: var(--primary); box-shadow: 0 0 0 4px rgba(10,92,255,0.18); }
.timeline li.blocked .dot { background: var(--danger); border-color: var(--danger); }
.timeline .stage-name { font-weight: 700; }
.timeline .stage-desc { color: var(--muted); font-size: 0.83rem; }
.timeline .stage-meta { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }

/* ---------- wizard ---------- */
.wizard-head { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.wizard-head h1 { margin: 0; font-size: 1.45rem; }
.wizard-nav { display: flex; justify-content: space-between; gap: 0.8rem; margin-top: 1.4rem; flex-wrap: wrap; }
.instructions {
  background: var(--primary-soft); border: 1px solid #c6dbff;
  border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1.2rem;
}
.instructions ul { margin: 0.5rem 0 0; padding-left: 1.2rem; }
.instructions li { margin-bottom: 0.25rem; font-size: 0.88rem; }
.review-note {
  background: var(--danger-soft); border: 1px solid #f2c4cc;
  border-radius: var(--radius); padding: 0.8rem 1.1rem; margin-bottom: 1.2rem;
}

/* data tables */
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
table.data th {
  text-align: left; padding: 0.45rem 0.5rem; white-space: nowrap;
  border-bottom: 2px solid var(--border); font-size: 0.78rem;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.02em;
}
table.data td { padding: 0.3rem 0.35rem; border-bottom: 1px solid var(--border); vertical-align: top; min-width: 120px; }
table.data td input, table.data td select { min-width: 110px; }
table.data td.rm { min-width: 30px; width: 30px; }

/* row cards (sites, queues, ivrs) */
.row-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 0.9rem; overflow: hidden; }
.row-card > summary {
  list-style: none; cursor: pointer; padding: 0.8rem 1.1rem;
  display: flex; align-items: center; gap: 0.7rem;
  background: var(--info-soft); font-weight: 700;
}
.row-card > summary::-webkit-details-marker { display: none; }
.row-card > summary .chev { transition: transform 0.15s; color: var(--muted); }
.row-card[open] > summary .chev { transform: rotate(90deg); }
.row-card .body { padding: 1rem 1.1rem 0.4rem; }
.row-card .rm-row { text-align: right; padding: 0 1.1rem 0.8rem; }
.group-label { grid-column: 1 / -1; font-weight: 700; font-size: 0.82rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin: 0.6rem 0 0.4rem; border-top: 1px dashed var(--border); padding-top: 0.7rem; }

/* ---------- admin ---------- */
.client-row {
  display: grid; grid-template-columns: 1.6fr 1fr 1fr auto; gap: 0.8rem;
  align-items: center; padding: 0.85rem 1.1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); margin-bottom: 0.7rem; cursor: pointer;
  box-shadow: var(--shadow);
}
.client-row:hover { border-color: var(--primary); }
.client-row .company { font-weight: 700; }
@media (max-width: 720px) { .client-row { grid-template-columns: 1fr; } }

.tabs { display: flex; gap: 0.3rem; border-bottom: 1px solid var(--border); margin-bottom: 1.2rem; flex-wrap: wrap; }
.tabs button {
  background: none; border: none; padding: 0.55rem 0.95rem; cursor: pointer;
  font-size: 0.92rem; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 40, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal { background: var(--surface); border-radius: var(--radius); max-width: 480px; width: 100%; padding: 1.4rem 1.5rem; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-top: 0; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; }
.admin-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.8rem;
  padding: 0.6rem 0; border-bottom: 1px solid var(--border);
}
.admin-row:last-child { border-bottom: none; }
.admin-row .company { font-weight: 700; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 0.6rem 1.2rem;
  border-radius: 999px; font-size: 0.9rem; z-index: 200;
  opacity: 0; transition: opacity 0.25s; pointer-events: none; max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); }

/* ---------- copilot ---------- */
.copilot-fab {
  position: fixed; right: 1.4rem; bottom: 1.4rem; z-index: 90;
  width: 56px; height: 56px; border-radius: 50%;
  border: none; cursor: pointer; font-size: 1.5rem; color: #fff;
  background: linear-gradient(135deg, var(--primary), #6a3df5);
  box-shadow: 0 6px 20px rgba(10, 92, 255, 0.4);
}
.copilot-panel {
  position: fixed; right: 1.4rem; bottom: 1.4rem; z-index: 95;
  width: 370px; max-width: calc(100vw - 2rem); height: 520px; max-height: calc(100vh - 3rem);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: 0 12px 40px rgba(16, 30, 54, 0.25);
  display: flex; flex-direction: column; overflow: hidden;
}
.copilot-header {
  padding: 0.85rem 1.1rem; display: flex; justify-content: space-between; align-items: flex-start;
  background: linear-gradient(135deg, var(--primary), #6a3df5); color: #fff;
}
.copilot-header .copilot-sub { font-size: 0.75rem; opacity: 0.85; }
.copilot-header .icon-btn { color: #fff; }
.copilot-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.copilot-msg { max-width: 88%; padding: 0.55rem 0.85rem; border-radius: 14px; font-size: 0.88rem; white-space: pre-wrap; }
.copilot-msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.copilot-msg.assistant { align-self: flex-start; background: var(--info-soft); border-bottom-left-radius: 4px; }
.copilot-msg.typing { color: var(--muted); font-style: italic; }
.copilot-input { display: flex; gap: 0.5rem; padding: 0.7rem; border-top: 1px solid var(--border); }
.copilot-input input { flex: 1; }

/* ---------- admin client view (impersonation) ---------- */
.impersonation-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.6rem 1.4rem; font-size: 0.86rem;
  background: var(--warn-soft); color: #7c5510; border-bottom: 2px solid #e6c98a;
  position: sticky; top: 0; z-index: 90;
}
.impersonation-bar .btn { background: #fff; border-color: #d9b36a; white-space: nowrap; }
.client-row-actions { display: flex; align-items: center; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; }

/* Deep link to an external tool from a timeline stage (e.g. number porting) */
.stage-link {
  font-size: 0.78rem; font-weight: 600; text-decoration: none; white-space: nowrap;
  color: var(--primary); background: var(--primary-soft);
  border: 1px solid #c6dbff; border-radius: 999px; padding: 0.1rem 0.55rem;
}
.stage-link:hover { background: #d9e7ff; }

/* ---------- bulk spreadsheet upload ---------- */
.bulk-panel {
  display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--info-soft); border: 1px dashed var(--border);
  border-radius: var(--radius); padding: 0.9rem 1.1rem; margin-bottom: 1rem;
}
.bulk-panel .bulk-copy { flex: 1; min-width: 260px; }
.bulk-panel .bulk-copy p { margin: 0.25rem 0 0; }
.bulk-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.bulk-result {
  border-radius: var(--radius); padding: 0.8rem 1.1rem; margin-bottom: 1rem; font-size: 0.88rem;
}
.bulk-result.ok { background: var(--success-soft); border: 1px solid #b7e3cb; color: #0b6b3d; }
.bulk-result.error { background: var(--danger-soft); border: 1px solid #f2c4cc; color: #96233a; }
.bulk-problems { margin: 0.5rem 0 0; padding-left: 1.1rem; max-height: 240px; overflow-y: auto; }
.bulk-problems li { margin-bottom: 0.15rem; }

/* ---------- settings ---------- */
.toggle-row {
  display: flex; gap: 0.7rem; align-items: flex-start; cursor: pointer;
  padding: 0.55rem 0; border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row input[type="checkbox"] { width: 17px; height: 17px; margin-top: 0.15rem; flex: none; accent-color: var(--primary); }
.toggle-row .toggle-label { display: block; font-weight: 600; font-size: 0.9rem; }
.toggle-row .muted { display: block; }
.toggle-master { border-bottom: none; padding: 0; }
table.settings-table th {
  text-transform: none; letter-spacing: 0; font-size: 0.82rem;
  width: 190px; vertical-align: top; padding: 0.5rem 0.8rem 0.5rem 0;
}
table.settings-table td { min-width: 0; padding: 0.5rem 0; }
.setup-steps { margin: 0; padding-left: 1.2rem; font-size: 0.88rem; line-height: 1.65; }
.setup-steps li { margin-bottom: 0.5rem; }
.setup-steps code, .settings-table code {
  background: var(--info-soft); border-radius: 5px; padding: 0.05rem 0.35rem; font-size: 0.85em;
}

/* ---------- audit log ---------- */
.audit-filters {
  display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end;
}
.audit-filter-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
table.audit-table td { min-width: 0; font-size: 0.83rem; }
table.audit-table td.nowrap, .audit-pager .nowrap { white-space: nowrap; }
table.audit-table .audit-action { font-weight: 600; }
table.audit-table .audit-detail { min-width: 220px; }
table.audit-table tr.audit-warning td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.audit-table tr.audit-error td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
table.audit-table tr.audit-error { background: var(--danger-soft); }
.audit-pager {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.8rem; flex-wrap: wrap; margin-top: 0.9rem;
}
