:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f4f6fa;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #111827;
  color: #f1f5f9;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  flex-shrink: 0;
}
.brand { font-weight: 700; font-size: 18px; padding: 0 20px 20px; }
.sidebar nav { display: flex; flex-direction: column; flex: 1; }
.sidebar nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 12px 20px;
  font-size: 14px;
}
.sidebar nav a:hover, .sidebar nav a.active {
  background: #1f2937;
  color: #fff;
  border-left: 3px solid var(--primary);
}
.sidebar-footer { padding: 16px 20px; border-top: 1px solid #1f2937; font-size: 13px; }
.sidebar-footer .me { margin-bottom: 8px; color: #e2e8f0; }
.sidebar-footer .me small { color: #94a3b8; }
.sidebar-footer .logout { color: #f87171; text-decoration: none; }

.content { flex: 1; padding: 32px 40px; max-width: 1200px; }

h1 { margin: 0 0 4px; font-size: 26px; }
h2 { font-size: 18px; margin: 32px 0 12px; color: var(--text); }
.subtitle { color: var(--text-muted); margin: 0 0 20px; }
.welcome { color: var(--text-muted); margin-top: 0; }

/* Stat cards */
.stat-cards { display: flex; gap: 16px; margin: 20px 0 32px; flex-wrap: wrap; }
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 24px;
  min-width: 150px;
}
.stat-card .num { font-size: 28px; font-weight: 700; }
.stat-card .label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.stat-card.overdue .num { color: var(--danger); }
.stat-card.today .num { color: var(--warning); }

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.data-table th, .data-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.data-table th { background: #f8fafc; font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.data-table tr:last-child td { border-bottom: none; }
.data-table a { color: var(--primary); text-decoration: none; font-weight: 500; }
.row-overdue { background: #fef2f2; }
.row-today { background: #fffbeb; }
.note-cell { max-width: 220px; color: var(--text-muted); }
.empty-state { padding: 24px; text-align: center; color: var(--text-muted); }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  background: #e2e8f0;
  color: #334155;
  margin-left: 6px;
}
.status-lead { background: #dbeafe; color: #1d4ed8; }
.status-active { background: #dcfce7; color: #15803d; }
.status-closed { background: #f1f5f9; color: #64748b; }
.priority-high { background: #fee2e2; color: #b91c1c; }
.priority-medium { background: #fef3c7; color: #b45309; }
.priority-low { background: #e0f2fe; color: #0369a1; }
.fstatus-pending { background: #fef3c7; color: #b45309; }
.fstatus-completed { background: #dcfce7; color: #15803d; }
.fstatus-missed { background: #fee2e2; color: #b91c1c; }

/* Forms */
.filter-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-bar input, .filter-bar select { padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
.filter-bar input[type="text"] { flex: 1; min-width: 200px; }

.form-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  max-width: 720px;
}
.inline-form { max-width: none; margin-bottom: 24px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-grid label.grow { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 14px; }
input, select, textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  font-weight: 400;
}
textarea { resize: vertical; }
fieldset.followup-fieldset { border: 1px dashed var(--border); border-radius: 8px; margin: 10px 0 20px; padding: 14px; }
legend { font-size: 13px; color: var(--text-muted); padding: 0 6px; }

.form-actions { display: flex; gap: 10px; align-items: center; }

button, .btn-secondary, .btn-small, .btn-danger {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  text-decoration: none;
  display: inline-block;
}
button[type="submit"], button:not(.btn-small):not(.btn-danger):not(.btn-secondary) {
  background: var(--primary);
  color: #fff;
}
button[type="submit"]:hover { background: var(--primary-dark); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-small { padding: 5px 10px; font-size: 12px; background: #e2e8f0; color: var(--text); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }

/* Detail page */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.detail-field { background: var(--card-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; font-size: 14px; }
.detail-field strong { display: block; font-size: 11px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }
.notes-box { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 14px 16px; margin-bottom: 10px; font-size: 14px; }

/* Auth pages */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px;
  width: 100%;
  max-width: 380px;
}
.auth-box h1 { text-align: center; margin-bottom: 4px; }
.auth-box .subtitle { text-align: center; }
.auth-box form { display: flex; flex-direction: column; }
.auth-box button { margin-top: 8px; }
.error { color: var(--danger); background: #fef2f2; padding: 10px 14px; border-radius: 6px; font-size: 14px; }
.success { color: var(--success); background: #f0fdf4; padding: 10px 14px; border-radius: 6px; font-size: 14px; }
