/* Gemstar Contractors. Internal ops tool: calm, dense where it matters, one teal accent. */
:root {
  --bg: #f4f5f6;
  --surface: #ffffff;
  --surface-2: #f9fafa;
  --ink: #17191c;
  --muted: #4f5660;
  --faint: #5b626b;
  --line: #e2e5e9;
  --line-strong: #cdd2d8;
  --accent: #0e7468;
  --accent-hover: #0b5f55;
  --accent-soft: #e3f2ef;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --warn: #9a4a07;
  --warn-soft: #fdf1df;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(23, 33, 43, .06), 0 4px 16px rgba(23, 33, 43, .06);
  --font: ui-sans-serif, -apple-system, "Segoe UI Variable", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
a { color: var(--accent); }
h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 12px; letter-spacing: -0.005em; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* Header */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; min-height: 64px; }
.brand { min-height: 44px; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--muted); text-decoration: none; padding: 0 12px; min-height: 44px; display: flex; align-items: center; border-radius: var(--radius); white-space: nowrap; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { color: var(--accent); background: var(--accent-soft); }
.who { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.who .email { color: var(--faint); font-size: 13px; }
.badge-demo { background: var(--warn-soft); color: var(--warn); border: 1px solid #f2d3a6; font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; gap: 4px 12px; padding-top: 8px; padding-bottom: 4px; }
  /* Wrap instead of hiding items off-screen, so every page (incl. Settings) is visible. */
  .nav { order: 3; flex-basis: 100%; margin: 0 -8px; flex-wrap: wrap; overflow: visible; gap: 2px; }
  .nav a { padding: 0 10px; }
  .who .email { display: none; }
  .who { margin-left: auto; }
}

main { max-width: 1400px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }

/* Buttons */
.btn { appearance: none; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; min-height: 44px; padding: 0 16px; border-radius: var(--radius); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .08s; }
.btn:hover { background: var(--surface-2); border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .nav a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .slot:focus-visible, .appt:focus-visible { outline: 3px solid rgba(14, 116, 104, .35); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: #efc4c0; }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-icon { width: 44px; padding: 0; font-size: 18px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Forms: label above input, error below */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field .help { font-size: 13px; color: var(--muted); }
.field .err { font-size: 13px; color: var(--danger); }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); min-height: 44px; padding: 8px 12px; width: 100%;
}
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #6f7680; }
input[disabled], select[disabled], textarea[disabled] { background: var(--surface-2); color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }
.form-error { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-weight: 500; }
.form-ok { background: var(--accent-soft); color: var(--accent-hover); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-weight: 500; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.panel-narrow { max-width: 760px; }

/* Pills */
.pill { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill-active { background: var(--accent-soft); color: var(--accent-hover); border-color: #bfe2dc; }
.pill-onboarding { background: #eef2f7; color: #34495e; border-color: #d5dde6; }
.pill-paused { background: var(--warn-soft); color: var(--warn); border-color: #f2d3a6; }
.pill-inactive { background: #f1f1f2; color: #5c6168; }
.pill-error { background: var(--danger-soft); color: var(--danger); border-color: #f2c3be; }
.pill-ok { background: var(--accent-soft); color: var(--accent-hover); border-color: #bfe2dc; }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }

/* Calendar */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.toolbar .field { margin: 0; min-width: 170px; }
.toolbar .week-nav { display: flex; gap: 6px; }
.status-line { font-size: 13px; color: var(--muted); margin-left: auto; align-self: center; }
.cal-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); max-height: calc(100dvh - 230px); min-height: 320px; }
.cal { display: grid; min-width: min-content; }
.cal-cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 8px; min-width: 0; }
.cal-head { position: sticky; top: 0; z-index: 3; background: var(--surface); padding: 10px 10px; }
.cal-head .name { font-weight: 700; }
.cal-head .meta { font-size: 12px; color: var(--muted); }
.cal-head.err { background: var(--danger-soft); }
.cal-head.err .name, .cal-head.err .meta { color: var(--danger); }
.cal-day { position: sticky; left: 0; z-index: 2; background: var(--surface-2); text-align: left; }
.cal-day .dow { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.cal-day .num { font-size: 20px; font-weight: 700; line-height: 1.1; }
.cal-day.today { background: var(--accent-soft); }
.cal-day.today .num { color: var(--accent); }
.cal-corner { position: sticky; left: 0; top: 0; z-index: 4; background: var(--surface); }
.cal-cell.past { background: repeating-linear-gradient(135deg, #fafbfb 0 8px, #f5f6f7 8px 16px); }
.cell-stack { display: flex; flex-direction: column; gap: 6px; }
.slots { display: flex; flex-wrap: wrap; gap: 6px; }
.slot { appearance: none; font: inherit; font-size: 13px; font-weight: 600; min-height: 44px; min-width: 76px; padding: 0 10px; border-radius: var(--radius); border: 1px dashed #9fcfc7; background: #f3faf8; color: var(--accent-hover); cursor: pointer; }
.slot:hover { background: var(--accent-soft); border-style: solid; }
.slot:active { transform: scale(.98); }
.appt { appearance: none; text-align: left; font: inherit; width: 100%; min-height: 44px; border: 1px solid #c8d3e0; border-left: 4px solid #3d5a80; background: #eef3f9; border-radius: var(--radius); padding: 6px 9px; cursor: pointer; color: var(--ink); }
.appt:hover { background: #e4ecf6; }
.appt .t { font-size: 12px; color: #34495e; font-weight: 600; }
.appt .x { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-cell { font-size: 12px; color: var(--faint); }
.conn-msg { font-size: 12px; color: var(--muted); }
.skeleton { background: linear-gradient(90deg, #eef0f2 25%, #f6f7f8 50%, #eef0f2 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .btn, .slot { transition: none; } }
.empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); }

/* Dialog */
dialog { border: none; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(23, 33, 43, .25); color: var(--ink); }
dialog::backdrop { background: rgba(23, 27, 33, .45); }
.dlg-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head h2 { margin: 0; flex: 1; }
.dlg-body { padding: 16px 20px; }
.dlg-foot { padding: 12px 20px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; position: sticky; bottom: 0; background: var(--surface); }
.dlg-foot .left { margin-right: auto; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 14px; margin-bottom: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Lists */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list-row { display: grid; grid-template-columns: minmax(180px, 2fr) 1.2fr 110px 1.3fr 200px; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 56px; }
.list-row:last-child { border-bottom: none; }
a.list-row:hover { background: var(--surface-2); }
.list-head { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; min-height: 40px; background: var(--surface-2); }
.list-row .name { font-weight: 600; }
.list-row .sub { font-size: 13px; }
@media (max-width: 760px) {
  .list-head { display: none; }
  .list-row { grid-template-columns: 1fr auto; gap: 4px 12px; }
  .list-row > .c-phone, .list-row > .c-zones { grid-column: 1; font-size: 13px; color: var(--muted); }
  .list-row > .c-status { grid-column: 2; grid-row: 1; }
  .list-row > .c-coi { grid-column: 2; grid-row: 2; text-align: right; font-size: 13px; }
}

/* Services grid */
.svc-table { width: 100%; border-collapse: collapse; }
.svc-table th, .svc-table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.svc-table th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.svc-table input[type=text], .svc-table input[type=number] { min-width: 90px; }
.svc-scroll { overflow-x: auto; }
.grid-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.cap-grid { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.cap-grid th, .cap-grid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; text-align: center; background: var(--surface); }
.cap-grid thead th { font-size: 12px; font-weight: 700; padding: 10px 8px; color: var(--muted); white-space: nowrap; }
.cap-grid .first { position: sticky; left: 0; z-index: 1; text-align: left; padding: 8px 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
.cap-grid thead .first { z-index: 2; }
.check { display: grid; place-items: center; min-width: 64px; min-height: 48px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); cursor: pointer; }
.check input[disabled] { cursor: not-allowed; }

/* Activity */
.act-row { display: grid; grid-template-columns: 150px 190px 1fr 70px; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 14px; align-items: start; }
.act-row:last-child { border-bottom: none; }
.act-row .what { font-weight: 600; }
.act-row .detail { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.act-row > div { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  /* Stacked card per entry on phones: nothing can push the page sideways. */
  .act-row { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; }
  .act-row .when, .act-row .who { font-size: 12px; color: var(--muted); }
  .act-row .result { order: -1; }
}

/* Toast */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius); box-shadow: var(--shadow); z-index: 100; max-width: calc(100vw - 32px); font-weight: 500; }
.toast.err { background: var(--danger); }

/* Login */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 14px 0 4px; }
.login-card .btn { width: 100%; margin-top: 4px; }

.conn-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--surface-2); margin-bottom: 14px; }
.ok-mark { color: var(--accent); font-weight: 700; }

.detail-line { display: block; font-size: 12px; font-weight: 400; opacity: .85; margin-top: 4px; font-family: var(--mono); overflow-wrap: anywhere; }
.alert-banner { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.alert-banner .btn { justify-content: flex-start; text-align: left; white-space: normal; width: 100%; background: var(--danger-soft); color: var(--danger); border-color: #efc4c0; font-weight: 600; }
.alert-banner .btn:hover { border-color: var(--danger); background: #fbe0de; }
.warn-box { background: var(--warn-soft); color: var(--warn); border: 1px solid #f2d3a6; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; }
.warn-box p { margin: 0 0 8px; }
.end-line { font-weight: 600; color: var(--ink); }
.cal-head.flash { animation: flash 1.2s ease-out 1; }
@keyframes flash { from { box-shadow: inset 0 0 0 3px var(--danger); } to { box-shadow: inset 0 0 0 0 transparent; } }
@media (max-width: 760px) { .list-row > .c-status { justify-self: end; } }
.grid-2 { align-items: start; }
.field { align-content: start; }
@media (max-width: 760px) { .act-row > div { text-align: left; align-self: stretch; } }

.cal-head { scroll-margin-left: 84px; }

/* Services on phones: each service is a card (name on its own line, then minutes, price, active),
   and grid names wrap onto two lines instead of being clipped. */
@media (max-width: 640px) {
  .svc-table thead { display: none; }
  .svc-table, .svc-table tbody { display: block; }
  .svc-table tr { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .svc-table td { display: grid; gap: 4px; padding: 0; border: none; }
  .svc-table td:first-child { grid-column: 1 / -1; }
  .svc-table td::before { content: attr(data-label); font-size: 12px; font-weight: 700; color: var(--muted); }
  .svc-table input[type=text], .svc-table input[type=number] { min-width: 0; }
  .svc-scroll { overflow-x: visible; }
  .cap-grid .first { white-space: normal; overflow-wrap: anywhere; min-width: 112px; max-width: 38vw; line-height: 1.25; }
  .cap-grid .first .pill { display: table; margin-top: 4px; }
}

/* Routing update: Find a time, Shop / Mobile switch, tag chips. */
fieldset.field { border: 0; padding: 0; min-width: 0; }
fieldset.field legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg label { position: relative; display: flex; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { min-height: 44px; min-width: 88px; padding: 0 16px; display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--muted); }
.seg label + label span { border-left: 1px solid var(--line-strong); }
.seg input:checked + span { background: var(--accent-soft); color: var(--accent-hover); }
.seg input:focus-visible + span { outline: 3px solid rgba(14, 116, 104, .35); outline-offset: -3px; }
.seg input:disabled + span { opacity: .45; }
.finder { padding: 0; margin-bottom: 14px; }
.finder > summary { list-style: none; cursor: pointer; min-height: 52px; padding: 0 20px; display: flex; align-items: center; gap: 12px; font-weight: 700; }
.finder > summary::-webkit-details-marker { display: none; }
.finder > summary::after { content: "+"; margin-left: auto; font-size: 20px; color: var(--muted); font-weight: 400; }
.finder[open] > summary::after { content: "\2212"; }
.finder > summary:focus-visible { outline: 3px solid rgba(14, 116, 104, .35); outline-offset: -3px; border-radius: var(--radius); }
.finder-form { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; padding: 0 20px 14px; }
.finder-form .field { margin: 0; min-width: 170px; }
.finder-form #ftWhereField { flex: 1 1 200px; }
.finder > .form-error { margin: 0 20px 14px; }
.finder-results { padding: 0 20px; }
.finder-results:not(:empty) { padding-bottom: 16px; }
.opt-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.opt { appearance: none; font: inherit; text-align: left; min-height: 56px; padding: 8px 12px; border-radius: var(--radius); border: 1px solid #9fcfc7; background: #f3faf8; color: var(--ink); cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.opt:hover { background: var(--accent-soft); }
.opt:focus-visible { outline: 3px solid rgba(14, 116, 104, .35); outline-offset: 1px; }
.opt-when { font-weight: 700; color: var(--accent-hover); }
.opt-who { font-size: 13px; color: var(--muted); }
.chip { display: inline-flex; align-items: center; font: 600 12px/1 var(--mono); padding: 5px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); white-space: nowrap; }
.chip-route { font-family: var(--font); background: var(--accent-soft); border-color: #bfe2dc; color: var(--accent-hover); align-self: flex-start; margin-top: 2px; }
.tag-preview { display: grid; gap: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag-where { font-size: 12px; color: var(--muted); font-weight: 600; flex-basis: 100%; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 16px; align-items: start; }
@media (max-width: 640px) { .grid-3 { grid-template-columns: 1fr 1fr; } .grid-3 > :first-child { grid-column: 1 / -1; } }
.cal-line { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.loc-line { font-size: 14px; font-weight: 600; margin: -4px 0 14px; }
.appt .mini { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.check-row { display: flex; gap: 8px; flex-wrap: wrap; }
.check-pill { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); cursor: pointer; font-weight: 600; }
.check-pill input { width: 20px; height: 20px; accent-color: var(--accent); }
.zip-row { display: grid; grid-template-columns: 90px 1fr 44px; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); }
.zip-add { display: grid; grid-template-columns: 110px 1fr auto; gap: 8px; align-items: end; margin-top: 12px; }
.zip-add .field { margin: 0; }
@media (max-width: 480px) { .zip-add { grid-template-columns: 1fr 1fr; } .zip-add .btn { grid-column: 1 / -1; } }
.zip-list { max-height: 320px; overflow: auto; }
.zip-list { max-height: none; }
.zip-group { padding: 8px 0; border-bottom: 1px solid var(--line); }
.zip-zone { font-weight: 700; margin-bottom: 6px; }
.zip-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.zip-chip { appearance: none; font: 600 13px/1 var(--mono); min-height: 44px; padding: 0 12px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; }
.zip-chip:hover { border-color: var(--danger); }
.zip-chip.armed { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.zip-chip:focus-visible { outline: 3px solid rgba(14, 116, 104, .35); outline-offset: 1px; }
.seg { justify-self: start; width: max-content; }
.field-err { color: var(--danger); background: var(--danger-soft); border-radius: var(--radius); padding: 10px 12px; margin: -4px 0 12px; font-weight: 600; font-size: 14px; }
.ft-more { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 10px 0 0; color: var(--muted); }
