/* =========================================================
   CRM Design System — "Pipeline" direction
   Display: Sora | Body: Inter | Data/mono: IBM Plex Mono
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700;800&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #0b1526;
  --ink-soft: #16233d;
  --ink-line: #24334f;

  --canvas: #f3f5f9;
  --card: #ffffff;
  --border: #e4e8f0;

  --signal: #2f6fed;
  --signal-dark: #2158c9;
  --signal-soft: #eaf1ff;
  --momentum: #7c5cfc;
  --momentum-soft: #f1edff;
  --won: #10b981;
  --won-soft: #e7f9f1;
  --risk: #f59e0b;
  --risk-soft: #fef3e2;
  --lost: #ef4444;
  --lost-soft: #fdeaea;

  --text: #101828;
  --text-soft: #667085;
  --text-faint: #98a2b3;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16,24,40,0.04), 0 4px 16px rgba(16,24,40,0.06);
  --shadow-lg: 0 8px 30px rgba(16,24,40,0.10);
  --topbar-h: 54px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--canvas);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: 'Sora', sans-serif; letter-spacing: -0.01em; margin: 0 0 4px; }
.mono, .stat-num, .data-table td.num { font-family: 'IBM Plex Mono', monospace; }

a { color: var(--signal); }

@media (prefers-reduced-motion: no-preference) {
  .card-anim { animation: riseIn 0.45s ease both; }
  @keyframes riseIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
}

/* ---------- Auth page ---------- */
.auth-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px;
  background: radial-gradient(1100px 500px at 15% -10%, #16233d 0%, var(--ink) 55%, #060b14 100%);
}
.auth-card {
  background: var(--card);
  border-radius: 20px;
  padding: 36px 30px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.auth-card h1 { text-align: center; font-size: 1.5rem; margin-bottom: 22px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--ink);
  color: #fff;
  padding: 14px 20px;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--ink-line);
}
.topbar-title { font-family: 'Sora', sans-serif; font-weight: 700; font-size: 1.05rem; flex: 1; letter-spacing: -0.01em; }
.topbar-user { font-size: 0.85rem; color: #b8c2d9; }
.topbar-user a { color: #fff; text-decoration: none; opacity: 0.85; }
.topbar-user a:hover { opacity: 1; }
.nav-toggle {
  display: inline-block;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
}

/* ---------- Layout ---------- */
.app-layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidenav {
  width: 232px;
  background: var(--ink);
  border-right: 1px solid var(--ink-line);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 2px;
  position: sticky;
  top: var(--topbar-h);
  align-self: flex-start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.sidenav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: #aab6cc;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.sidenav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.sidenav a:hover { background: var(--ink-soft); color: #fff; }
.sidenav a.active { background: var(--signal); color: #fff; }
.main-content { flex: 1; padding: 28px 32px; min-width: 0; }

@media (max-width: 768px) {
  .sidenav {
    position: fixed; left: -260px; top: 54px; bottom: 0; z-index: 15;
    transition: left 0.2s ease; box-shadow: 2px 0 16px rgba(0,0,0,0.25); width: 220px;
  }
  .sidenav.open { left: 0; }
  .main-content { padding: 16px; }
}
@media (min-width: 769px) { .nav-toggle { display: none; } }

/* ---------- Dashboard hero / KPI ---------- */
.dash-hero { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.dash-hero h1 { font-size: 1.6rem; }
.dash-hero p { color: var(--text-soft); margin: 0; font-size: 0.92rem; }
.dash-date { font-family: 'IBM Plex Mono', monospace; font-size: 0.78rem; color: var(--text-faint); background: #fff; border: 1px solid var(--border); padding: 6px 12px; border-radius: 20px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
@media (max-width: 900px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--accent, var(--signal));
}
.kpi-label { font-size: 0.78rem; color: var(--text-soft); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-family: 'IBM Plex Mono', monospace; font-size: 1.9rem; font-weight: 600; margin-top: 6px; color: var(--text); }
.kpi-sub { font-size: 0.78rem; color: var(--text-faint); margin-top: 4px; }
.kpi-sub.up { color: var(--won); }
.kpi-sub.down { color: var(--lost); }

/* ---------- Panels / charts ---------- */
.panel-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 1000px) { .panel-grid { grid-template-columns: 1fr; } }
.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow);
}
.panel-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; flex-wrap: wrap; gap: 6px; }
.panel-header h2 { font-size: 1.02rem; }
.panel-header .panel-sub { font-size: 0.8rem; color: var(--text-faint); }
.chart-wrap { position: relative; width: 100%; }

.legend-row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 0.78rem; color: var(--text-soft); }
.legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

/* ---------- Activity feed ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 0.85rem; }
.feed li:last-child { border-bottom: none; }
.feed-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--signal); margin-top: 5px; flex-shrink: 0; }
.feed-text b { font-weight: 600; }
.feed-time { color: var(--text-faint); font-size: 0.74rem; font-family: 'IBM Plex Mono', monospace; }

/* ---------- Forms ---------- */
label { display: block; margin: 11px 0 4px; font-weight: 600; font-size: 0.82rem; color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: 'Inter', sans-serif;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft);
}
textarea { resize: vertical; }

.form-page-wrap { display: flex; justify-content: center; padding-top: 4px; }
.form-card, .search-form {
  background: var(--card);
  padding: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  max-width: 640px;
  width: 100%;
  overflow: hidden;
}
.form-card-header {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 26px; background: linear-gradient(135deg, var(--ink) 0%, #1a2b4a 100%); color: #fff;
}
.form-card-header .fch-icon {
  width: 38px; height: 38px; border-radius: 10px; background: rgba(255,255,255,0.12);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.form-card-header .fch-icon svg { width: 20px; height: 20px; stroke: #fff; }
.form-card-header h1 { font-size: 1.08rem; margin: 0; color: #fff; }
.form-card-header p { margin: 2px 0 0; font-size: 0.78rem; color: #b8c2d9; }
.form-card-body { padding: 20px 26px 26px; }
.form-card label:first-of-type { margin-top: 0; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.search-form { display: flex; gap: 8px; margin-bottom: 18px; max-width: none; padding: 0; border: none; background: none; box-shadow: none; }
.search-form input { flex: 1; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
}
.btn:hover { box-shadow: var(--shadow); }
.btn-primary { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn-primary:hover { background: var(--signal-dark); }
.btn-secondary { background: #fff; }
.btn-block { width: 100%; margin-top: 8px; }
.link-btn { background: none; border: none; color: var(--signal); cursor: pointer; padding: 0; font-size: 0.88rem; font-weight: 600; }
.link-danger { color: var(--lost); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.88rem; }
.data-table th { background: #f8f9fc; font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-soft); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafbfd; }
.actions a, .actions form { display: inline-block; margin-right: 10px; }

@media (max-width: 640px) {
  .table-wrap { background: none; border: none; box-shadow: none; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr { margin-bottom: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; background: var(--card); box-shadow: var(--shadow); }
  .data-table td { border: none; padding: 6px 0; display: flex; justify-content: space-between; gap: 10px; }
  .data-table td::before { content: attr(data-label); font-weight: 600; color: var(--text-soft); }
}

/* ---------- Misc ---------- */
.page-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.page-header h1 { font-size: 1.4rem; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.stat-num { display: block; font-size: 1.8rem; font-weight: 600; color: var(--signal); }
.stat-label { font-size: 0.82rem; color: var(--text-soft); margin-top: 2px; }

.alert { padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.88rem; font-weight: 500; }
.alert-success { background: var(--won-soft); color: #0a6b4f; border: 1px solid #b7ecd8; }
.alert-error { background: var(--lost-soft); color: #b42318; border: 1px solid #f6c6c3; }

.badge { display: inline-block; padding: 4px 11px; border-radius: 20px; background: #eee; font-size: 0.74rem; font-weight: 600; }
.badge-new, .badge-prospecting { background: var(--signal-soft); color: var(--signal-dark); }
.badge-contacted, .badge-qualifying { background: var(--risk-soft); color: #92400e; }
.badge-qualified, .badge-proposal { background: var(--momentum-soft); color: #5b3fd6; }
.badge-unqualified, .badge-closed_lost { background: var(--lost-soft); color: #b42318; }
.badge-converted, .badge-closed_won { background: var(--won-soft); color: #0a6b4f; }
.badge-active { background: var(--won-soft); color: #0a6b4f; }
.badge-inactive { background: #eee; color: var(--text-soft); }
.badge-negotiation { background: #fff4de; color: #92400e; }

.pagination { display: flex; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.pagination a { padding: 7px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); text-decoration: none; color: var(--text); background: #fff; font-size: 0.85rem; font-weight: 500; }
.pagination a.active { background: var(--signal); color: #fff; border-color: var(--signal); }
