:root {
  color-scheme: light;
  --red: #d51018;
  --red-dark: #9d0710;
  --black: #0a0a0c;
  --ink: #17171a;
  --muted: #696b73;
  --line: #dedfe4;
  --soft: #f4f4f6;
  --white: #ffffff;
  --shadow: 0 16px 40px rgba(10, 10, 12, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--soft);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-height: 100vh;
  padding: 22px;
  background: var(--black);
  color: var(--white);
  border-right: 6px solid var(--red);
}

.brand {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  min-height: 88px;
}

.brand img {
  width: 78px;
  height: 78px;
  object-fit: contain;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.brand span,
.system-label,
.eyebrow {
  display: block;
  color: var(--red);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand strong {
  display: block;
  margin-top: 4px;
  font-size: 1.12rem;
  line-height: 1.15;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab[hidden] {
  display: none;
}

.role-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.75rem;
  font-weight: 850;
  text-transform: uppercase;
}

.role-card select,
.connection-card input {
  border-color: rgba(255, 255, 255, 0.22);
  background: #161619;
  color: var(--white);
  text-transform: none;
}

.role-card strong {
  display: none;
  color: var(--white);
  font-size: 1rem;
  text-transform: none;
}

body.supabase-connected .role-card select,
body.supabase-connected .demo-actions {
  display: none;
}

body.supabase-connected .role-card strong {
  display: block;
}

.connection-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}

.connection-card strong {
  color: var(--white);
  font-size: 0.9rem;
}

.connection-card strong.connected {
  color: #79e5a2;
}

.connection-card form {
  display: grid;
  gap: 8px;
}

.connection-card .primary-button,
.connection-card .ghost-button {
  width: 100%;
}

.nav-tab {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: transparent;
  color: var(--white);
  text-align: left;
}

.nav-tab.active,
.nav-tab:hover {
  background: var(--red);
  border-color: var(--red);
}

.tab-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.7rem;
  font-weight: 900;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
}

.sidebar-footer strong {
  display: block;
  margin-top: 5px;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1,
.panel h2 {
  margin: 0;
  color: var(--black);
}

.topbar h1 {
  font-size: clamp(1.8rem, 3vw, 2.8rem);
}

.eyebrow {
  margin: 0 0 5px;
}

.quick-actions,
.ticket-actions,
.segmented,
.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-button,
.ghost-button,
.danger-button,
.small-button,
.segment {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  background: var(--red);
  color: var(--white);
}

.primary-button:hover,
.danger-button:hover {
  background: var(--red-dark);
}

.ghost-button,
.small-button,
.segment {
  background: var(--white);
  color: var(--black);
  border-color: var(--line);
}

.danger-button {
  background: var(--black);
  color: var(--white);
}

.danger-inline {
  background: #fff1f1;
  border-color: #ffd2d5;
  color: var(--red-dark);
}

.segment.active {
  background: var(--red);
  color: var(--white);
  border-color: var(--red);
}

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

body.maintenance-mode .stats-grid,
body.driver-mode .stats-grid {
  display: none;
}

.driver-app-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  padding: 16px;
  border-radius: 8px;
  background: var(--black);
  color: var(--white);
}

.driver-app-banner h2 {
  margin: 0;
  color: var(--white);
}

.metric {
  padding: 16px;
  background: var(--white);
  border: 1px solid var(--line);
  border-left: 5px solid var(--red);
  border-radius: 8px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 1.75rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-grid,
.admin-grid,
.reports-grid {
  display: grid;
  gap: 18px;
}

.view-grid {
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
}

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

.admin-wide {
  grid-column: 1 / -1;
}

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

.panel {
  min-width: 0;
  padding: 18px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-heading,
.ticket-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.ticket-number {
  white-space: nowrap;
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--black);
  color: var(--white);
  font-weight: 900;
}

.ticket-form,
.inline-form,
.stack-form {
  display: grid;
  gap: 14px;
}

.form-grid,
.inline-form {
  display: grid;
  gap: 12px;
}

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

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

label,
.compact-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cfd1d8;
  border-radius: 8px;
  padding: 9px 11px;
  background: var(--white);
  color: var(--ink);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(213, 16, 24, 0.22);
  outline-offset: 2px;
}

.ticket-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
  max-height: 690px;
  overflow: auto;
  padding-right: 2px;
}

.ticket-list.wide {
  max-height: none;
}

.ticket-card {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ticket-card h3 {
  margin: 8px 0 0;
  font-size: 1.05rem;
}

.pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 0.72rem;
  font-weight: 900;
}

.pill {
  background: var(--black);
  color: var(--white);
}

.status-pill {
  background: #f1f1f3;
  color: var(--black);
  border: 1px solid var(--line);
}

.status-Sent {
  background: #fff1f1;
  color: var(--red-dark);
  border-color: #ffd2d5;
}

.status-Accepted {
  background: #fff8e3;
  color: #755800;
  border-color: #f4df91;
}

.status-In-Progress {
  background: #eaf3ff;
  color: #064d8f;
  border-color: #cce2ff;
}

.status-Completed {
  background: #eaf8ef;
  color: #116132;
  border-color: #c8ecd5;
}

.status-Invoiced {
  background: #ececf0;
  color: #31333a;
}

.status-Canceled {
  background: #fff1f1;
  color: var(--red-dark);
  border-color: #ffd2d5;
}

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

.ticket-details div {
  min-width: 0;
}

.ticket-details dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.ticket-details dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.ticket-notes {
  margin: 0 0 14px;
  color: #45474d;
  line-height: 1.45;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: #f2f2f4;
  border: 1px solid var(--line);
  color: #303238;
  font-size: 0.74rem;
  font-weight: 800;
}

.muted-small {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.empty-state {
  padding: 26px;
  border: 1px dashed #c7c9d0;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.driver-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.driver-mobile-actions {
  display: none;
  gap: 8px;
  margin-top: 14px;
}

.summary-box {
  padding: 14px;
  border-radius: 8px;
  background: var(--soft);
  border: 1px solid var(--line);
}

.summary-box span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.summary-box strong {
  display: block;
  margin-top: 5px;
}

.invoice-table-wrap {
  margin-top: 16px;
  overflow-x: auto;
}

.invoice-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.invoice-table th,
.invoice-table td {
  padding: 13px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.invoice-table th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.inline-form {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  margin: 14px 0 16px;
}

.user-form {
  display: grid;
  grid-template-columns: 1.15fr 1fr 0.9fr 1fr auto;
  gap: 12px;
  margin: 14px 0 16px;
}

.admin-list {
  display: grid;
  gap: 10px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 0.6fr) minmax(190px, 0.8fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-row form {
  display: flex;
  gap: 8px;
}

.admin-row span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.signature-panel canvas {
  display: block;
  width: 100%;
  height: 180px;
  border: 1px solid #cfd1d8;
  border-radius: 8px;
  background:
    linear-gradient(transparent 78%, rgba(10, 10, 12, 0.12) 78%, rgba(10, 10, 12, 0.12) 79%, transparent 79%),
    var(--white);
  touch-action: none;
}

.schedule-grid,
.map-board {
  display: grid;
  gap: 12px;
}

.schedule-day,
.map-pin {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.schedule-day {
  border-left: 5px solid var(--red);
}

.schedule-day span,
.map-pin span {
  color: #3d4047;
  font-size: 0.9rem;
}

.map-board {
  min-height: 360px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(213, 16, 24, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(10, 10, 12, 0.07) 1px, transparent 1px),
    #fafafa;
  background-size: 42px 42px;
}

.map-pin {
  position: relative;
  padding-left: 32px;
}

.map-pin::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 18px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(213, 16, 24, 0.14);
}

.report-row {
  display: grid;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.report-row div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.report-row span {
  color: var(--muted);
  font-weight: 800;
}

.bar {
  overflow: hidden;
  height: 10px;
  border-radius: 999px;
  background: #ececf0;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--red);
}

.big-number {
  margin-top: 12px;
  color: var(--black);
  font-size: clamp(2rem, 4vw, 4rem);
  font-weight: 900;
}

.equipment-status {
  width: auto;
  min-width: 160px;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 5px solid var(--red);
  }

  .nav-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .sidebar-footer {
    display: none;
  }

  .view-grid,
  .admin-grid,
  .reports-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .stats-grid,
  .driver-summary,
  .form-grid.two,
  .form-grid.three,
  .inline-form,
  .user-form,
  .user-row {
    grid-template-columns: 1fr;
  }

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

  .ticket-details {
    grid-template-columns: 1fr;
  }

  body.driver-mode .sidebar {
    gap: 16px;
    padding-bottom: 12px;
  }

  body.driver-mode .brand {
    min-height: auto;
  }

  body.driver-mode .nav-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.driver-mode .workspace {
    padding-bottom: 88px;
  }

  body.driver-mode .topbar,
  body.driver-mode .stats-grid {
    display: none;
  }

  body.driver-mode .driver-app-banner {
    display: flex;
  }

  body.driver-mode #driversView .view-grid {
    gap: 14px;
  }

  body.driver-mode #driversView .panel {
    padding: 14px;
  }

  body.driver-mode #driversView .panel-heading h2 {
    font-size: 1.28rem;
  }

  body.driver-mode .driver-summary {
    grid-template-columns: 1fr;
  }

  body.driver-mode .driver-mobile-actions {
    display: flex;
  }

  body.driver-mode .ticket-list {
    max-height: none;
  }

  body.driver-mode .ticket-card {
    padding: 14px;
  }

  body.driver-mode .ticket-card h3 {
    font-size: 1.12rem;
  }

  body.driver-mode .ticket-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  body.driver-mode .ticket-actions .small-button,
  body.driver-mode .signature-panel .quick-actions button {
    width: 100%;
  }

  body.driver-mode .signature-panel {
    order: -1;
  }
}
