/* ═══════════════════════════════════════════════════════════════
   DETAIL PANEL — modal slide-over sheet (shadcn Sheet / Supabase style)
   The <turbo-frame> is a full-screen layer holding a clickable dark
   backdrop + the right-hand sheet. Empty frame collapses (:empty).
   ═══════════════════════════════════════════════════════════════ */
/* Animation lives on the persistent layer element (not the swapped-in
   backdrop/sheet), so it runs once on open — not on every frame update. */
.panel-layer { position: fixed; inset: 0; z-index: 40; animation: panel-layer-in var(--duration-base) var(--ease-out); }
.panel-layer:empty { display: none; }
.panel-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); cursor: pointer; }
.panel-sheet { position: absolute; top: 0; right: 0; bottom: 0; width: 460px; max-width: 100vw; background: var(--bg-surface); border-left: 1px solid var(--border-default); box-shadow: -16px 0 48px rgba(0, 0, 0, 0.4); display: flex; flex-direction: column; }
@keyframes panel-layer-in { from { opacity: 0; } to { opacity: 1; } }

.edit-panel__head { padding: var(--space-5) var(--space-6); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.edit-panel__head-title { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.edit-panel__eyebrow { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-tertiary); font-weight: 500; }
.edit-panel__eyebrow strong { color: var(--accent-emphasis); font-weight: 600; }
.edit-panel__title { font-family: var(--font-display); font-size: 20px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; color: var(--text-primary); }
.edit-panel__close { width: 32px; height: 32px; border: 1px solid var(--border-default); background: var(--bg-elevated); color: var(--text-secondary); border-radius: var(--radius-md); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; text-decoration: none; }
.edit-panel__close svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 2.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.edit-panel__body { flex: 1; overflow-y: auto; padding: var(--space-5) var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); }

.identity-card { padding: var(--space-4); background: linear-gradient(135deg, var(--bg-elevated), var(--bg-surface)); border: 1px solid var(--border-default); border-radius: var(--radius-lg); display: flex; align-items: center; gap: var(--space-4); }
.identity-card__avatar { width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, var(--brand-orange), var(--brand-red)); color: white; display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-size: 18px; font-weight: 700; flex-shrink: 0; }
.identity-card__body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.identity-card__name { font-family: var(--font-display); font-size: 18px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; color: var(--text-primary); }
.identity-card__role { font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); letter-spacing: 0.04em; }
.identity-card__ids { display: flex; gap: var(--space-2); margin-top: 6px; flex-wrap: wrap; }

.detail-section { display: flex; flex-direction: column; }
.section-divider { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-1); }
.section-divider__line { flex: 1; height: 1px; background: var(--border-subtle); }
.section-divider__title { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.15em; text-transform: uppercase; color: var(--text-tertiary); font-weight: 600; }
.section-divider__meta { font-family: var(--font-mono); font-size: 10px; color: var(--text-tertiary); }
.detail-section__body { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-3); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field__label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-tertiary); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.field__hint { font-family: var(--font-mono); font-size: 10px; color: var(--text-tertiary); letter-spacing: 0.04em; font-weight: 400; text-transform: none; margin-left: auto; }
.field__input, .field__select { height: 36px; padding: 0 var(--space-3); background: var(--bg-elevated); border: 1px solid var(--border-default); border-radius: var(--radius-md); color: var(--text-primary); font-family: var(--font-body); font-size: 13px; outline: none; width: 100%; }
.field__input:focus, .field__select:focus { border-color: var(--accent-emphasis); box-shadow: 0 0 0 3px rgba(233, 114, 76, 0.15); }
.field__input[readonly] { color: var(--text-secondary); background: var(--bg-sunken); }
.field__select { cursor: pointer; appearance: none; padding-right: var(--space-6); background-image: linear-gradient(45deg, transparent 50%, var(--text-tertiary) 50%), linear-gradient(135deg, var(--text-tertiary) 50%, transparent 50%); background-position: right 14px top 50%, right 9px top 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.field--check { flex-direction: row; align-items: center; gap: var(--space-2); }
.field--check .field__label { text-transform: none; letter-spacing: 0.04em; font-size: 12px; color: var(--text-secondary); }
.field--check input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent-emphasis); cursor: pointer; }
.check-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-2) var(--space-4); }

/* Weekly service-day strip (calendars) */
.week-strip { display: flex; gap: 4px; }
.week-day { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: 10px; font-weight: 600; background: var(--bg-sunken); color: var(--text-tertiary); border: 1px solid var(--border-default); }
.week-day--on { background: var(--accent-bg); color: var(--accent-emphasis); border-color: var(--accent-border); }

/* Read-panel empty state + compact lists (trips) */
.detail-empty { margin: 0; font-size: 12px; color: var(--text-tertiary); font-style: italic; }
.itinerary { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.itinerary__row { display: flex; align-items: center; gap: var(--space-3); padding: 6px 0; border-bottom: 1px solid var(--border-muted, var(--border-default)); font-size: 13px; }
.itinerary__row:last-child { border-bottom: 0; }
.itinerary__seq { flex: 0 0 22px; display: inline-flex; align-items: center; justify-content: center; height: 22px; border-radius: var(--radius-sm); background: var(--bg-sunken); border: 1px solid var(--border-default); font-family: var(--font-mono); font-size: 10px; color: var(--text-secondary); }
.itinerary__stop { flex: 1; font-weight: 600; color: var(--text-primary); }
.itinerary__time { font-family: var(--font-mono); font-size: 11px; color: var(--text-tertiary); }
.mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.mini-list__row { display: flex; flex-direction: column; gap: 1px; padding: 6px 0; border-bottom: 1px solid var(--border-muted, var(--border-default)); }
.mini-list__row:last-child { border-bottom: 0; }
.mini-list__primary { font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--text-primary); }
.mini-list__secondary { font-size: 12px; color: var(--text-tertiary); }
.trip-map { width: 100%; }

/* Trip management sheets (stop times + assignments inside the slide-over) */
.sheet-back { margin-bottom: calc(-1 * var(--space-2)); }
.sheet-list { display: flex; flex-direction: column; border: 1px solid var(--border-default); border-radius: var(--radius-md); overflow: hidden; background: var(--bg-elevated); }
.sheet-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); border-top: 1px solid var(--border-default); font-size: 13px; color: var(--text-primary); }
.sheet-row:first-child { border-top: 0; }
.sheet-row--form { align-items: stretch; }
.sheet-row__handle { flex: 0 0 auto; }
.sheet-row__seq { flex: 0 0 22px; display: inline-flex; align-items: center; justify-content: center; height: 22px; border-radius: var(--radius-sm); background: var(--bg-sunken); border: 1px solid var(--border-default); font-family: var(--font-mono); font-size: 10px; color: var(--text-secondary); }
.sheet-row__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.sheet-row__title { font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--text-primary); }
.sheet-row__meta { font-size: 12px; color: var(--text-tertiary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-row__actions { flex: 0 0 auto; display: flex; gap: var(--space-1); align-items: center; }
.sheet-empty { padding: var(--space-4); text-align: center; }

.drag-handle { cursor: grab; color: var(--text-tertiary); user-select: none; line-height: 1; }
.drag-handle:active { cursor: grabbing; }

/* Stacked add/edit forms rendered into a sheet row / add-box. */
.sheet-form { display: flex; flex-direction: column; gap: var(--space-3); width: 100%; }
.sheet-form .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.sheet-form__actions { display: flex; gap: var(--space-2); align-items: center; margin-top: var(--space-1); }
.sheet-add { border: 1px dashed var(--border-default); border-radius: var(--radius-md); padding: var(--space-4); background: var(--bg-elevated); }
.sheet-add turbo-frame { display: block; }
.sheet-add__title { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: var(--space-3); }
.sheet-errors { color: var(--fail-color, #d64545); font-size: 12px; margin-bottom: var(--space-2); }
.sheet-errors ul { margin: 0; padding-left: 1.1rem; }

/* Roles list / generic rows (reuses prototype perm-row) */
.perm-list { display: flex; flex-direction: column; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); overflow: hidden; }
.perm-row { display: grid; grid-template-columns: 1fr auto; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--bg-elevated); border-bottom: 1px solid var(--border-subtle); align-items: center; }
.perm-row:last-child { border-bottom: 0; }
.perm-row__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.perm-row__name { font-family: var(--font-display); font-size: 12px; font-weight: 600; color: var(--text-primary); }
.perm-row__detail { font-family: var(--font-mono); font-size: 10px; color: var(--text-tertiary); letter-spacing: 0.04em; }
.perm-remove { font-family: var(--font-mono); font-size: 10px; color: var(--fail-color); background: transparent; border: 1px solid var(--fail-border); border-radius: var(--radius-sm); padding: 3px 8px; letter-spacing: 0.04em; }
.perm-remove:hover { background: var(--fail-bg); }
.add-role-form { display: flex; gap: var(--space-2); margin-top: var(--space-3); }
.add-role-form .field__select { flex: 1; }

/* Sessions */
.session-list { display: flex; flex-direction: column; border: 1px solid var(--border-subtle); border-radius: var(--radius-md); overflow: hidden; }
.session-row { display: grid; grid-template-columns: 24px 1fr auto; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--bg-elevated); border-bottom: 1px solid var(--border-subtle); align-items: center; }
.session-row:last-child { border-bottom: 0; }
.session-row__icon { width: 24px; height: 24px; border-radius: 6px; background: var(--bg-surface); color: var(--text-secondary); display: flex; align-items: center; justify-content: center; }
.session-row__icon svg { width: 13px; height: 13px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.session-row__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.session-row__device { font-family: var(--font-display); font-size: 12px; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: 6px; }
.session-row__current { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; padding: 1px 5px; border-radius: 3px; background: var(--pass-bg); color: var(--pass-color); border: 1px solid var(--pass-border); }
.session-row__meta { font-family: var(--font-mono); font-size: 10px; color: var(--text-tertiary); letter-spacing: 0.04em; }
.session-row__revoke { font-family: var(--font-mono); font-size: 10px; color: var(--fail-color); background: transparent; border: 0; letter-spacing: 0.04em; font-weight: 600; cursor: pointer; }
.session-row__revoke:hover { text-decoration: underline; }

/* Danger zone */
.danger-zone { border: 1px solid var(--fail-border); border-radius: var(--radius-lg); background: rgba(197, 40, 61, 0.04); }
.danger-zone__head { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--fail-border); display: flex; align-items: center; gap: var(--space-2); }
.danger-zone__icon { width: 20px; height: 20px; color: var(--fail-color); }
.danger-zone__icon svg { width: 100%; height: 100%; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.danger-zone__title { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.15em; text-transform: uppercase; color: var(--fail-color); font-weight: 700; }
.danger-zone__body { display: flex; flex-direction: column; }
.danger-row { display: grid; grid-template-columns: 1fr auto; gap: var(--space-3); padding: var(--space-3) var(--space-4); align-items: center; border-bottom: 1px solid var(--fail-border); }
.danger-row:last-child { border-bottom: 0; }
.danger-row__body { display: flex; flex-direction: column; gap: 1px; }
.danger-row__title { font-family: var(--font-display); font-size: 12px; font-weight: 600; color: var(--text-primary); }
.danger-row__detail { font-family: var(--font-mono); font-size: 10px; color: var(--text-tertiary); letter-spacing: 0.04em; }

/* One-time generated PIN callout */
.pin-callout { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-color); font-family: var(--font-mono); font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
.pin-callout strong { font-size: 18px; letter-spacing: 0.2em; color: var(--text-primary); }

/* Standalone form page (users/roles new) inside the shell */
.form-page { max-width: 640px; padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); overflow-y: auto; }
/* Read-only spec grid (detail show pages) */
.spec-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3) var(--space-4); }
.spec { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.spec--wide { grid-column: 1 / -1; }
.spec__label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-tertiary); font-weight: 500; }
.spec__value { font-family: var(--font-body); font-size: 13px; color: var(--text-primary); word-break: break-word; }
.spec__value--mono { font-family: var(--font-mono); letter-spacing: 0.03em; }
.spec__value--empty { color: var(--text-disabled); }
.spec__value--warn { color: var(--warn-color); }
.spec__value--fail { color: var(--fail-color); }
.spec__flag { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; margin-left: 6px; }

/* A detail page laid out as scrollable sections (show pages) */
.detail-page { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); overflow-y: auto; max-width: 900px; }

/* Standalone form page (users/roles/vehicles new/edit) inside the shell */
.form-page { max-width: 760px; padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); overflow-y: auto; }
.form-page .field-row, .form-page .field { max-width: 100%; }
.form-page .field__input, .form-page .field__select, .form-page textarea.field__input { width: 100%; }
.form-page textarea.field__input { height: auto; padding: var(--space-3); resize: vertical; font-family: var(--font-body); }
.form-actions { display: flex; gap: var(--space-2); margin-top: var(--space-2); }

/* Edit form rendered inside the slide-over panel body */
.panel-form { display: flex; flex-direction: column; gap: var(--space-4); }

/* Reverse-geocode suggestion shown below the stop address input (driven by StopMapPicker) */
.map-suggestion { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3) var(--space-4); border: 1px solid var(--border-default); border-radius: var(--radius-sm); background: var(--bg-elevated); }
.map-suggestion[hidden] { display: none; }
.map-suggestion__label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-tertiary); }
.map-suggestion__text { margin: 0; font-size: 13px; line-height: 1.35; color: var(--text-primary); word-break: break-word; }
.map-suggestion__actions { display: flex; gap: var(--space-2); }
.map-suggestion--loading .map-suggestion__label,
.map-suggestion--loading .map-suggestion__actions { display: none; }
.map-suggestion--loading .map-suggestion__text { font-family: var(--font-mono); font-size: 12px; color: var(--text-tertiary); }

/* Checklist template — read panel: items grouped by category, plus per-item flags. */
.checklist-cat + .checklist-cat { margin-top: var(--space-4); }
.checklist-cat__name { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-secondary); font-weight: 600; margin-bottom: var(--space-1); }
.item-flag { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600; padding: 1px 5px; border-radius: var(--radius-sm); border: 1px solid; vertical-align: middle; margin-left: 6px; }
.item-flag--muted { color: var(--text-tertiary); background: var(--bg-elevated); border-color: var(--border-default); }
.item-flag--warn { color: var(--warn-color); background: var(--warn-bg); border-color: var(--warn-border); }
