/* ============================================================
   SimpleCRM — design system
   ============================================================ */

:root {
  /* Color */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-hover: #f9fafb;
  --border: #e6e9ef;
  --border-strong: #d6dae2;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-border: #c7d2fe;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;

  --success: #16a34a;
  --success-soft: #ecfdf5;
  --success-border: #a7f3d0;

  --warning: #b45309;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;

  /* Shape */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.07), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 20px -4px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.06);

  /* Motion */
  --fast: 120ms ease;
  --normal: 180ms ease;
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top nav ─────────────────────────────────────────────── */
header.topnav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.75rem;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
header.topnav .brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--text);
  flex-shrink: 0;
}
header.topnav .brand::before {
  content: '';
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: inline-block;
  background: linear-gradient(135deg, var(--primary), #818cf8);
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.4);
}
header.topnav nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}
header.topnav nav a {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.875rem;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  transition: background var(--fast), color var(--fast);
  white-space: nowrap;
}
header.topnav nav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
header.topnav nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
header.topnav .nav-user {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding-right: 0.25rem;
  white-space: nowrap;
}

main {
  max-width: 1160px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0.25rem 0 1.25rem;
  color: var(--text);
}
h2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 1.75rem 0 1rem;
  color: var(--text);
}

/* ── Cards / panels ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* ── Forms ───────────────────────────────────────────────── */
form.inline-form { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }

/* ── Read-only detail grid (profile / tenant info) ──────────*/
.detail-grid { display: flex; flex-wrap: wrap; gap: 1.25rem 2rem; margin: 0.75rem 0; }
.detail-grid .field { min-width: 11rem; }
.detail-grid .field > div { font-size: 0.9rem; }

input, select, textarea {
  font: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  min-width: 10rem;
  transition: border-color var(--fast), box-shadow var(--fast);
}
input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { min-height: 4rem; }
::placeholder { color: var(--text-faint); }

/* ── Buttons ─────────────────────────────────────────────── */
button, .btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.55rem 1.05rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25);
  transition: background var(--fast), box-shadow var(--fast), transform var(--fast), border-color var(--fast);
}
button:hover, .btn:hover { background: var(--primary-hover); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}
button.secondary:hover { background: var(--bg); border-color: var(--text-faint); }

button.danger {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  box-shadow: none;
}
button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.error { color: var(--danger); margin: 0.5rem 0; font-size: 0.875rem; font-weight: 500; }
.hint { color: var(--text-muted); font-size: 0.85rem; }

/* ── Tables ──────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  text-transform: uppercase;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 0.6rem 0.65rem;
  border-bottom: 1px solid var(--border);
}
td {
  text-align: left;
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.885rem;
}
tbody tr { transition: background var(--fast); }
tbody tr:hover { background: var(--surface-hover); }
tr:last-child td { border-bottom: none; }

/* ── Kanban deals board ──────────────────────────────────── */
.board { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 0.75rem; }
.board-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 230px;
  flex: 1 1 230px;
  padding: 0.9rem;
  box-shadow: var(--shadow-sm);
}
.board-col h3 {
  margin: 0 0 0.75rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.deal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.65rem;
  font-size: 0.88rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--normal), transform var(--normal), border-color var(--normal);
}
.deal-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); border-color: var(--border-strong); }
.deal-card .value { color: var(--success); font-weight: 700; }
.deal-card select { width: 100%; margin-top: 0.5rem; min-width: 0; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}
.badge-meeting { background: var(--primary-soft); border-color: var(--primary-border); color: var(--primary); }
.badge-action_item { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning); }
.badge-lesson_learned { background: var(--success-soft); border-color: var(--success-border); color: var(--success); }

/* ── Row actions / inline edit ──────────────────────────────*/
.row-actions { display: flex; gap: 0.4rem; }
.row-actions button { padding: 0.4rem 0.75rem; font-size: 0.8rem; }
td input, td select { width: 100%; min-width: 8rem; }

/* ── Search box ──────────────────────────────────────────── */
.search-box { margin-bottom: 1rem; }
.search-box input { width: 100%; max-width: 340px; }

/* ── Notes ───────────────────────────────────────────────── */
.notes-panel {
  margin-top: 0.65rem;
  padding: 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.note { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.note:last-of-type { border-bottom: none; }
.note-meta { font-size: 0.78rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.note-meta button { padding: 0.15rem 0.5rem; font-size: 0.72rem; margin-left: auto; }
.note-body { font-size: 0.9rem; margin-top: 0.3rem; white-space: pre-wrap; color: var(--text); }
.note-form { display: flex; gap: 0.5rem; margin-top: 0.65rem; align-items: flex-start; flex-wrap: wrap; }
.note-form textarea { flex: 1; min-height: 2.4rem; min-width: 12rem; }
.note-form select { min-width: 9rem; }
.note-form input[type="date"] { min-width: 9rem; }
.note-form input[type="text"] { min-width: 9rem; }

/* ── Dashboard stat tiles ────────────────────────────────── */
.stats-grid { display: flex; flex-wrap: wrap; gap: 1rem; }
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.3rem;
  min-width: 150px;
  flex: 1 1 150px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--normal), transform var(--normal), border-color var(--normal);
}
.stat-tile .stat-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.stat-tile .stat-label { color: var(--text-muted); font-size: 0.82rem; font-weight: 500; margin-top: 0.25rem; }
a.stat-tile { display: block; color: inherit; text-decoration: none; }
a.stat-tile:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-2px); text-decoration: none; }
.stage-breakdown { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.85rem; }

/* ── CRM Agent chat ──────────────────────────────────────── */
.chat-window {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 16rem;
  max-height: 32rem;
  overflow-y: auto;
  padding: 0.25rem 0.25rem 0.5rem;
}
.chat-message { max-width: 80%; }
.chat-message.chat-user { align-self: flex-end; }
.chat-message.chat-assistant { align-self: flex-start; }
.chat-role { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.2rem; }
.chat-message.chat-user .chat-role { text-align: right; }
.chat-bubble { border-radius: var(--radius); padding: 0.6rem 0.85rem; font-size: 0.9rem; white-space: pre-wrap; }
.chat-user .chat-bubble { background: var(--primary); color: #fff; }
.chat-assistant .chat-bubble { background: var(--bg); border: 1px solid var(--border); color: var(--text); }
.chat-form { display: flex; gap: 0.6rem; margin-top: 1rem; align-items: flex-end; }
.chat-form textarea { flex: 1; min-height: 2.6rem; resize: vertical; }
.budget-bar { height: 6px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); overflow: hidden; margin-top: 0.4rem; }
.budget-bar-fill { height: 100%; background: var(--primary); transition: width var(--normal); }
.budget-bar-fill.budget-full { background: var(--danger); }
