:root {
  --primary: #1f4e78;
  --primary-light: #2e75b6;
  --primary-dark: #163a5a;
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #1c2733;
  --muted: #6b7a8d;
  --border: #dbe4ee;
  --good: #2e7d32;
  --warn: #f9a825;
  --bad: #c62828;
  --purple: #7b3fbf;
  --star: #f5b301;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(31, 78, 120, 0.06), 0 6px 20px rgba(31, 78, 120, 0.05);
}
* { box-sizing: border-box; }
body {
  margin: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
.hidden { display: none !important; }
.link { color: var(--primary-light); text-decoration: none; font-weight: 600; font-size: 13px; }
.link:hover { text-decoration: underline; }

/* ===== App shell ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 244px; flex-shrink: 0; background: linear-gradient(180deg, var(--primary-dark), var(--primary));
  color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 16px; }
.side-brand .logo { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; font-size: 16px; background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.22); }
.side-brand-txt { display: flex; flex-direction: column; line-height: 1.2; }
.side-brand-txt strong { font-size: 15px; }
.side-brand-txt span { font-size: 12px; opacity: 0.8; }

.side-nav { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; border-radius: 10px;
  text-decoration: none; color: rgba(255,255,255,0.85); font-weight: 600; font-size: 14px; transition: background .12s;
}
.nav-link .ni { width: 18px; text-align: center; font-size: 14px; }
.nav-link:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.18); color: #fff; }
.nav-badge { margin-left: auto; background: rgba(255,255,255,0.22); border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 700; }
.nav-badge:empty { display: none; }

.side-foot { padding: 14px 16px 18px; border-top: 1px solid rgba(255,255,255,0.12); display: flex; flex-direction: column; gap: 10px; }
.side-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.username { font-size: 13px; font-weight: 600; opacity: 0.95; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.username::before { content: '👤 '; }
.acct-btn { background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.25); color: #fff; font-family: inherit; font-size: 12px; font-weight: 600; padding: 6px 11px; border-radius: 8px; cursor: pointer; }
.acct-btn:hover { background: rgba(255,255,255,0.28); }
.key-status { font-size: 12px; font-weight: 600; padding: 7px 12px; border-radius: 9px; background: rgba(255,255,255,0.12); text-align: center; }
.key-status.ok::before { content: '● '; color: #8ef0a4; }
.key-status.warn { background: rgba(249,168,37,0.85); }
.key-status.bad { background: rgba(198,40,40,0.7); }
.key-status.bad::before { content: '● '; color: #ffd3d3; }

/* ===== Content ===== */
.content { flex: 1; min-width: 0; padding: 26px 30px 70px; max-width: 1180px; }
.view { display: none; animation: fade .18s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.3px; }
.page-sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.header-actions { display: flex; gap: 8px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 18px; }
.card h2 { margin: 0 0 16px; font-size: 15px; font-weight: 700; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h2 { margin: 0; }

/* ===== Buttons ===== */
.btn { cursor: pointer; border: none; border-radius: 10px; font-family: inherit; font-weight: 600; font-size: 14px; padding: 10px 17px; transition: transform .08s, background .15s; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.primary:disabled { opacity: 0.6; cursor: progress; }
.btn.big { padding: 13px 22px; font-size: 15px; }
.btn.ghost { background: #eef2f7; color: var(--primary); }
.btn.ghost:hover { background: #e2e9f1; }
.btn.ghost:disabled { opacity: 0.6; cursor: progress; }
.btn.small { padding: 8px 13px; font-size: 13px; }
.btn.export { background: #e6f4ea; color: var(--good); }
.btn.export:hover { background: #d6ecdd; }
.btn.enrich { background: #f0e8fa; color: var(--purple); }
.btn.enrich:hover { background: #e7daf6; }
.btn.enrich:disabled { opacity: 0.6; cursor: progress; }
.btn.danger { background: #fdeaea; color: var(--bad); }
.btn.danger:hover { background: #f9d9d9; }

.pill { display: inline-block; background: var(--primary-light); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; margin-left: 4px; vertical-align: middle; }

/* ===== Dashboard ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border-top: 3px solid var(--primary-light); }
.stat.green { border-top-color: var(--good); }
.stat.purple { border-top-color: var(--purple); }
.stat .num { font-size: 27px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.stat .lbl { font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .4px; }
.dash-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 18px; }
.dash-cols .card { margin: 0; }
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 34px; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .bl { color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 9px; background: #eef2f7; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary-light); border-radius: 6px; }
.bar-row .bn { text-align: right; font-weight: 700; }
.bars .empty-mini { color: var(--muted); font-size: 13px; }
.recent-list { display: flex; flex-direction: column; }
.recent-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid #eef3f8; cursor: pointer; }
.recent-row:last-child { border-bottom: none; }
.recent-row:hover { background: #f7fafd; }
.recent-row .rn { font-weight: 600; flex: 1; }
.recent-row .rc { color: var(--muted); font-size: 12.5px; }

/* ===== Search ===== */
.search-grid { display: grid; grid-template-columns: 1fr 160px; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field em { font-style: normal; font-weight: 400; opacity: 0.7; }
.field input { padding: 12px 14px; font-size: 15px; border: 1.5px solid var(--border); border-radius: 10px; outline: none; transition: border-color .15s, box-shadow .15s; font-family: inherit; width: 100%; }
.field input:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(46,117,182,0.15); }
.cities-block { margin: 18px 0 16px; }
.cities-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; gap: 8px; }
.cities-head > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.city-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.link-btn { background: none; border: none; color: var(--primary-light); font-weight: 600; font-size: 13px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.link-btn:hover { background: rgba(46,117,182,0.1); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none; padding: 8px 13px; border-radius: 999px; border: 1.5px solid var(--border); background: #f7fafd; font-size: 13px; font-weight: 500; transition: all .12s; }
.chip:hover { border-color: var(--primary-light); }
.chip input { display: none; }
.chip.checked { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.chip.checked .dot { background: #8ef0a4; }
.chip.primary { border-color: var(--primary-light); }
.chip.primary::after { content: '★ deep'; font-size: 10px; font-weight: 700; color: var(--star); }
.chip.major:not(.primary)::after { content: '★'; font-size: 11px; color: var(--star); }
.all-toggle { display: flex; align-items: flex-start; gap: 10px; margin: 16px 0 6px; padding: 12px 14px; background: #f5f8fb; border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer; font-size: 13px; line-height: 1.45; }
.all-toggle input { margin-top: 2px; width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; }
.all-toggle:has(input:checked) { background: #eaf1fa; border-color: var(--primary-light); }
.search-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.est { font-size: 13px; color: var(--muted); }
.est strong { color: var(--text); }

/* ===== Progress ===== */
.progress-card { border-left: 4px solid var(--primary-light); }
.progress-head { display: flex; align-items: center; justify-content: space-between; }
.progress-head h2 { margin: 0; }
.log { margin-top: 14px; max-height: 300px; overflow-y: auto; font-size: 13px; display: flex; flex-direction: column; gap: 5px; }
.log .line { padding: 6px 10px; border-radius: 7px; background: #f5f8fb; }
.log .line.city { font-weight: 600; background: #eaf1fa; }
.log .line.err { background: #fdeaea; color: var(--bad); }
.log .line.done { background: #e6f4ea; color: var(--good); font-weight: 600; }

/* ===== Leads table ===== */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 9px; font-family: inherit; font-size: 13px; background: #fff; outline: none; }
.filters input { flex: 1; min-width: 200px; }
.filters input:focus, .filters select:focus { border-color: var(--primary-light); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; padding: 11px 12px; color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 2px solid var(--border); white-space: nowrap; }
tbody td { padding: 11px 12px; border-bottom: 1px solid #eef3f8; vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7fafd; }
.b-name { font-weight: 600; }
.b-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.contact-cell { font-size: 12.5px; line-height: 1.5; }
.contact-cell a { color: var(--primary-light); text-decoration: none; }
.contact-cell a:hover { text-decoration: underline; }
.contact-cell .muted { color: var(--muted); }
.contact-cell .email-link { color: var(--purple); }
.socials { display: inline-flex; gap: 4px; }
.socials a { display: inline-grid; place-items: center; min-width: 22px; height: 17px; padding: 0 4px; border-radius: 5px; background: #eef0f4; color: var(--muted); font-size: 10px; font-weight: 700; text-decoration: none; }
.socials a:hover { background: var(--primary-light); color: #fff; }
.rating-cell { white-space: nowrap; }
.stars { color: var(--star); letter-spacing: 1px; }
.rating-num { font-weight: 700; margin-left: 4px; }
.reviews-num { color: var(--muted); font-size: 12px; }
.status-select { border: 1.5px solid var(--border); border-radius: 8px; padding: 6px 8px; font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; background: #fff; }
.status-New { color: var(--primary-light); }
.status-Contacted { color: var(--warn); }
.status-InProgress { color: #00838f; }
.status-Negotiating { color: var(--purple); }
.status-Client { color: var(--good); }
.status-NotInterested { color: var(--bad); }
.row-view { background: none; border: none; color: var(--primary-light); font-weight: 700; cursor: pointer; font-size: 16px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); font-size: 15px; }

/* ===== Lead drawer ===== */
.drawer { position: fixed; inset: 0; z-index: 60; }
.drawer-overlay { position: absolute; inset: 0; background: rgba(20,35,55,0.45); animation: fade .15s; }
.drawer-panel { position: absolute; top: 0; right: 0; height: 100%; width: 440px; max-width: 92vw; background: var(--card); box-shadow: -10px 0 40px rgba(0,0,0,.2); overflow-y: auto; animation: slideIn .22s ease; }
@keyframes slideIn { from { transform: translateX(100%); } }
.drawer-hd { background: linear-gradient(120deg, var(--primary-dark), var(--primary-light)); color: #fff; padding: 22px 24px; position: sticky; top: 0; }
.drawer-hd .dh-cat { font-size: 12px; opacity: 0.85; text-transform: uppercase; letter-spacing: .5px; }
.drawer-hd h2 { margin: 4px 0 8px; font-size: 21px; color: #fff; }
.drawer-hd .dh-rating { font-size: 14px; }
.drawer-hd .dh-rating .stars { color: #ffe08a; }
.drawer-close { position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,0.2); border: none; color: #fff; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 16px; }
.drawer-close:hover { background: rgba(255,255,255,0.35); }
.drawer-body { padding: 20px 24px 40px; }
.d-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.d-actions a, .d-actions button { flex: 1; min-width: 92px; justify-content: center; }
.d-field { padding: 11px 0; border-bottom: 1px solid #eef3f8; display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: start; font-size: 13.5px; }
.d-field .dl { color: var(--muted); font-weight: 600; }
.d-field .dv { word-break: break-word; }
.d-field .dv a { color: var(--primary-light); text-decoration: none; }
.d-field .dv a:hover { text-decoration: underline; }
.d-edit { margin: 18px 0; }
.d-edit label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.d-edit select, .d-edit textarea { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 9px; font-family: inherit; font-size: 14px; outline: none; }
.d-edit textarea { min-height: 70px; resize: vertical; margin-top: 12px; }
.d-edit select:focus, .d-edit textarea:focus { border-color: var(--primary-light); }
.d-attach { margin: 22px 0 4px; }
.d-attach-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.d-attach-head strong { font-size: 14px; }
.upload-btn { cursor: pointer; }
.upload-btn input { display: none; }
.attach-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.att-item { position: relative; border-radius: 9px; overflow: hidden; background: #000; aspect-ratio: 1; }
.att-item img, .att-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border: none; border-radius: 6px; background: rgba(0,0,0,0.55); color: #fff; cursor: pointer; font-size: 12px; line-height: 1; }
.att-del:hover { background: var(--bad); }
.att-uploading { grid-column: 1 / -1; }

/* ===== API keys ===== */
.keys-add { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.keys-add input { padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 9px; font-family: inherit; font-size: 13px; outline: none; }
.keys-add input:focus { border-color: var(--primary-light); }
#newKeyLabel { width: 160px; }
#newKey { flex: 1; min-width: 200px; }
.keys-list { display: flex; flex-direction: column; gap: 8px; }
.key-row { display: flex; align-items: center; gap: 10px; padding: 11px 13px; border-radius: 10px; border: 1.5px solid var(--border); background: #f7fafd; font-size: 13px; }
.key-row .kdot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
.key-row.ready .kdot { background: var(--good); }
.key-row.exhausted .kdot, .key-row.invalid .kdot { background: var(--bad); }
.key-row.rate_limited .kdot { background: var(--warn); }
.key-row.disabled { opacity: 0.6; }
.key-row .kid { font-weight: 700; color: var(--muted); }
.key-row .klabel { font-weight: 600; }
.key-row .kmask { font-family: ui-monospace, Menlo, monospace; color: var(--muted); }
.key-row .kmetrics { margin-left: auto; display: flex; align-items: baseline; gap: 12px; }
.key-row .kused { font-size: 12px; color: var(--muted); font-weight: 600; }
.key-row .kright { font-weight: 700; }
.key-row.ready .kright { color: var(--good); }
.key-row.exhausted .kright, .key-row.invalid .kright { color: var(--bad); }
.key-row .kstatus { font-size: 11px; font-weight: 600; text-transform: capitalize; color: var(--muted); }
.key-usage-bar { height: 5px; background: #e3e9f1; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.key-usage-bar > span { display: block; height: 100%; background: var(--primary-light); }
.kwrap { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.kswitch { display: inline-flex; align-items: center; cursor: pointer; }
.kedit, .kdel { background: none; border: none; cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 6px; color: var(--muted); }
.kedit:hover { background: #e7eef6; color: var(--primary); }
.kdel:hover { background: #fdeaea; color: var(--bad); }
.key-edit { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: #eef4fb; border-radius: 10px; flex-wrap: wrap; }
.key-edit input { padding: 8px 10px; border: 1.5px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 13px; outline: none; }
.key-edit .ke-label { width: 140px; }
.key-edit .ke-key { flex: 1; min-width: 160px; }
.keys-hint { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); }
.keys-hint a { color: var(--primary-light); }

/* ===== Settings ===== */
.settings-card .set-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid #eef3f8; font-size: 14px; }
.settings-card .set-row:last-child { border-bottom: none; }
.settings-card .set-row span { color: var(--muted); }

/* ===== Login ===== */
.login-body { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(135deg, var(--primary-dark), var(--primary) 55%, var(--primary-light)); }
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-card { background: var(--card); border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.3); padding: 34px 30px; text-align: center; }
.login-logo { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 16px; display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-light)); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-card .field { text-align: left; margin-bottom: 14px; }
.login-card .btn.big { margin-top: 6px; width: 100%; justify-content: center; }
.login-error { background: #fdeaea; color: var(--bad); padding: 10px 12px; border-radius: 9px; font-size: 13px; margin-bottom: 12px; font-weight: 500; }
.login-foot { text-align: center; color: rgba(255,255,255,0.8); font-size: 12.5px; margin-top: 16px; }

/* ===== Toast ===== */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--primary-dark); color: #fff; padding: 12px 22px; border-radius: 10px; font-size: 14px; font-weight: 500; box-shadow: 0 8px 28px rgba(0,0,0,.25); z-index: 90; animation: pop .2s ease; }
.toast.bad { background: var(--bad); }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ===== Responsive ===== */
@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side-brand { padding: 12px 16px; }
  .side-nav { flex-direction: row; flex: 1 1 100%; overflow-x: auto; padding: 0 10px 10px; }
  .nav-link { white-space: nowrap; }
  .nav-badge { margin-left: 6px; }
  .side-foot { border-top: none; flex-direction: row; align-items: center; padding: 10px 16px; }
  .content { padding: 20px 16px 60px; }
  .search-grid { grid-template-columns: 1fr; }
}
