:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --ink: #16181d;
  --muted: #687182;
  --line: #dfe3ea;
  --brand: #f5c400;
  --brand-2: #1e2a36;
  --accent: #0f766e;
  --danger: #c2410c;
  --ok: #15803d;
  --shadow: 0 18px 60px rgba(17, 24, 39, 0.12);
  --font-scale: 1;
  --text-color: #16181d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-color);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: calc(15px * var(--font-scale));
}

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

button {
  border: 0;
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(115deg, rgba(0, 0, 0, 0.84), rgba(16, 24, 32, 0.64)),
    url("assets/login-shelby-bg.png") center / cover no-repeat;
}

.login-panel {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-brand {
  padding: 42px;
  background: #050505;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 40px;
}

.login-brand img {
  width: min(330px, 100%);
}

.login-brand h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 0.95;
  letter-spacing: 0;
}

.login-brand p {
  margin: 14px 0 0;
  color: #d8dee8;
  line-height: 1.6;
}

.login-form {
  padding: 42px;
}

.login-form h2,
.panel h2,
.section-title h2 {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
}

.field {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.field label,
.mini-label {
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 6px 8px;
}

textarea {
  min-height: 34px;
  resize: vertical;
  overflow: hidden;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.btn,
.icon-btn {
  min-height: 40px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
}

.icon-btn {
  width: 42px;
  padding: 0;
  font-size: 18px;
}

.btn {
  padding: 0 16px;
  background: var(--brand-2);
  color: #fff;
}

.btn.primary {
  background: var(--brand);
  color: #121212;
}

.btn.ghost,
.icon-btn {
  background: var(--surface-2);
  color: var(--ink);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.small-btn {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.btn:disabled,
.icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.login-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

.remember-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-weight: 700;
}

.remember-row input {
  width: 18px;
  min-height: 18px;
}

.demo-users {
  margin-top: 28px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  line-height: 1.7;
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: #090909;
  color: #fff;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand-block {
  padding: 10px 10px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-block img {
  width: 220px;
  max-width: 100%;
}

.user-chip {
  margin-top: 14px;
  padding: 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  color: #d8dee8;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 5px;
  margin-top: 18px;
}

.nav button {
  min-height: 42px;
  padding: 0 12px;
  border-radius: 6px;
  background: transparent;
  color: #dfe4ea;
  text-align: left;
  font-weight: 700;
}

.nav button.active,
.nav button:hover {
  background: var(--brand);
  color: #111;
}

.main {
  min-width: 0;
}

.topbar {
  min-height: 74px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.page {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
}

.section-title p,
.small-text {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
}

.stat {
  padding: 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.stat strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 22px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(180px, 420px) auto;
  gap: 10px;
  align-items: center;
}

.search-panel input {
  min-height: 36px;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  margin-bottom: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  padding-bottom: 4px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  touch-action: pan-x;
}

.tab {
  min-height: 30px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 800;
  font-size: 12px;
  flex: 0 0 auto;
}

.tab.active {
  background: var(--brand-2);
  color: #fff;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
}

th,
td {
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.badge.danger {
  background: #fee2e2;
  color: #991b1b;
}

.badge.ok {
  background: #dcfce7;
  color: #166534;
}

.badge.warn {
  background: #fef3c7;
  color: #92400e;
}

.settings-popover {
  position: fixed;
  right: 20px;
  top: 78px;
  width: min(360px, calc(100vw - 40px));
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.inspection-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 12px;
}

.inspection-head {
  width: 100%;
  padding: 13px 14px;
  background: var(--surface-2);
  color: var(--ink);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
}

.inspection-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.check-row {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) 180px 1fr 210px;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.check-row strong {
  padding-top: 10px;
}

.media-tools {
  display: grid;
  gap: 8px;
}

.media-tools small {
  color: var(--muted);
}

.record-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 6px;
}

.workflow-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 8px;
  background: var(--surface);
}

.workflow-card.compact {
  grid-template-columns: 1.1fr 0.9fr auto;
  align-items: center;
}

.step-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-drawer {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-2);
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.invoice-preview {
  background: #fff;
  color: #111;
  border: 1px solid #d7dce5;
  border-radius: 8px;
  padding: 22px;
  line-height: 1.5;
}

.invoice-preview .terms {
  color: #8a93a3;
  font-size: 12px;
}

.media-link {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-weight: 700;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.media-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  background: var(--surface);
  color: var(--ink);
  display: grid;
  gap: 6px;
  text-align: left;
  cursor: pointer;
}

.media-tile img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: #111827;
}

.media-tile span {
  font-size: 11px;
  font-weight: 700;
}

.proof-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 8px;
}

.proof-panel summary {
  cursor: pointer;
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 10px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.compact-media {
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
}

.compact-media .media-tile {
  padding: 5px;
}

.file-preview {
  display: grid;
  place-items: center;
  min-height: 74px;
  border-radius: 6px;
  background: #111827;
  color: #fff;
  font-size: 12px;
  text-align: center;
  padding: 8px;
}

.file-preview.large {
  min-height: 220px;
  font-size: 14px;
}

.media-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(3, 7, 18, 0.72);
  display: grid;
  place-items: center;
  padding: 18px;
}

.media-modal-card {
  width: min(900px, 96vw);
  max-height: 94vh;
  overflow: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 12px;
  display: grid;
  gap: 10px;
}

.media-modal-card img {
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  background: #050816;
  border-radius: 6px;
}

.media-modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.toast-stack {
  position: fixed;
  right: 18px;
  top: 86px;
  z-index: 60;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast-stack .toast {
  position: static;
  animation: notificationBlink 1s ease-in-out 0s 5;
}

@keyframes notificationBlink {
  0%, 100% {
    box-shadow: var(--shadow);
    transform: translateX(0);
  }
  50% {
    box-shadow: 0 0 0 3px rgba(245, 184, 0, 0.35), var(--shadow);
    transform: translateX(-2px);
  }
}

.dispatch-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 14px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
}

.theme-dark {
  --bg: #101317;
  --surface: #181d24;
  --surface-2: #232a34;
  --ink: #f7fafc;
  --muted: #a7b0bd;
  --line: #303844;
  --text-color: #f7fafc;
}

.theme-light {
  --bg: #f5f6f8;
}

.theme-workshop {
  --bg: #eef2f3;
  --surface-2: #e4eceb;
  --brand-2: #18312f;
  --accent: #0f766e;
}

@media (max-width: 980px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .login-panel,
  .app-shell,
  .grid,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    max-height: none;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
  }

  .nav {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    padding-bottom: 4px;
    width: calc(100vw - 28px);
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    touch-action: pan-x;
  }

  .nav button {
    flex: 0 0 auto;
    min-width: max-content;
    white-space: nowrap;
  }

  .tabs,
  .sub-tabs,
  .toolbar,
  .inline-actions,
  .step-actions {
    overflow-x: auto;
    flex-wrap: nowrap;
    align-items: center;
  }

  .tabs,
  .sub-tabs {
    display: flex;
    width: calc(100vw - 44px);
    max-width: 100%;
    min-width: 0;
    scrollbar-gutter: stable;
    scroll-snap-type: x proximity;
  }

  .tabs .tab,
  .sub-tabs .tab {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .tab,
  .btn,
  button,
  select,
  input,
  textarea {
    min-height: 38px;
  }

  .panel,
  .detail-drawer,
  .workflow-card,
  .record-card {
    padding: 10px;
    min-width: 0;
    max-width: 100%;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 720px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .check-row {
    grid-template-columns: 1fr;
  }

  .search-panel {
    grid-template-columns: 1fr;
  }

  .dispatch-panel {
    grid-template-columns: 1fr;
  }

  .workflow-card.compact,
  .mini-grid {
    grid-template-columns: 1fr;
  }

  .toast-stack {
    top: auto;
    right: 10px;
    bottom: 12px;
    width: calc(100vw - 20px);
  }
}

@media (max-width: 560px) {
  .page,
  .topbar,
  .login-form,
  .login-brand {
    padding: 18px;
  }

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

  .page,
  .topbar {
    padding: 12px;
  }

  .login-shell {
    padding: 10px;
  }

  .login-panel {
    width: 100%;
  }

  .login-brand {
    align-items: flex-start;
  }

  .login-brand img {
    max-width: 150px;
  }

  .login-actions {
    gap: 6px;
  }

  .small-btn,
  .tab,
  .btn {
    padding: 8px 10px;
    font-size: 12px;
  }

  .field input,
  .field select,
  .field textarea {
    width: 100%;
    font-size: 14px;
  }

  .dispatch-panel {
    padding: 10px;
  }

  .media-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
