:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-muted: #eef3f8;
  --border: #cfd9e5;
  --border-strong: #aebccd;
  --text: #172033;
  --muted: #5f6f84;
  --primary: #245c9f;
  --primary-dark: #174372;
  --critical: #c62828;
  --warning: #b66a00;
  --ok: #258052;
  --shadow: 0 10px 24px rgba(22, 34, 51, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 6px;
  background: var(--text);
  color: #ffffff;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  letter-spacing: 0;
}

.session-text {
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.form-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.auth-panel {
  display: grid;
  min-height: calc(100vh - 75px);
  place-items: center;
}

.auth-form,
.section-form,
.list-pane,
.yard-form {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-form {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 18px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--text);
  font-weight: 400;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus,
.button:focus {
  outline: 2px solid rgba(36, 92, 159, 0.28);
  outline-offset: 2px;
}

.button,
.icon-button {
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  min-height: 38px;
  padding: 8px 12px;
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}

.button-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

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

.button-secondary:hover,
.icon-button:hover {
  background: var(--surface-muted);
}

.button-disabled {
  pointer-events: none;
  opacity: 0.65;
}

.button-small {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 13px;
}

.icon-button {
  width: 36px;
  padding: 0;
  font-size: 21px;
  line-height: 1;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

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

.stat {
  display: grid;
  gap: 4px;
  min-height: 78px;
  padding: 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  background: var(--surface);
}

.stat-critical {
  border-left-color: var(--critical);
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.stat strong {
  font-size: 24px;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.list-pane,
.detail-pane {
  min-width: 0;
}

.list-pane {
  display: grid;
  gap: 12px;
  padding: 14px;
  position: sticky;
  top: 12px;
}

.detail-pane {
  display: grid;
  gap: 16px;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.search-input {
  min-height: 38px;
}

.trailer-list,
.notes-list {
  display: grid;
  gap: 8px;
}

.trailer-row {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 58px;
  border: 1px solid var(--border);
  border-left: 4px solid transparent;
  border-radius: 5px;
  padding: 10px;
  background: #ffffff;
  color: var(--text);
  text-align: left;
}

.trailer-row:hover,
.trailer-row-selected {
  border-left-color: var(--primary);
  background: #f7fbff;
}

.trailer-row-title {
  font-weight: 700;
}

.trailer-row-meta {
  color: var(--muted);
  font-size: 13px;
}

.section-form {
  display: grid;
  gap: 13px;
  padding: 14px;
  box-shadow: none;
}

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

.option-group {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 10px 12px 12px;
}

.option-group legend {
  padding: 0 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

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

.notes-section {
  display: grid;
  gap: 12px;
  padding: 14px 0 0;
  border-top: 1px solid var(--border);
}

.note-row {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 5px;
  padding: 10px;
  background: #ffffff;
}

.note-row-critical {
  border-left-color: var(--critical);
}

.note-row-warning {
  border-left-color: var(--warning);
}

.note-row-info {
  border-left-color: var(--primary);
}

.note-row-resolved {
  opacity: 0.72;
}

.note-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 4px;
  padding: 3px 7px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge-severity-critical {
  background: #fde8e8;
  color: #8f1717;
}

.badge-severity-warning {
  background: #fff1d8;
  color: #7a4700;
}

.badge-severity-info {
  background: #e7f0fb;
  color: #174372;
}

.badge-resolved {
  background: #e7f5ed;
  color: #1c6842;
}

.note-text {
  overflow-wrap: anywhere;
}

.empty-state {
  padding: 14px;
  border: 1px dashed var(--border-strong);
  border-radius: 5px;
  color: var(--muted);
}

.disabled-form {
  opacity: 0.72;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-left: 4px solid var(--ok);
  border-radius: 5px;
  padding: 12px 14px;
  background: #ffffff;
  box-shadow: var(--shadow);
  color: var(--text);
  font-weight: 700;
}

.toast-error {
  border-left-color: var(--critical);
}

.view-tabs {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  overflow: hidden;
  background: var(--surface);
}

.view-tab {
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--border-strong);
  padding: 8px 16px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

.view-tab:last-child {
  border-right: 0;
}

.view-tab:hover {
  background: var(--surface-muted);
}

.view-tab-active,
.view-tab-active:hover {
  background: var(--text);
  color: #ffffff;
}

.yard-form {
  display: grid;
  gap: 13px;
  margin-bottom: 18px;
  padding: 16px;
}

.compact-field {
  width: min(190px, 100%);
}

.yard-overview {
  display: grid;
  gap: 14px;
}

.yard-overview-header {
  padding-top: 2px;
}

.section-subtitle {
  color: var(--muted);
  font-size: 13px;
}

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

.yard-stat {
  display: grid;
  gap: 3px;
  min-height: 68px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 5px;
  padding: 11px 12px;
  background: var(--surface);
}

.yard-stat-warning {
  border-left-color: var(--warning);
}

.yard-stat-critical {
  border-left-color: var(--critical);
}

.yard-stat strong {
  font-size: 21px;
}

.yard-list {
  display: grid;
  gap: 8px;
}

.yard-row {
  display: grid;
  grid-template-columns: minmax(110px, 0.8fr) minmax(240px, 1.4fr) minmax(220px, 1.6fr) auto;
  gap: 12px;
  align-items: center;
  min-width: 0;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 5px;
  padding: 11px 12px;
  background: var(--surface);
}

.yard-row-warning {
  border-left-color: var(--warning);
}

.yard-row-critical {
  border-left-color: var(--critical);
}

.yard-row-number {
  overflow-wrap: anywhere;
  font-size: 16px;
  font-weight: 700;
}

.yard-row-info,
.yard-row-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
}

.yard-note-summary {
  width: 100%;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 13px;
}

.badge-equipment {
  background: #e7f5ed;
  color: #1c6842;
}

.badge-date-warning {
  background: #fff1d8;
  color: #7a4700;
}

.badge-date-critical,
.badge-unknown {
  background: #fde8e8;
  color: #8f1717;
}

.yard-row-action {
  justify-self: end;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .button {
    flex: 1;
  }

  main {
    padding: 12px;
  }

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

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .list-pane {
    position: static;
  }

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

  .yard-row {
    grid-template-columns: minmax(100px, 0.7fr) minmax(220px, 1.3fr);
  }

  .yard-row-action {
    justify-self: start;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

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

  .view-tabs {
    display: grid;
    width: 100%;
  }

  .yard-form .pane-header,
  .yard-overview-header {
    align-items: stretch;
    flex-direction: column;
  }

  .compact-field {
    width: 100%;
  }

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

  .note-row-header,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .row-actions {
    width: 100%;
  }

  .row-actions .button,
  .form-actions .button {
    flex: 1;
  }
}
