/* Grid styles, ported from docs/mockups/index.html. */
:root {
  --bg: #f6f7f9; --surface: #fff; --surface-2: #f0f2f5; --line: #dfe3e8; --line-strong: #c5ccd5;
  --text: #1c2430; --muted: #66717f; --accent: #2457d6; --accent-soft: #e6edfd;
  --amber: #b7791f; --amber-soft: #fdf3dc; --red: #c53030; --red-soft: #fde8e8; --green: #2f855a; --green-soft: #e3f5ea;
  --s-ordered: #7a5af8; --s-build: #0e7490; --s-ship: #b45309; --s-install: #1d4ed8; --s-live: #15803d; --s-exception: #c53030;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --surface: #1a1f27; --surface-2: #222833; --line: #2d3440; --line-strong: #3d4655;
    --text: #e3e7ee; --muted: #8d97a6; --accent: #6d95f5; --accent-soft: #1f2a44;
    --amber: #e0a84a; --amber-soft: #3a2e15; --red: #f07070; --red-soft: #3d1c1c; --green: #5cc28a; --green-soft: #173426;
  }
}

body { background: var(--bg); color: var(--text); font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
kbd { font: 11px ui-monospace, Menlo, monospace; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--surface); }

.app-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.app-header button, .app-header [data-current-user] { color: var(--muted); }

.toolbar { display: flex; padding: 8px 16px 0; background: var(--surface); }
.search { flex: 1; max-width: 460px; position: relative; }
.search input { width: 100%; padding: 6px 30px 6px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
.search kbd { position: absolute; right: 8px; top: 6px; }

.filters { display: flex; gap: 4px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.chip { border: 1px solid transparent; border-radius: 999px; padding: 4px 11px; white-space: nowrap; color: var(--muted); text-decoration: none; }
.chip .n { font-variant-numeric: tabular-nums; margin-left: 5px; opacity: .75; }
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.chip.exc.has { color: var(--red); }
.filters .sep { width: 1px; background: var(--line); margin: 2px 6px; }

.gridwrap { flex: 1; min-height: 0; overflow: auto; position: relative; }
.install-grid { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.install-grid th, .install-grid td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; white-space: nowrap; text-align: left; background: var(--surface); }
.install-grid thead th { position: sticky; z-index: 3; background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: 11.5px; }
.install-grid thead tr.g th { top: 0; height: 24px; padding: 0 8px; text-transform: uppercase; letter-spacing: .5px; font-size: 10.5px; user-select: none; }
.install-grid .group-toggle { all: unset; cursor: pointer; display: block; width: 100%; }
.install-grid .group-toggle:hover { color: var(--text); }
.install-grid .group-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.install-grid thead tr.c th { top: 24px; height: 26px; padding: 0 8px; }
.install-grid .stk { position: sticky; z-index: 2; }
.install-grid thead th.stk { z-index: 4; }
.install-grid .stk.last { box-shadow: 2px 0 0 var(--line-strong); }
.install-grid td .v { display: block; padding: 5px 8px; min-height: 27px; overflow: hidden; text-overflow: ellipsis; position: relative; }
.install-grid td.empty .v { color: var(--line-strong); }
.install-grid td.ro .v { color: var(--muted); background: var(--surface-2); }
.install-grid tr:hover td { background: color-mix(in srgb, var(--surface) 92%, var(--accent)); }
.install-grid tr.exc td { background: color-mix(in srgb, var(--surface) 90%, var(--red)); }
.install-grid td.need .v::after { content: ""; position: absolute; right: 5px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--amber); }
.install-grid td.need.empty .v { background: var(--amber-soft); }

/* Collapsible groups: hide a group's cells and show its narrow stub instead. */
.install-grid .stub { display: none; width: 30px; min-width: 30px; max-width: 30px; background: var(--surface-2); color: var(--muted); text-align: center; }
.install-grid.hide-order .g-order, .install-grid.hide-build .g-build, .install-grid.hide-ship .g-ship,
.install-grid.hide-install .g-install, .install-grid.hide-live .g-live, .install-grid.hide-commercial .g-commercial { display: none; }
.install-grid.hide-order .stub-order, .install-grid.hide-build .stub-build, .install-grid.hide-ship .stub-ship,
.install-grid.hide-install .stub-install, .install-grid.hide-live .stub-live, .install-grid.hide-commercial .stub-commercial { display: table-cell; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; color: #fff; }
.pill.st-anticipated { background: none; color: var(--s-ordered); border: 1px dashed var(--s-ordered); }
.pill.st-ordered { background: var(--s-ordered); } .pill.st-build { background: var(--s-build); } .pill.st-ship { background: var(--s-ship); }
.pill.st-install { background: var(--s-install); } .pill.st-live { background: var(--s-live); } .pill.st-exception { background: var(--s-exception); }
.pill.ghost { background: none; color: var(--muted); border: 1px dashed var(--line-strong); }
.pill .was { font-weight: 400; opacity: .85; }
.tag { display: inline-block; font-size: 10.5px; padding: 0 5px; border-radius: 4px; border: 1px solid var(--line-strong); color: var(--muted); margin-left: 4px; vertical-align: 1px; }
.tag.amber { border-color: var(--amber); color: var(--amber); }
.shared { font-size: 10px; color: var(--accent); margin-left: 5px; font-weight: 600; }
.next.todo { color: var(--amber); font-weight: 500; }
.next.ready { color: var(--green); }
.next.exception { color: var(--red); }
.next.done { color: var(--muted); }
.empty-state { padding: 24px 16px; color: var(--muted); }
.gridwrap:has(tbody tr) .empty-state { display: none; }

/* Phone: cards instead of the table. */
.cards { display: none; }
@media (max-width: 720px) {
  .gridwrap { display: none; }
  .cards { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; overflow: auto; }
  .card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
  .card.exc { border-color: var(--red); }
  .card-ids { display: flex; gap: 12px; }
  .card-customer { margin: 4px 0 6px; font-weight: 500; }
  .card-foot { display: flex; gap: 8px; align-items: center; }
}

/* Selection and editing (S3). */
.gridwrap:focus { outline: none; }
.install-grid td.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.install-grid tr.selrow td { background: color-mix(in srgb, var(--surface) 88%, var(--accent)); }
.install-grid td.editing { outline: 2px solid var(--accent); outline-offset: -2px; }
.install-grid td.editing:not(.stk) { position: relative; }
.install-grid td.stk.editing { z-index: 5; }
.install-grid td.editing input, .install-grid td.editing select { width: 100%; border: 0; padding: 5px 8px; font: inherit; background: var(--surface); color: var(--text); outline: none; height: 27px; }
.install-grid td.editing.bad input { background: var(--red-soft); }
.install-grid td.editing .cal { position: absolute; right: 2px; top: 3px; border: 0; background: none; cursor: pointer; font-size: 13px; padding: 2px 4px; color: var(--muted); }
.dhint { position: absolute; left: 0; top: 100%; z-index: 30; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 4px; padding: 2px 6px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.install-grid td.editing.bad .dhint { color: var(--red); border-color: var(--red); }
.install-grid td.saving .v { color: var(--muted); }
.install-grid td.saving .v::after { content: "…"; position: absolute; right: 6px; color: var(--muted); }
.install-grid td.saved .v { background: var(--green-soft); transition: background 1s; }
.install-grid td.err { outline: 2px solid var(--red) !important; outline-offset: -2px; }
.install-grid td.err .v { background: var(--red-soft); }
.tip { position: fixed; z-index: 20; background: var(--surface); border: 1px solid var(--red); border-radius: 6px; box-shadow: 0 8px 30px rgba(20, 30, 50, .18); padding: 8px 10px; max-width: 330px; font-size: 12px; white-space: normal; }
.tip b { color: var(--red); }
.tip .acts, .bar .acts { margin-top: 6px; color: var(--muted); }
.bar { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); z-index: 40; background: var(--surface); border: 1px solid var(--accent); border-radius: 8px; box-shadow: 0 8px 30px rgba(20, 30, 50, .18); padding: 10px 14px; max-width: 620px; width: calc(100% - 32px); }
.calpop { position: fixed; z-index: 70; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 8px 30px rgba(20, 30, 50, .18); padding: 8px; width: 236px; user-select: none; }
.calpop .ch { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-weight: 600; }
.calpop .ch button { border: 0; background: none; cursor: pointer; font-size: 15px; padding: 0 8px; color: var(--text); }
.calpop .cg { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.calpop .wd { font-size: 10.5px; color: var(--muted); }
.calpop .d { border: 0; background: none; border-radius: 4px; padding: 4px 0; cursor: pointer; color: var(--text); font: inherit; font-size: 12px; }
.calpop .d:hover { background: var(--surface-2); }
.calpop .d.today { outline: 1px solid var(--accent); }
.calpop .d.on { background: var(--accent); color: #fff; }
.gridfoot { display: flex; justify-content: space-between; gap: 12px; padding: 6px 16px; border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 12px; }
@media (max-width: 720px) { .gridfoot { display: none; } }

/* Stage dialogs (S4). */
.modal { border: 1px solid var(--line-strong); border-radius: 10px; padding: 18px 20px; width: min(460px, calc(100% - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 8px 30px rgba(20, 30, 50, .25); }
.modal::backdrop { background: rgba(10, 15, 25, .35); }
.modal h2 { margin: 6px 0 12px; font-size: 16px; }
.modal-sub { margin: 0; color: var(--muted); font-size: 12px; }
.modal-text { margin: 0 0 12px; }
.modal form { display: flex; flex-direction: column; gap: 10px; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.modal label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.modal input[type=text], .modal textarea, .modal select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line-strong); border-radius: 6px; padding: 6px 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal-actions button, .modal-actions input[type=submit], .modal-temp input[type=submit] { font: inherit; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.modal-actions .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.modal-actions .primary.danger { background: var(--red); border-color: var(--red); }
.modal-actions .primary:disabled { opacity: .45; cursor: not-allowed; }
.modal-missing { background: var(--amber-soft); border: 1px solid var(--amber); border-radius: 6px; padding: 8px 10px; }
.modal-errors { background: var(--red-soft); border: 1px solid var(--red); border-radius: 6px; padding: 6px 10px; margin: 8px 0; }
.modal-errors p { margin: 2px 0; }
.modal-temp { flex-direction: row !important; align-items: center; justify-content: space-between; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }

/* Details drawer (S5). */
#drawer:empty { display: none; }
.drawer { position: fixed; right: 0; top: 44px; bottom: 0; width: 440px; max-width: 100%; z-index: 50; background: var(--surface); border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(20, 30, 50, .18); overflow: auto; }
.dh { position: sticky; top: 0; z-index: 2; display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.dh h2 { margin: 0; font-size: 15px; }
.dsub { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.dh-actions { display: flex; gap: 6px; align-items: center; }
.dh-actions button { font: inherit; font-size: 12px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 6px; padding: 3px 8px; cursor: pointer; }
.dh-actions .x { border: 0; font-size: 18px; color: var(--muted); }
.ds { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.ds h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.dfield { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.dfield:has(textarea) { grid-column: 1 / -1; }
.dlabel { font-size: 11px; color: var(--muted); }
.dfield input, .dfield select, .dfield textarea, .ds textarea, .addrow input, .addrow select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line-strong); border-radius: 5px; padding: 4px 6px; min-width: 0; }
.dfield.saving input { color: var(--muted); }
.dfield.saved input, .dfield.saved textarea, .dfield.saved select { background: var(--green-soft); }
.dfield.err input, .dfield.err textarea, .dfield.err select { border-color: var(--red); background: var(--red-soft); }
.derror { color: var(--red); font-size: 11px; }
.dhint-static { color: var(--muted); font-size: 11px; }
.dwarn { color: var(--amber); font-size: 12px; }
.derror-banner { margin: 8px 16px; padding: 6px 10px; border: 1px solid var(--red); background: var(--red-soft); border-radius: 6px; }
.dlist { list-style: none; margin: 6px 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.dlist small { color: var(--muted); margin-left: 4px; }
.dlist.notes p { margin: 2px 0 6px; white-space: pre-wrap; }
.ds form.inline { display: inline; }
.ds input.link { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 12px; padding: 0 4px; }
.ds input[type=submit]:not(.link) { margin-top: 6px; font: inherit; font-size: 12px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 5px; padding: 3px 10px; cursor: pointer; }
.addrow { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.ship { border: 1px solid var(--line); border-radius: 6px; padding: 8px; margin-bottom: 8px; }
.ship.review { border-color: var(--amber); }
.idkind { margin-top: 8px; }
.exception-box { background: var(--red-soft); }
.exception-box p { margin: 2px 0; }
.install-grid td.c-customer .rowopen { position: absolute; right: 3px; top: 4px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 4px; font-size: 11px; line-height: 16px; padding: 0 5px; color: var(--accent); text-decoration: none; visibility: hidden; }
.install-grid tr:hover td.c-customer .rowopen, .install-grid tr.selrow td.c-customer .rowopen { visibility: visible; }
.card { position: relative; }
.card-open { position: absolute; inset: 0; }
@media (max-width: 720px) { .drawer { top: 0; width: 100%; } .dgrid { grid-template-columns: 1fr; } }

/* Date inputs outside the grid (drawer, dialogs). */
input[data-controller~="date-field"].bad { border-color: var(--red); background: var(--red-soft); }
.cal-inline { border: 0; background: none; cursor: pointer; font-size: 13px; padding: 0 4px; color: var(--muted); align-self: flex-start; }
.date-hint { color: var(--muted); font-size: 10.5px; }
input[data-controller~="date-field"].bad ~ .date-hint { color: var(--red); }

/* Intake and lifecycle (S6). */
.modal-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lifecycle p { margin: 2px 0; }
.lifecycle-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lifecycle-actions .addrow { margin-top: 0; }
.toolbar { gap: 10px; align-items: center; }
.newbtn { border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px; padding: 5px 10px; text-decoration: none; white-space: nowrap; }
.newbtn kbd { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .5); }

/* Live updates (S7). */
.dremote { display: flex; gap: 8px; align-items: center; margin: 8px 16px; padding: 6px 10px; border: 1px solid var(--amber); background: var(--amber-soft); border-radius: 6px; }
.dremote button, .reloadbar button { font: inherit; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 5px; padding: 2px 8px; cursor: pointer; }
.install-grid tr.remote-changed td.c-stage { box-shadow: inset 3px 0 0 var(--amber); }
.reloadbar { display: flex; gap: 10px; align-items: center; padding: 6px 16px; background: var(--amber-soft); border-bottom: 1px solid var(--amber); }

/* Import review (S8b). */
.importpage { padding: 16px; overflow: auto; }
.importpage h1 { font-size: 18px; margin: 4px 0 8px; }
.importpage .note { color: var(--muted); }
.itable { border-collapse: collapse; margin: 8px 0; }
.itable td, .itable th { border: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.ifilters { display: flex; gap: 12px; margin: 8px 0; }
.ifilters .on { font-weight: 600; }
.imatch { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 10px 0; background: var(--surface); }
.imatch.confirmed { border-color: var(--green); } .imatch.rejected { opacity: .7; }
.imatch header { display: flex; gap: 8px; } .istatus { margin-left: auto; color: var(--muted); }
.ipair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ipair h3 { font-size: 13px; margin: 6px 0 2px; } .ipair dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 4px 0; }
.ipair dt { color: var(--muted); }
.iactions { display: flex; gap: 8px; margin-top: 6px; }
.iactions button { font: inherit; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); border-radius: 6px; padding: 3px 10px; cursor: pointer; }
.igaps { margin: 8px 0; }
