:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  color: #172033;
  background: #f3f6f9;
  --navy: #12243d;
  --blue: #2563eb;
  --line: #dbe3ec;
  --muted: #667085;
  --green: #16803a;
  --amber: #a15c00;
  --red: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, #dcecff 0, transparent 30rem),
    #f3f6f9;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px max(20px, calc((100vw - 1320px) / 2));
  color: white;
  background: var(--navy);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.signed-in-user {
  max-width: 220px;
  overflow: hidden;
  color: #dbeafe;
  font-size: .86rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.8rem, 4vw, 2.5rem); }
h2 { margin-bottom: 0; }

.eyebrow {
  margin-bottom: 6px;
  color: #6c8fc5;
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .14em;
}

main {
  width: min(1320px, calc(100% - 32px));
  margin: 28px auto 60px;
}

.portal-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 18px;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
  box-shadow: 0 8px 25px rgba(31, 52, 78, .06);
}

.sidebar-link {
  display: block;
  width: 100%;
  margin-top: 8px;
  color: #344054;
  border: 1px solid transparent;
  background: #f5f7fb;
  text-align: left;
}

.sidebar-link.active {
  color: white;
  background: var(--blue);
}

.portal-content {
  min-width: 0;
}

.portal-view[hidden] {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.summary-card, .panel, .machine-card {
  border: 1px solid var(--line);
  background: white;
  box-shadow: 0 8px 25px rgba(31, 52, 78, .06);
}

.summary-card {
  padding: 18px;
  border-radius: 16px;
}

.summary-card strong {
  display: block;
  margin-bottom: 5px;
  font-size: 1.7rem;
}

.summary-card span { color: var(--muted); }

.panel {
  padding: 22px;
  border-radius: 20px;
}

.panel-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.result-count {
  color: var(--muted);
  white-space: nowrap;
}

.group-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.group-button {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: #30425a;
  background: #f8fafc;
  text-align: left;
}

.group-button.active {
  color: white;
  border-color: var(--blue);
  background: var(--blue);
}

.group-button strong, .group-button span { display: block; }
.group-button span { margin-top: 4px; font-size: .8rem; opacity: .8; }

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

label {
  display: block;
  color: #344054;
  font-size: .87rem;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  margin-top: 7px;
  padding: 11px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  color: #172033;
  background: white;
}

input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(37, 99, 235, .13);
  border-color: var(--blue);
}

.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 14px;
  margin-top: 22px;
}

.machine-card {
  padding: 18px;
  border-radius: 15px;
}

.machine-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.machine-type {
  margin-bottom: 3px;
  color: var(--navy);
  font-size: 1.1rem;
}

.machine-code, .machine-meta {
  color: var(--muted);
  font-size: .84rem;
}

.machine-location {
  min-height: 48px;
  margin: 16px 0;
  font-weight: 700;
  line-height: 1.4;
}

.status {
  display: inline-block;
  padding: 5px 8px;
  border-radius: 999px;
  color: #475467;
  background: #f0f2f5;
  font-size: .72rem;
  font-weight: 800;
}

.status.operational { color: var(--green); background: #ecfdf3; }
.status.needs-attention, .status.awaiting-parts {
  color: var(--amber);
  background: #fffaeb;
}
.status.out-of-service { color: var(--red); background: #fef3f2; }

button {
  padding: 11px 15px;
  border: 0;
  border-radius: 10px;
  color: white;
  background: var(--blue);
  font-weight: 800;
}

.machine-card button { width: 100%; margin-top: 15px; }
.secondary-button { color: #243b5a; background: #e8eef6; }
.topbar .secondary-button { color: white; background: rgba(255,255,255,.14); }

.modal {
  width: min(720px, calc(100% - 24px));
  max-height: calc(100vh - 30px);
  padding: 0 20px 20px;
  border: 0;
  border-radius: 18px;
  overflow-y: auto;
  box-shadow: 0 25px 80px rgba(10, 29, 53, .28);
}

.wide-modal { width: min(1180px, calc(100% - 24px)); }
.modal::backdrop { background: rgba(10, 23, 41, .65); }

.modal-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  margin: 0 -20px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(8px);
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  color: #344054;
  background: #eef2f6;
  font-size: 1.5rem;
}

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

.detail-item {
  padding: 9px 10px;
  border-radius: 8px;
  background: #f7f9fc;
  font-size: .85rem;
}

.detail-item span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: .75rem;
}

.detail-section {
  margin-top: 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.detail-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.detail-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #475467;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.detail-tab span {
  min-width: 24px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #475467;
  background: #e8edf3;
  font-size: .75rem;
}

.detail-tab.active {
  color: white;
  border-color: var(--blue);
  background: var(--blue);
}

.detail-tab.active span {
  color: white;
  background: rgba(255,255,255,.2);
}

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

.maintenance-section {
  border-color: #cbdaf0;
  background: #fbfdff;
}

.payment-section {
  border-color: #d9d2ef;
  background: #fcfbff;
}

.detail-section-heading {
  display: flex;
  align-items: center;
  gap: 11px;
}

.detail-section-heading h3,
.detail-section-heading p {
  margin-bottom: 0;
}

.section-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 10px;
  color: white;
  background: var(--blue);
  font-weight: 900;
}

.payment-icon {
  background: #6941c6;
}

.payment-grid .detail-item {
  border: 1px solid #e6e0f2;
  background: white;
}

.report-heading {
  margin-top: 15px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
}

.report-heading h3 {
  margin-bottom: 4px;
}

.report-heading p {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: .83rem;
}

.report-item {
  margin-top: 10px;
  background: white;
}

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

.history-record {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
}

.history-record summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
}

.history-record summary::-webkit-details-marker {
  display: none;
}

.history-record summary div > strong,
.history-record summary div > span {
  display: block;
}

.history-record summary div > span {
  margin-top: 3px;
  color: var(--muted);
  font-size: .78rem;
}

.history-record[open] summary {
  border-bottom: 1px solid var(--line);
  background: #f8fbff;
}

.history-record-content {
  padding: 11px;
}

.history-record-content h4 {
  margin: 14px 0 8px;
}

.history-checklist {
  display: grid;
  gap: 8px;
}

.history-checklist-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 15px;
  padding: 8px 9px;
  border-radius: 9px;
  background: #f7f9fc;
}

.history-checklist-row strong,
.history-checklist-row span {
  display: block;
}

.history-checklist-row div > span {
  margin-top: 3px;
  color: var(--muted);
  font-size: .76rem;
}

.history-checklist-row p {
  grid-column: 1 / -1;
  margin: 0;
  color: #475467;
  font-size: .82rem;
}

.check-result {
  align-self: start;
  padding: 4px 7px;
  border-radius: 999px;
  color: #475467;
  background: #e9edf2;
  font-size: .7rem;
  font-weight: 800;
}

.check-result.passed {
  color: var(--green);
  background: #ecfdf3;
}

.check-result.issue-found {
  color: var(--red);
  background: #fef3f2;
}

.report-note {
  margin-top: 16px;
  padding: 12px;
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: #f1f6ff;
}

.report-note p {
  margin: 5px 0 0;
}

.modal-actions { display: flex; justify-content: end; margin-top: 20px; }

.report-comments {
  margin: 9px 0 0;
  color: #475467;
  font-weight: 400;
}

.report-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.photo-thumbnail {
  padding: 0;
  border: 0;
  background: transparent;
}

.photo-thumbnail img {
  display: block;
  width: 82px;
  height: 66px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}

.photo-thumbnail:hover img,
.photo-thumbnail:focus-visible img {
  outline: 3px solid rgba(37, 99, 235, .2);
  border-color: var(--blue);
}

.photo-dialog {
  width: calc(100vw - 16px);
  max-width: none;
  height: calc(100vh - 16px);
  max-height: none;
  padding: 0;
  border: 0;
  border-radius: 16px;
  overflow: hidden;
  color: white;
  background: #111827;
  box-shadow: 0 25px 90px rgba(0,0,0,.5);
}

.photo-dialog::backdrop {
  background: rgba(3, 9, 18, .86);
}

.photo-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 15px;
  background: #1f2937;
}

.photo-dialog-header h2,
.photo-dialog-header p {
  margin-bottom: 0;
}

.photo-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: calc(100vh - 124px);
  min-height: 0;
  padding: 10px 64px;
  overflow: hidden;
}

.photo-stage img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
  border-radius: 8px;
  object-fit: contain;
  object-position: center center;
}

.photo-navigation {
  position: absolute;
  z-index: 5;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 58px;
  padding: 0;
  color: white;
  background: rgba(255,255,255,.12);
  font-size: 2rem;
}

#photo-previous { left: 12px; }
#photo-next { right: 12px; }

.photo-counter {
  margin: 0;
  padding: 9px;
  color: #d1d5db;
  background: #1f2937;
  text-align: center;
}

#inspection-form { padding-top: 20px; }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.gps-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 20px 0;
  padding: 16px;
  border: 1px solid #bfd4ff;
  border-radius: 13px;
  background: #f1f6ff;
}

.gps-card h3 { margin-bottom: 5px; }
.gps-card p { margin-bottom: 0; color: var(--muted); }

.table-wrap {
  margin: 20px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

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

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

th {
  color: #475467;
  background: #f8fafc;
  font-size: .78rem;
}

td { font-size: .85rem; }
td select, td input { margin-top: 0; }

.photo-field { margin: 18px 0; }
.photo-field span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 400;
}

.form-status { min-height: 24px; font-weight: 800; }
.form-status.error { color: var(--red); }
.form-status.success { color: var(--green); }

.empty-state {
  grid-column: 1 / -1;
  padding: 50px 20px;
  color: var(--muted);
  text-align: center;
}

.refund-filters {
  grid-template-columns: minmax(0, 2fr) minmax(180px, 1fr);
  margin-bottom: 18px;
}

.refund-list {
  display: grid;
  gap: 14px;
}

.refund-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: white;
  box-shadow: 0 8px 25px rgba(31, 52, 78, .06);
}

.refund-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.refund-card-header h3 {
  margin-bottom: 3px;
}

.refund-status {
  display: inline-block;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 800;
  white-space: nowrap;
}

.refund-status.not-processed {
  color: var(--amber);
  background: #fffaeb;
}

.refund-status.processed {
  color: var(--green);
  background: #ecfdf3;
}

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

.refund-actions {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.refund-actions label {
  width: min(260px, 100%);
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: min(440px, 100%);
}

.auth-brand {
  margin-bottom: 18px;
  text-align: center;
}

.auth-brand h1 {
  color: var(--navy);
}

.auth-card {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: white;
  box-shadow: 0 18px 50px rgba(31, 52, 78, .12);
}

.auth-card h2 {
  margin-bottom: 8px;
}

.auth-description {
  margin-bottom: 22px;
  color: var(--muted);
}

.auth-card label + label {
  margin-top: 15px;
}

.auth-submit {
  width: 100%;
  margin-top: 20px;
}

@media (max-width: 800px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gps-card { align-items: stretch; flex-direction: column; }
  .detail-grid, .form-grid, .refund-detail-grid { grid-template-columns: 1fr; }
  .portal-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}

@media (max-width: 520px) {
  .topbar { padding: 22px 16px; }
  .topbar { align-items: flex-start; gap: 16px; flex-direction: column; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .signed-in-user { width: 100%; max-width: none; }
  main { width: min(100% - 20px, 1320px); margin-top: 12px; }
  .panel { padding: 15px; }
  .filters { grid-template-columns: 1fr; }
  .refund-actions { align-items: stretch; flex-direction: column; }
  .refund-actions label { width: 100%; }
  .panel-heading { align-items: start; flex-direction: column; }
  .detail-tabs { grid-template-columns: 1fr; }
  .modal {
    width: calc(100% - 10px);
    max-height: calc(100vh - 10px);
    padding: 0 12px 12px;
  }
  .modal-header {
    margin: 0 -12px;
    padding: 13px 12px 11px;
  }
  .detail-section { padding: 10px; }
  .photo-stage {
    height: calc(100vh - 112px);
    padding: 6px 42px;
  }
  .photo-navigation {
    width: 34px;
    height: 48px;
  }
  #photo-previous { left: 4px; }
  #photo-next { right: 4px; }
}
