/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:        #1a3e6f;
  --brand-light:  #2563a8;
  --accent:       #e6a817;
  --bg:           #f4f6f9;
  --surface:      #ffffff;
  --border:       #dde1e8;
  --text:         #1e2330;
  --muted:        #6b7280;
  --success:      #16a34a;
  --warning:      #d97706;
  --danger:       #dc2626;
  --info:         #2563eb;
  --radius:       6px;
  --shadow:       0 1px 4px rgba(0,0,0,.10);
  --nav-h:        56px;
  --sidebar-w:    240px;
  --logo-purple:  #a259f7;
}

[hidden] { display: none !important; }

body { font-family: system-ui, -apple-system, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ── Navigation (left sidebar) ── */
body.has-sidebar { padding-left: var(--sidebar-w); }

.sidenav { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--border); z-index: 100; }

.sidenav-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 22px 16px 18px; text-decoration: none; border-bottom: 1px solid var(--border); }
.sidenav-brand img { width: 96px; height: auto; display: block; }
.sidenav-title { font-size: 13px; font-weight: 700; color: var(--brand); letter-spacing: .2px; }

.sidenav-links { list-style: none; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidenav-links ul { list-style: none; }

/* Level 1: top links and group headers */
.nav-item span { white-space: nowrap; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-left: 3px solid transparent; border-radius: var(--radius); background: none; color: var(--text); text-decoration: none; font: inherit; font-size: 14px; font-weight: 500; text-align: left; cursor: pointer; transition: background .15s, color .15s; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--muted); }
.nav-item:hover { background: #f0f3f8; }
.nav-item.active { background: #eef0fb; color: var(--brand); font-weight: 600; border-left-color: var(--logo-purple); }
.nav-item.active svg, .nav-group.has-active > .nav-item svg { color: var(--logo-purple); }
.nav-group.has-active > .nav-item { color: var(--brand); font-weight: 600; }
.nav-chevron { margin-left: auto; display: flex; }
.nav-chevron svg { width: 14px; height: 14px; transition: transform .15s; }
.nav-group.open .nav-chevron svg { transform: rotate(90deg); }

/* Level 2: links inside a group */
.nav-sub { display: none; margin: 2px 0 6px 21px; padding-left: 10px; border-left: 1px solid var(--border); }
.nav-group.open .nav-sub { display: block; }
.nav-sub a { display: block; padding: 7px 10px; margin: 1px 0; border-radius: var(--radius); color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 500; }
.nav-sub a:hover { background: #f0f3f8; color: var(--text); }
.nav-sub a.active { background: #eef0fb; color: var(--brand); font-weight: 600; box-shadow: inset 3px 0 0 var(--logo-purple); }

.sidenav-user { border-top: 1px solid var(--border); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.sidenav-who { color: var(--text); font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidenav-who span { display: block; color: var(--muted); font-size: 11px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.sidenav-user button { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; font-size: 12px; cursor: pointer; font-family: inherit; }
.sidenav-user button:hover { background: #f0f3f8; }

/* Phone/tablet: sidebar becomes a top bar with a slide-out menu */
.sidenav-topbar { display: none; }
@media (max-width: 800px) {
  body.has-sidebar { padding-left: 0; }
  .sidenav-topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; position: sticky; top: 0; height: var(--nav-h); padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 110; }
  .sidenav-topbar img { height: 34px; width: auto; display: block; }
  .sidenav-toggle { background: none; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; font-size: 18px; line-height: 1; cursor: pointer; color: var(--brand); }
  .sidenav { top: var(--nav-h); transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 16px rgba(0,0,0,.12); }
  .sidenav-brand { display: none; }
  body.sidebar-open .sidenav { transform: none; }
}

/* ── Layout ── */
.page-wrap { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 22px; font-weight: 700; color: var(--brand); }
.page-header p { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 18px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid transparent; transition: opacity .15s, background .15s; }
.btn:hover { opacity: .88; }
.btn-primary   { background: var(--brand-light); color: #fff; }
.btn-success   { background: var(--success); color: #fff; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost     { background: transparent; color: var(--muted); border-color: transparent; }
.btn-sm        { padding: 4px 10px; font-size: 12px; }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; color: var(--text); background: var(--surface); font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-light); border-color: var(--brand-light); }
textarea { resize: vertical; min-height: 80px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: #f0f3f8; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover td { background: #f7f9fc; cursor: pointer; }

/* ── Status badges ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.badge-new        { background: #dbeafe; color: #1e40af; }
.badge-contacted  { background: #fef3c7; color: #92400e; }
.badge-qualified  { background: #d1fae5; color: #065f46; }
.badge-proposal   { background: #ede9fe; color: #5b21b6; }
.badge-negotiation{ background: #ffedd5; color: #9a3412; }
.badge-won        { background: #d1fae5; color: #065f46; }
.badge-lost       { background: #fee2e2; color: #991b1b; }
.badge-active     { background: #d1fae5; color: #065f46; }
.badge-inactive   { background: #f3f4f6; color: #6b7280; }
.badge-call       { background: #dbeafe; color: #1e40af; }
.badge-email      { background: #d1fae5; color: #065f46; }
.badge-meeting    { background: #ede9fe; color: #5b21b6; }
.badge-demo       { background: #fef3c7; color: #92400e; }
.badge-other      { background: #f3f4f6; color: #6b7280; }

/* ── Stat cards ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; border-top: 3px solid var(--brand-light); }
.stat-card.green  { border-top-color: var(--success); }
.stat-card.amber  { border-top-color: var(--warning); }
.stat-card.red    { border-top-color: var(--danger); }
.stat-card.purple { border-top-color: #7c3aed; }
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1.1; margin-top: 4px; }

/* ── Toolbar ── */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fafbfc; border-radius: var(--radius) var(--radius) 0 0; }
.toolbar-search { flex: 1; min-width: 160px; }
.toolbar-search input { padding: 7px 10px; }
.toolbar select { width: auto; min-width: 150px; }

/* ── Modal ── */
.modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; align-items: flex-start; justify-content: center; padding-top: 60px; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border-radius: 8px; box-shadow: 0 8px 32px rgba(0,0,0,.25); width: 100%; max-width: 640px; max-height: 85vh; overflow-y: auto; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.btn-close { background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1; }

/* ── Alerts ── */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.alert-danger   { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-state p { font-size: 15px; }

/* ── Utilities ── */
.text-muted  { color: var(--muted); }
.text-right  { text-align: right; }
.mt-4        { margin-top: 16px; }
.flex        { display: flex; }
.gap-2       { gap: 8px; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--brand-light); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Sign-in page ── */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px 18px 16px; color: var(--brand); font-weight: 700; border-bottom: 1px solid var(--border); }
.auth-brand img { width: 110px; height: auto; }
.auth-submit { width: 100%; justify-content: center; padding: 9px 14px; }
.auth-submit:disabled { opacity: .6; cursor: wait; }
.auth-lead { color: var(--muted); font-size: 13px; line-height: 1.5; margin-bottom: 16px; text-align: center; }
.auth-sent { text-align: center; }
.auth-sent h2 { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.auth-sent p { font-size: 13px; line-height: 1.55; margin-top: 8px; }
.auth-sent-icon { width: 48px; height: 48px; margin: 4px auto 12px; border-radius: 50%; background: #eef0fb; color: var(--logo-purple); display: flex; align-items: center; justify-content: center; }
.auth-sent-icon svg { width: 24px; height: 24px; }
.link-button { background: none; border: 0; padding: 0; color: var(--brand-light); font: inherit; text-decoration: underline; cursor: pointer; }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 16px; font: inherit; font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); font-weight: 600; border-bottom-color: var(--logo-purple); }
.tab:focus-visible { outline: 2px solid var(--brand-light); outline-offset: -2px; border-radius: var(--radius) var(--radius) 0 0; }
