:root {
  --primary: #163252;
  --secondary: #2F80ED;
  --bg: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --text: #1F2937;
  --muted: #6B7280;
  --success: #22C55E;
  --warning: #F4B400;
  --danger: #EF4444;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(22, 50, 82, 0.08);
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  height: 100%;
}

a { color: var(--secondary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- layout ---------- */
#app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.topbar .brand span { color: var(--secondary); }
.topbar input {
  flex: 1;
  max-width: 420px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: #fff;
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
}
.topbar input::placeholder { color: rgba(255,255,255,0.6); }
.topbar .spacer { flex: 1; }

.quick-add-btn {
  background: var(--secondary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 14px;
}
.quick-add-btn:hover { filter: brightness(1.1); }

.nav {
  display: flex;
  gap: 2px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  overflow-x: auto;
  position: sticky;
  top: 52px;
  z-index: 40;
}
.nav a {
  padding: 12px 16px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav a.active { color: var(--primary); border-bottom-color: var(--secondary); }
.nav a .badge {
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  font-size: 11px;
  padding: 1px 7px;
  font-weight: 700;
}

main { flex: 1; padding: 16px; width: 100%; }

/* ---------- cards & sections ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 {
  font-size: 15px;
  color: var(--primary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2 .count {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.stat .num { font-size: 22px; font-weight: 700; color: var(--primary); }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat.alert .num { color: var(--danger); }
.stat.warn .num { color: var(--warning); }
.stat.good .num { color: var(--success); }

/* ---------- list items ---------- */
.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: none; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; font-size: 14px; }
.item .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.item .title a { color: var(--text); }
.item .title a:hover { color: var(--secondary); }

.empty { color: var(--muted); font-size: 13.5px; padding: 8px 4px; font-style: italic; }

/* ---------- pills / badges ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 10px;
  white-space: nowrap;
}
.pill.lead { background: #EFF6FF; color: var(--secondary); }
.pill.prospect { background: #FEF9E7; color: #B7791F; }
.pill.client { background: #F0FDF4; color: #15803D; }
.pill.past_client { background: var(--bg); color: var(--muted); }
.pill.fired, .pill.lost { background: #FEF2F2; color: var(--danger); }
.pill.stage { background: var(--bg); color: var(--primary); border: 1px solid var(--border); }
.pill.overdue { background: #FEF2F2; color: var(--danger); }
.pill.due { background: #FEF9E7; color: #B7791F; }
.pill.paid { background: #F0FDF4; color: #15803D; }
.pill.partial { background: #EFF6FF; color: var(--secondary); }
.pill.expected { background: var(--bg); color: var(--muted); }

.src-icon { font-size: 14px; width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; flex-shrink: 0; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13.5px;
  font-weight: 600;
}
.btn:hover { border-color: var(--secondary); color: var(--secondary); }
.btn.primary { background: var(--secondary); border-color: var(--secondary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger-outline { color: var(--danger); border-color: #FECACA; }
.btn.danger-outline:hover { background: #FEF2F2; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; border-radius: 6px; }
.btn.icon { padding: 4px 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- forms ---------- */
label.f { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
input.f, select.f, textarea.f {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
input.f:focus, select.f:focus, textarea.f:focus { border-color: var(--secondary); }
textarea.f { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(22, 50, 82, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 30px 12px;
  z-index: 100;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(22,50,82,0.25);
}
.modal h3 { color: var(--primary); font-size: 17px; margin-bottom: 6px; }

/* ---------- suggestions ---------- */
.suggestion {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0;
  font-size: 13.5px;
}
.suggestion .grow { flex: 1; }
.suggestion .kind { font-size: 10.5px; font-weight: 700; text-transform: uppercase; color: var(--secondary); }

/* ---------- timeline ---------- */
.timeline { position: relative; padding-left: 18px; }
.timeline::before {
  content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border);
}
.tl-event { position: relative; padding: 8px 0 8px 10px; }
.tl-event::before {
  content: ""; position: absolute; left: -17px; top: 14px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--secondary); border: 2px solid var(--surface);
}
.tl-event .when { font-size: 11.5px; color: var(--muted); }
.tl-event .what { font-size: 13.5px; margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.tl-event .tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; color: var(--secondary); margin-right: 6px; }

/* ---------- pipeline board ---------- */
.board { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.board .col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 210px;
  max-width: 240px;
  flex-shrink: 0;
  padding: 10px;
}
.board .col h4 { font-size: 12.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; }
.deal-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 13px;
}
.deal-card:hover { border-color: var(--secondary); }
.deal-card .val { color: var(--success); font-weight: 700; font-size: 12.5px; }

/* ---------- tables ---------- */
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; color: var(--muted); font-size: 12px; padding: 8px 6px; border-bottom: 2px solid var(--border); }
table.t td { padding: 9px 6px; border-bottom: 1px solid var(--border); }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--primary); color: #fff;
  padding: 10px 20px; border-radius: 8px;
  font-size: 14px; z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); }

/* ---------- misc ---------- */
.muted { color: var(--muted); }
.money { font-weight: 700; color: var(--primary); }
.danger-text { color: var(--danger); }
.flex { display: flex; align-items: center; gap: 8px; }
.right { margin-left: auto; }
.mt { margin-top: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.section-head h1 { font-size: 19px; color: var(--primary); }

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .topbar input { order: 3; max-width: 100%; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  main { padding: 10px; padding-bottom: 64px; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }

  /* hide top nav on mobile, use bottom tab bar instead */
  .nav { display: none; }
  .bottom-bar { display: flex; }
}

/* ---------- bottom tab bar (mobile only) ---------- */
.bottom-bar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 50;
  padding: 4px 0;
  padding-bottom: env(safe-area-inset-bottom, 4px);
}
.bottom-bar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  text-decoration: none;
  position: relative;
}
.bottom-bar a .icon { font-size: 20px; line-height: 1; }
.bottom-bar a.active { color: var(--secondary); }
.bottom-bar a .badge {
  position: absolute;
  top: 2px;
  left: 50%;
  margin-left: 6px;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  padding: 0 5px;
  font-weight: 700;
  min-width: 16px;
  text-align: center;
}
