:root {
  --navy:      #0F2044;
  --navy-mid:  #1A3460;
  --gold:      #B8902A;
  --off-white: #F7F6F2;
  --charcoal:  #1C2333;
  --slate-100: #ECEEF3;
  --slate-300: #C2C8D4;
  --slate-500: #7A8499;
  --white:     #FFFFFF;
  --success:   #2E7D52;
  --warning:   #B8902A;
  --danger:    #9B2335;
  --blue:      #2C5FA8;
  --dark-green:#1C5237;
  --dark-red:  #6B1424;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--off-white);
  color: var(--charcoal);
  font-size: 14px;
}
a { color: var(--navy-mid); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; min-width: 240px; background: var(--navy); color: var(--slate-300);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  padding: 20px 18px; color: var(--white); font-weight: 700; font-size: 16px;
  border-bottom: 1px solid var(--navy-mid); letter-spacing: 0.3px;
}
.sidebar .brand span { color: var(--gold); }
.sidebar nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 11px 18px;
  color: var(--slate-300); text-decoration: none; font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--navy-mid); color: var(--white); }
.sidebar nav a.active { background: var(--navy-mid); color: var(--gold); border-left-color: var(--gold); }
.sidebar nav a .icon { width: 18px; text-align: center; }
.nav-badge {
  margin-left: auto; background: var(--danger); color: var(--white);
  font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; min-width: 18px; text-align: center;
}
.nav-badge.gold { background: var(--gold); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--white); border-bottom: 1px solid var(--slate-300);
  padding: 10px 24px; display: flex; align-items: center; gap: 16px; position: sticky; top: 0; z-index: 50;
}
.search-wrap { position: relative; flex: 1; max-width: 420px; }
.search-wrap input {
  width: 100%; padding: 8px 12px; border: 1px solid var(--slate-300); border-radius: 6px; font-size: 14px;
}
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; background: var(--white);
  border: 1px solid var(--slate-300); border-radius: 6px; margin-top: 4px;
  box-shadow: 0 4px 16px rgba(15,32,68,0.15); z-index: 100; max-height: 360px; overflow-y: auto;
}
.search-results .item { padding: 10px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.search-results .item:hover { background: var(--slate-100); }

.content { padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }
.page-title { font-size: 22px; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.page-sub { color: var(--slate-500); margin-bottom: 20px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards / tables ---------- */
.card { background: var(--white); border: 1px solid var(--slate-300); border-radius: 8px; padding: 18px; }
.card + .card { margin-top: 16px; }
.cards-row { display: grid; gap: 14px; margin-bottom: 16px; }
.cards-row.c4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat-card .label { color: var(--slate-500); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 28px; font-weight: 700; color: var(--navy); margin-top: 6px; }
.stat-card .value.gold { color: var(--gold); }
.stat-card .sub { color: var(--slate-500); font-size: 12px; margin-top: 4px; }
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { border-color: var(--gold); }

table.data { width: 100%; border-collapse: collapse; background: var(--white); }
table.data th {
  text-align: left; padding: 10px 10px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--slate-500); border-bottom: 2px solid var(--slate-300);
  white-space: nowrap; cursor: pointer; user-select: none;
}
table.data td { padding: 10px 10px; border-bottom: 1px solid var(--slate-100); vertical-align: middle; }
table.data tr:hover td { background: var(--slate-100); }
table.data td a.firm-link { font-weight: 600; color: var(--navy); text-decoration: none; }
table.data td a.firm-link:hover { color: var(--gold); }
.table-wrap { overflow-x: auto; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 11px; font-size: 11px;
  font-weight: 600; color: var(--white); white-space: nowrap; text-transform: capitalize;
}
.badge.st-not_contacted { background: var(--slate-500); }
.badge.st-contacted { background: var(--blue); }
.badge.st-replied { background: var(--gold); }
.badge.st-call_booked { background: var(--success); }
.badge.st-partner { background: var(--dark-green); }
.badge.st-dead { background: var(--danger); }
.badge.st-do_not_contact { background: var(--dark-red); }
.badge.li-not_connected { background: var(--slate-500); }
.badge.li-request_sent { background: var(--blue); }
.badge.li-connected { background: var(--success); }
.badge.li-messaged { background: var(--navy-mid); }
.badge.li-replied { background: var(--gold); }
.badge.tier { background: var(--navy); }
.badge.tag { background: var(--slate-100); color: var(--charcoal); font-weight: 500; }
.badge.outline { background: var(--white); color: var(--navy); border: 1px solid var(--slate-300); }
.badge.success { background: var(--success); }
.badge.warn { background: var(--warning); }
.badge.danger { background: var(--danger); }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 6px;
  border: 1px solid var(--navy); background: var(--navy); color: var(--white);
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--navy-mid); }
.btn.secondary { background: var(--white); color: var(--navy); }
.btn.secondary:hover { background: var(--slate-100); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { opacity: 0.9; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.link { background: none; border: none; color: var(--navy-mid); text-decoration: underline; padding: 2px 4px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

label.field { display: block; margin-bottom: 12px; }
label.field span.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--slate-500); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.3px; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=time],
input[type=password], input[type=datetime-local], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--slate-300); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: var(--white); color: var(--charcoal);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ---------- Filters ---------- */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filter-panel { background: var(--white); border: 1px solid var(--slate-300); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.check-list { max-height: 140px; overflow-y: auto; border: 1px solid var(--slate-100); border-radius: 6px; padding: 6px 8px; background: var(--white); }
.check-list label { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 13px; cursor: pointer; }
.filter-count { background: var(--gold); color: var(--white); border-radius: 10px; padding: 1px 8px; font-size: 11px; font-weight: 700; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,32,68,0.55); z-index: 200;
  display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px;
}
.modal {
  background: var(--white); border-radius: 10px; width: 100%; max-width: 560px;
  max-height: 85vh; overflow-y: auto; box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}
.modal.wide { max-width: 860px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--slate-100); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { color: var(--navy); font-size: 17px; }
.modal-head .x { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--slate-500); }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--slate-100); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Toasts ---------- */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 400; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--navy); color: var(--white); padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25); display: flex; align-items: center; gap: 10px;
  min-width: 240px; max-width: 400px; animation: toast-in 0.2s ease-out;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast .x { margin-left: auto; cursor: pointer; opacity: 0.7; background: none; border: none; color: inherit; font-size: 16px; }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--slate-500); }
.empty-state h3 { color: var(--charcoal); margin-bottom: 8px; }
.empty-state .btn { margin-top: 14px; }
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 14px; }
.pagination .info { color: var(--slate-500); margin-right: auto; font-size: 13px; }
.timeline { list-style: none; }
.timeline li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--slate-100); }
.timeline .tl-icon {
  width: 32px; height: 32px; min-width: 32px; border-radius: 50%; background: var(--slate-100);
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.timeline .tl-body { flex: 1; min-width: 0; }
.timeline .tl-title { font-weight: 600; color: var(--navy); }
.timeline .tl-detail { color: var(--slate-500); margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.timeline .tl-time { color: var(--slate-500); font-size: 12px; white-space: nowrap; }
.overdue { color: var(--danger); font-weight: 600; }
.muted { color: var(--slate-500); }
.flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.section-title { font-size: 15px; font-weight: 700; color: var(--navy); margin-bottom: 10px; }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.alert.danger { background: #F8E8EB; color: var(--danger); border: 1px solid var(--danger); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--slate-500); }
.kv dd { word-break: break-word; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.bar-row .bar-label { width: 120px; font-size: 13px; text-align: right; color: var(--slate-500); }
.bar-row .bar { height: 18px; background: var(--navy-mid); border-radius: 3px; min-width: 2px; }
.bar-row .bar-val { font-size: 13px; font-weight: 600; }
.progress { height: 8px; background: var(--slate-100); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--gold); transition: width 0.3s; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--navy); }
.login-card { background: var(--white); border-radius: 12px; padding: 40px; width: 100%; max-width: 380px; }
.login-card h1 { color: var(--navy); font-size: 20px; margin-bottom: 4px; }
.login-card .gold { color: var(--gold); }
.login-card p { color: var(--slate-500); margin-bottom: 24px; }
.login-error { color: var(--danger); margin-top: 10px; font-size: 13px; min-height: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .sidebar { width: 60px; min-width: 60px; }
  .sidebar .brand { font-size: 12px; padding: 16px 8px; text-align: center; }
  .sidebar nav a span.txt { display: none; }
  .sidebar nav a { justify-content: center; padding: 12px 0; }
  .nav-badge { position: absolute; margin-left: 18px; margin-top: -16px; }
  .sidebar nav a { position: relative; }
}
@media (max-width: 640px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; }
  .sidebar .brand { border: none; padding: 10px; }
  .sidebar nav { display: flex; padding: 0; overflow-x: auto; }
  .content { padding: 14px; }
  .form-row, .form-row3 { grid-template-columns: 1fr; }
}
