:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --line: #d8dee8;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --warn: #b45309;
  --nav: #0f172a;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

body.modal-open {
  overflow: hidden;
}

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

button {
  color: inherit;
}

button,
label,
.side-action {
  -webkit-tap-highlight-color: transparent;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  align-content: start;
  gap: 16px;
  height: 100vh;
  overflow-y: auto;
  padding: 18px;
  background: var(--nav);
  color: #fff;
}

.brand-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.brand-logo {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #f8fafc;
  color: #0f172a;
  font-size: 21px;
  font-weight: 900;
}

.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.eyebrow {
  margin: 0 0 4px;
  color: #8ea3c1;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin-bottom: 0;
  font-size: 25px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 23px;
}

h3 {
  margin-bottom: 0;
}

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

.nav-button,
.side-action,
.ghost-button,
.primary-button,
.card-actions button,
.gallery-head button,
.gallery-nav {
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}

.nav-button,
.side-action {
  min-height: 44px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #dbeafe;
  font-weight: 800;
  text-align: left;
}

.nav-button.active,
.side-action:hover,
.nav-button:hover {
  background: #f8fafc;
  color: #0f172a;
}

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

.metric {
  min-height: 82px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.metric-label {
  display: block;
  color: #b7c7de;
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 5px;
  color: #fff;
  font-size: 28px;
}

.backup-box {
  display: grid;
  gap: 8px;
}

.side-action {
  display: grid;
  align-items: center;
}

.main-panel {
  min-width: 0;
  padding: 18px clamp(12px, 3vw, 28px) 40px;
}

.cover-panel {
  min-height: 178px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(120deg, rgba(15, 23, 42, 0.9), rgba(15, 118, 110, 0.52)),
    linear-gradient(45deg, #0f172a, #0f766e);
  background-position: center;
  background-size: cover;
  box-shadow: var(--shadow);
}

.cover-shade {
  display: grid;
  align-content: end;
  min-height: 178px;
  padding: 22px;
  color: #fff;
}

.cover-shade .eyebrow {
  color: #b7f7ef;
}

.cover-shade h2 {
  font-size: clamp(30px, 5vw, 48px);
}

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

.view-panel {
  display: none;
}

.view-panel.active {
  display: grid;
}

.inventory,
.editor,
.settings-panel {
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.inventory {
  min-height: 540px;
  padding: 16px;
}

.editor,
.settings-panel {
  width: min(720px, 100%);
  padding: 16px;
}

.section-title,
.filter-row,
.field-row,
.card-actions,
.photo-meta {
  display: flex;
  gap: 10px;
}

.section-title {
  align-items: center;
  justify-content: space-between;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #cfd6e2;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.filter-row select {
  min-width: 160px;
}

.field-row > label {
  flex: 1;
  min-width: 0;
}

.photo-picker {
  position: relative;
  display: grid;
  min-height: 230px;
  place-items: center;
  overflow: hidden;
  border: 1px dashed #9aa8bc;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  cursor: pointer;
}

.photo-picker img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-picker span {
  position: relative;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

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

.photo-action {
  display: grid;
  min-height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #e0f2fe;
  color: #075985;
  cursor: pointer;
  font-weight: 900;
  text-align: center;
}

.photo-action:last-child {
  background: #ecfdf3;
  color: #027a48;
}

.photo-meta {
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.photo-meta strong {
  color: var(--ink);
}

.photo-thumbs,
.card-thumbs,
.gallery-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.photo-thumb,
.card-thumbs button,
.gallery-thumbs button {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #e6ebf2;
  cursor: pointer;
}

.photo-thumb {
  width: 58px;
  height: 58px;
  padding: 0;
}

.photo-thumb.active,
.gallery-thumbs button.active {
  border-color: var(--accent);
}

.photo-thumb img,
.card-thumbs img,
.gallery-thumbs img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-thumb span {
  position: absolute;
  left: 3px;
  bottom: 3px;
  padding: 2px 5px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.76);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}

.photo-thumb b {
  position: absolute;
  top: 2px;
  right: 2px;
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 999px;
  background: rgba(180, 35, 24, 0.92);
  color: #fff;
  font-size: 12px;
  line-height: 1;
}

.primary-button,
.ghost-button,
.card-actions button {
  min-height: 42px;
  padding: 0 12px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

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

.primary-button.compact {
  min-height: 40px;
}

.ghost-button,
.card-actions button {
  background: #f1f5f9;
  color: #1f2937;
}

.empty-state {
  display: grid;
  min-height: 260px;
  place-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--ink);
  font-size: 20px;
}

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

.tire-card {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.tire-photo {
  position: relative;
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 132px;
  place-items: center;
  border: 0;
  background: #e6ebf2;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
}

.tire-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tire-photo span {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.76);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
}

.tire-info {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-head h3 {
  font-size: 18px;
  line-height: 1.2;
}

.pill {
  display: inline-flex;
  margin-bottom: 5px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #075985;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.pill.usado {
  background: #fef3c7;
  color: #92400e;
}

.qty {
  flex: 0 0 auto;
  padding: 6px 9px;
  border-radius: 8px;
  background: #ecfdf3;
  color: #027a48;
}

.qty.zero {
  background: #fee4e2;
  color: var(--danger);
}

dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-weight: 900;
}

.notes {
  margin-bottom: 0;
  color: #475467;
  font-size: 13px;
  line-height: 1.4;
}

.card-thumbs button {
  width: 42px;
  height: 42px;
  padding: 0;
}

.card-actions {
  flex-wrap: wrap;
}

.card-actions button[data-action="minus"] {
  color: var(--warn);
}

.card-actions button[data-action="delete"] {
  margin-left: auto;
  color: var(--danger);
}

.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
}

.gallery-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.78);
}

.gallery-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(980px, 100%);
  max-height: min(820px, calc(100vh - 32px));
  overflow: hidden;
  border-radius: 8px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}

.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.gallery-head div {
  display: grid;
  gap: 3px;
}

.gallery-head span {
  color: #cbd5e1;
  font-size: 12px;
}

.gallery-head button,
.gallery-nav {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
}

.gallery-stage {
  position: relative;
  display: grid;
  min-height: 420px;
  place-items: center;
  background: #020617;
  touch-action: pan-y;
}

.gallery-stage img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
}

.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 26px;
}

.gallery-nav.prev {
  left: 12px;
}

.gallery-nav.next {
  right: 12px;
}

.gallery-thumbs {
  padding: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.gallery-thumbs button {
  width: 64px;
  height: 52px;
  padding: 0;
}

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

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

  .side-nav,
  .backup-box {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 680px) {
  .main-panel {
    padding-inline: 10px;
  }

  .side-nav,
  .backup-box,
  .tools,
  .filter-row,
  .field-row,
  .photo-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .tire-card {
    grid-template-columns: 104px minmax(0, 1fr);
  }

  .tire-photo {
    min-height: 126px;
  }

  dl {
    grid-template-columns: 1fr;
  }

  .gallery-modal {
    padding: 0;
  }

  .gallery-panel {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
  }

  .gallery-stage {
    min-height: 0;
  }

  .gallery-nav {
    display: none;
  }
}
