/* ============================================================
   AlphaLenz — Design System
   ============================================================ */

:root {
  --primary: #246084;
  --primary-dark: #285772;
  --secondary: #89acc0;
  --bg: #fdfeff;
  --surface: #fdfdfa;
  --text: #010101;
  --text-muted: #b7b7b7;
  --accent: #4ac7aa;
  --accent-light: #b1eade;
  --accent-pale: #e1f6f1;
  --gold: #f0a500;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #16a34a;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.08), 0 8px 32px rgba(0,0,0,0.06);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── LOGIN SCREEN ─────────────────────────────────────── */
#loginScreen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.login-box {
  background: white; border-radius: var(--radius-lg);
  padding: 48px 40px; width: 400px; max-width: 92%;
  text-align: center; box-shadow: 0 24px 80px rgba(0,0,0,0.3);
}
.login-box h1 { font-size: 28px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.login-box .subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }
.login-input {
  width: 100%; padding: 12px 16px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit;
  margin-bottom: 12px; outline: none;
  transition: border-color 0.15s;
}
.login-input:focus { border-color: var(--accent); }
.login-btn {
  width: 100%; padding: 12px;
  background: var(--primary); color: white;
  border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  transition: background 0.18s;
}
.login-btn:hover { background: var(--primary-dark); }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.login-error { color: var(--danger); font-size: 12px; margin-top: 10px; min-height: 18px; }
.totp-input {
  width: 200px; padding: 14px 20px;
  border: 2px solid var(--border); border-radius: var(--radius);
  font-size: 24px; font-weight: 700;
  text-align: center; letter-spacing: 8px;
  font-family: monospace; outline: none;
  margin: 16px auto; display: block;
}
.totp-input:focus { border-color: var(--accent); }
#totpStep { display: none; }

/* ── HEADER ───────────────────────────────────────────── */
#appContainer { display: none; }
.header {
  background: var(--primary); padding: 0 40px;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; border-bottom: 2px solid var(--accent);
  position: sticky; top: 0; z-index: 100;
}
.logo { font-size: 20px; font-weight: 700; color: white; letter-spacing: 0.01em; white-space: nowrap; }
.logo-sub { font-size: 11px; color: rgba(255,255,255,0.5); margin-left: 8px; font-weight: 400; }
.header-meta {
  font-size: 11px; color: rgba(255,255,255,0.45);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.header-meta strong { color: var(--accent-light); font-weight: 500; }
.header-right { display: flex; align-items: center; gap: 12px; }
.view-toggle { display: flex; border-radius: 20px; overflow: hidden; border: 1.5px solid rgba(255,255,255,0.2); }
.view-toggle button {
  padding: 5px 14px; border: none; font-size: 11px;
  font-weight: 600; cursor: pointer; font-family: inherit;
  background: transparent; color: rgba(255,255,255,0.5);
  transition: all 0.15s;
}
.view-toggle button.active { background: var(--accent); color: var(--primary-dark); }
.user-email { font-size: 11px; color: rgba(255,255,255,0.5); }
.sign-out-btn {
  padding: 5px 12px; border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-sm); background: transparent;
  color: rgba(255,255,255,0.6); font-size: 11px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.sign-out-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.sync-badge {
  font-size: 10px; background: var(--warning); color: white;
  padding: 2px 8px; border-radius: 10px; font-weight: 700;
  display: none;
}

/* ── NAV ──────────────────────────────────────────────── */
.nav {
  background: var(--primary-dark); padding: 0 40px;
  display: flex; gap: 2px;
  border-bottom: 1px solid rgba(74,199,170,0.15);
  overflow-x: auto;
}
.nav-btn {
  padding: 12px 16px; font-size: 11px; font-weight: 600;
  color: rgba(255,255,255,0.5); background: transparent;
  border: none; cursor: pointer; letter-spacing: 0.05em;
  text-transform: uppercase; transition: all 0.18s;
  border-bottom: 2px solid transparent; white-space: nowrap;
  font-family: inherit;
}
.nav-btn:hover { color: var(--accent-light); }
.nav-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── LAYOUT ───────────────────────────────────────────── */
.main { padding: 24px 40px; max-width: 1440px; margin: 0 auto; }
.section { display: none; }
.section.active { display: block; }
.page-title { margin-bottom: 20px; }
.page-title h2 { font-size: 22px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.page-title p { font-size: 13px; color: var(--text-muted); }

/* ── CARDS ────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 20px;
  border: 1px solid var(--border-light);
}
.card-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border-light); gap: 16px;
}
.card-header h3 { font-size: 16px; font-weight: 700; color: var(--primary); }
.card-header p { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* ── METRIC CARDS ─────────────────────────────────────── */
.metrics-row { display: grid; grid-template-columns: repeat(5,1fr); gap: 14px; margin-bottom: 24px; }
.metric-card {
  background: var(--surface); border-radius: var(--radius);
  padding: 20px 18px; box-shadow: var(--shadow);
  border-top: 3px solid var(--accent); transition: box-shadow 0.2s;
  border: 1px solid var(--border-light);
}
.metric-card:hover { box-shadow: var(--shadow-hover); }
.metric-card .label {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-muted); margin-bottom: 10px;
}
.metric-card .value { font-size: 26px; font-weight: 700; color: var(--primary); line-height: 1; margin-bottom: 6px; }
.metric-card .benchmark { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── TABLES ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  background: var(--primary); color: rgba(255,255,255,0.8);
  padding: 10px 12px; text-align: left; font-weight: 600;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  white-space: nowrap; cursor: pointer; user-select: none;
}
thead th:hover { background: var(--primary-dark); color: var(--accent-light); }
thead th.sort-asc::after { content: ' ▲'; color: var(--accent); font-size: 9px; }
thead th.sort-desc::after { content: ' ▼'; color: var(--accent); font-size: 9px; }
tbody tr { border-bottom: 1px solid var(--border-light); transition: background 0.1s; }
tbody tr:hover { background: var(--accent-pale); }
tbody td { padding: 10px 12px; vertical-align: middle; }

/* ── Z-SCORE HEAT CELLS ───────────────────────────────── */
.z-high  { background: var(--accent); color: #085041; font-weight: 600; }
.z-mid-h { background: var(--accent-light); color: #085041; }
.z-neut  { background: #f8f8f8; color: var(--text); }
.z-mid-l { background: #fee2e2; color: #991b1b; }
.z-low   { background: #fca5a5; color: #991b1b; font-weight: 600; }

/* ── SIGNAL BADGES ────────────────────────────────────── */
.signal-badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
}
.signal-early   { background: #dbeafe; color: #1d4ed8; }
.signal-intact  { background: #dcfce7; color: #166534; }
.signal-breaking{ background: #fef3c7; color: #92400e; }
.signal-exit    { background: #fee2e2; color: #991b1b; }
.signal-skip    { background: #f3f4f6; color: #6b7280; }

/* ── PORTFOLIO BADGES ─────────────────────────────────── */
.port-badge {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
}
.port-core { background: #dbeafe; color: var(--primary); }
.port-sat  { background: var(--accent-pale); color: #085041; }
.port-gold { background: #fef3c7; color: #92400e; }
.port-cash { background: #f3f4f6; color: #6b7280; }

/* ── BUTTONS ──────────────────────────────────────────── */
.btn {
  padding: 9px 18px; border-radius: var(--radius-sm); border: none;
  cursor: pointer; font-family: inherit; font-size: 12px; font-weight: 600;
  transition: all 0.18s; display: inline-flex; align-items: center;
  gap: 6px; letter-spacing: 0.01em;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-accent:hover { background: #3db89a; }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 11px; }

/* ── FORMS ────────────────────────────────────────────── */
.form-label {
  display: block; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); margin-bottom: 5px;
}
.form-input {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13px; color: var(--text);
  background: white; outline: none; transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--accent); }
.form-grid { display: grid; gap: 14px; }
.form-grid.cols2 { grid-template-columns: 1fr 1fr; }
.form-grid.cols3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── STATUS MESSAGES ──────────────────────────────────── */
.status-msg {
  padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; margin-bottom: 16px; display: none;
}
.status-msg.success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.status-msg.error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.status-msg.info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── DROP ZONE ────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 40px 24px; text-align: center; cursor: pointer;
  transition: all 0.2s; background: var(--bg); margin-bottom: 16px;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: var(--accent-pale); }

/* ── SELL SIGNAL BANNER ───────────────────────────────── */
.sell-banner {
  background: #991b1b; color: white; padding: 14px 24px;
  border-radius: var(--radius); margin-bottom: 16px;
  display: flex; align-items: center; gap: 12px;
  font-weight: 600; font-size: 13px;
}
.sell-banner .dismiss {
  margin-left: auto; background: rgba(255,255,255,0.2);
  border: none; color: white; padding: 4px 12px; border-radius: 4px;
  cursor: pointer; font-size: 11px; font-family: inherit;
}

/* ── SECTOR CHUNKS ────────────────────────────────────── */
.sector-block { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
.sector-header {
  padding: 12px 16px; background: #f8fafc; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; font-size: 13px; color: var(--primary);
  transition: background 0.15s;
}
.sector-header:hover { background: var(--accent-pale); }
.sector-body { display: none; }
.sector-block.expanded .sector-body { display: block; }
.sector-winner { border-left: 3px solid var(--gold); }

/* ── WORKSPACE STEPS ──────────────────────────────────── */
.ws-steps { display: flex; flex-direction: column; gap: 12px; }
.ws-step {
  background: var(--surface); border-radius: var(--radius);
  border: 1.5px solid var(--border); box-shadow: var(--shadow);
  overflow: hidden; transition: border-color 0.2s;
}
.ws-step.ws-step-locked { opacity: .5; pointer-events: none; }
.ws-step.ws-step-active { border-color: var(--accent); }
.ws-step.ws-step-done { border-color: var(--success); }
.ws-step-header {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px; cursor: pointer; transition: background 0.15s;
}
.ws-step-header:hover { background: var(--accent-pale); }
.ws-step-num {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary); color: white;
  font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ws-step-done .ws-step-num { background: var(--success); }
.ws-step-active .ws-step-num { background: var(--accent); color: var(--primary-dark); }
.ws-step-info { flex: 1; }
.ws-step-title { font-weight: 600; font-size: 14px; color: var(--primary); }
.ws-step-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.ws-step-status { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px; }
.ws-step-chevron { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.ws-step-body { padding: 0 20px 20px; border-top: 1px solid var(--border-light); }

/* ── CRM ──────────────────────────────────────────────── */
.crm-client-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; border-bottom: 1px solid var(--border-light);
  cursor: pointer; transition: background 0.15s;
}
.crm-client-row:hover { background: var(--accent-pale); }
.crm-client-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--primary); color: white;
  font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.crm-client-name { font-weight: 600; font-size: 14px; color: var(--primary); }
.crm-client-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.crm-client-info { flex: 1; }
.crm-review-badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.crm-review-badge.overdue { background: #fee2e2; color: var(--danger); }
.crm-review-badge.due-week { background: #fff7ed; color: #c2410c; }
.crm-review-badge.due-fortnight { background: #fef3c7; color: var(--warning); }
.crm-review-badge.ok { background: #dcfce7; color: var(--success); }
.crm-review-badge.none { background: var(--border-light); color: var(--text-muted); }

/* ── MODALS ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(36,96,132,0.5);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; backdrop-filter: blur(4px);
}
.modal-box {
  background: white; border-radius: var(--radius-lg);
  padding: 28px; width: 90%; max-width: 640px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  max-height: 90vh; overflow-y: auto;
}

/* ── CLIENT VIEW ──────────────────────────────────────── */
.advisor-only {}
.client-only { display: none; }
body.client-mode .advisor-only { display: none !important; }
body.client-mode .client-only { display: block !important; }
body.client-mode .nav { display: none !important; }
body.client-mode .header-meta { display: none !important; }

/* ── POSITIVE / NEGATIVE ──────────────────────────────── */
.pos { color: var(--success); font-weight: 500; }
.neg { color: var(--danger); font-weight: 500; }

/* ── EMPTY STATE ──────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; }
.empty-state .icon { font-size: 40px; margin-bottom: 16px; }
.empty-state .title { font-size: 20px; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.empty-state .desc { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }

/* ── SCROLLBARS ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--border-light); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }

/* ── PRINT ────────────────────────────────────────────── */
@media print {
  .header, .nav, .view-toggle, .sign-out-btn, .btn { display: none !important; }
  .main { padding: 0; }
  body.client-mode .client-only { display: block !important; }
}

/* ── RESPONSIVE ───────────────────────────────────────── */
@media (max-width: 900px) {
  .main { padding: 16px; }
  .metrics-row { grid-template-columns: repeat(2,1fr); }
  .header { padding: 0 16px; height: auto; min-height: 56px; flex-wrap: wrap; }
  .nav { padding: 0 16px; }
  .form-grid.cols3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .main { padding: 12px 10px; }
  .metrics-row { grid-template-columns: 1fr; }
  .form-grid.cols2, .form-grid.cols3 { grid-template-columns: 1fr; }
  .nav-btn { padding: 10px 10px; font-size: 10px; }
  .header-meta { display: none; }
}
