/* ==========================================================================
   CaseReview.Health admin — shared stylesheet (login + admin panel)
   ========================================================================== */

:root {
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --green-50: #f0fdf4;
  --green-600: #16a34a;
  --green-700: #15803d;
  --amber-50: #fffbeb;
  --amber-600: #d97706;
  --amber-700: #b45309;
  --red-50: #fef2f2;
  --red-100: #fee2e2;
  --red-600: #dc2626;
  --red-700: #b91c1c;

  --bg: #f6f8fb;
  --surface: #ffffff;
  --border: var(--slate-200);
  --text: var(--slate-800);
  --muted: var(--slate-500);
  --primary: var(--blue-600);
  --primary-hover: var(--blue-700);
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.25);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.25);
  --sidebar-w: 250px;
  --topbar-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--slate-900); }
p { margin: 0; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.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;
}

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
mark { background: #fef08a; color: inherit; padding: 0 1px; border-radius: 2px; }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 8px 14px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--slate-700);
  font-weight: 600; font-size: 13.5px; line-height: 1.2; white-space: nowrap;
  cursor: pointer; text-decoration: none; user-select: none;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { border-color: var(--slate-300); }
.btn-secondary:hover:not(:disabled) { background: var(--slate-50); border-color: var(--slate-400); }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--slate-100); }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--red-700); }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 12.5px; }
.btn-icon { width: 34px; min-height: 34px; padding: 0; color: var(--slate-500); background: transparent; }
.btn-icon:hover:not(:disabled) { background: var(--slate-100); color: var(--slate-800); }
.btn-icon.danger:hover:not(:disabled) { background: var(--red-50); color: var(--red-600); }
.btn-block { width: 100%; }
.btn .fa-spinner { animation: spin .8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-weight: 600; font-size: 13px; color: var(--slate-700); }
.field .req { color: var(--red-600); margin-left: 2px; }
.field .hint { font-size: 12px; color: var(--muted); }
.field .error-text { font-size: 12px; color: var(--red-600); font-weight: 500; }

.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--slate-300); border-radius: var(--radius-sm);
  background: #fff; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.select { appearance: auto; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--blue-500); box-shadow: var(--focus); }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea, .field.has-error .picker { border-color: var(--red-600); }
.input[readonly] { background: var(--slate-50); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { margin-top: 22px; }
.form-section:first-child { margin-top: 0; }
.form-section-title {
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--slate-500); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.form-alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; margin-bottom: 16px; border-radius: var(--radius-sm);
  background: var(--red-50); color: var(--red-700); border: 1px solid var(--red-100); font-weight: 500;
}

/* Link picker (multi-select with search) */
.picker { border: 1px solid var(--slate-300); border-radius: var(--radius-sm); background: #fff; }
.picker:focus-within { border-color: var(--blue-500); box-shadow: var(--focus); }
.picker-selected { display: flex; flex-direction: column; max-height: 260px; overflow-y: auto; }
.picker-selected:empty { display: none; }
.picker-item {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 12px;
  border-bottom: 1px solid var(--slate-100);
}
.picker-item .pi-text { flex: 1; min-width: 0; }
.picker-item .pi-name { overflow: hidden; text-overflow: ellipsis; }
.picker-item .pi-group { font-size: 11.5px; color: var(--muted); }
.picker-strength { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.picker-strength input { width: 64px; min-height: 30px; padding: 4px 6px; text-align: right; }
.picker-search { position: relative; }
.picker-search .input { border: 0; border-radius: var(--radius-sm); min-height: 40px; box-shadow: none !important; padding-left: 34px; }
.picker-search > .fa-magnifying-glass { position: absolute; left: 12px; top: 13px; color: var(--slate-400); font-size: 13px; }
.picker-menu {
  position: absolute; left: -1px; right: -1px; top: calc(100% + 4px); z-index: 30;
  max-height: 260px; overflow-y: auto; background: #fff;
  border: 1px solid var(--slate-300); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.picker-option { display: flex; gap: 10px; padding: 8px 12px; cursor: pointer; align-items: baseline; }
.picker-option:hover, .picker-option.active { background: var(--blue-50); }
.picker-option .pi-group { margin-left: auto; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.picker-empty { padding: 10px 12px; color: var(--muted); }
.picker-footer { display: flex; justify-content: space-between; padding: 6px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--slate-100); }
.picker-footer button { background: none; border: 0; color: var(--primary); cursor: pointer; font-weight: 600; font-size: 12px; padding: 0; }

/* --------------------------------------------------------------------------
   Badges, chips
   -------------------------------------------------------------------------- */
.code {
  display: inline-block; padding: 1px 7px; border-radius: 5px;
  background: var(--slate-100); color: var(--slate-700);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.code.missing { background: var(--amber-50); color: var(--amber-700); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--blue-50); color: var(--blue-700); border: 1px solid var(--blue-100);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.gray { background: var(--slate-100); color: var(--slate-600); border-color: var(--slate-200); }
.chip.more { background: transparent; border-style: dashed; color: var(--slate-500); border-color: var(--slate-300); }
.count-pill {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--slate-100); color: var(--slate-600); font-size: 11.5px; font-weight: 700;
}
.status { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pending_review { background: #fef3c7; color: #92400e; }
.status-contacted { background: #dbeafe; color: #1e40af; }
.status-scheduled { background: #e0e7ff; color: #4338ca; }
.status-completed { background: #dcfce7; color: #166534; }
.status-cancelled { background: #fee2e2; color: #991b1b; }
.status-select { border: 0; border-radius: 999px; padding: 4px 26px 4px 10px; font-size: 12px; font-weight: 600; cursor: pointer; min-height: 28px; }
.pain { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 24px; border-radius: 6px; font-weight: 700; font-size: 12.5px; }
.pain-low { background: var(--green-50); color: var(--green-700); }
.pain-mid { background: var(--amber-50); color: var(--amber-700); }
.pain-high { background: var(--red-50); color: var(--red-700); }

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--slate-900); color: var(--slate-300);
  display: flex; flex-direction: column; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; height: var(--topbar-h); padding: 0 20px; color: #fff; font-weight: 700; font-size: 16px; flex-shrink: 0; }
.brand i { color: #60a5fa; font-size: 18px; }
.nav { padding: 8px 12px 24px; flex: 1; }
.nav-group { margin-top: 18px; }
.nav-label { padding: 0 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--slate-500); }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; margin: 2px 0;
  border-radius: 8px; color: var(--slate-300); text-decoration: none; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link i { width: 18px; text-align: center; color: var(--slate-400); }
.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link.active i { color: #fff; }
.nav-link .count { margin-left: auto; font-size: 11.5px; font-weight: 600; color: var(--slate-400); }
.nav-link.active .count { color: #dbeafe; }
.nav-link .count.alert { background: #f59e0b; color: #111827; padding: 0 7px; border-radius: 999px; }
.sidebar-footer { padding: 14px 20px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 12px; color: var(--slate-500); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar .menu-btn { display: none; }
.topbar-title { font-weight: 700; font-size: 16px; color: var(--slate-900); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--slate-600); font-weight: 500; min-width: 0; }
.user-chip .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--blue-100); color: var(--blue-700); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.user-chip .email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

.page { padding: 24px; width: 100%; max-width: 1600px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p { color: var(--muted); margin-top: 4px; max-width: 70ch; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-body { padding: 20px; }

.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 45; }

.boot { display: grid; place-items: center; min-height: 60vh; color: var(--muted); gap: 12px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--slate-200); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }

/* --------------------------------------------------------------------------
   Data table
   -------------------------------------------------------------------------- */
.dt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.dt-search { position: relative; flex: 1 1 280px; max-width: 420px; }
.dt-search .input { padding-left: 36px; padding-right: 34px; }
.dt-search > .fa-magnifying-glass { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--slate-400); pointer-events: none; }
.dt-search .clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
/* Hide the browser's built-in clear button; the table has its own. */
.dt-search input[type="search"]::-webkit-search-cancel-button,
.dt-search input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.dt-search input[type="search"]::-ms-clear { display: none; width: 0; height: 0; }
.dt-filter { flex: 0 1 200px; min-width: 150px; }
.dt-filter .select { min-height: 40px; }
.dt-count { color: var(--muted); font-size: 13px; margin-left: auto; white-space: nowrap; }
.dt-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 16px 0; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--slate-300); background: #fff; font-size: 12.5px; font-weight: 600; color: var(--slate-600); cursor: pointer;
}
.filter-chip .n { color: var(--slate-400); font-weight: 600; }
.filter-chip.active { background: var(--slate-900); border-color: var(--slate-900); color: #fff; }
.filter-chip.active .n { color: var(--slate-300); }

.dt-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.dt { width: 100%; border-collapse: separate; border-spacing: 0; }
.dt th {
  position: sticky; top: 0; z-index: 1;
  padding: 10px 14px; background: var(--slate-50); border-bottom: 1px solid var(--border);
  text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--slate-500);
  white-space: nowrap;
}
.dt th.sortable { cursor: pointer; user-select: none; }
.dt th.sortable:hover { color: var(--slate-800); }
.dt th .sort-icon { margin-left: 6px; font-size: 10px; opacity: .35; }
.dt th.sorted .sort-icon { opacity: 1; color: var(--primary); }
.dt td { padding: 12px 14px; border-bottom: 1px solid var(--slate-100); vertical-align: top; }
.dt tbody tr:last-child td { border-bottom: 0; }
.dt tbody tr { transition: background .1s; }
.dt tbody tr:hover { background: #fafcff; }
.dt tbody tr.clickable { cursor: pointer; }
.dt td.actions { width: 1%; white-space: nowrap; text-align: right; padding-top: 7px; padding-bottom: 7px; }
.dt td.actions .btn-icon { vertical-align: middle; }
.dt .cell-title { font-weight: 600; color: var(--slate-900); }
.dt .cell-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.dt .clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; min-width: 220px; max-width: 420px; color: var(--slate-600); }
.dt .clamp-2 { -webkit-line-clamp: 2; }
.dt .col-code { width: 1%; white-space: nowrap; }
.dt .col-num { text-align: center; }
.dt .skeleton-row td { padding: 16px 14px; }
.skeleton { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--slate-100), var(--slate-200), var(--slate-100)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.dt-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.dt-pagesize { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dt-pagesize .select { width: auto; min-height: 34px; padding: 4px 8px; }
.pager { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pager button {
  min-width: 34px; height: 34px; padding: 0 8px; border: 1px solid var(--slate-200); border-radius: var(--radius-sm);
  background: #fff; color: var(--slate-600); font-weight: 600; font-size: 13px; cursor: pointer;
}
.pager button:hover:not(:disabled) { border-color: var(--slate-400); }
.pager button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager button:disabled { opacity: .45; cursor: not-allowed; }
.pager .gap { padding: 0 4px; color: var(--slate-400); }

.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 48px 20px; color: var(--muted); }
.state i { font-size: 28px; color: var(--slate-300); }
.state.error i { color: var(--red-600); }
.state strong { color: var(--slate-800); font-size: 15px; }

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; background: rgba(15, 23, 42, .5); overflow-y: auto; animation: fade .15s ease-out;
}
.modal {
  width: 100%; max-width: 640px; margin: auto 0; display: flex; flex-direction: column; max-height: 90vh;
  background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); animation: pop .15s ease-out;
}
.modal.lg { max-width: 920px; }
.modal.sm { max-width: 440px; }
.modal-header { display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--slate-50); border-radius: 0 0 14px 14px; }
.modal-footer .left { margin-right: auto; }
.footer-status { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
body.modal-open { overflow: hidden; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

/* Detail view */
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 24px; margin: 0; }
.detail-grid .span-2 { grid-column: 1 / -1; }
.detail-item dt { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--slate-500); margin-bottom: 4px; }
.detail-item dd { margin: 0; color: var(--slate-800); white-space: pre-wrap; word-break: break-word; }
.detail-section { margin-top: 22px; }
.detail-section h3 { font-size: 13px; font-weight: 700; color: var(--slate-900); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.link-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.link-list > div { display: flex; gap: 10px; align-items: baseline; padding: 8px 12px; border-bottom: 1px solid var(--slate-100); }
.link-list > div:last-child { border-bottom: 0; }
.link-list .grow { flex: 1; min-width: 0; }
.callout { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--blue-50); border: 1px solid var(--blue-100); }
.callout.warn { background: var(--amber-50); border-color: #fde68a; }

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: flex-start; gap: 10px; min-width: 260px; max-width: 420px; padding: 12px 14px;
  background: var(--slate-900); color: #fff; border-radius: 10px; box-shadow: var(--shadow-lg); animation: pop .15s ease-out;
}
.toast i { margin-top: 2px; }
.toast.success i { color: #4ade80; }
.toast.error { background: #7f1d1d; }
.toast.error i { color: #fecaca; }
.toast .msg { flex: 1; word-break: break-word; }
.toast button { background: none; border: 0; color: #cbd5e1; cursor: pointer; padding: 0 2px; }

/* --------------------------------------------------------------------------
   Import page
   -------------------------------------------------------------------------- */
.steps { display: grid; gap: 16px; }
.step-card .card-body { display: grid; gap: 14px; }
.step-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: var(--slate-900); }
.step-num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--blue-100); color: var(--blue-700); font-size: 13px; font-weight: 700; flex-shrink: 0; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 26px 16px; text-align: center;
  border: 2px dashed var(--slate-300); border-radius: var(--radius); background: var(--slate-50); cursor: pointer; transition: all .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--blue-500); background: var(--blue-50); }
.dropzone i { font-size: 28px; color: var(--green-600); }
.dropzone .file-name { font-weight: 600; color: var(--slate-900); word-break: break-all; }
.or-divider { display: flex; align-items: center; gap: 12px; color: var(--slate-400); font-size: 12px; font-weight: 700; letter-spacing: .06em; }
.or-divider::before, .or-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.mode-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mode-option { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 14px; border: 1px solid var(--slate-300); border-radius: var(--radius); cursor: pointer; background: #fff; }
.mode-option input { position: absolute; opacity: 0; pointer-events: none; }
.mode-option .mode-title { font-weight: 700; color: var(--slate-900); display: flex; gap: 8px; align-items: center; }
.mode-option .mode-desc { font-size: 12.5px; color: var(--muted); }
.mode-option:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); background: var(--blue-50); }
.mode-option:has(input:focus-visible) { box-shadow: var(--focus); }
.mode-option.danger:has(input:checked) { border-color: var(--red-600); box-shadow: 0 0 0 1px var(--red-600); background: var(--red-50); }
.badge-rec { font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--green-50); color: var(--green-700); text-transform: uppercase; letter-spacing: .04em; }
.import-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.result-banner { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius); border: 1px solid; }
.result-banner i { font-size: 20px; margin-top: 1px; }
.result-banner.success { background: var(--green-50); border-color: #bbf7d0; color: #14532d; }
.result-banner.warning { background: var(--amber-50); border-color: #fde68a; color: #78350f; }
.result-banner.error { background: var(--red-50); border-color: #fecaca; color: #7f1d1d; }
.result-banner.info { background: var(--blue-50); border-color: var(--blue-100); color: #1e3a8a; }
.summary-table { width: 100%; border-collapse: collapse; }
.summary-table th, .summary-table td { padding: 9px 12px; border-bottom: 1px solid var(--slate-100); text-align: right; white-space: nowrap; }
.summary-table th:first-child, .summary-table td:first-child { text-align: left; }
.summary-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--slate-500); background: var(--slate-50); }
.summary-table .zero { color: var(--slate-300); }
.n-created { color: var(--green-700); font-weight: 700; }
.n-updated { color: var(--blue-700); font-weight: 700; }
.n-deleted { color: var(--red-700); font-weight: 700; }
.n-skipped { color: var(--amber-700); font-weight: 700; }
details.sheet-details { border: 1px solid var(--border); border-radius: var(--radius-sm); }
details.sheet-details + details.sheet-details { margin-top: 8px; }
details.sheet-details summary { padding: 10px 14px; cursor: pointer; font-weight: 600; display: flex; gap: 10px; align-items: center; }
details.sheet-details[open] summary { border-bottom: 1px solid var(--border); }
.issue-list, .change-list { list-style: none; margin: 0; padding: 0; }
.issue-list li, .change-list li { padding: 8px 14px; border-bottom: 1px solid var(--slate-100); display: flex; gap: 10px; align-items: baseline; }
.issue-list li:last-child, .change-list li:last-child { border-bottom: 0; }
.issue-list .lvl-error { color: var(--red-600); }
.issue-list .lvl-warning { color: var(--amber-600); }
.change-fields { margin: 4px 0 0; padding-left: 0; list-style: none; font-size: 12.5px; color: var(--slate-600); }
.change-fields .old { text-decoration: line-through; color: var(--slate-400); }
.act { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 1px 6px; border-radius: 4px; flex-shrink: 0; }
.act-create { background: var(--green-50); color: var(--green-700); }
.act-update { background: var(--blue-50); color: var(--blue-700); }
.act-delete { background: var(--red-50); color: var(--red-700); }

/* --------------------------------------------------------------------------
   Login
   -------------------------------------------------------------------------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 20% 10%, #dbeafe 0, transparent 40%), radial-gradient(circle at 90% 90%, #e0e7ff 0, transparent 40%), var(--bg); }
.login-card { width: 100%; max-width: 400px; padding: 32px; }
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; color: var(--slate-900); margin-bottom: 24px; }
.login-brand i { color: var(--primary); }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card form { display: grid; gap: 16px; margin-top: 22px; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 44px; }
.pw-wrap .btn-icon { position: absolute; right: 3px; top: 3px; }
.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-weight: 500; font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.alert.error { background: var(--red-50); color: var(--red-700); border: 1px solid var(--red-100); }
.alert.info { background: var(--blue-50); color: #1e3a8a; border: 1px solid var(--blue-100); }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 280px; max-width: 85vw; transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .topbar .menu-btn { display: inline-flex; }
  .mode-options { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  body { font-size: 14px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .user-chip .email { display: none; }
  .page { padding: 16px 12px; }
  .page-header h1 { font-size: 19px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .form-grid, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .dt-toolbar { padding: 12px; }
  .dt-search { flex-basis: 100%; max-width: none; }
  .dt-filter { flex: 1 1 140px; }
  .dt-count { margin-left: 0; width: 100%; }

  /* Tables become stacked cards */
  .dt thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .dt, .dt tbody, .dt tr, .dt td { display: block; width: 100%; }
  .dt tbody tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .dt tbody tr:last-child { border-bottom: 0; }
  .dt td { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px; padding: 5px 0; border: 0; text-align: left; justify-items: start; }
  .dt td::before { content: attr(data-label); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--slate-400); padding-top: 2px; }
  .dt td[data-label=""]::before { display: none; }
  .dt td[data-label=""] { grid-template-columns: minmax(0, 1fr); }
  .dt td.actions { width: 100%; text-align: left; display: flex; gap: 4px; justify-content: flex-end; padding-top: 6px; }
  .dt td.actions::before { display: none; }
  .dt .clamp { max-width: none; min-width: 0; }
  .dt .skeleton-row td { grid-template-columns: minmax(0, 1fr); }

  .dt-footer { justify-content: center; }
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal, .modal.lg, .modal.sm { max-width: none; max-height: none; min-height: 100%; border-radius: 0; margin: 0; }
  .modal-body { flex: 1; }
  .modal-footer { border-radius: 0; position: sticky; bottom: 0; flex-wrap: wrap; }
  .modal-footer .footer-status { order: -1; flex: 1 1 100%; justify-content: space-between; }
  .modal-footer .btn { flex: 1; }
  .modal-footer .left { flex: 0 0 auto; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: none; }
  .login-card { padding: 24px 20px; }
}

/* Column chooser */
.col-chooser { position: relative; }
.col-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px; padding: 6px;
  background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.col-menu-title { padding: 6px 8px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--slate-500); }
.col-menu-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-weight: 500; }
.col-menu-item:hover { background: var(--slate-50); }
.col-menu-item input { width: 16px; height: 16px; accent-color: var(--primary); }
@media (max-width: 720px) { .hide-sm { display: none; } .col-menu { right: auto; left: 0; } }

/* --------------------------------------------------------------------------
   Detail dialogs (view record) — same look as the pages: brand header,
   light-gray canvas and white cards with icon headers.
   -------------------------------------------------------------------------- */
.modal.detail { background: var(--bg); overflow: hidden; }
.modal.detail .modal-header { align-items: flex-start; padding: 18px 22px; border-bottom: 0; color: #fff; background: #111827; }
.modal.detail .modal-header h2 { color: #fff; }
.modal.detail .modal-header > .btn-icon { color: #d1d5db; margin: -4px -6px 0 0; }
.modal.detail .modal-header > .btn-icon:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.hero-title { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.hero-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hero-line .code { background: rgba(255, 255, 255, .16); color: #fff; border: 1px solid rgba(255, 255, 255, .22); }
.hero-name { font-size: 19px; font-weight: 700; line-height: 1.25; }
.hero-sub { font-size: 13px; font-weight: 500; color: #9ca3af; }
.modal.detail .modal-body { background: var(--bg); padding: 18px 22px 22px; }
.modal.detail .modal-footer { background: #fff; }

.detail-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat-tile { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.stat-tile .ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; font-size: 15px; }
.stat-tile .n { font-size: 20px; font-weight: 800; color: var(--slate-900); line-height: 1.1; }
.stat-tile .l { font-size: 11px; font-weight: 700; letter-spacing: .04em; white-space: nowrap; text-transform: uppercase; color: var(--muted); margin-top: 2px; }
.tone-blue .ic { background: var(--blue-50); color: var(--blue-600); }
.tone-indigo .ic { background: #eef2ff; color: #4f46e5; }
.tone-amber .ic { background: var(--amber-50); color: var(--amber-600); }
.tone-green .ic { background: var(--green-50); color: var(--green-600); }
.tone-rose .ic { background: #fff1f2; color: #e11d48; }

.detail-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.detail-card + .detail-card, .detail-stats + .detail-card, .detail-card + .detail-cols, .detail-cols + .detail-card { margin-top: 14px; }
.detail-card-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--slate-100); background: linear-gradient(#fff, #fbfcfe); }
.detail-card-header h3 { font-size: 14px; font-weight: 700; color: var(--slate-900); margin: 0; }
.detail-card-header .ic { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--blue-50); color: var(--blue-600); font-size: 13px; flex-shrink: 0; }
.detail-card-header .count-pill { margin-left: auto; background: var(--blue-50); color: var(--blue-700); }
.detail-card-body { padding: 16px; }
.detail-card.flush .detail-card-body { padding: 0; }
.detail-card .detail-grid { gap: 10px; }
.detail-card .detail-item { padding: 10px 12px; background: var(--slate-50); border: 1px solid var(--slate-100); border-radius: 8px; min-width: 0; }
.detail-card .detail-item dt { margin-bottom: 3px; }
.detail-card .detail-item dd { font-weight: 500; color: var(--slate-900); }
.detail-card .detail-item dd.muted { color: var(--slate-400); font-weight: 400; }
.value-link { display: inline-flex; align-items: center; gap: 7px; color: var(--blue-700); font-weight: 600; text-decoration: none; word-break: break-all; }
.value-link i { font-size: 12px; color: var(--blue-500); }
.value-link:hover { text-decoration: underline; }
.empty-note {
  display: flex; align-items: center; justify-content: center; gap: 8px; margin: 12px 16px; padding: 12px;
  border: 1px dashed var(--slate-300); border-radius: 8px; background: var(--slate-50); color: var(--slate-500); font-size: 13px;
}
.empty-note i { color: var(--slate-400); }
.not-provided { font-style: italic; }
.detail-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.detail-cols .detail-card + .detail-card { margin-top: 0; }

.detail-card .link-list { border: 0; border-radius: 0; }
.detail-card .link-list > div { padding: 10px 16px; transition: background .1s; }
.detail-card .link-list > div:hover { background: var(--slate-50); }
.detail-card .link-list .code { background: var(--blue-50); color: var(--blue-700); }
.detail-card .strength { font-size: 12px; font-weight: 700; color: var(--blue-700); background: var(--blue-50); padding: 1px 8px; border-radius: 999px; white-space: nowrap; }

.text-blocks { display: grid; gap: 10px; }
.text-block { padding: 12px 14px; background: var(--slate-50); border: 1px solid var(--slate-100); border-radius: 8px; }
.text-block h4 { font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--slate-500); margin-bottom: 6px; }
.text-block .prose, .match .prose { white-space: pre-wrap; color: var(--slate-700); line-height: 1.65; margin: 0; }
.text-block.highlight { background: var(--blue-50); border-color: var(--blue-100); border-left: 3px solid var(--primary); }
.text-block.highlight h4 { color: var(--blue-700); }
.text-block.highlight .prose { color: var(--slate-800); }
.match-list { display: grid; gap: 10px; }
.match { padding: 12px 14px; border-radius: 8px; background: var(--green-50); border-left: 3px solid var(--green-600); }
.match .prose { margin-top: 6px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 14px; font-size: 12.5px; color: var(--muted); }
.detail-meta i { margin-right: 6px; color: var(--slate-400); }

.btn-danger-outline { background: #fff; border-color: #fecaca; color: var(--red-600); }
.btn-danger-outline:hover:not(:disabled) { background: var(--red-50); border-color: var(--red-600); }

@media (max-width: 720px) {
  .modal.detail .modal-header { padding: 16px; }
  .modal.detail .modal-body { padding: 14px 12px 18px; }
  .hero-name { font-size: 17px; }
  .detail-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-cols { grid-template-columns: minmax(0, 1fr); }
  .detail-cols .detail-card + .detail-card { margin-top: 0; }
}
