:root {
  --color-background-primary: #ffffff;
  --color-background-secondary: #f4f3f0;
  --color-background-tertiary: #ebe9e4;
  --color-background-info: #E6F1FB;
  --color-background-warning: #FAEEDA;
  --color-text-primary: #1a1a1a;
  --color-text-secondary: #6b6a66;
  --color-text-tertiary: #9a9890;
  --color-text-info: #0C447C;
  --color-text-warning: #633806;
  --color-border-tertiary: rgba(0,0,0,0.1);
  --color-border-secondary: rgba(0,0,0,0.2);
  --color-border-info: #378ADD;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --school-navy: #003573;
  --topbar-navy: #003573;
}
@media (prefers-color-scheme: dark) {
  :root {
    --color-background-primary: #1e1e1c;
    --color-background-secondary: #2a2a27;
    --color-background-tertiary: #353330;
    --color-background-info: #0C447C;
    --color-background-warning: #633806;
    --color-text-primary: #f0efe9;
    --color-text-secondary: #b4b2a9;
    --color-text-tertiary: #888780;
    --color-text-info: #B5D4F4;
    --color-text-warning: #FAC775;
    --color-border-tertiary: rgba(255,255,255,0.12);
    --color-border-secondary: rgba(255,255,255,0.25);
    --color-border-info: #378ADD;
    --school-navy: #8FBFFA;
  }
}
* { box-sizing: border-box; }
body {
  font-family: var(--font-sans);
  background: var(--color-background-tertiary);
  color: var(--color-text-primary);
  margin: 0;
  padding: 1rem;
  line-height: 1.6;
}
.container {
  max-width: 900px;
  margin: 0 auto;
  background: var(--color-background-primary);
  border-radius: var(--border-radius-lg);
  border: 0.5px solid var(--color-border-tertiary);
  padding: 1.5rem;
}
h1 { font-size: 18px; font-weight: 500; margin: 0 0 1rem; color: var(--school-navy); }
h2.section-title { font-size: 14px; font-weight: 500; margin: 0 0 0.75rem; color: var(--color-text-secondary); }

.section-block {
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-lg);
  margin-bottom: 1.25rem;
  padding: 0 1rem;
}
.section-block > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.85rem 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.section-block > summary::-webkit-details-marker { display: none; }
.section-block > summary::after {
  content: '▾';
  font-size: 11px;
  color: var(--color-text-tertiary);
  transition: transform 0.15s;
  margin-left: 8px;
}
.section-block:not([open]) > summary::after { transform: rotate(-90deg); }
.section-block > .section-body { padding-bottom: 1.25rem; }
input, select, button, textarea {
  font-family: var(--font-sans);
  font-size: 14px;
  border-radius: var(--border-radius-md);
  border: 0.5px solid var(--color-border-tertiary);
  background: var(--color-background-primary);
  color: var(--color-text-primary);
  padding: 8px 12px;
  height: 36px;
}
textarea { height: auto; resize: vertical; }
input:focus, select:focus, button:focus, textarea:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-border-info);
}
button { cursor: pointer; }
button:hover { background: var(--color-background-secondary); }
button:active { transform: scale(0.98); }
button.primary { background: var(--school-navy); color: #fff; border-color: var(--school-navy); }
button.primary:hover { opacity: 0.9; }
button.destructive { background: #fff; color: #791F1F; border-color: #C77; }
button.destructive:hover { background: #FCEBEB; }
button.destructive:disabled { opacity: 0.5; cursor: not-allowed; }
@media (prefers-color-scheme: dark) {
  button.primary { background: var(--color-border-info); color: #fff; border-color: var(--color-border-info); }
  button.destructive { background: transparent; color: #F7C1C1; border-color: #944; }
  button.destructive:hover { background: #501313; }
}
a { color: var(--color-text-info); text-decoration: none; }

label { display: block; font-size: 12px; color: var(--color-text-secondary); margin-bottom: 4px; }

.alert-error { background: #FCEBEB; color: #501313; padding: 10px 12px; border-radius: var(--border-radius-md); margin-bottom: 1rem; font-size: 13px; }
.alert-success { background: #EAF3DE; color: #27500A; padding: 10px 12px; border-radius: var(--border-radius-md); margin-bottom: 1rem; font-size: 13px; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--topbar-navy); color: #fff;
  padding: 0.85rem 1.5rem; margin: -1rem -1rem 1.5rem -1rem;
  flex-wrap: wrap; gap: 8px;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 500; color: #fff; font-size: 15px; }
.topbar .brand img { height: 32px; width: 32px; display: block; }
.topbar .brand a { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 10px; }
.topbar nav { display: flex; gap: 14px; align-items: center; }
.topbar nav a, .topbar nav button { font-size: 13px; }
.topbar nav span { color: rgba(255,255,255,0.75); font-size: 13px; }
.topbar nav a { color: #fff; }
.topbar nav a:hover { text-decoration: underline; }
.topbar nav button {
  background: rgba(255,255,255,0.12); color: #fff; border: 0.5px solid rgba(255,255,255,0.3);
}
.topbar nav button:hover { background: rgba(255,255,255,0.2); }
@media print {
  .topbar { background: none; color: var(--color-text-primary); margin: 0; padding: 0; }
  .topbar .brand, .topbar .brand a { color: var(--color-text-primary); }
}

.field-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 1.5rem; }
.field-grid input, .field-grid select { width: 100%; }
@media (max-width: 700px) {
  .field-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .field-grid { grid-template-columns: 1fr; }
}

.phone-row { display: flex; gap: 6px; }
.phone-row select { flex: 0 0 90px; }
.phone-row input { flex: 1; }
.email-btn { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; font-size: 13px; white-space: nowrap; text-decoration: none; color: var(--color-text-primary); }

.stage-wrap { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
.stage-btn { padding: 8px 12px; }
.stage-btn:hover { background: var(--color-background-secondary); }
.stage-btn.active { border: 2px solid var(--color-border-info); background: var(--color-background-info); color: var(--color-text-info); font-weight: 500; }

.status-select { width: 100%; height: 28px; font-size: 11px; padding: 2px 6px; text-align: center; }
.status-select.status-pending { background: var(--color-background-secondary); color: var(--color-text-secondary); }
.status-select.status-in-progress { background: #FAEEDA; color: #633806; border-color: #BA7517; }
.status-select.status-completed { background: #EAF3DE; color: #27500A; border-color: #639922; }
.status-select.status-skipped { background: #FCEBEB; color: #501313; border-color: #E24B4A; }
@media (prefers-color-scheme: dark) {
  .status-select.status-in-progress { background: #633806; color: #FAC775; }
  .status-select.status-completed { background: #3B6D11; color: #C0DD97; }
  .status-select.status-skipped { background: #791F1F; color: #F7C1C1; }
}

.tracker-card { border-radius: var(--border-radius-lg); padding: 1rem; cursor: pointer; }
.tracker-card:hover { opacity: 0.9; }
.c-pink   { background: #FBEAF0; color: #72243E; }
.c-purple { background: #EEEDFE; color: #3C3489; }
.c-teal   { background: #E1F5EE; color: #085041; }
.c-amber  { background: #FAEEDA; color: #633806; }
.c-gray   { background: #F1EFE8; color: #444441; }
.c-blue   { background: #E6F1FB; color: #0C447C; }
.c-green  { background: #EAF3DE; color: #27500A; }
.c-red    { background: #FCEBEB; color: #501313; }
@media (prefers-color-scheme: dark) {
  .c-pink   { background: #72243E; color: #F4C0D1; }
  .c-purple { background: #3C3489; color: #CECBF6; }
  .c-teal   { background: #085041; color: #9FE1CB; }
  .c-amber  { background: #633806; color: #FAC775; }
  .c-gray   { background: #444441; color: #D3D1C7; }
  .c-blue   { background: #0C447C; color: #B5D4F4; }
  .c-green  { background: #3B6D11; color: #C0DD97; }
  .c-red    { background: #791F1F; color: #F7C1C1; }
}

.tracker-panel { margin-top: 8px; padding: 12px; border-radius: var(--border-radius-md); background: var(--color-background-secondary); display: none; }
.tracker-panel.open { display: block; }
.tracker-option { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 0; font-size: 12px; }
.tracker-option input[type=checkbox] { width: auto; height: auto; margin: 0; }
.tracker-notes { margin-top: 8px; padding-top: 8px; border-top: 0.5px solid var(--color-border-tertiary); }
.tracker-notes textarea, .tracker-notes input { width: 100%; font-size: 12px; }

.tag-btn { padding: 4px 10px; height: auto; font-size: 12px; }
.tag-btn.active { border: 2px solid var(--color-border-info); background: var(--color-background-info); color: var(--color-text-info); font-weight: 500; }

.view-tab { padding: 8px 16px; border: 0.5px solid var(--color-border-tertiary); }
.view-tab.active { border: 2px solid var(--color-border-info); background: var(--color-background-info); color: var(--color-text-info); font-weight: 500; }

.note-item { font-size: 13px; padding: 8px 0; border-bottom: 0.5px solid var(--color-border-tertiary); }
.note-item:last-child { border-bottom: none; }
.history-item { font-size: 13px; padding: 10px 0; border-bottom: 0.5px solid var(--color-border-tertiary); display: flex; gap: 10px; align-items: flex-start; }
.history-item:last-child { border-bottom: none; }
.history-icon { width: 28px; height: 28px; border-radius: 50%; display:flex; align-items:center; justify-content:center; flex-shrink:0; font-size: 14px; }
.private-badge { font-size: 11px; padding: 2px 8px; border-radius: var(--border-radius-md); background: var(--color-background-warning); color: var(--color-text-warning); white-space: nowrap; }

label.checkbox-label { display:flex; align-items:center; gap:6px; font-size:13px; color: var(--color-text-secondary); white-space:nowrap; height: auto; }
label.checkbox-label input[type=checkbox] { width: auto; height: auto; }
hr.divider { border: none; border-top: 0.5px solid var(--color-border-tertiary); margin: 1.5rem 0; }

.save-bar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
  margin-top: 1rem; padding-top: 1rem; border-top: 0.5px solid var(--color-border-tertiary);
}
.save-bar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.save-status { font-size: 13px; color: var(--color-text-secondary); transition: opacity 0.3s; }
.save-status.saved { color: #27500A; }
@media (prefers-color-scheme: dark) { .save-status.saved { color: #C0DD97; } }

/* Records list table */
.records-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.records-table th, .records-table td { text-align: left; padding: 8px; border-bottom: 0.5px solid var(--color-border-tertiary); }
.records-table th { color: var(--color-text-secondary); font-weight: 500; }
.records-table th[data-sort-key]:hover { color: var(--school-navy); }
@media (prefers-color-scheme: dark) {
  .records-table th[data-sort-key]:hover { color: var(--color-text-info); }
}
.records-table tr:hover { background: var(--color-background-secondary); cursor: pointer; }
.stage-badge { font-size: 11px; padding: 2px 8px; border-radius: var(--border-radius-md); background: var(--color-background-info); color: var(--color-text-info); }
.stage-badge.status-pending { background: var(--color-background-secondary); color: var(--color-text-secondary); }
.stage-badge.status-in-progress { background: #FAEEDA; color: #633806; }
.stage-badge.status-completed { background: #EAF3DE; color: #27500A; }
.stage-badge.status-skipped { background: #FCEBEB; color: #501313; }
@media (prefers-color-scheme: dark) {
  .stage-badge.status-in-progress { background: #633806; color: #FAC775; }
  .stage-badge.status-completed { background: #3B6D11; color: #C0DD97; }
  .stage-badge.status-skipped { background: #791F1F; color: #F7C1C1; }
}

.print-only { display: none; }
@media print {
  body { background: #fff; padding: 0; }
  .container { max-width: 100%; border: none; padding: 0; }
  .topbar, .view-tab, #print-btn, .email-btn, .tracker-card, .tracker-panel,
  #note-input, #note-private, #add-note-btn, select, input[type=date],
  input[type=email], input[type=tel], input[type=text], .screen-only-note,
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  #view-record, #view-history { display: block !important; }
  h1 { font-size: 18px; }
  h2.section-title { font-size: 13px; font-weight: 500; margin-top: 1rem; border-bottom: 0.5px solid #ccc; padding-bottom: 4px; }
  .print-field { margin-bottom: 6px; font-size: 12px; }
  .print-field strong { display: inline-block; min-width: 140px; }
  .history-item, .note-item { color: #000; }
  .private-badge { background: #eee; color: #333; border: 0.5px solid #999; }
  .section-block { border: none; padding: 0; }
  .section-block > summary::after { display: none; }
  .section-block .section-body { display: block !important; }
}

/* ------------------------------------------------------------
   Mobile responsiveness pass
   ------------------------------------------------------------ */
@media (max-width: 600px) {
  #main-pipeline { flex-direction: column; }
  .stage-wrap { width: 100%; }
  .stage-btn { width: 100%; }
  .status-select { width: 100%; }
  #trackers-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .topbar { padding: 0.75rem 1rem; }
  .topbar .brand { font-size: 13px; }
  .topbar nav { font-size: 11px; gap: 8px; }
  .topbar nav span { font-size: 11px; }
  .save-bar { flex-direction: column; align-items: stretch; }
  .save-bar-actions { flex-direction: column; }
  .save-bar-actions button { width: 100%; }
  .records-table { font-size: 12px; }
  .records-table th, .records-table td { padding: 6px 4px; }
}

@media (max-width: 420px) {
  #trackers-grid { grid-template-columns: 1fr !important; }
}
