:root {
  --ink: #142033;
  --muted: #64748b;
  --surface: #ffffff;
  --surface-soft: #f6f8fb;
  --soft: #eaf3f7;
  --brand: #10446f;
  --brand-bright: #1977a3;
  --teal: #0f8a92;
  --accent: #d6a33e;
  --accent-soft: #fff4d8;
  --line: #dbe4ea;
  --good: #168052;
  --bad: #b3404a;
  --sidebar-bg: #0d2338;
  --sidebar-ink: #dce8f2;
  --shadow: 0 12px 28px rgba(20, 32, 51, 0.10);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--surface-soft);
}

a { color: var(--brand-bright); }

.form-control {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--surface);
  color: var(--ink);
}

.primary-action {
  display: inline-block;
  padding: 10px 18px;
  border: none;
  border-radius: 8px;
  background: var(--brand-bright);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.primary-action:hover { background: var(--brand); }

.ghost-action {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

.danger-action {
  background: var(--bad);
  color: #fff;
  border: none;
}

.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.notice-error { background: #fff1f2; color: var(--bad); border: 1px solid #efcaca; }
.notice-success { background: #eefbf4; color: var(--good); border: 1px solid #bbebd2; }

/* Login */
.admin-login-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0b2f55 0%, #14618d 56%, #0f8a92 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 18px; }
.login-mark { font-size: 36px; }
.login-brand h1 { margin: 6px 0 0; font-size: 1.3rem; color: var(--brand); }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: .85rem; letter-spacing: .04em; text-transform: uppercase; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; color: var(--muted); font-weight: 600; }
.login-card .primary-action { margin-top: 4px; }
.login-footer { margin-top: 16px; color: rgba(255,255,255,.75); font-size: .8rem; }

/* Shell layout */
.admin-shell {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  margin-bottom: 14px;
}
.admin-brand-mark { font-size: 26px; }
.admin-brand strong { display: block; font-size: .95rem; }
.admin-brand span { display: block; font-size: .72rem; color: #9fb7ca; letter-spacing: .05em; text-transform: uppercase; }

.admin-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.admin-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-ink);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
}
.admin-nav-link:hover { background: rgba(255,255,255,.08); }
.admin-nav-link.is-active { background: var(--brand-bright); color: #fff; font-weight: 700; }

.admin-sidebar-footer { border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; margin-top: 12px; }
.admin-user-pill { font-size: .82rem; color: #cfe1ee; padding: 4px 8px; margin-bottom: 6px; word-break: break-word; }
.admin-logout-link { display: flex; align-items: center; gap: 8px; padding: 8px; color: #f3d9db; text-decoration: none; font-size: .85rem; }
.admin-logout-link:hover { color: #fff; }

.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.admin-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.admin-topbar h1 { margin: 0; font-size: 1.2rem; flex: 1; }
.admin-nav-toggle { display: none; border: none; background: none; font-size: 20px; cursor: pointer; }
.admin-back-link { font-size: .82rem; color: var(--muted); }

.admin-content { padding: 22px 24px 40px; flex: 1; }

.admin-footer { padding: 14px 24px; font-size: .78rem; color: var(--muted); border-top: 1px solid var(--line); }

/* Cards & metrics */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.metric-card .metric-value { font-size: 1.6rem; font-weight: 700; color: var(--brand); }
.metric-card .metric-label { font-size: .8rem; color: var(--muted); margin-top: 2px; }

.admin-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.admin-panel-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.admin-panel-title h2 { margin: 0; font-size: 1.02rem; }

.admin-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .admin-grid-2 { grid-template-columns: 1fr; } }

.admin-subnav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0;
}
.admin-subnav-link {
  display: inline-block;
  padding: 9px 14px;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 600;
  border: 1px solid transparent;
  margin-bottom: -1px;
}
.admin-subnav-link:hover { color: var(--brand); }
.admin-subnav-link.is-active {
  color: var(--brand);
  background: var(--surface);
  border-color: var(--line);
  border-bottom-color: var(--surface);
}

/* Tables */
.admin-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.admin-table th, .admin-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin-table th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; background: var(--soft); color: var(--brand); border: 1px solid var(--line); }
.badge-good { background: #eefbf4; color: var(--good); border-color: #bbebd2; }
.badge-bad { background: #fff1f2; color: var(--bad); border-color: #efcaca; }
.badge-warn { background: var(--accent-soft); color: #8b6914; border-color: #ead393; }
.badge-muted { background: var(--soft); color: var(--muted); border-color: var(--line); }

.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: flex-end; }
.filter-bar label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; color: var(--muted); font-weight: 600; }
.filter-bar .form-control { min-width: 160px; }

.empty-state { padding: 24px; text-align: center; color: var(--muted); font-size: .9rem; }

.inline-form { display: inline; }

.icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: .82rem;
}
.icon-button:hover { background: var(--soft); }

.icon-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px;
  text-decoration: none; font-size: 1rem; line-height: 1; cursor: pointer;
  /* Reset so a <button class="icon-link"> (delete/duplicate actions) matches
     the plain <a class="icon-link"> ones (edit/impersonate/unsubscribe). */
  border: none; background: none; padding: 0; font-family: inherit; color: inherit;
}
.icon-link:hover { background: var(--soft); }

.pagination { display: flex; gap: 6px; margin-top: 14px; align-items: center; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.pagination .page-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 30px; height: 30px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface); color: var(--brand); font-size: .82rem; font-weight: 600;
  text-decoration: none;
}
.pagination .page-link:hover { background: var(--soft); }
.pagination .page-link.is-active { background: var(--brand-bright); border-color: var(--brand-bright); color: #fff; cursor: default; }
.pagination .page-ellipsis { padding: 0 4px; color: var(--muted); }
.pagination .page-summary { margin-right: 6px; }
.pagination .page-link.is-disabled { opacity: .45; cursor: default; pointer-events: none; }

.log-results-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; font-size: .85rem; color: var(--muted); }
.log-results-bar .pagination { margin-top: 0; }
.log-results-bar-bottom { justify-content: center; margin-top: 14px; margin-bottom: 0; }
.log-time { white-space: nowrap; }

.log-detail { white-space: pre-wrap; font-family: "Cascadia Code", Consolas, monospace; font-size: .78rem; color: var(--muted); max-width: 480px; }
.log-mono { font-family: "Cascadia Code", Consolas, monospace; font-size: .78rem; color: var(--muted); white-space: nowrap; }

.thread-message { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.thread-message.is-admin { background: var(--accent-soft); border-color: #ead393; }
.thread-message header { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.thread-message p { margin: 0; white-space: pre-wrap; }

/* Ticket detail (Message / Response / History), modeled on ExpSplits' support popup */
.ticket-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.ticket-detail-header h2 { margin: 0; font-size: 1.15rem; }
.ticket-detail-header .form-control { min-width: 130px; padding: 6px 9px; font-size: .82rem; }

.ticket-meta-list { list-style: none; margin: 0 0 14px; padding: 0; font-size: .85rem; }
.ticket-meta-list li { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.ticket-meta-list li:last-child { border-bottom: none; }
.ticket-meta-list .meta-label { width: 76px; flex: 0 0 76px; color: var(--muted); font-weight: 700; text-transform: uppercase; font-size: .72rem; letter-spacing: .03em; padding-top: 2px; }

.ticket-message-frame {
  width: 100%;
  height: 300px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.ticket-message-text {
  width: 100%;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
  white-space: pre-wrap;
  font-size: .88rem;
}

.ai-badge-row { display: flex; align-items: center; gap: 10px; }
.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--brand);
  font-size: .75rem;
  font-weight: 700;
}
.ai-generate-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--brand-bright);
  color: var(--brand-bright);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
}
.ai-generate-link:hover { background: var(--soft); }

.ticket-action-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 18px;
  margin-top: 4px;
  box-shadow: var(--shadow);
}
.ticket-action-bar .action-bar-right { display: flex; gap: 10px; }

.notes-scroll { max-height: 320px; overflow-y: auto; padding-right: 4px; }
.notes-scroll .thread-message:last-child { margin-bottom: 0; }

@media (max-width: 860px) {
  .admin-sidebar {
    position: fixed;
    z-index: 20;
    left: -240px;
    transition: left .18s ease;
    box-shadow: var(--shadow);
  }
  .admin-shell.nav-open .admin-sidebar { left: 0; }
  .admin-nav-toggle { display: inline-block; }
  .admin-content { padding: 16px; }
  .admin-topbar { padding: 12px 16px; }
}

/* Embedded (modal iframe) rendering of a page - no sidebar/topbar/footer */
.admin-embedded { background: var(--surface-soft); }
.admin-content-embedded { padding: 16px 18px 24px; }

/* Support ticket modal (support.cfm), modeled on ExpSplits' support popup */
.cch-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.cch-modal[hidden] { display: none; }
.cch-modal-backdrop { position: absolute; inset: 0; background: rgba(16, 24, 38, .55); }
.cch-modal-dialog {
  position: relative;
  width: min(1320px, 97vw);
  height: min(calc(100vh - 40px), 960px);
  background: var(--surface-soft);
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cch-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.cch-modal-header h2 { margin: 0; font-size: 1rem; }
.cch-modal-close { border: none; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.cch-modal-close:hover { color: var(--ink); }
.cch-modal-frame { flex: 1; width: 100%; border: 0; background: var(--surface-soft); }
body.cch-modal-open { overflow: hidden; }
@media (max-width: 900px) { .cch-modal-dialog { width: 100vw; height: 100vh; border-radius: 0; } }

.admin-table tr.is-current-ticket td { background: var(--accent-soft); }

.admin-table td.num, .admin-table th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.admin-table tfoot th { border-top: 2px solid var(--line); font-size: .8rem; color: var(--muted); padding-top: 8px; }

.ticket-header-field { display: flex; align-items: center; gap: 6px; margin: 0; }
.ticket-field-label { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }

/* Onboarding: category delivery bars (onboard.cfm dashboard) */
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-label { width: 150px; flex-shrink: 0; font-size: .82rem; color: var(--ink); }
.bar-track { flex: 1; height: 18px; background: var(--soft); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.bar-fill { height: 100%; background: var(--brand-bright); display: flex; align-items: center; justify-content: flex-end; color: #fff; font-size: .68rem; font-weight: 700; padding-right: 6px; white-space: nowrap; min-width: 28px; }

/* Onboarding: message library drag-to-reorder + hover preview (onboard-messages.cfm) */
.onboard-drag-handle { cursor: grab; color: var(--muted); user-select: none; font-size: 1.05rem; display: inline-block; padding: 2px 6px; }
.onboard-drag-handle:active { cursor: grabbing; }
.onboard-message-row.dragging { opacity: .4; }
.onboard-message-row.drag-over { box-shadow: inset 0 3px 0 var(--brand-bright); }
.msg-preview-trigger { cursor: help; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.onboard-hover-preview {
  position: fixed; z-index: 1100; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(620px, calc(100vw - 32px)); height: min(720px, calc(100vh - 32px));
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 16px 48px rgba(20, 32, 51, .28); overflow: hidden; display: none;
}
.onboard-hover-preview .preview-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; background: var(--surface-soft); border-bottom: 1px solid var(--line);
  font-size: .82rem; font-weight: 700; color: var(--ink);
}
.onboard-hover-preview .preview-sub { font-weight: 400; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.onboard-hover-preview iframe { width: 100%; height: calc(100% - 42px); border: 0; background: var(--surface-soft); }

/* Onboarding: per-user tracking progress bar (onboard-tracking.cfm) */
.tracking-progress { display: flex; align-items: center; gap: 8px; }
.tracking-progress .bar-track { max-width: 90px; height: 6px; }
.tracking-progress .bar-fill { font-size: 0; }
