:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --ink: #17201c;
  --muted: #66716c;
  --line: #dce3de;
  --panel: #ffffff;
  --panel-soft: #eef5f1;
  --green: #1d7352;
  --green-dark: #15583e;
  --teal: #207a8a;
  --red: #b8463f;
  --amber: #b57921;
  --blue: #3569a8;
  --shadow: 0 18px 50px rgba(31, 50, 42, 0.12);
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(32, 122, 138, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(181, 121, 33, 0.08), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Authentication */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 1rem;
  background:
    linear-gradient(135deg, rgba(32, 122, 138, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(181, 121, 33, 0.12), transparent 30%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-brand .brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background: var(--green);
  color: white;
  border-radius: 8px;
  font-weight: bold;
  font-size: 24px;
  margin-bottom: 1rem;
}

.auth-brand h1 {
  margin: 0 0 0.25rem;
  color: var(--ink);
}

.auth-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-form h2 {
  margin: 0 0 0.5rem;
  font-size: 20px;
  color: var(--ink);
}

.auth-form input {
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  font-size: 16px;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(29, 115, 82, 0.1);
}

.auth-form button {
  padding: 0.75rem 1rem;
  background: var(--green);
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  transition: background 200ms;
}

.auth-form button:hover {
  background: var(--green-dark);
}

.auth-toggle {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.auth-toggle button {
  background: none;
  border: none;
  color: var(--green);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  padding: 0;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 24px;
  background: #0f211a;
  color: #f8fbf8;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #d7f1df;
  color: #102219;
  font-weight: 900;
}

.brand span,
.session-panel p {
  display: block;
  margin: 2px 0 0;
  color: #b8c8c0;
  font-size: 0.86rem;
}

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

.nav-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: transparent;
  color: #e8f1ec;
  text-align: left;
}

.nav-tab.active,
.nav-tab:hover {
  background: rgba(255, 255, 255, 0.12);
}

.session-panel {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.add-user-details summary {
  color: #b8c8c0;
  font-size: 0.82rem;
  cursor: pointer;
  user-select: none;
}

.add-user-form {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.add-user-form input {
  border-color: rgba(255, 255, 255, 0.22);
  background: #163127;
  color: #fff;
}

.session-panel label,
label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.session-panel select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

.session-panel select {
  border-color: rgba(255, 255, 255, 0.22);
  background: #163127;
  color: #fff;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-row select {
  min-width: 0;
  flex: 1;
}

.alert-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  border: 1px solid rgba(184, 70, 63, 0.24);
  border-radius: 10px;
  background: #fff5f3;
  padding: 12px 14px;
  color: #8a2f27;
  font-weight: 700;
}

main {
  min-width: 0;
  padding: 28px;
}

.topbar,
.panel-header,
.detail-head,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 3vw, 3.2rem);
  line-height: 1;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.05rem;
}

h3 {
  margin-bottom: 6px;
}

.top-actions,
.inline-control,
.status-controls,
.owner-chips,
.event-meta,
.qr-actions,
.detail-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-actions {
  align-items: start;
  justify-content: space-between;
  flex-wrap: wrap;
}

.primary-action,
.secondary-action,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-action {
  padding: 0 16px;
  background: var(--green);
  color: #fff;
}

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

.icon-button.danger {
  color: var(--red);
}

.secondary-action,
.icon-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.secondary-action {
  padding: 0 14px;
}

.icon-button {
  width: 40px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric,
.panel,
dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.metric {
  padding: 16px;
}

.metric strong {
  display: block;
  font-size: 1.8rem;
}

.metric span,
.panel p,
.item-card p,
.timeline p,
.qr-card p {
  color: var(--muted);
}

.content-grid,
.scan-layout {
  display: grid;
  grid-template-columns: minmax(320px, 0.85fr) minmax(360px, 1.15fr);
  gap: 16px;
}

.panel {
  padding: 18px;
}

.panel + .panel,
.global-map-panel {
  margin-top: 16px;
}

.inventory-panel {
  min-height: 520px;
}

.item-list,
.repair-list,
.quick-scan-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.item-card,
.repair-card,
.alert-card,
.timeline-event {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.item-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  text-align: left;
}

.item-card.active {
  border-color: var(--green);
  box-shadow: inset 4px 0 0 var(--green);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--green-dark);
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.badge.red {
  background: #fbe7e4;
  color: var(--red);
}

.badge.amber {
  background: #fff0d8;
  color: var(--amber);
}

.badge.blue {
  background: #e6effb;
  color: var(--blue);
}

.detail-panel {
  min-height: 520px;
}

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

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

.meta-box span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.owner-chips {
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.status-controls {
  flex-wrap: wrap;
  margin: 16px 0;
}

.status-controls button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.status-controls button.active {
  background: var(--green);
  color: #fff;
}

.map-canvas {
  position: relative;
  min-height: 250px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(23, 32, 28, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(23, 32, 28, 0.06) 1px, transparent 1px),
    linear-gradient(135deg, #dfeee8, #f9fbf5);
  background-size: 42px 42px, 42px 42px, auto;
}

.trail-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  font-size: 0.74rem;
  font-weight: 900;
}

.map-pin.current {
  background: var(--red);
}

.map-label {
  position: absolute;
  transform: translate(-50%, 18px);
  min-width: 110px;
  max-width: 160px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 6px 8px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.leaflet-canvas {
  min-height: 320px;
}

.item-image {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  margin: 10px 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.map-empty {
  margin: 0;
  padding: 20px;
  color: var(--muted);
}

.timeline {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.timeline-event {
  padding: 12px;
}

.event-meta {
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.76rem;
}

.scan-form {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.inline-control input {
  min-width: 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row input {
  width: auto;
}

.repair-card,
.alert-card {
  padding: 14px;
}

.repair-card {
  display: grid;
  gap: 10px;
}

.coowner-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.coowner-row:last-child {
  border-bottom: 0;
}

.coowner-row p {
  margin-bottom: 0;
}

.add-coowner-form {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.add-coowner-form select {
  flex: 1;
}

.dialog-inner {
  padding: 20px;
}

.alert-stack {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.qr-card {
  display: grid;
  gap: 10px;
  border: 1px dashed #9daaa3;
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.qr-image,
.qr-fallback {
  display: block;
  width: 180px;
  height: 180px;
  margin-bottom: 4px;
  border: 1px solid var(--line);
  background: #fff;
}

.qr-image {
  object-fit: contain;
}

.qr-fallback {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 14px;
  text-align: center;
}

.qr-fallback small {
  color: var(--muted);
  font-size: 0.72rem;
  word-break: break-all;
}

dialog {
  width: min(520px, calc(100vw - 28px));
  border: 0;
  padding: 0;
}

dialog::backdrop {
  background: rgba(15, 33, 26, 0.45);
}

#item-form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

#item-form label {
  display: grid;
  gap: 6px;
}

menu {
  display: flex;
  justify-content: end;
  gap: 10px;
  padding: 0;
  margin: 0;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

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

  .nav-tab {
    justify-content: center;
  }

  .content-grid,
  .scan-layout,
  .metrics-grid {
    grid-template-columns: 1fr;
  }
}

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

  .topbar,
  .panel-header,
  .detail-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .inline-control {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-action,
  .secondary-action,
  .icon-button {
    width: 100%;
  }

  .nav-tabs {
    grid-template-columns: 1fr 1fr;
  }

  .detail-meta {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  #auth-view,
  .sidebar,
  .topbar,
  .alert-banner,
  #dashboard-view,
  #scan-view,
  #repair-view {
    display: none !important;
  }

  #app-view {
    display: block !important;
  }

  main {
    padding: 0 !important;
  }

  #print-view {
    display: block !important;
  }

  .app-shell {
    display: block !important;
  }

  .panel {
    border: 0;
    box-shadow: none;
  }

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