:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #1d2320;
  --muted: #5f6a64;
  --line: #dde1dc;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0ec;
  --danger: #b3261e;
  --start: #1f6f5c;
  --end: #c0582b;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; }
h1 { font-size: 1.3rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
a { color: var(--accent); }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: .6rem 1.25rem;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 650; color: var(--accent); }
.brand span { color: var(--ink); }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; }
.tab {
  border: 0; background: none; padding: .5rem .8rem; border-radius: 8px;
  font: inherit; color: var(--muted); cursor: pointer;
}
.tab:hover { background: var(--bg); color: var(--ink); }
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { max-width: 900px; margin: 1.5rem auto; padding: 0 16px; }
.view { display: none; }
.view.active { display: block; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.5rem; margin-bottom: 1rem;
}

label { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; font-size: .88rem; }
label.inline { flex-direction: row; align-items: center; gap: .5rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; margin: .75rem 0; }
input[type=text], input[type=date], input[type=month], input[type=number], select {
  font: inherit; font-weight: 400; padding: .55rem .65rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: 1fr 2fr auto; align-items: end; }

.route { position: relative; display: flex; flex-direction: column; gap: .5rem; padding-left: 1.6rem; margin: .5rem 0; }
.route::before { content: ""; position: absolute; left: 6px; top: 2.1rem; bottom: 2.6rem; border-left: 2px dashed var(--line); }
.stop { position: relative; display: flex; flex-direction: column; gap: .4rem; }
.dot { position: absolute; left: -1.6rem; top: 2.05rem; width: 14px; height: 14px; border-radius: 50%; border: 3px solid; background: #fff; }
.dot.start { border-color: var(--start); }
.dot.end { border-color: var(--end); background: var(--end); }
.swap { align-self: flex-end; border: 1px solid var(--line); background: #fff; border-radius: 50%; width: 32px; height: 32px; cursor: pointer; color: var(--muted); margin: -.25rem 0; }
.swap:hover { color: var(--accent); border-color: var(--accent); }

.calc-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.result { font-size: .95rem; }
.result .big { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.result.error { color: var(--danger); }
.miles-row { display: grid; grid-template-columns: 160px 180px 1fr; gap: 1rem; margin-bottom: .5rem; align-items: end; }
.miles-row #adjust-wrap { grid-column: 1 / -1; }
.span2 { grid-column: span 2; }
.grid.four { grid-template-columns: repeat(4, 1fr); }
.warn { background: #fff4e5; border: 1px solid #f3cf99; color: #7a4a00; border-radius: 8px; padding: .6rem .8rem; font-size: .9rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn { font: inherit; font-weight: 600; border-radius: 8px; padding: .6rem 1.1rem; cursor: pointer; border: 1px solid transparent; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--accent); border-color: var(--accent); }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }
.toast { color: var(--accent); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.row-between h1 { margin: 0; }

.summary { display: flex; gap: 2rem; margin-bottom: 1rem; flex-wrap: wrap; }
.summary div { display: flex; flex-direction: column; }
.summary b { font-size: 1.35rem; }
.summary span { color: var(--muted); font-size: .82rem; }

.table-wrap { overflow-x: auto; margin-bottom: 1rem; }
table.trips { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.trips th, table.trips td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.trips th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.num { text-align: right !important; white-space: nowrap; }
.del { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1.1rem; }
.del:hover { color: var(--danger); }
.addr { color: var(--muted); font-size: .8rem; }
.flag { color: var(--end); font-weight: 700; }

/* ---------- sign-in & account ---------- */
body.loading main { visibility: hidden; }
body.signed-out .signed-in-only, body.loading .signed-in-only { display: none !important; }
.who { margin-left: auto; display: flex; align-items: center; gap: .75rem; font-size: .88rem; color: var(--muted); }
.signout { font-weight: 600; text-decoration: none; }
.signin { max-width: 460px; margin: 3rem auto; }
.ms-btn { display: inline-flex; align-items: center; gap: .6rem; text-decoration: none; margin: .5rem 0 1rem; }
.dev-login { border-top: 1px dashed var(--line); margin-top: 1rem; padding-top: .5rem; }
.import-card { background: var(--accent-soft); border-color: #b9d9cf; }
.import-card p { margin: 0 0 .75rem; }
.edit-banner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: #fff4e5; border: 1px solid #f3cf99; color: #7a4a00; border-radius: 8px; padding: .5rem .8rem; margin-bottom: 1rem; }
.btn.link { background: none; border: 0; color: var(--accent); padding: .3rem .4rem; font-weight: 600; }
.btn.link.danger { color: var(--danger); }
.btn.link:hover { text-decoration: underline; filter: none; }
.small-btn { padding: .45rem .8rem; }
h2 + .muted.small { margin-top: 0; }
.card h2 { margin-top: .25rem; }

.fav-bar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: -.25rem 0 1rem; }
.fav-label { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip { font: inherit; font-size: .88rem; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: .3rem .75rem; cursor: pointer; color: var(--ink); }
.chip span { color: var(--muted); font-size: .8rem; margin-left: .25rem; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.fav-save { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: -.5rem 0 .75rem; }
.fav-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.fav-form input { width: 260px; max-width: 100%; }

.custom-wrap { display: flex; flex-direction: column; gap: .35rem; }
label.check.small-check { margin: 0; font-size: .85rem; flex-wrap: wrap; }
.inline-input { width: 240px !important; max-width: 100%; padding: .35rem .5rem !important; }
.inline-input:disabled { background: var(--bg); }
input:disabled { background: var(--bg); color: var(--muted); }

.filters { display: flex; gap: 1rem; flex-wrap: wrap; }
.filters select { width: auto; }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; border-radius: 999px; padding: .15rem .55rem; white-space: nowrap; }
.badge.open { background: #fff4e5; color: #7a4a00; }
.badge.done { background: var(--accent-soft); color: var(--accent); }
td.acts { white-space: nowrap; text-align: right; }
td.acts.wide .btn.link { font-size: .85rem; }
.icon { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1.05rem; padding: .1rem .3rem; }
.icon:hover { color: var(--accent); }
.icon.del:hover { color: var(--danger); }
.lock { font-size: .85rem; opacity: .6; }
.submit-box { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
  border: 1px solid #b9d9cf; background: var(--accent-soft); border-radius: 8px; padding: .75rem 1rem; margin-top: 1rem; }
.submit-box p { margin: .2rem 0 0; }
.add-place { margin-top: 1rem; }

/* ---------- Google Maps support printout ---------- */
.trip-support { border: 1px solid #bbb; border-radius: 6px; padding: 10px 12px; margin: 0 0 12px; page-break-inside: avoid; break-inside: avoid; }
.ts-head { display: flex; gap: .4em; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.ts-miles { margin-left: auto; font-weight: bold; }
.ts-route div { margin: 2px 0; }
.pin { display: inline-block; width: 18px; height: 18px; border-radius: 50%; color: #fff; text-align: center; font-size: 11px; line-height: 18px; font-weight: bold; }
.pin.a { background: #1e8e3e; } .pin.b { background: #d93025; }
.ts-map { display: block; width: 100%; max-width: 640px; height: auto; aspect-ratio: 640 / 300; margin: 8px 0 6px; border: 1px solid #ddd; background: #f2f2f2; }
.paper a { color: #1a0dab; }

/* ---------- Printable form ---------- */
.paper {
  background: #fff; color: #000; border: 1px solid var(--line);
  padding: .6in .55in; font-family: Arial, Helvetica, sans-serif; font-size: 10.5pt;
}
.paper h2 { text-align: center; margin: 0; font-size: 15pt; }
.paper .org { text-align: center; margin: 0 0 .2in; font-size: 11pt; }
.paper .fields { display: grid; grid-template-columns: 1fr 1fr; gap: .08in .3in; margin-bottom: .2in; }
.paper .field { display: flex; gap: .4em; border-bottom: 1px solid #000; padding: 2px 0; }
.paper .field b { white-space: nowrap; }
.paper table { width: 100%; border-collapse: collapse; }
.paper th, .paper td { border: 1px solid #000; padding: 4px 5px; text-align: left; vertical-align: top; }
.paper th { background: #eee; font-size: 9pt; }
.paper td.num, .paper th.num { text-align: right; }
.paper .totals td { font-weight: bold; }
.paper .note { font-size: 8.5pt; margin-top: .08in; }
.paper .cert { margin: .25in 0 .3in; font-size: 9.5pt; }
.paper .sigs { display: grid; grid-template-columns: 2fr 1fr; gap: .35in .3in; }
.paper .sig { border-top: 1px solid #000; padding-top: 3px; font-size: 9pt; }

@media (max-width: 860px) { .grid.four { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) {
  .grid.two, .grid.three, .grid.four, .miles-row { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .card { padding: 1rem; }
  .paper { padding: .3in .2in; font-size: 9pt; overflow-x: auto; }
  .paper .fields { grid-template-columns: 1fr; }
}

@media print {
  @page { size: letter; margin: .5in; }
  body { background: #fff; }
  .no-print, .topbar { display: none !important; }
  main { margin: 0; max-width: none; padding: 0; }
  #view-form { display: block !important; }
  .paper { border: 0; padding: 0; }
  .paper tr { page-break-inside: avoid; }
}
