:root {
  --navy-900: #0a1a30;
  --navy-800: #0f2547;
  --navy-700: #15315f;
  --navy-600: #1c3f78;
  --accent: #c9a86a;
  --accent-soft: #e3d3ab;
  --text-light: #eef2f8;
  --text-muted: #9fb0c9;
  --surface: #ffffff;
  --surface-alt: #f4f6fb;
  --border: #dfe4ee;
  --danger: #c0392b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--surface-alt);
  color: var(--navy-900);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: linear-gradient(135deg, var(--navy-900), var(--navy-700));
  color: var(--text-light);
  box-shadow: 0 2px 12px rgba(10, 26, 48, 0.25);
}
header h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--accent-soft);
}
header h1 .mark { color: var(--text-light); font-weight: 300; }

.main-nav { display: flex; gap: 4px; }
.main-nav .nav-link {
  padding: 9px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
}
.main-nav .nav-link:hover { color: var(--text-light); }
.main-nav .nav-link.active {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  color: var(--accent-soft);
  font-weight: 600;
}

.risk-banner {
  background: rgba(220, 38, 38, 0.12);
  border: 1px solid rgba(220, 38, 38, 0.4);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 14px;
  color: #fecaca;
}
.risk-banner ul { margin: 8px 0 0; padding-left: 20px; }
.risk-banner li { margin-bottom: 4px; }
.risk-banner a { color: #fecaca; text-decoration: underline; }

.ai-provider-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}

.legend-wrap { position: relative; }
.legend-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--navy-700);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 16px;
  line-height: 1;
}
.legend-list {
  position: absolute;
  top: 36px;
  right: 0;
  z-index: 20;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 12px 16px;
  grid-template-columns: 120px 1fr;
  gap: 4px 14px;
  font-size: 12.5px;
  color: var(--navy-900);
  width: 320px;
}
/* `display: grid` hanya berlaku saat TIDAK [hidden] — kalau di set tanpa
   syarat, ia menimpa aturan UA `[hidden]{display:none}` (specificity sama,
   author stylesheet menang) sehingga atribut hidden yang dipasang JS tidak
   pernah benar-benar menyembunyikan elemen ini. */
.legend-list:not([hidden]) { display: grid; }
.legend-list dt { font-weight: 600; color: var(--navy-800); }
.legend-list dd { margin: 0 0 6px; color: var(--text-muted); }

.toolbar { display: flex; gap: 10px; }
.toolbar button,
.toolbar a.btn {
  padding: 9px 16px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-light);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.toolbar button:hover,
.toolbar a.btn:hover { background: rgba(255, 255, 255, 0.14); border-color: var(--accent); }
.toolbar button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--navy-900);
  font-weight: 600;
}
.toolbar button.primary:hover { background: var(--accent-soft); }

main { padding: 24px 28px; overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-size: 13px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(10, 26, 48, 0.08);
}
th, td { border-bottom: 1px solid var(--border); padding: 12px 14px; text-align: left; vertical-align: top; }
th {
  background: var(--navy-800);
  color: var(--text-light);
  font-weight: 500;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  font-size: 12px;
  text-transform: uppercase;
}
tr:hover td { background: var(--surface-alt); }

.stage {
  padding: 3px 10px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  display: inline-block;
}
.stage-new { background: #6b7c93; }
.stage-contacted { background: var(--navy-600); }
.stage-interested { background: #b08a3e; }
.stage-negotiation { background: #6b4fa0; }
.stage-closed_won { background: #1c7a4d; }
.stage-closed_lost { background: var(--danger); }

.auth-card {
  max-width: 380px;
  margin: 110px auto;
  background: var(--surface);
  padding: 36px 32px;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(10, 26, 48, 0.18);
  border-top: 3px solid var(--accent);
}
.auth-card .brand { text-align: center; margin-bottom: 24px; }
.auth-card .brand h1 {
  margin: 0;
  font-size: 24px;
  color: var(--navy-800);
  letter-spacing: 0.04em;
  font-weight: 700;
}
.auth-card .brand span {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.auth-card input {
  width: 100%;
  padding: 11px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--surface-alt);
}
.auth-card input:focus { outline: none; border-color: var(--navy-600); background: #fff; }
.auth-actions button {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 6px;
  background: var(--navy-800);
  color: var(--text-light);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.auth-actions button:hover { background: var(--navy-700); }
.error { color: var(--danger); font-size: 13px; min-height: 16px; margin-top: 10px; }
.success { color: #1c7a4d; font-size: 13px; margin-top: 10px; }

.settings-panel {
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 10px;
  padding: 24px 28px;
  box-shadow: 0 1px 4px rgba(10, 26, 48, 0.08);
}
.settings-panel h2 { color: var(--navy-800); font-size: 17px; margin-top: 0; }
.settings-panel form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.settings-panel form input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.settings-panel form button {
  grid-column: 1 / -1;
  padding: 10px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--navy-900);
  font-weight: 600;
  cursor: pointer;
}
.settings-panel table { box-shadow: none; }

/* ---- Modal (pairing & kredensial client) ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 26, 48, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
/* Tanpa rule ini, "display: flex" di atas punya spesifisitas sama dengan
   default UA stylesheet "[hidden]{display:none}" tapi dimuat lebih akhir,
   sehingga selalu menang — modal jadi selalu tampil (kotak putih kosong)
   sejak halaman dibuka dan atribut hidden lewat JS tidak berefek sama sekali. */
.modal-overlay[hidden] {
  display: none;
}
.modal {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  padding: 28px 30px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 18px 50px rgba(10, 26, 48, 0.35);
  border-top: 3px solid var(--accent);
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { color: var(--navy-800); font-size: 18px; margin-top: 0; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}
.modal-close:hover { color: var(--navy-800); }
.modal-form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.modal-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.modal-form > button {
  padding: 11px;
  border: none;
  border-radius: 6px;
  background: var(--navy-800);
  color: var(--text-light);
  font-weight: 600;
  cursor: pointer;
}
.modal-form > button:hover { background: var(--navy-700); }
.method-row { display: flex; gap: 16px; font-size: 13px; color: var(--navy-900); }
.method-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.pair-area { margin-top: 16px; text-align: center; }
.qr-img {
  width: 240px;
  height: 240px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}
.hint { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

.copy-field { text-align: left; margin-top: 12px; }
.copy-field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.copy-row { display: flex; gap: 8px; }
.copy-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: "Consolas", "Menlo", monospace;
  background: var(--surface-alt);
}
.copy-row button {
  padding: 10px 14px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--navy-900);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.copy-row button:hover { background: var(--accent-soft); }

/* ---- Kartu info fitur (pojok kiri bawah) ---- */
.intro-card {
  position: fixed;
  left: 20px;
  bottom: 20px;
  width: 280px;
  background: var(--surface);
  border-radius: 10px;
  padding: 18px 18px 16px;
  box-shadow: 0 10px 30px rgba(10, 26, 48, 0.25);
  border-left: 3px solid var(--accent);
  z-index: 50;
}
.intro-card[hidden] { display: none; }
.intro-card h3 { margin: 0 0 8px; font-size: 14px; color: var(--navy-800); }
.intro-card ul { margin: 0; padding-left: 18px; font-size: 12.5px; line-height: 1.5; color: var(--navy-900); }
.intro-card li { margin-bottom: 6px; }
.intro-card li:last-child { margin-bottom: 0; }
.intro-close {
  position: absolute;
  top: 8px;
  right: 10px;
  border: none;
  background: none;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}
.intro-close:hover { color: var(--navy-800); }

/* ---- Halaman Detail Lead ---- */
.lead-link { color: var(--navy-700); font-weight: 600; text-decoration: none; }
.lead-link:hover { text-decoration: underline; }

.risk {
  padding: 3px 10px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  display: inline-block;
}
.risk-rendah { background: #1c7a4d; }
.risk-sedang { background: #b08a3e; }
.risk-tinggi { background: var(--danger); }
.risk-selesai { background: #6b7c93; }

.modal-lead { max-width: 640px; }

.ai-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 14px 0;
  font-size: 13px;
  line-height: 1.5;
}
.ai-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.ai-score { font-size: 12px; color: var(--navy-700); font-weight: 600; }
.ai-card p { margin: 6px 0; }

.chip-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.chip-row-label { font-size: 12px; color: var(--text-muted); margin-right: 2px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--navy-900);
}
.chip-tag { background: var(--navy-800); color: var(--text-light); border-color: var(--navy-800); }
.chip-remove {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  opacity: 0.75;
}
.chip-remove:hover { opacity: 1; }

.lead-section { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.lead-section h3 { font-size: 14px; color: var(--navy-800); margin: 0 0 8px; }

.inline-form { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.inline-form select,
.inline-form input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.inline-form input { flex: 1; }
.inline-form button {
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  background: var(--navy-800);
  color: var(--text-light);
  font-size: 13px;
  cursor: pointer;
}
.inline-form button:hover { background: var(--navy-700); }

.note-form { display: flex; flex-direction: column; gap: 8px; }
.note-form textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}
.note-form button {
  align-self: flex-start;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: var(--navy-900);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.note-form button:hover { background: var(--accent-soft); }

.timeline { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.timeline-item {
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  max-width: 85%;
}
.timeline-inbound { background: var(--surface-alt); align-self: flex-start; }
.timeline-outbound { background: var(--navy-800); color: var(--text-light); align-self: flex-end; }
.timeline-meta { font-size: 11px; opacity: 0.7; margin-bottom: 3px; }
.timeline-body { white-space: pre-wrap; word-break: break-word; }

/* ---- Dashboard topbar: filter + legend ---- */
.dashboard-topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  background: var(--surface);
  color: var(--navy-900);
}
.filter-bar #filterSearch { min-width: 200px; }
.filter-bar button {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--navy-800);
  color: var(--text-light);
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
.filter-bar button:hover { background: var(--navy-700); }

/* ---- Kanban ---- */
.kanban-board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.kanban-column {
  flex: 0 0 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  max-height: 75vh;
}
.kanban-column-header {
  padding: 12px 14px;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-light);
  background: var(--navy-800);
  border-radius: 10px 10px 0 0;
}
.kanban-card-list { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1; }
.kanban-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  cursor: grab;
}
.kanban-card.dragging { opacity: 0.4; }
.kanban-card-name { display: block; font-weight: 600; font-size: 13px; color: var(--navy-800); text-decoration: none; margin-bottom: 4px; }
.kanban-card-name:hover { text-decoration: underline; }
.kanban-card-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }

/* ---- Analitik ---- */
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.analytics-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.analytics-card-wide { grid-column: 1 / -1; }
.analytics-card h3 { margin: 0 0 10px; font-size: 14px; color: var(--navy-800); }
.analytics-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.analytics-list li { display: flex; justify-content: space-between; font-size: 13px; color: var(--navy-900); }
.analytics-value { font-weight: 600; color: var(--accent); background: var(--navy-800); padding: 2px 8px; border-radius: 12px; font-size: 12px; }
.analytics-chart { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.analytics-bar-row { display: flex; align-items: center; gap: 8px; }
.analytics-bar-label { flex: 0 0 92px; font-size: 12px; color: var(--navy-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.analytics-bar-track { flex: 1; height: 12px; background: var(--navy-50, #eef1f6); border-radius: 6px; overflow: hidden; }
.analytics-bar-fill { height: 100%; background: linear-gradient(90deg, var(--navy-800), var(--accent)); border-radius: 6px; }
.analytics-bar-count { flex: 0 0 28px; text-align: right; font-size: 12px; font-weight: 600; color: var(--navy-800); }
.leaderboard-table { width: 100%; border-collapse: collapse; box-shadow: none; }
.leaderboard-table th, .leaderboard-table td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: left; font-size: 13px; }
.leaderboard-table th { background: var(--navy-800); color: var(--text-light); }

.pdf-download-btn {
  display: inline-block;
  margin: 6px 0 14px;
  border: 1px solid var(--accent);
  background: var(--navy-800);
  color: var(--accent-soft);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.pdf-download-btn:hover { background: var(--navy-700); }
.pdf-download-btn:disabled { opacity: 0.6; cursor: default; }

/* ====================================================================
   Mobile (<=768px): header/nav jadi scroll horizontal, form 1 kolom,
   modal/legend/intro-card menyesuaikan lebar viewport, dan tabel data
   (#sheet, #staffTable, #clientTable, .leaderboard-table) berubah jadi
   "card" bertumpuk — pola td::before(attr(data-label)) — supaya tidak
   perlu geser jari horizontal lewat tabel padat-kolom di layar sempit.
   ==================================================================== */
@media (max-width: 768px) {
  header {
    flex-wrap: wrap;
    padding: 14px 16px;
    gap: 10px;
  }
  header h1 { font-size: 17px; }

  .main-nav {
    width: 100%;
    order: 3;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 2px;
  }
  .main-nav .nav-link {
    flex: 0 0 auto;
    padding: 8px 12px;
    font-size: 12.5px;
    white-space: nowrap;
  }

  .toolbar { flex-wrap: wrap; gap: 8px; }
  .toolbar button, .toolbar a.btn { padding: 8px 12px; font-size: 12.5px; }

  main { padding: 14px; }

  .dashboard-topbar { flex-direction: column; align-items: stretch; }
  .filter-bar { gap: 6px; }
  .filter-bar input, .filter-bar select, .filter-bar button { flex: 1 1 calc(50% - 6px); min-width: 0; }
  .filter-bar #filterSearch { min-width: 0; flex: 1 1 100%; }

  .legend-wrap { width: 100%; }
  .legend-list {
    left: 0;
    right: 0;
    width: 100%;
    grid-template-columns: 100px 1fr;
  }

  .auth-card { margin: 40px 16px; padding: 28px 20px; }

  .settings-panel { padding: 18px 16px; }
  .settings-panel form { grid-template-columns: 1fr; }

  .modal { padding: 20px 16px; max-width: calc(100% - 24px); }
  .modal-overlay { padding: 12px; }

  .intro-card { left: 12px; right: 12px; bottom: 12px; width: auto; }

  /* ---- Tabel data jadi tampilan "card" bertumpuk ---- */
  #sheet, #staffTable, #clientTable, .leaderboard-table {
    border: none;
    box-shadow: none;
  }
  #sheet thead, #staffTable thead, #clientTable thead, .leaderboard-table thead {
    position: absolute;
    left: -9999px;
    top: -9999px;
  }
  #sheet tr, #staffTable tr, #clientTable tr, .leaderboard-table tr {
    display: block;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 1px 4px rgba(10, 26, 48, 0.08);
    padding: 6px 4px;
  }
  #sheet td, #staffTable td, #clientTable td, .leaderboard-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    text-align: right;
    border-bottom: 1px solid var(--surface-alt);
    padding: 8px 10px;
  }
  #sheet td:last-child, #staffTable td:last-child, #clientTable td:last-child, .leaderboard-table td:last-child {
    border-bottom: none;
  }
  #sheet td::before, #staffTable td::before, #clientTable td::before, .leaderboard-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    text-align: left;
    flex: 0 0 auto;
  }
  #sheet tbody tr:not([data-label]):only-child td,
  #sheet tbody tr td[colspan] {
    display: block;
    text-align: left;
  }
  #sheet tbody tr td[colspan]::before { content: none; }
}
