:root {
  --ink: #101214; --surface: #1f2327; --line-dark: #2a2f34; --on-dark: #e8ecef; --muted-dark: #b4bcc3;
  --accent: #b6f23c; --on-accent: #101214;
  --canvas: #f1f2ef; --card: #fff; --line: #dde0d9; --text: #14181b; --muted: #4d575e;
  --red: #c0392b; --red-bg: #fbe2df; --amber: #7d5200; --amber-bg: #fbeed0; --green: #1b6b36; --green-bg: #e2f3e6; --blue: #1f4f8f; --blue-bg: #e1ebf8; --grey-bg: #eceee9;
  --font: 'Manrope', system-ui, sans-serif; --mono: 'JetBrains Mono', ui-monospace, monospace; --r: 10px;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--text); font: 400 15px/1.5 var(--font); }
h1, h2, h3, h4, p, ul, ol, dl, dd { margin: 0; }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 5px var(--accent); }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }

.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr) 330px; min-height: 100vh; }
.shell > * { min-width: 0; }

/* Left nav */
.nav { background: var(--ink); color: var(--on-dark); padding: 18px 12px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.brand-text { display: grid; line-height: 1.2; }
.brand-text small { color: var(--muted-dark); font-size: 12.5px; }
.tabs { display: grid; gap: 2px; }
.tab { background: none; border: 0; color: var(--on-dark); text-align: left; padding: 9px 12px; border-radius: 8px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tab:hover { background: var(--surface); }
.tab.is-on { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); }
.tab .count { font: 500 12px var(--mono); color: var(--accent); }
.nav-foot { margin-top: auto; color: var(--muted-dark); font-size: 12.5px; line-height: 1.45; padding: 0 6px; }

/* Top bar */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.live { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #9aa3ab; }
.live.on .dot { background: #2fae52; box-shadow: 0 0 0 0 rgba(47, 174, 82, .5); animation: ping 2s infinite; }
.live.err .dot { background: var(--red); }
@keyframes ping { 70% { box-shadow: 0 0 0 8px rgba(47, 174, 82, 0); } 100% { box-shadow: 0 0 0 0 rgba(47, 174, 82, 0); } }
.btn { border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; font-weight: 700; font-size: 14px; line-height: 1.2; text-decoration: none; display: inline-block; text-align: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: #9fd62a; }
.btn-primary:hover:not(:disabled) { background: #c6fa56; }
.btn-dark { background: var(--ink); color: var(--on-dark); }
.btn-dark:hover:not(:disabled) { background: var(--surface); }
.btn-ghost { background: var(--card); border-color: #b9beb5; }
.btn-ghost:hover { background: var(--canvas); }
.btn-danger { background: var(--card); border-color: var(--red); color: var(--red); }

/* Views */
main { padding: 20px 24px 40px; display: grid; gap: 18px; align-content: start; grid-template-columns: minmax(0, 1fr); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; min-width: 0; }
.card h2 { font-size: 15px; font-weight: 800; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; }
.grid2 table { min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.stat span { display: block; font-size: 12px; color: var(--muted); font-weight: 700; }
.stat strong { display: block; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat.hot strong { color: var(--red); }

.attention { display: grid; gap: 8px; }
.alert { border-radius: 8px; padding: 10px 14px; font-weight: 600; font-size: 14.5px; display: flex; gap: 10px; align-items: center; }
.alert.bad { background: var(--red-bg); color: #8c1f17; }
.alert.warn { background: var(--amber-bg); color: var(--amber); }
.alert.ok { background: var(--green-bg); color: var(--green); }
.alert b { font: 800 11px var(--font); text-transform: uppercase; letter-spacing: .06em; }

.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.pill.ok { background: var(--green-bg); color: var(--green); } .pill.warn { background: var(--amber-bg); color: var(--amber); }
.pill.bad { background: var(--red-bg); color: #8c1f17; } .pill.info { background: var(--blue-bg); color: var(--blue); } .pill.neutral { background: var(--grey-bg); color: #4a545b; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 620px; }
th { text-align: left; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); font-weight: 800; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.sub { display: block; color: var(--muted); font-size: 12.5px; }
.sheet-view { padding: 20px 24px 24px; display: grid; gap: 10px; align-content: start; }
.sheet-view[hidden], main[hidden] { display: none; }
.stars { color: var(--amber); letter-spacing: 1px; white-space: nowrap; }
.barrow { display: grid; grid-template-columns: 90px minmax(0, 1fr) 28px; align-items: center; gap: 10px; font-size: 13px; margin: 8px 0; }
.barrow b { text-align: right; }
.bar { height: 10px; border-radius: 6px; background: var(--grey-bg); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 6px; background: var(--accent); }
/* Editing is for signed-in editors only: Edit and Add buttons, the side panel and the search. */
body:not(.is-admin) .admin-only { display: none !important; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.card-head h2 { font-size: 16px; font-weight: 800; }
td.req { min-width: 120px; }
td.req .sub { margin-top: 2px; }
.card h2 .btn { margin-left: 10px; font-size: 12.5px; padding: 4px 10px; vertical-align: middle; }
td .btn, .tech .btn { padding: 4px 10px; font-size: 12.5px; }
.manage-top { display: grid; gap: 12px; margin-bottom: 4px; }
.searchbox { display: flex; gap: 8px; }
.searchbox input { flex: 1; min-width: 0; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; font: inherit; font-size: 15px; background: #fff; color: inherit; }
.q-results { display: grid; gap: 12px; }
.q-group { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.q-group h3 { font-size: 14px; font-weight: 800; margin-bottom: 6px; }
.q-group .count { font: 500 12px var(--mono); color: var(--muted); margin-left: 6px; }
.q-group ul { list-style: none; padding: 0; display: grid; gap: 4px; }
.q-item { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; text-align: left; background: none; border: 1px solid transparent; border-radius: 8px; padding: 8px 10px; }
.q-item:hover { background: var(--grey-bg); border-color: var(--line); }
.q-title { font-weight: 700; overflow-wrap: anywhere; }
.q-sub { grid-column: 1; font-size: 12.5px; color: var(--muted); overflow-wrap: anywhere; }
.q-go { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 12.5px; font-weight: 700; color: var(--blue); }
.q-total { font-size: 12.5px; }
mark { background: #fff1a8; color: inherit; border-radius: 3px; padding: 0 1px; }
#dr-shade { position: fixed; inset: 0; background: rgba(16, 18, 20, .38); z-index: 30; }
#drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--canvas); z-index: 31; box-shadow: -12px 0 32px rgba(0, 0, 0, .18); display: grid; grid-template-rows: auto minmax(0, 1fr); }
#drawer[hidden], #dr-shade[hidden] { display: none; }
.dr-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; background: var(--card); border-bottom: 1px solid var(--line); }
.dr-head h2 { font-size: 17px; font-weight: 800; }
.dr-body { padding: 16px 18px 28px; overflow-y: auto; display: grid; gap: 12px; align-content: start; }
body.dr-open { overflow: hidden; }
/* Inside the panel, sections are plain headed groups with a rule between them, not boxed cards. */
#drawer .edit-card { background: none; border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 14px 0 0; }
#drawer .edit-card h3 { font-size: 14px; font-weight: 800; }
.edit-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 8px; align-content: start; min-width: 0; }
.edit-card h3 { font-size: 15px; font-weight: 800; }
.edit-card label { display: grid; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.edit-card small { font-weight: 400; }
.edit-card input, .edit-card select { width: 100%; min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 13.5px; color: inherit; background: #fff; }
.edit-card .two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.edit-card .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.edit-msg { font-size: 12.5px; min-height: 18px; color: var(--muted); }
.edit-msg.run { color: var(--amber); font-weight: 700; } .edit-msg.done { color: var(--green); font-weight: 700; } .edit-msg.fail { color: var(--red); font-weight: 700; }
.off-list { list-style: none; display: grid; gap: 6px; font-size: 12.5px; }
.off-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.admin-form { display: flex; align-items: center; gap: 6px; }
.admin-form[hidden] { display: none; }
.admin-form input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; font-size: 13.5px; width: 150px; }
.admin-msg { font-size: 12.5px; font-weight: 700; color: var(--red); }
.sr { position: absolute; left: -9999px; }
body:not(.is-admin) #restore-btn, body:not(.is-admin) #step-startover { display: none; }
/* The Google Sheet itself (link and embedded view) is for signed-in editors only. */
body:not(.is-admin) #sheet-link, body:not(.is-admin) #tabs .tab[data-tab="sheet"], body:not(.is-admin) #sheet-view { display: none; }
.restore-banner { margin: 14px 24px 0; padding: 10px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 700; background: var(--amber-bg); color: var(--amber); }
.restore-banner[hidden] { display: none; }
.restore-banner.done { background: var(--green-bg); color: var(--green); }
.restore-banner.fail { background: var(--red-bg); color: var(--red); }
.sheet-view iframe { width: 100%; height: calc(100vh - 190px); min-height: 480px; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.empty { color: var(--muted); padding: 14px 4px; }
.is-new { animation: flash 5s ease-out; }
@keyframes flash { 0% { background: #e9fbb8; } 100% { background: transparent; } }

/* Schedule board */
.board { display: grid; gap: 6px; }
.b-axis, .b-row { display: grid; grid-template-columns: 190px minmax(0, 1fr); align-items: center; }
.b-ticks { position: relative; height: 16px; }
.b-ticks span { position: absolute; transform: translateX(-50%); font: 500 11px var(--mono); color: var(--muted); }
.b-name { font-weight: 700; font-size: 13.5px; padding-right: 8px; display: grid; gap: 1px; }
.b-name small { font-weight: 500; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.sdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.sdot.ok { background: #2fae52; } .sdot.bad { background: var(--red); } .sdot.wait, .sdot.none { background: #e0a200; } .sdot.off { background: #9aa3ab; }
.b-track { position: relative; height: 46px; border: 1px solid var(--line); border-radius: 6px; background: repeating-linear-gradient(to right, #f6f7f4 0, #f6f7f4 calc(100%/12 - 1px), var(--line) calc(100%/12 - 1px), var(--line) calc(100%/12)); }
.b-track.off { background: var(--grey-bg); }
.b-off { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.block { position: absolute; top: 4px; bottom: 4px; border-radius: 5px; padding: 3px 7px; font-size: 12px; font-weight: 700; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #fff; border-left: 4px solid rgba(255, 255, 255, .55); }
.block small { display: block; font-weight: 500; opacity: .85; }
.block.emergency { background: var(--red); } .block.estimate { background: var(--blue); } .block.routine { background: #3a4249; }
.block.done { background: #7b868d; } .block.late { box-shadow: 0 0 0 2px #e0a200; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 5px 11px; font-weight: 700; font-size: 13px; }
.seg button.is-on { background: var(--ink); color: var(--on-dark); }

/* Activity feed */
.feed { list-style: none; padding: 0; display: grid; gap: 8px; }
.feed.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.feed li { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 9px 12px; background: #fafbf9; }
.feed li.customer { border-left-color: var(--blue); } .feed li.owner { border-left-color: #e0a200; }
.feed header { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-size: 12.5px; color: var(--muted); }
.feed header strong { color: var(--text); font-size: 13.5px; }
.feed p { margin-top: 4px; font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.feed li { min-width: 0; }

/* Team and cards */
.cards3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.tech { border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 8px; background: var(--card); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--ink); color: var(--accent); display: grid; place-items: center; font-weight: 800; flex: none; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Runner column */
.runner { background: var(--card); border-left: 1px solid var(--line); padding: 18px; display: grid; gap: 12px; align-content: start; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.runner h2 { font-size: 16px; font-weight: 800; }
.conn { border-radius: 8px; padding: 8px 12px; font-size: 13.5px; font-weight: 700; }
.conn.on { background: var(--green-bg); color: var(--green); } .conn.off { background: var(--amber-bg); color: var(--amber); }
.run-intro { font-size: 13.5px; color: var(--muted); }
.step { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 8px; background: #fafbf9; }
.step h3 { font-size: 14px; font-weight: 800; }
.step .what { font-size: 13px; color: var(--muted); line-height: 1.4; }
.step .watch { font-size: 12.5px; color: var(--text); font-weight: 600; }
.step select { width: 100%; border: 1px solid #c9cec6; border-radius: 6px; padding: 7px 8px; background: #fff; font-size: 13.5px; }
.step .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.step .btns .btn { flex: 1 1 auto; }
.status { font-size: 12.5px; min-height: 18px; color: var(--muted); }
.status.run { color: var(--amber); font-weight: 700; } .status.done { color: var(--green); font-weight: 700; } .status.fail { color: var(--red); font-weight: 700; }

@media (max-width: 1280px) { .shell { grid-template-columns: 190px minmax(0, 1fr); } .runner { grid-column: 1 / -1; position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); } .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }
  .tabs { grid-auto-flow: column; overflow-x: auto; max-width: 100%; grid-auto-columns: max-content; } .nav-foot { display: none; }
  .grid2, .cards3, .feed.two { grid-template-columns: 1fr; } .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  main { padding: 16px; } .topbar { padding: 14px 16px; } .b-axis, .b-row { grid-template-columns: 90px minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) { .is-new, .live.on .dot { animation: none; } }

/* Date and status filters, click-to-sort headers */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 0 0 12px; }
.filters label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.filters input, .filters select { font: inherit; font-size: 14px; font-weight: 400; color: var(--text); background: var(--card); border: 1px solid #b9beb5; border-radius: 8px; padding: 5px 8px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable::after { content: " \2195"; opacity: .35; }
th.sorted-asc::after { content: " \25B2"; opacity: 1; font-size: 10px; }
th.sorted-desc::after { content: " \25BC"; opacity: 1; font-size: 10px; }
