:root {
  --bg: #f3f8f5;
  --panel: #ffffff;
  --border: #dce9e2;
  --text: #263a32;
  --text-strong: #102d22;
  --muted: #687d74;
  --primary: #087b58;
  --primary-dark: #00593a;
  --primary-light: #e3f4ec;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --orange: #d97706;
  --orange-bg: #fef3c7;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --purple: #7c3aed;
  --purple-bg: #ede9fe;
  --radius: 12px;
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }

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

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

/* ---------- Sidebar layout ---------- */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar .brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 0 10px 18px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.sidebar .brand-logo { width: 164px; height: 58px; object-fit: contain; object-position: left center; }
.sidebar .brand-product {
  color: var(--primary-dark); font-size: 10.5px; font-weight: 700;
  letter-spacing: .045em; text-transform: uppercase;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin-top: 14px; flex: 1; }

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
  font-size: 13.5px;
}

.sidebar nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .75; }

.sidebar nav a:hover { background: #f1f8f4; text-decoration: none; }
.sidebar nav a.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 700; }
.sidebar nav a.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 8px;
  min-width: 20px;
  text-align: center;
}

.sidebar .footer-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 0;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.sidebar .avatar {
  width: 34px; height: 34px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}

.sidebar .footer-user .who { line-height: 1.2; }
.sidebar .footer-user .who .n { font-weight: 600; font-size: 13px; color: var(--text-strong); }
.sidebar .footer-user .who .r { font-size: 11.5px; color: var(--muted); }

.main {
  margin-left: var(--sidebar-w);
  padding: 28px 32px;
  max-width: 1280px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page-header h1 { font-size: 24px; font-weight: 700; color: var(--text-strong); margin: 0 0 4px; }
.page-header p { color: var(--muted); margin: 0; font-size: 13.5px; }

/* ---------- Grid / cards ---------- */

.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

/* Wide tables never push the page wider than the viewport. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--border), 0 1px 2px rgba(0,0,0,.05);
  padding: 18px 20px;
  overflow-x: auto;  /* wide tables scroll inside the card instead of widening the page */
}

.main { min-width: 0; }

.card h3 {
  margin: 0 0 12px;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
}

.kpi-card { display: flex; align-items: center; gap: 14px; padding: 16px 18px; }
.kpi-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.kpi-icon svg { width: 21px; height: 21px; }
.kpi-icon.blue { background: var(--blue-bg); color: var(--blue); }
.kpi-icon.green { background: var(--green-bg); color: var(--green); }
.kpi-icon.orange { background: var(--orange-bg); color: var(--orange); }
.kpi-icon.red { background: var(--red-bg); color: var(--red); }
.kpi-icon.purple { background: var(--purple-bg); color: var(--purple); }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--text-strong); line-height: 1.2; }
.kpi-label { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.kpi-delta {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 7px;
  vertical-align: middle;
}
.kpi-delta.up { background: var(--green-bg); color: var(--green); }
.kpi-delta.down { background: var(--red-bg); color: var(--red); }
.kpi-delta.flat { background: #f1f5f9; color: var(--muted); }

.margin-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.margin-badge.pos { background: var(--green-bg); color: var(--green); }
.margin-badge.neg { background: var(--red-bg); color: var(--red); }

.kpi { font-size: 26px; font-weight: 700; color: var(--text-strong); }
.kpi small { font-size: 12.5px; color: var(--muted); font-weight: 500; display: block; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f2f8f5; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-gray { background: #f1f5f9; color: var(--muted); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }

/* Clickable KPI cards (task category filters) */
.kpi-link { display: block; text-decoration: none; border-radius: var(--radius); transition: transform .05s ease; }
.kpi-link:hover { text-decoration: none; }
.kpi-link:hover .card { box-shadow: 0 0 0 1px var(--border), 0 3px 8px rgba(0,0,0,.08); }
.kpi-link.active .card { box-shadow: 0 0 0 2px var(--primary); }

/* Pagination */
.pager { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.pager a, .pager span {
  min-width: 34px; text-align: center; padding: 6px 10px; border-radius: 8px;
  font-size: 13px; font-weight: 600; box-shadow: 0 0 0 1px var(--border); background: white; color: var(--text);
}
.pager a:hover { background: #f8fafc; text-decoration: none; }
.pager .cur { background: var(--primary); color: white; box-shadow: none; }
.pager .gap { box-shadow: none; background: none; color: var(--muted); min-width: auto; padding: 6px 2px; }
.pager .disabled { opacity: .4; pointer-events: none; }
.pager-info { color: var(--muted); font-size: 12.5px; margin-left: auto; }

.btn, button, input[type=submit] {
  font-family: inherit;
}

.btn, .btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: white;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13.5px;
}
.btn:hover, .btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: white; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-secondary {
  background: white;
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border);
}
.btn-secondary:hover { background: #f8fafc; color: var(--text); }

/* pill / segmented control (day-month-year switcher, tabs) */
.pill-group { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  background: white;
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border);
}
.pill:hover { background: #f8fafc; text-decoration: none; color: var(--text); }
.pill.active { background: var(--primary-dark); color: white; box-shadow: none; }
.pill .count {
  background: rgba(255,255,255,.25);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  margin-left: 6px;
}
.pill:not(.active) .count { background: var(--primary-light); color: var(--primary-dark); }

input[type=text], input[type=date], input[type=file], select {
  padding: 8px 11px;
  box-shadow: 0 0 0 1px var(--border);
  border: none;
  border-radius: 8px;
  font-size: 13.5px;
  background: white;
  color: var(--text);
  font-family: inherit;
}

.form-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.form-row label { font-weight: 600; color: var(--muted); font-size: 12.5px; }

.section-title { font-size: 17px; font-weight: 700; color: var(--text-strong); margin: 30px 0 12px; }
.section-title:first-child { margin-top: 0; }

.muted { color: var(--muted); }
.mt-0 { margin-top: 0; }
.mb-16 { margin-bottom: 16px; }

.manager-picker { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; }
.manager-picker a {
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--border);
  padding: 9px 16px;
  border-radius: 10px;
  color: var(--text);
  font-weight: 600;
  font-size: 13.5px;
}
.manager-picker a:hover { text-decoration: none; }
.manager-picker a.active { background: var(--primary-light); color: var(--primary-dark); box-shadow: none; }

.upload-box { border: 1.5px dashed var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; background: white; }
.upload-box h4 { margin: 0 0 6px; color: var(--text-strong); }
.upload-box p { color: var(--muted); margin: 0 0 12px; font-size: 13px; }

.chart-wrap { height: 240px; }

.flag-row td { background: #fffbf2; }

.tag {
  display: inline-block;
  background: #f1f5f9;
  color: #475569;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11.5px;
  font-weight: 500;
}

.ai-box {
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.ai-box .ai-icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.ai-box .ai-icon svg { width: 20px; height: 20px; }
.ai-box h3 { margin: 0 0 4px; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.ai-box p { margin: 0; font-size: 14px; line-height: 1.5; }
.ai-box.urgent { background: var(--red-bg); }
.ai-box.urgent .ai-icon { background: var(--red); color: white; }
.ai-box.urgent h3 { color: var(--red); }
.ai-box.watch { background: var(--orange-bg); }
.ai-box.watch .ai-icon { background: var(--orange); color: white; }
.ai-box.watch h3 { color: var(--orange); }
.ai-box.ok { background: var(--green-bg); }
.ai-box.ok .ai-icon { background: var(--green); color: white; }
.ai-box.ok h3 { color: var(--green); }
.ai-box.lead { background: var(--blue-bg); }
.ai-box.lead .ai-icon { background: var(--blue); color: white; }
.ai-box.lead h3 { color: var(--blue); }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 24px; }
.info-item .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.info-item .v { font-size: 14px; color: var(--text-strong); margin-top: 2px; }
.comment-block { background: #f8fafc; border-radius: 8px; padding: 12px 14px; font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; }

/* Task feed */
.task-row { display: flex; align-items: center; gap: 14px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.task-row:last-child { border-bottom: none; }
.task-cat {
  width: 8px; align-self: stretch; border-radius: 4px; flex-shrink: 0;
}
.task-cat.urgent { background: var(--red); }
.task-cat.watch { background: var(--orange); }
.task-cat.contact { background: var(--purple); }
.task-cat.lead { background: var(--blue); }
.task-main { flex: 1; min-width: 0; }
.task-main .t-name { font-weight: 600; color: var(--text-strong); }
.task-main .t-reason { font-size: 13px; color: var(--muted); margin-top: 2px; }
.task-main .t-contact { font-size: 12.5px; color: var(--text); margin-top: 3px; }
.task-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* Contact action buttons */
.contact-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Edit-contacts / outcome form grid */
.edit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 16px; }
.edit-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.edit-grid input, .edit-grid select { font-weight: 400; color: var(--text); }

/* Interaction timeline */
.tl-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.tl-item:last-child { border-bottom: none; }
.tl-dot { width: 10px; height: 10px; border-radius: 999px; margin-top: 5px; flex-shrink: 0; background: var(--muted); }
.tl-call .tl-dot { background: var(--green); }
.tl-comment .tl-dot { background: var(--primary); }
.tl-snooze .tl-dot { background: var(--orange); }
.tl-contact_edit .tl-dot { background: var(--purple); }
.tl-manager_change .tl-dot { background: #94a3b8; }
.tl-order .tl-dot { background: var(--blue); }
.tl-body { flex: 1; min-width: 0; }
.tl-meta { font-size: 12px; color: var(--muted); }
.tl-note { font-size: 13.5px; color: var(--text); margin-top: 2px; white-space: pre-wrap; }

.task-actions { flex-direction: column; align-items: flex-end; gap: 6px; }
.task-outcome { display: flex; gap: 6px; align-items: center; }

/* Clickable status legend / filter */
.health-legend { display: flex; gap: 8px; flex-wrap: wrap; }
.health-legend .hl {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px; font-size: 13px; color: var(--text);
  box-shadow: 0 0 0 1px var(--border); background: white;
}
.health-legend .hl:hover { background: #f8fafc; text-decoration: none; }
.health-legend .hl.active { box-shadow: 0 0 0 2px var(--primary); font-weight: 600; }

/* Compact controls on the contractors page */
.admin-action {
  display: inline-block; background: white; border-radius: 9px;
  box-shadow: 0 0 0 1px var(--border); padding: 8px 12px;
}
.admin-action summary, .filters-more summary {
  color: var(--primary-dark); font-weight: 600; font-size: 13px; cursor: pointer;
}
.admin-action form { margin: 12px 0 2px; }
.filters-primary, .filters-secondary {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
}
.filters-primary label, .filters-secondary label {
  display: flex; flex-direction: column; gap: 5px;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.filters-primary input { min-width: 260px; }
.filters-more { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.filters-secondary { margin-top: 12px; }
.filter-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
