:root {
  --ink: #15212b;
  --paper: #eef2ef;
  --paper-raised: #ffffff;
  --line: #d6502b;
  --line-soft: #f6ddd1;
  --moss: #3a6b52;
  --moss-soft: #dde8e0;
  --sand: #c9c2ab;
  --text: #15212b;
  --text-muted: #5c6b66;
  --border: #ccd6cd;
  --warn-bg: #fbe7e4;
  --warn-text: #a8341f;
  --caution-bg: #fbf0d9;
  --caution-text: #8a5a00;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #10161c;
    --paper-raised: #17212a;
    --line: #ff7f55;
    --line-soft: #3a2a22;
    --moss: #74b393;
    --moss-soft: #1d2a24;
    --sand: #3a4138;
    --text: #e8ece6;
    --text-muted: #93a59c;
    --border: #2b352f;
    --warn-bg: #3a211d;
    --warn-text: #ff9478;
    --caution-bg: #3a2f14;
    --caution-text: #e0b84d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #10161c;
  --paper-raised: #17212a;
  --line: #ff7f55;
  --line-soft: #3a2a22;
  --moss: #74b393;
  --moss-soft: #1d2a24;
  --sand: #3a4138;
  --text: #e8ece6;
  --text-muted: #93a59c;
  --border: #2b352f;
  --warn-bg: #3a211d;
  --warn-text: #ff9478;
  --caution-bg: #3a2f14;
  --caution-text: #e0b84d;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: 'IBM Plex Sans', -apple-system, sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  line-height: 1.55;
}
.wrap { max-width: 920px; margin: 0 auto; padding: 36px 20px 80px; }
header.hero { margin-bottom: 24px; }
h1 {
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: clamp(28px, 5vw, 40px);
  margin: 0;
  letter-spacing: -0.01em;
}

.panel {
  background: var(--paper-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 22px 24px;
  margin-bottom: 20px;
}
.panel h2 {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel h2 .tag {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 6px;
}

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; color: var(--text-muted); }
.field input {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--paper);
  color: var(--text);
  width: 150px;
}

button {
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 600;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--paper-raised);
  color: var(--text);
  cursor: pointer;
}
button.primary { background: var(--line); border-color: var(--line); color: #fff; }
button.primary:hover { filter: brightness(1.06); }
button.ghost { background: transparent; }
button.danger { color: var(--warn-text); border-color: var(--warn-text); }
button.small { padding: 6px 12px; font-size: 12.5px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--line); outline-offset: 2px; }

textarea {
  width: 100%;
  min-height: 90px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--paper);
  color: var(--text);
  padding: 8px 10px;
  resize: vertical;
}

select, input[type="search"] {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 14px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--paper);
  color: var(--text);
}
#countySelect { font-family: 'IBM Plex Mono', monospace; font-size: 13px; }
input[type="file"] { font-size: 13px; }

.hint { font-size: 12.5px; color: var(--text-muted); margin-top: 8px; }
.muted { color: var(--text-muted); }
.upload-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.toolbar { margin: 4px 0 12px; }
.grow { flex: 1; min-width: 180px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }

.summary {
  display: flex; gap: 28px; flex-wrap: wrap;
  padding: 4px 0;
}
.summary .stat .num {
  font-family: 'Fraunces', serif;
  font-size: 30px;
  font-weight: 600;
  color: var(--line);
  line-height: 1;
}
.summary .stat .label { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid .field.wide { grid-column: 1 / -1; }
.form-grid .field input,
.form-grid .field select { width: 100%; font-family: 'IBM Plex Sans', sans-serif; }
.form-grid textarea { min-height: 64px; }
.add-form {
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 14px;
  margin-bottom: 14px;
}

.crm-list { display: flex; flex-direction: column; gap: 8px; }
.crm-row {
  display: flex; gap: 12px; justify-content: space-between; align-items: flex-start;
  border: 1px solid var(--border); border-radius: 4px; padding: 10px 12px;
  cursor: pointer; background: var(--paper);
}
.crm-row:hover { border-color: var(--moss); }
.crm-row.closed .crm-name { color: var(--text-muted); text-decoration: line-through; }
.crm-main { min-width: 0; flex: 1; }
.crm-name { font-weight: 600; font-size: 14.5px; }
.stop-addr { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.crm-meta {
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  flex-shrink: 0; font-size: 12px; color: var(--text-muted);
}
.crm-date { font-family: 'IBM Plex Mono', monospace; font-size: 12px; }
.tag-mini {
  font-family: 'IBM Plex Mono', monospace; font-size: 10.5px; font-weight: 400;
  color: var(--text-muted); border: 1px solid var(--border); border-radius: 3px;
  padding: 0 4px; margin-left: 6px; vertical-align: 2px;
}

.status {
  font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 3px;
  border: 1px solid var(--border); color: var(--text-muted);
}
.status.s-active { background: var(--caution-bg); color: var(--caution-text); border-color: transparent; }
.status.s-won { background: var(--moss-soft); color: var(--moss); border-color: transparent; }
.status.s-paused { background: var(--sand); color: var(--text); border-color: transparent; }
.status.s-closed { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }

.pager {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin-top: 14px; font-size: 13px;
}
.pager-info { display: flex; flex-direction: column; align-items: center; font-family: 'IBM Plex Mono', monospace; font-size: 13px; }

.sub {
  font-family: 'Fraunces', serif; font-size: 16px; font-weight: 600;
  margin: 22px 0 10px; padding-top: 16px; border-top: 1px dashed var(--border);
}
.sub-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sub-head .sub { margin-bottom: 0; }

.crm-dialog {
  background: var(--paper-raised); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 22px 24px; width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); overflow-y: auto;
  box-shadow: 0 12px 40px rgba(21, 33, 43, 0.25);
}
.pharmacy-dialog { width: min(640px, calc(100vw - 32px)); }
.crm-dialog::backdrop { background: rgba(21, 33, 43, 0.45); }
.crm-dialog h3 {
  font-family: 'Fraunces', serif; font-size: 18px; font-weight: 600; margin: 0 0 14px;
}
.crm-dialog .field { margin-bottom: 12px; }
.crm-dialog .field input { width: 100%; font-family: 'IBM Plex Sans', sans-serif; }
.crm-dialog .sub { margin-top: 18px; }
.crm-dialog .actions-row { margin-top: 4px; }
.visit-list { display: flex; flex-direction: column; margin-top: 12px; }
.visit-item {
  display: flex; gap: 12px; font-size: 13.5px;
  border-bottom: 1px solid var(--border); padding: 7px 0;
}
.visit-item .crm-date { flex-shrink: 0; padding-top: 1px; }
.visit-content { flex: 1; min-width: 0; white-space: pre-line; }

.log-status { font-size: 12.5px; color: var(--moss); }

.info-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; padding: 0; border-radius: 50%;
  font-family: 'IBM Plex Mono', monospace; font-size: 12px; font-weight: 500; line-height: 1;
  color: var(--text-muted); background: transparent; border: 1px solid var(--border);
  vertical-align: 2px;
}
.info-btn::after {
  content: attr(data-tip);
  position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%);
  width: max-content; max-width: 260px; padding: 8px 10px; border-radius: 4px;
  background: #15212b; color: #fff; font-family: 'IBM Plex Sans', sans-serif;
  font-size: 12.5px; font-weight: 400; line-height: 1.5; white-space: normal;
  opacity: 0; pointer-events: none; transition: opacity 0.15s; z-index: 10;
}
.info-btn:hover::after, .info-btn:focus-visible::after { opacity: 1; }
.info-btn:focus-visible { outline: 2px solid var(--line); outline-offset: 2px; }
.actions-row { justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.empty {
  text-align: center; padding: 40px 10px; color: var(--text-muted); font-size: 14px;
}
.footer-note {
  font-size: 12.5px; color: var(--text-muted); border-top: 1px solid var(--border);
  padding: 14px 0 0 18px; margin: 10px 0 0; list-style: disc;
}
.footer-note li { margin-bottom: 4px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  background: transparent; border: none; border-bottom: 2px solid transparent; border-radius: 0;
  padding: 8px 14px; color: var(--text-muted); font-size: 15px;
}
.tab.active { color: var(--text); border-bottom-color: var(--line); }

.day-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 18px; }
.day-tab {
  font-family: 'IBM Plex Mono', monospace; font-size: 13px; padding: 6px 12px; border-radius: 3px;
  border: 1px solid var(--border); background: var(--paper); color: var(--text-muted); cursor: pointer;
}
.day-tab.active { background: var(--moss-soft); border-color: var(--moss); color: var(--text); font-weight: 600; }

.day-meta { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.day-meta h3 { font-family: 'Fraunces', serif; font-size: 20px; margin: 0; }
.day-meta .dist { font-family: 'IBM Plex Mono', monospace; font-size: 13px; color: var(--text-muted); }

svg.route-map { width: 100%; height: 240px; border: 1px solid var(--border); border-radius: 3px; background: var(--paper); margin-bottom: 14px; }

.stop-list { display: flex; flex-direction: column; gap: 10px; }
.stop-card { border: 1px solid var(--border); border-radius: 4px; padding: 12px 14px; }
.stop-head { display: flex; gap: 10px; align-items: flex-start; }
.stop-idx { font-family: 'IBM Plex Mono', monospace; color: var(--line); font-weight: 600; font-size: 13px; padding-top: 2px; flex-shrink: 0; width: 20px; }
.stop-title { flex: 1; min-width: 0; }
.stop-name { font-weight: 600; font-size: 14.5px; }
.stop-sub { color: var(--text-muted); font-size: 12.5px; margin-top: 1px; }
.nav-link {
  font-size: 12.5px; font-weight: 600; color: #fff; background: var(--line);
  text-decoration: none; white-space: nowrap; padding: 6px 12px; border-radius: 3px; flex-shrink: 0;
}
.nav-link:hover { filter: brightness(1.08); }

.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 3px; margin-left: 6px; }
.badge.closed { background: var(--warn-bg); color: var(--warn-text); }
.badge.late { background: var(--caution-bg); color: var(--caution-text); }

.hours-box { margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.hr-row { display: flex; gap: 8px; align-items: center; line-height: 1.5; margin-bottom: 2px; }
.hr-days { display: flex; gap: 2px; flex-shrink: 0; width: 92px; flex-wrap: wrap; }
.day-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 3px; background: var(--moss-soft); color: var(--text);
  font-size: 10px; font-family: 'IBM Plex Mono', monospace; line-height: 1;
}
.day-chip.off { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }

.stop-log {
  margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border);
  display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-muted);
}
.stop-notes { color: var(--text); }

.gmaps-btn {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600;
  text-decoration: none; color: #fff; background: var(--moss); padding: 8px 14px; border-radius: 3px; margin-top: 12px;
}
.gmaps-btn:hover { filter: brightness(1.08); }

@media (max-width: 480px) {
  .wrap { padding: 24px 14px 60px; }
  .form-grid { grid-template-columns: 1fr; }
  .field input { width: 100%; }
  .crm-meta { align-items: flex-start; }
}
