:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e3e5e9;
  --text: #1c1f26;
  --muted: #6b7280;
  --primary: #2a5d8f;
  --primary-dark: #1f4771;
  --accent: #d97a3d;
  --danger: #c0392b;
  --green: #2e8b57;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 20, 30, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--primary-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar-brand {
  font-size: 18px;
  font-weight: 700;
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  margin-bottom: 12px;
}

.sidebar-brand span { color: var(--accent); }

.sidebar-nav { display: flex; flex-direction: column; flex: 1; }

.sidebar-link {
  color: rgba(255, 255, 255, 0.75);
  padding: 10px 20px;
  font-weight: 500;
}

.sidebar-link:hover { color: #fff; text-decoration: none; background: rgba(255, 255, 255, 0.06); }

.sidebar-link.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border-right: 3px solid var(--accent);
}

.sidebar-footer {
  padding: 12px 20px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin-top: 12px;
}

.sidebar-user { font-weight: 600; margin-bottom: 6px; }

.btn-link {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  padding: 0;
  font-size: 13px;
}
.btn-link:hover { color: #fff; text-decoration: underline; }

/* Content */

.content {
  flex: 1;
  padding: 28px 36px;
  max-width: 1200px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-header h1 { font-size: 22px; margin: 0; }

.subtle { color: var(--muted); }

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--primary); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--panel); }
.btn-danger:hover { background: #fdecea; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Cards / panels */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.card + .card { margin-top: 18px; }

.card h2 {
  font-size: 15px;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}

.stat-card .stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat-card .stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

.two-col { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; align-items: start; }

/* Tables */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f8f9fb; }

/* Forms */

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.field textarea { resize: vertical; min-height: 60px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }

.search-input { width: 280px; }

/* Badges */

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #eef1f5;
  color: var(--muted);
}
.stage-new { background: #e6eef7; color: #2a5d8f; }
.stage-contacted { background: #eef2e0; color: #6b7f1f; }
.stage-consultation-scheduled { background: #fbeee0; color: #b06a1e; }
.stage-proposal-sent { background: #f3e7fb; color: #7a3f9e; }
.stage-won { background: #e2f5e8; color: #227845; }
.stage-lost { background: #fbe4e2; color: var(--danger); }

.badge-overdue { background: #fbe4e2; color: var(--danger); }
.badge-today { background: #fbeee0; color: #b06a1e; }

/* Lists */

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }

.empty-state { color: var(--muted); padding: 20px 0; text-align: center; }

/* Timeline */

.timeline-entry { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.timeline-entry:last-child { border-bottom: none; }
.timeline-type {
  flex-shrink: 0;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #eef1f5;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.timeline-body { flex: 1; white-space: pre-line; }
.timeline-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* Task rows */

.task-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.task-row:last-child { border-bottom: none; }
.task-row.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { flex: 1; }
.task-due { font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Kanban */

.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.kanban-col {
  background: #eceef2;
  border-radius: var(--radius);
  padding: 12px;
  width: 240px;
  flex-shrink: 0;
}
.kanban-col-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; padding: 0 2px; }
.kanban-col-header h3 { font-size: 13px; margin: 0; }
.kanban-col-header .subtle { font-size: 11px; }

.kanban-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.kanban-card .deal-title { font-weight: 600; margin-bottom: 4px; }
.kanban-card .deal-contact { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.kanban-card .deal-value { font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.kanban-card select { width: 100%; font-size: 12px; padding: 5px; }

/* Modal */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 22, 28, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px 24px;
  width: 420px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal h2 { margin-top: 0; font-size: 17px; }
.hidden { display: none !important; }

/* Login page */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--primary-dark), var(--primary));
}
.login-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  padding: 32px 30px;
  width: 340px;
}
.login-card .brand { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-card .brand span { color: var(--accent); }
.login-card p.subtle { margin-top: 0; margin-bottom: 20px; }
.error-text { color: var(--danger); font-size: 13px; margin: 8px 0 0; min-height: 16px; }

/* Contact detail */

.contact-header { display: flex; justify-content: space-between; align-items: flex-start; }
.contact-name { font-size: 22px; font-weight: 700; margin: 0; }
.contact-sub { color: var(--muted); margin-top: 4px; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; margin-top: 14px; }
.info-grid .label { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.03em; }
.info-grid .value { margin-top: 2px; }

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 16px; }
  .sidebar-nav { flex-direction: row; }
  .sidebar-footer { display: none; }
  .content { padding: 20px; }
}
