:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-soft: #f1f5f9;
  --ink: #111827;
  --muted: #64748b;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-ink: #ffffff;
  --warn: #dc2626;
  --warn-soft: #fee2e2;
  --shadow: 0 16px 40px rgba(15, 23, 42, .08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111827;
  --panel: #1f2937;
  --panel-soft: #111827;
  --ink: #f9fafb;
  --muted: #9ca3af;
  --line: #374151;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --accent-soft: rgba(37, 99, 235, .18);
  --accent-ink: #ffffff;
  --warn: #fca5a5;
  --warn-soft: rgba(127, 29, 29, .55);
  --shadow: 0 18px 44px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

html { height: 100%; }

body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior-y: contain;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  padding: 0 16px;
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 700;
}

button:active { transform: translateY(1px); }

button.secondary {
  background: var(--panel-soft);
  color: var(--accent);
}

button.ghost {
  background: transparent;
  color: var(--accent);
  padding-inline: 8px;
}

.danger-button {
  background: var(--warn-soft);
  color: var(--warn);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.hidden { display: none !important; }

.boot-view {
  min-height: 100vh;
  min-height: 100svh;
  display: none;
  place-items: center;
  align-content: center;
  gap: 14px;
  background: #111827;
}

.boot-view img {
  width: 128px;
  height: 128px;
  border-radius: 24px;
  object-fit: contain;
}

.duplicate-instance-view {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
  background: var(--bg);
  color: var(--ink);
}

.duplicate-instance-view img {
  width: 72px;
  height: 72px;
  border-radius: 18px;
}

.duplicate-instance-view p {
  max-width: 280px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.auth-state-view {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
  background: var(--bg);
  color: var(--ink);
}

.auth-state-view img {
  width: 88px;
  height: 88px;
  border-radius: 20px;
}

.auth-state-view h2,
.auth-state-view p {
  margin: 0;
}

.auth-state-view p {
  color: var(--muted);
}

.auth-state-view button {
  margin-top: 10px;
}

body.booting .boot-view {
  display: grid;
}

body.booting .auth-view,
body.booting .shell {
  display: none !important;
}

.camera-file-input {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  inset: auto 0 0 auto;
}

.auth-view {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 24px;
  background: var(--bg);
}

.brand {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.brand img {
  width: 256px;
  height: 256px;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 8px;
  box-shadow: var(--shadow);
}

.profile-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 6px;
  box-shadow: var(--shadow);
}

.profile-name {
  font-size: 20px;
  line-height: 1.2;
}

.profile-role,
.profile-position {
  color: var(--muted);
}

.profile-role {
  width: max-content;
  padding: 4px 9px;
  border-radius: 8px;
  background: #dcfce7;
  color: #166534;
  font-weight: 800;
  font-size: 13px;
}

html[data-theme="dark"] .profile-role {
  background: rgba(22, 101, 52, .35);
  color: #bbf7d0;
}

#login-form,
#register-form {
  width: min(100%, 390px);
  margin: 0 auto;
}

.shell {
  height: 100vh;
  height: 100svh;
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
  background: var(--bg);
}

.content-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.topbar {
  padding: calc(14px + env(safe-area-inset-top)) 20px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar h2 {
  margin: 6px 0 0;
  font-size: 18px;
  line-height: 1.35;
  white-space: pre-line;
}

.pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.tabs {
  display: grid;
  grid-auto-flow: column;
  background: var(--panel);
}

.bottom-nav {
  padding: 7px max(8px, env(safe-area-inset-left)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, .06);
}

.tab {
  min-width: 0;
  min-height: 56px;
  padding: 6px 4px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}

.tab.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-icon {
  width: 23px;
  height: 23px;
  display: block;
  opacity: .58;
  background: currentColor;
  mask: var(--nav-mask) center / contain no-repeat;
  -webkit-mask: var(--nav-mask) center / contain no-repeat;
}

.nav-icon-info {
  --nav-mask: url("/icons/info_new.svg");
}

.nav-icon-queue {
  --nav-mask: url("/icons/queue_new.svg");
}

.nav-icon-camera {
  --nav-mask: url("/icons/camera_new.svg");
}

.nav-icon-remind {
  --nav-mask: url("/icons/remind_new.svg");
}

.nav-icon-broadcast {
  --nav-mask: url("/icons/broadcast.svg");
}

.nav-icon-settings {
  --nav-mask: url("/icons/settings_new.svg");
}

.nav-icon-admin {
  --nav-mask: url("/icons/admin_new.svg");
}

.tab.active .nav-icon {
  opacity: 1;
}

html[data-theme="dark"] .nav-icon {
  opacity: .78;
}

html[data-theme="dark"] .tab.active .nav-icon {
  opacity: 1;
}

.tab-view {
  display: none;
  padding: 18px;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-view.active {
  display: grid;
  align-content: start;
}

.toolbar,
.section-title,
.screen-title,
.camera-head,
.camera-actions,
.setting-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.screen-title h3,
.section-title h3,
.queue-grid h3,
.panel h3 {
  margin: 0;
}

.admin-photo-capture {
  width: 100%;
}

.compact-heading {
  font-size: 14px;
  line-height: 1.25;
}

.toolbar select {
  flex: 1;
}

.queue-grid {
  display: grid;
  gap: 16px;
}

.queue-grid article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.queue-list {
  display: grid;
  gap: 5px;
  margin-top: 14px;
}

.queue-row,
.session-row,
.user-row,
.notification {
  display: grid;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.queue-row {
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
}

.queue-row strong {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--ink);
}

.queue-row.current-driver {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--panel));
  font-weight: 800;
}

.queue-row.loading-current {
  border-color: #ef4444;
  background: #fee2e2;
  color: #7f1d1d;
}

.queue-row.loading-current small {
  color: #991b1b;
}

html[data-theme="dark"] .queue-row.loading-current {
  background: rgba(127, 29, 29, .46);
  color: #fee2e2;
}

html[data-theme="dark"] .queue-row.loading-current small {
  color: #fecaca;
}

.queue-row.current-driver strong {
  background: var(--accent);
  color: var(--accent-ink);
}

.queue-time {
  justify-self: end;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.queue-row.loading-current strong {
  background: #dc2626;
  color: #fff;
}

#loading-list .queue-row {
  background: var(--accent-soft);
}

#loading-list .queue-row strong {
  background: var(--accent);
  color: var(--accent-ink);
}

#loading-list .queue-row.loading-current {
  background: #fee2e2;
}

html[data-theme="dark"] #loading-list .queue-row.loading-current {
  background: rgba(127, 29, 29, .46);
}

#loading-list .queue-row.loading-current strong {
  background: #dc2626;
}

.loading-line {
  display: grid;
  gap: 9px;
}

.loading-line + .loading-line {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.loading-line h4 {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.empty,
.hint,
.status,
small {
  color: var(--muted);
}

.error {
  min-height: 20px;
  color: var(--warn);
}

.danger-zone {
  border-color: color-mix(in srgb, var(--warn) 34%, var(--line));
}

.queue-exit-panel.disabled {
  opacity: .58;
}

.queue-exit-panel.disabled button {
  pointer-events: none;
}

.segmented {
  display: grid;
  gap: 8px;
}

.segmented button {
  justify-content: center;
}

.segmented button[data-reason="repair"] {
  background: #f97316;
  color: #fff7ed;
}

.segmented button[data-reason="dayoff"] {
  background: #16a34a;
  color: #f0fdf4;
}

.segmented button[data-reason="shift_change"] {
  background: #2563eb;
  color: #eff6ff;
}

.segmented button[data-reason="other"] {
  background: #64748b;
  color: #f8fafc;
}

.cars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(116px, 1fr));
  gap: 9px;
}

.car-btn {
  min-height: 54px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 900;
  letter-spacing: 0;
}

.car-btn:focus,
.car-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.camera-panel {
  display: grid;
  gap: 12px;
}

.camera-panel.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 20;
  grid-template-rows: auto 1fr auto auto;
  padding: calc(10px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  background: #050607;
  color: #fff;
}

.camera-panel.fullscreen .ghost {
  color: #fff;
}

.camera-panel.fullscreen .secondary {
  background: #25302e;
  color: #fff;
}

.camera-box {
  position: relative;
  min-height: 58vh;
  min-height: 58svh;
  border-radius: 8px;
  overflow: hidden;
  background: #111;
}

.camera-panel.fullscreen .camera-box {
  min-height: 0;
  border-radius: 0;
}

#camera-feed {
  width: 100%;
  height: 100%;
  min-height: 58vh;
  min-height: 58svh;
  object-fit: cover;
}

.camera-panel.fullscreen #camera-feed {
  min-height: 0;
}

.camera-panel.fullscreen .status {
  color: #d7dedc;
}

#photo-guide {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  object-fit: contain;
  opacity: .7;
  pointer-events: none;
}

.sessions,
.users,
.notifications,
.settings-panel {
  display: grid;
  gap: 12px;
}

.session-row,
.notification {
  box-shadow: var(--shadow);
}

button.session-row {
  width: 100%;
  min-height: 0;
  padding: 14px;
  color: var(--ink);
  text-align: left;
  background: var(--panel);
  font-weight: 400;
}

.user-row {
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  box-shadow: none;
}

.user-row strong,
.user-row small {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.user-row strong {
  font-size: 16px;
  line-height: 1.25;
}

.user-login,
.user-row .user-status {
  color: var(--muted);
  line-height: 1.3;
}

.user-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  gap: 6px;
  width: 100%;
  margin-top: 8px;
}

.user-actions button {
  width: 100%;
  min-height: 32px;
  padding-inline: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.notifications.compact {
  gap: 8px;
}

.notifications.compact .notification {
  padding: 10px 12px;
  box-shadow: none;
}

@media (max-width: 560px) {
  .user-actions {
    grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
  }
}

.setting-row {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.setting-row > div:first-child {
  display: grid;
  gap: 4px;
}

.theme-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.theme-switch button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.password-box {
  display: grid;
  gap: 10px;
}

.status-text {
  margin: 0;
  white-space: pre-line;
  line-height: 1.45;
}

.info-panel .status-text {
  font-size: calc(1rem + 2px);
}

.album {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  color: #fff;
  overflow: hidden;
}

.album-bar {
  position: absolute;
  inset: 0 0 auto;
  z-index: 2;
  padding: calc(10px + env(safe-area-inset-top)) 14px 18px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  text-align: center;
  background: linear-gradient(180deg, rgba(0, 0, 0, .55), rgba(0, 0, 0, 0));
  pointer-events: none;
}

.album-bar strong {
  grid-column: 2;
}

.album-bar .ghost {
  grid-column: 3;
  min-height: 44px;
  color: #fff;
  font-size: 28px;
  pointer-events: auto;
}

#album-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  min-width: 0;
  min-height: 0;
}

.album-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  width: 24%;
  min-height: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: #fff;
  font-size: 44px;
}

#album-prev {
  left: 0;
}

#album-next {
  right: 0;
}

.album-nav:disabled {
  opacity: .2;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  padding: 14px;
  border-radius: 8px;
  color: #fff;
  background: #1f2937;
  z-index: 30;
  text-align: center;
}

@media (min-width: 760px) {
  .tab-view {
    max-width: 1040px;
    width: 100%;
    margin: 0 auto;
  }

  .queue-grid {
    grid-template-columns: 1fr 1fr;
  }

  .bottom-nav {
    max-width: 560px;
    width: calc(100% - 32px);
    justify-self: center;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }
}
