/* SafeServe CRM — app stylesheet
   Brand palette matches safeservesolutions.co.uk */

:root {
  --accent: #3b5bfd;
  --accent-dark: #2643d9;
  --accent-light: #dde5ff;
  --orange: #f5a524;
  --text-dark: #12172b;
  --text-body: #4b5563;
  --text-muted: #8b93a7;
  --border: #e5e9f2;
  --bg-alt: #f4f6fb;
  --bg: #ffffff;
  --danger: #e0472c;
  --success: #1b9e63;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-dark);
  background: var(--bg-alt);
}

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

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Logo (shared with marketing site) ---------- */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--orange);
  flex-shrink: 0;
}
.logo-text { display: flex; flex-direction: column; line-height: 1.1; }
.logo-name { font-weight: 700; font-size: 16px; color: var(--text-dark); }
.logo-sub { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }

/* ============================================================
   AUTH PAGES (login.html)
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-alt);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: 0 4px 20px rgba(18, 23, 43, 0.06);
}
.auth-card .logo { justify-content: center; margin-bottom: 24px; }
.auth-card h1 {
  font-size: 20px;
  margin: 0 0 6px;
  text-align: center;
}
.auth-card .auth-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 24px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-dark);
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-dark);
  background: var(--bg);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { background: var(--text-muted); cursor: not-allowed; }
.btn-secondary { background: var(--bg-alt); color: var(--text-dark); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--accent-light); }
.btn-danger { background: #fdecea; color: var(--danger); border: 1px solid #f6c9c2; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 18px;
}
.auth-switch a { font-weight: 600; text-decoration: none; }

.form-msg {
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  display: none;
}
.form-msg.error { display: block; background: #fdecea; color: var(--danger); }
.form-msg.ok { display: block; background: #e8f7ef; color: var(--success); }

/* ============================================================
   APP SHELL (app.html)
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .logo { padding: 0 8px; margin-bottom: 28px; }
.nav-list { list-style: none; margin: 0; padding: 0; flex: 1; }
.nav-list li { margin-bottom: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-body);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}
.nav-link:hover { background: var(--bg-alt); color: var(--text-dark); }
.nav-link.active { background: var(--accent-light); color: var(--accent-dark); font-weight: 700; }
.nav-icon { width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 14px; }
.biz-name { font-size: 13px; font-weight: 600; padding: 0 12px 4px; }
.user-email { font-size: 12px; color: var(--text-muted); padding: 0 12px 10px; word-break: break-all; }

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 32px 60px;
}
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.main-header h1 { font-size: 22px; margin: 0; }
.main-header .sub { color: var(--text-muted); font-size: 14px; margin-top: 2px; }

/* Mobile top bar (hidden on desktop) */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.hamburger {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .mobile-topbar { display: flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 240px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 30;
    height: 100vh;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(18,23,43,0.35);
    z-index: 25;
  }
  .sidebar-scrim.open { display: block; }
  .main { padding: 20px 16px 60px; }
  .main-header h1 { font-size: 19px; }
}

/* ---------- Cards / stat tiles ---------- */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .stat-grid { grid-template-columns: 1fr; } }
.stat-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-tile .stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-tile .stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; color: var(--text-dark); }
.stat-tile .stat-value.accent { color: var(--accent); }

.funnel { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 10px; font-size: 13px; }
.funnel-bar-track { background: var(--bg-alt); border-radius: 6px; overflow: hidden; height: 18px; }
.funnel-bar-fill { background: var(--accent); height: 100%; border-radius: 6px; min-width: 3px; }
.funnel-count { text-align: right; font-weight: 600; color: var(--text-dark); }

/* ---------- Tables / lists ---------- */
.list-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.list-toolbar input[type="search"] {
  flex: 1;
  min-width: 160px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.data-table { width: 100%; border-collapse: collapse; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.data-table th, .data-table td { text-align: left; padding: 12px 14px; font-size: 14px; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--bg-alt); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: var(--bg-alt); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-light);
  color: var(--accent-dark);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state .btn { margin-top: 12px; }

/* Mobile card list (shown instead of table below 700px) */
.mobile-card-list { display: none; flex-direction: column; gap: 10px; }
@media (max-width: 700px) {
  .data-table { display: none; }
  .mobile-card-list { display: flex; }
}
.mobile-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.mobile-card .mc-title { font-weight: 700; font-size: 15px; }
.mobile-card .mc-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.mobile-card .mc-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }

/* ---------- Kanban ---------- */
.kanban-board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 10px;
}
.kanban-col {
  background: var(--bg-alt);
  border-radius: var(--radius);
  min-width: 250px;
  max-width: 250px;
  flex-shrink: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
}
.kanban-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
  padding: 0 2px;
}
.kanban-col-header .count { color: var(--text-muted); font-weight: 600; }
.kanban-col.drag-over { background: var(--accent-light); }
.kanban-cards { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.kanban-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  cursor: grab;
  box-shadow: 0 1px 2px rgba(18,23,43,0.04);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.4; }
.kanban-card .kc-name { font-weight: 700; margin-bottom: 2px; }
.kanban-card .kc-company { color: var(--text-muted); font-size: 12px; }
.kanban-card .kc-value { margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--accent-dark); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18,23,43,0.4);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 10px 40px rgba(18,23,43,0.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-header h2 { font-size: 17px; margin: 0; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  line-height: 1;
}
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: space-between; }
.modal-actions .right { display: flex; gap: 10px; margin-left: auto; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 480px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Task list ---------- */
.task-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}
.task-row:last-child { border-bottom: none; }
.task-row input[type="checkbox"] { margin-top: 3px; width: 16px; height: 16px; }
.task-row .t-title { font-size: 14px; }
.task-row .t-title.done { text-decoration: line-through; color: var(--text-muted); }
.task-row .t-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.task-row .t-meta.overdue { color: var(--danger); font-weight: 600; }

/* ---------- Email template picker ---------- */
.template-list { display: flex; flex-direction: column; gap: 8px; }
.template-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.template-item .ti-name { font-weight: 600; font-size: 14px; }
.template-item .ti-subject { font-size: 12px; color: var(--text-muted); }

.section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 24px 0 12px;
}
.section-title:first-child { margin-top: 0; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }

.top-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.loading-inline { color: var(--text-muted); font-size: 14px; padding: 20px 0; }

.helper-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Contact notes timeline ---------- */
.notes-list {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  margin-bottom: 8px;
  background: var(--bg-alt);
}
.note-item { padding: 8px 0; border-bottom: 1px solid var(--border); }
.note-item:last-child { border-bottom: none; }
.note-date { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.note-body { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.notes-empty { font-size: 13px; color: var(--text-muted); padding: 10px 0; }

/* ---------- Email preview (template -> before sending) ---------- */
.preview-box {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.preview-box.preview-body { max-height: 260px; overflow-y: auto; }
.preview-box.warn { color: var(--danger); }
