* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #F7F6F2; --surface: #FFFFFF; --surface2: #F0EFE9; --surface3: #E8E7E1;
  --border: #E2E0D8; --border2: #CFCDC5;
  --text: #1A1917; --muted: #7A7870;
  --accent: #C42B2B; --accent-hover: #A82020; --accent-bg: rgba(196,43,43,0.08); --accent-text: #8B1A1A;
  --amber: #92540A; --amber-bg: #FEF3E2;
  --green: #1A6B3A; --green-bg: #E8F5EE;
  --blue: #1A4A80; --blue-bg: #E8F0FA;
  --purple: #4A2A80; --purple-bg: #F0E8FA;
  --font: 'DM Sans', sans-serif; --mono: 'DM Mono', monospace;
}

body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: flex; min-height: 100vh; }

.sidebar { width: 220px; min-width: 220px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.logo { padding: 16px; border-bottom: 1px solid var(--border); }
.logo-sub { font-size: 10px; color: var(--muted); font-family: var(--mono); margin-top: 5px; letter-spacing: 0.8px; }
.logo-fallback { display: flex; align-items: center; gap: 8px; }
.logo-icon { width: 28px; height: 28px; background: var(--accent); border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.logo-icon svg { width: 16px; height: 16px; fill: white; }
.logo-name { font-size: 15px; font-weight: 600; color: var(--accent); letter-spacing: -0.3px; }

.nav { padding: 10px 8px; flex: 1; }
.nav-section { margin-bottom: 18px; }
.nav-label { font-size: 10px; font-weight: 600; color: var(--muted); letter-spacing: 0.7px; text-transform: uppercase; padding: 0 8px; margin-bottom: 4px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 13px; transition: all 0.13s; margin-bottom: 1px; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent-text); font-weight: 500; border-left: 2px solid var(--accent); padding-left: 8px; }
.nav-item .icon { width: 15px; height: 15px; opacity: 0.6; flex-shrink: 0; }
.nav-item.active .icon { opacity: 1; }

.user-bar { padding: 11px 14px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 600; color: white; flex-shrink: 0; }
.user-name { font-size: 12px; font-weight: 500; }
.user-role { font-size: 10px; color: var(--muted); }
.user-bar form { margin-left: auto; }
.user-bar button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 11px; }
.user-bar button:hover { color: var(--accent); }

.main { flex: 1; min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 26px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 7px; font-size: 12px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-family: var(--font); transition: all 0.12s; text-decoration: none; }
.btn:hover { background: var(--surface2); text-decoration: none; }
.btn.primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); color: white; }
.btn.danger { color: var(--accent); border-color: var(--accent); background: var(--surface); }
.btn.danger:hover { background: var(--accent-bg); }
.btn.sm { padding: 4px 9px; font-size: 11px; }

.content { padding: 22px 26px; }

.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 14px 16px; }
.stat-card.hi { border-color: rgba(196,43,43,0.25); background: rgba(196,43,43,0.04); }
.stat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 5px; }
.stat-val { font-size: 23px; font-weight: 600; font-family: var(--mono); letter-spacing: -0.8px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 18px 20px; }
.card-title { font-size: 10px; font-weight: 600; margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; padding: 9px 14px; border-bottom: 1px solid var(--border); text-align: left; background: var(--surface2); }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 12px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }
td .mono { font-family: var(--mono); }
td a.lead-ref { color: var(--accent); font-family: var(--mono); font-weight: 500; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 4px; font-size: 10px; font-weight: 500; font-family: var(--mono); white-space: nowrap; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.red   { background: var(--accent-bg); color: var(--accent); }
.badge.blue  { background: var(--blue-bg); color: var(--blue); }
.badge.purple{ background: var(--purple-bg); color: var(--purple); }
.badge.gray  { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.action-btn { padding: 4px 9px; border: 1px solid var(--border); border-radius: 5px; background: none; font-size: 11px; cursor: pointer; font-family: var(--font); color: var(--muted); transition: all 0.1s; margin-right: 3px; text-decoration: none; display: inline-block; }
.action-btn:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.action-btn.danger { color: var(--accent); }

.divider { height: 1px; background: var(--border); margin: 13px 0; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.field .help { font-size: 10px; color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; margin-left: 6px; }
.field input, .field select, .field textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font-family: var(--font); font-size: 12px; background: var(--surface); color: var(--text); outline: none; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 65px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.pill-tabs { display: flex; gap: 3px; background: var(--surface2); padding: 3px; border-radius: 8px; margin-bottom: 16px; width: fit-content; }
.pill-tab { padding: 5px 13px; border-radius: 6px; font-size: 12px; font-weight: 500; cursor: pointer; color: var(--muted); transition: all 0.13s; text-decoration: none; }
.pill-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.lead-detail-header { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 18px 20px; margin-bottom: 14px; }
.lead-id { font-family: var(--mono); font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.lead-name { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.lead-meta-row { display: flex; gap: 20px; flex-wrap: wrap; }
.lead-meta-item { font-size: 11px; color: var(--muted); }
.lead-meta-item strong { color: var(--text); display: block; margin-top: 1px; }

.lead-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.lead-tab { padding: 9px 16px; font-size: 12px; font-weight: 500; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; transition: all 0.12s; background: none; border-left: none; border-right: none; border-top: none; font-family: var(--font); }
.lead-tab:hover { color: var(--text); }
.lead-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.lead-tab.locked { opacity: 0.5; cursor: not-allowed; }

.timeline-item { display: flex; gap: 10px; margin-bottom: 14px; }
.tl-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-top: 4px; flex-shrink: 0; }
.tl-title { font-size: 12px; font-weight: 500; }
.tl-meta { font-size: 10px; color: var(--muted); margin-top: 1px; }

.panel-hidden { display: none; }

.flash { padding: 10px 14px; border-radius: 7px; margin-bottom: 14px; font-size: 12px; }
.flash.success { background: var(--green-bg); color: var(--green); }
.flash.error { background: var(--accent-bg); color: var(--accent); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 30px; width: 100%; max-width: 360px; }
.login-title { font-size: 20px; font-weight: 600; margin-bottom: 4px; color: var(--accent); }
.login-sub { font-size: 12px; color: var(--muted); margin-bottom: 20px; }

.row-actions { display: flex; gap: 6px; }
.inline-form { display: inline; }

.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 12px; }
.locked-state { background: var(--surface2); border: 1px dashed var(--border2); border-radius: 9px; padding: 30px; text-align: center; color: var(--muted); font-size: 12px; }

.app-footer { padding: 10px 26px 14px; font-size: 10px; color: var(--muted); font-family: var(--mono); border-top: 1px solid var(--border); background: var(--surface); display: flex; gap: 8px; align-items: center; }
.app-footer .app-version { color: var(--accent); font-weight: 500; }
.app-footer .sep { color: var(--border2); }

.login-footer { text-align: center; font-size: 10px; font-family: var(--mono); color: var(--muted); margin-top: 18px; }
