/* ─── Design Tokens ───────────────────────────────────────────── */
:root {
  --navy:       #0f172a;
  --navy-mid:   #1e293b;
  --blue:       #3b82f6;
  --blue-dark:  #2563eb;
  --blue-soft:  #eff6ff;
  --slate:      #64748b;
  --slate-lt:   #94a3b8;
  --border:     #e2e8f0;
  --bg:         #f8fafc;
  --surface:    #ffffff;
  --accent:     #06b6d4;
  --success:    #10b981;
  --success-soft:#ecfdf5;
  --warn:       #f59e0b;
  --warn-soft:  #fffbeb;
  --danger:     #ef4444;
  --danger-soft:#fef2f2;
  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  14px;
  --shadow-sm:  0 1px 3px rgba(15,23,42,.06),0 1px 2px rgba(15,23,42,.04);
  --shadow:     0 4px 16px rgba(15,23,42,.08);
  --shadow-lg:  0 12px 40px rgba(15,23,42,.14);
}

/* ─── Reset ───────────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0 }
body {
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--navy);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}
h1,h2,h3,h4,.display { font-family: "Instrument Sans", system-ui, sans-serif }
a { color: inherit; text-decoration: none }

/* ─── Layout ──────────────────────────────────────────────────── */
.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 12px 80px; /* bottom padding for mobile tab bar */
}
@media (min-width: 768px) {
  .app { padding: 20px 20px 20px }
}
@media (min-width: 1024px) {
  .app { padding: 24px }
}

/* ─── Topbar ──────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.logo {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .04em;
}
.brand h1 {
  font-size: 16px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Hide subtitle on small screens */
.brand p { display: none }
@media (min-width: 640px) {
  .brand p { display: block; font-size: 12px; color: var(--slate); margin-top: 1px }
  .brand h1 { font-size: 18px }
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
}
.status-pill.ok { background: var(--success-soft); color: var(--success); border-color: #a7f3d0 }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor }

/* Hide conn status + user pill on tiny screens */
#connStatus, .user-pill { display: none }
@media (min-width: 480px) { #connStatus { display: inline-flex } }
@media (min-width: 640px) { .user-pill { display: inline-flex } }

/* ─── Module Tabs — Desktop ───────────────────────────────────── */
.module-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
/* Hide desktop tabs on mobile (using bottom bar instead) */
@media (max-width: 639px) {
  .module-tabs { display: none }
}
.module-tab {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: left;
  transition: border-color .18s, box-shadow .18s, background .18s;
  font: inherit;
  color: inherit;
}
.module-tab strong { display: block; font-size: 14px; font-family: "Instrument Sans", sans-serif }
.module-tab small { display: block; font-size: 12px; color: var(--slate); margin-top: 2px }
.module-tab .tab-icon {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  color: #fff;
  border-radius: var(--radius-sm);
}
.module-tab.active .tab-icon { background: var(--blue) }
.module-tab:hover { border-color: rgba(59,130,246,.3); box-shadow: var(--shadow-sm) }
.module-tab.active {
  border-color: var(--blue);
  background: linear-gradient(135deg, #fff, var(--blue-soft));
  box-shadow: 0 4px 16px rgba(59,130,246,.12);
}

/* ─── Mobile Bottom Tab Bar ───────────────────────────────────── */
.mobile-tabs {
  display: none;
}
@media (max-width: 639px) {
  .mobile-tabs {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 90;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(15,23,42,.1);
  }
  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 8px;
    font: inherit;
    font-size: 10px;
    font-weight: 600;
    color: var(--slate);
    background: none;
    border: none;
    cursor: pointer;
    transition: color .15s;
    letter-spacing: .03em;
  }
  .mobile-tab .tab-icon {
    font-size: 10px;
    font-weight: 700;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    color: var(--slate);
    transition: background .15s, color .15s;
  }
  .mobile-tab.active .tab-icon { background: var(--blue); color: #fff }
  .mobile-tab.active { color: var(--blue) }
}

/* ─── Module Panels ───────────────────────────────────────────── */
.module-panel { display: none }
.module-panel.active { display: block }

/* ─── Grid / Sidebar / Main ───────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: start;
}
.sidebar { display: flex; flex-direction: column; gap: 12px }

/* Collapse sidebar into horizontal row on mobile */
@media (max-width: 767px) {
  .sidebar {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none }
  .sidebar .card {
    flex-shrink: 0;
    min-width: 200px;
  }
  /* Hide steps card on mobile to save space */
  .sidebar .card:has(.steps) { display: none }
}
@media (min-width: 1024px) {
  .grid { grid-template-columns: 280px 1fr }
}

.main { display: flex; flex-direction: column; gap: 14px }

/* ─── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
@media (min-width: 640px) {
  .card { padding: 20px }
}
.card h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--slate-lt);
  margin-bottom: 12px;
}

/* ─── Steps ───────────────────────────────────────────────────── */
.steps { display: flex; flex-direction: column; gap: 8px }
.step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid transparent;
}
.step.active { background: var(--blue-soft); border-color: rgba(59,130,246,.15) }
.step.done .num { background: var(--success); color: #fff }
.num {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.step strong { display: block; font-size: 13px; margin-bottom: 1px }
.step span { font-size: 11px; color: var(--slate) }

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1.5px solid transparent;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, border-color .15s, opacity .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed }
.btn-primary { background: var(--navy); color: #fff }
.btn-primary:hover:not(:disabled) { background: var(--navy-mid) }
.btn-secondary { background: var(--bg); color: var(--navy); border-color: var(--border) }
.btn-secondary:hover:not(:disabled) { background: var(--blue-soft); border-color: rgba(59,130,246,.25) }
.btn-success { background: var(--success); color: #fff; border-color: var(--success) }
.btn-success:hover:not(:disabled) { background: #059669 }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger) }
.btn-block { width: 100%; text-align: center }
.btn-sm { padding: 6px 12px; font-size: 12px }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px }
.btn-group.col { flex-direction: column }
.btn-group-mobile { display: flex; flex-wrap: wrap; gap: 8px }

/* ─── Stats ───────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, 1fr) }
}
.stat {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--border);
}
.stat .lbl {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--slate-lt);
  margin-bottom: 4px;
}
.stat .val {
  font-size: 22px;
  font-weight: 700;
  font-family: "Instrument Sans", sans-serif;
}
.stat.ok .val { color: var(--success) }
.stat.bad .val { color: var(--danger) }

/* ─── Dropzone ────────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 20px;
  text-align: center;
  background: linear-gradient(160deg, #fff, var(--bg));
  transition: border-color .2s, background .2s;
  cursor: pointer;
}
.dropzone.dragover { border-color: var(--blue); background: var(--blue-soft) }
.dropzone h4 { font-size: 15px; margin-bottom: 5px }
.dropzone p { font-size: 12px; color: var(--slate) }

/* ─── Toolbar ─────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
@media (min-width: 640px) {
  .toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }
}
.toolbar .filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.toolbar input[type=search],
.toolbar select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 13px;
  width: 100%;
  background: var(--surface);
  color: var(--navy);
}
@media (min-width: 640px) {
  .toolbar input[type=search],
  .toolbar select { width: auto; min-width: 160px }
}
.toolbar input[type=search]:focus,
.toolbar select:focus {
  outline: none;
  border-color: var(--blue);
}
.section-title { font-size: 16px; font-weight: 700; color: var(--navy) }
.mb { margin-bottom: 12px }
.mt { margin-top: 12px }

/* ─── Table ───────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 900px;
}
thead th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  text-align: left;
  padding: 11px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--slate);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  z-index: 1;
}
tbody td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none }
tbody tr:hover { background: #f8fbff }
tbody tr.invalid { background: #fff5f5 }
tbody tr.valid { background: #fff }

/* ─── Badges & Chips ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
}
.badge.ok { background: var(--success-soft); color: var(--success) }
.badge.bad { background: var(--danger-soft); color: var(--danger) }
.badge.warn { background: var(--warn-soft); color: var(--warn) }
.chips { display: flex; flex-wrap: wrap; gap: 4px }
.chip { padding: 3px 7px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--border); font-size: 11px }

/* ─── Field ───────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px }
.field label { font-size: 12px; font-weight: 600; color: var(--slate) }
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 13px;
  background: var(--surface);
  color: var(--navy);
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

/* ─── Card note ───────────────────────────────────────────────── */
.card-note { font-size: 12px; color: var(--slate); margin-top: 8px; line-height: 1.5 }

/* ─── Detail modal grid ───────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px }
@media (min-width: 560px) { .detail-grid { grid-template-columns: 1fr 1fr } }
.detail-box { padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg) }
.detail-box h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--slate-lt); margin-bottom: 6px }
.detail-box pre, .detail-box ul { font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-word }
.err-list { color: var(--danger) }
.warn-list { color: var(--warn) }

/* ─── Phone risk / banners ────────────────────────────────────── */
.phone-alert-banner {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--warn-soft);
  border: 1px solid rgba(245,158,11,.3);
  color: #92400e;
  font-size: 13px;
}
.phone-risk-intro { margin-bottom: 12px; color: var(--slate); line-height: 1.5; font-size: 13px }
.phone-risk-list { display: grid; gap: 10px }
.phone-risk-item { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg) }
.phone-risk-item strong { display: block; margin-bottom: 4px }
.phone-risk-item p { margin: 0 0 8px; color: var(--slate); font-size: 13px }
tr.phone-risk td { background: #fffbeb }
.warn-chip { background: #fef3c7; color: #92400e }

/* ─── Progress ────────────────────────────────────────────────── */
.progress { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--border) }
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--accent));
  width: 0;
  transition: width .3s;
}

/* ─── Batch log ───────────────────────────────────────────────── */
.batch-log {
  max-height: 200px;
  overflow: auto;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px;
  border-radius: var(--radius);
  line-height: 1.6;
}

/* ─── Modals ──────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.5);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
  backdrop-filter: blur(2px);
}
@media (min-width: 640px) {
  .modal {
    align-items: center;
    padding: 20px;
  }
}
.modal.open { display: flex }

.modal-card {
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 16px;
  border: 1px solid var(--border);
  border-bottom: none;
}
@media (min-width: 640px) {
  .modal-card {
    border-radius: var(--radius-lg);
    border-bottom: 1px solid var(--border);
    padding: 22px;
    max-height: 85vh;
  }
}
/* Drag handle indicator for mobile sheets */
.modal-card::before {
  content: '';
  display: block;
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 0 auto 16px;
}
@media (min-width: 640px) {
  .modal-card::before { display: none }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.modal-head h3 { font-size: 16px }

/* Edit modal: 2 column grid on desktop, 1 col on mobile */
.edit-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}
@media (min-width: 540px) {
  .edit-form-grid { grid-template-columns: 1fr 1fr; gap: 0 12px }
}

/* ─── Ref table ───────────────────────────────────────────────── */
.ref-table { font-size: 12px; width: 100%; border-collapse: collapse }
.ref-table td, .ref-table th { padding: 8px; border-bottom: 1px solid var(--border); text-align: left }
.empty { padding: 48px 20px; text-align: center; color: var(--slate) }

/* ─── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 76px; /* above mobile tab bar */
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  padding: 12px 18px;
  background: var(--navy);
  color: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity .22s, transform .22s;
  z-index: 200;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0) }
@media (min-width: 640px) {
  .toast {
    bottom: 24px;
    left: auto;
    right: 24px;
    transform: translateY(10px);
  }
  .toast.show { transform: translateY(0) }
}

/* ─── Login page ──────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(59,130,246,.08), transparent), var(--bg);
}
.login-wrap { width: 100%; max-width: 420px }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px }
.login-brand h1 { font-size: 20px; margin-bottom: 2px }
.login-brand p { font-size: 13px; color: var(--slate) }
.login-form { margin-top: 8px }
.login-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}
.login-note { margin-top: 14px; font-size: 12px; color: var(--slate); line-height: 1.6; text-align: center }

/* ─── Misc helpers ────────────────────────────────────────────── */
.col { flex-direction: column }
.detail-panel { display: none }
.detail-panel.open { display: block }
