/* =========================================================
   London Car Detail — app UI
   Mobile-first management app. Dark automotive theme,
   London red identity. Touch-first, AA contrast.
   ========================================================= */

:root {
  /* Surfaces (dark ramp) */
  --bg: #14171a;
  --surface: #1d2126;
  --surface-2: #262b31;
  --surface-3: #30363d;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);

  /* Text (AA on --surface) */
  --text: #f1f3f5;
  --text-muted: #a7b0ba;   /* ~6:1 on --surface */
  --text-faint: #79828c;   /* labels/icons, ~4.6:1 */

  /* Brand */
  --brand: #e3202a;
  --brand-hover: #f23942;
  --brand-press: #c41b24;
  --brand-soft: rgba(227, 32, 42, 0.14);
  --on-brand: #ffffff;

  /* Semantic */
  --danger: #f04d56;
  --danger-soft: rgba(240, 77, 86, 0.13);
  --success: #2fc08a;
  --focus: #6fa8ff;

  /* Radius */
  --r-sm: 9px;
  --r: 13px;
  --r-lg: 18px;
  --r-full: 999px;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, 0.45);

  /* Layout */
  --sidebar-w: 248px;
  --topbar-h: 58px;
  --bottomnav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 200ms;

  /* Z-index scale */
  --z-nav: 1020;
  --z-fab: 1025;
  --z-topbar: 1030;
  --z-modal: 1050;
  --z-toast: 1080;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  margin: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { letter-spacing: -0.02em; text-wrap: balance; }
h1 { font-size: 1.6rem; font-weight: 700; line-height: 1.15; }
h2 { font-size: 1.2rem; font-weight: 650; }

a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

/* iOS: inputs >=16px to avoid zoom; touch targets >=44px */
.form-control, .form-select { font-size: 16px; min-height: 46px; }
.btn { min-height: 44px; }

/* =========================================================
   App shell
   ========================================================= */
.app-shell { min-height: 100dvh; }

.content {
  padding: 18px 16px calc(var(--bottomnav-h) + var(--safe-b) + 24px);
  max-width: 1080px;
}

/* ---- Top bar (mobile only) ---- */
.topbar {
  height: var(--topbar-h);
  background: color-mix(in oklab, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
}
.topbar .brand { display: inline-flex; align-items: center; }
.topbar .brand img { height: 26px; display: block; }
.topbar .topbar-title {
  display: none; /* oculto na visão mobile (topbar só aparece no mobile) */
  font-weight: 650;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  margin-left: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .spacer { margin-left: auto; }

/* ---- Desktop sidebar (hidden on mobile) ---- */
.sidebar { display: none; }

/* ---- Bottom navigation (mobile) ---- */
.bottom-nav {
  position: fixed;
  inset: auto 0 0 0;
  height: calc(var(--bottomnav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: color-mix(in oklab, var(--surface) 90%, transparent);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: var(--z-nav);
}
.bottom-nav > form { flex: 1; display: flex; margin: 0; }
.bottom-nav__item {
  flex: 1;
  background: none;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 550;
  font-family: inherit;
  padding: 8px 4px;
  cursor: pointer;
  transition: color var(--dur) var(--ease);
  position: relative;
}
.bottom-nav__item svg { width: 23px; height: 23px; }
.bottom-nav__item:active { color: var(--text); }
.bottom-nav__item.active { color: var(--brand); }
.bottom-nav__item.active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 26px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--brand);
}

/* =========================================================
   Buttons (override Bootstrap, unify the vocabulary)
   ========================================================= */
.btn {
  --bs-btn-focus-box-shadow: none;
  font-weight: 600;
  border-radius: var(--r-sm);
  padding: 10px 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              transform 80ms var(--ease), color var(--dur) var(--ease);
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-sm { min-height: 38px; padding: 7px 14px; font-size: 0.86rem; border-radius: var(--r-sm); }
.btn-lg { min-height: 50px; padding: 13px 22px; font-size: 1rem; }

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
  box-shadow: 0 4px 14px rgba(227, 32, 42, 0.28);
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--on-brand); }
.btn-primary:active { background: var(--brand-press); border-color: var(--brand-press); }

/* secondary / neutral — replaces the washed-out btn-outline-light */
.btn-outline-light,
.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-outline-light:hover,
.btn-secondary:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: var(--text);
}

/* ghost — quiet tertiary action */
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-outline-danger {
  background: transparent;
  border-color: color-mix(in oklab, var(--danger) 55%, transparent);
  color: var(--danger);
}
.btn-outline-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.btn-link { color: var(--text-muted); text-decoration: none; }
.btn-link:hover { color: var(--text); }

.btn-block, .d-grid > .btn { width: 100%; }

/* =========================================================
   Cards & sections
   ========================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.page-head h1 { margin: 0; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 26px 0 12px;
}
.section-head h2 { margin: 0; font-size: 1.05rem; }

/* =========================================================
   List rows (the app-style listing)
   ========================================================= */
.list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.list-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 13px;
  padding: 13px 15px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  transition: background 140ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
.list-row:active { background: var(--surface-3); }

.avatar {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: var(--r-full);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
  color: var(--text);
  background: linear-gradient(150deg, var(--surface-3), var(--surface-2));
  border: 1px solid var(--border);
}
.avatar--brand { background: var(--brand-soft); color: var(--brand-hover); border-color: transparent; }

/* Coluna central: empilha sempre nome (linha 1) sobre os detalhes (abaixo). */
.list-row__main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.list-row__title {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
/* Detalhes menores, logo abaixo do nome. Quebram em até 3 linhas (ex.: produto
   com estoque + venda + status) em vez de estourar/sobrescrever a linha. */
.list-row__meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.list-row__chevron { flex: 0 0 auto; color: var(--text-faint); }
/* Coluna lateral à direita: valor em cima, ação (ícone) logo abaixo. */
.list-row__trail {
  flex: 0 0 auto;
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.list-row__actions { flex: 0 0 auto; display: flex; gap: 8px; align-items: center; }
.list-row__actions form { margin: 0; }
/* Botão de ação só com ícone (ex.: excluir) — compacto, na lateral da linha. */
.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--text-faint);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn--danger:hover { color: var(--danger); border-color: var(--border-strong); }
.icon-btn--danger:active { background: var(--surface-3); }
/* Valor monetário à direita: largura fixa, nunca encolhe nem quebra,
   independentemente do tamanho do nome/descrição (que trunca em .list-row__main). */
.list-row__amount {
  flex: 0 0 auto;
  margin-left: auto;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.92rem;
  text-align: right;
}

/* Rows with inline action buttons: on mobile drop the buttons to a full-width
   second line so they never crowd or overlap the title. */
@media (max-width: 575.98px) {
  .list-row--actions { flex-wrap: wrap; row-gap: 12px; }
  .list-row--actions .list-row__actions {
    flex-basis: 100%;
    margin-left: 57px; /* avatar (44) + gap (13), aligns with the title */
  }
  .list-row--actions .list-row__actions .btn { flex: 1 1 auto; }
}

/* =========================================================
   Search
   ========================================================= */
.search { position: relative; margin-bottom: 18px; }
.search__icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}
.search input.form-control {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-full);
  padding-left: 44px;
  padding-right: 14px;
}
.search input.form-control::placeholder { color: var(--text-faint); }
.search input.form-control:focus {
  background: var(--surface);
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.18);
  color: var(--text);
}

/* =========================================================
   Floating action button (mobile)
   ========================================================= */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--bottomnav-h) + var(--safe-b) + 18px);
  width: 56px;
  height: 56px;
  border-radius: var(--r-full);
  background: var(--brand);
  color: var(--on-brand);
  border: 0;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-lg), 0 6px 18px rgba(227, 32, 42, 0.4);
  z-index: var(--z-fab);
  transition: transform 140ms var(--ease), background var(--dur) var(--ease);
}
.fab:hover { background: var(--brand-hover); color: var(--on-brand); }
.fab:active { transform: scale(0.93); }
.fab svg { width: 26px; height: 26px; }

/* =========================================================
   Forms (Bootstrap ActiveForm)
   ========================================================= */
.form-control, .form-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-sm);
}
.form-control::placeholder { color: var(--text-faint); }
.form-control:focus, .form-select:focus {
  background: var(--surface-2);
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.2);
  color: var(--text);
}
.form-label, .control-label { color: var(--text-muted); font-weight: 550; font-size: 0.88rem; margin-bottom: 6px; }
.form-text, .hint-block { color: var(--text-faint); }
.invalid-feedback, .help-block-error { color: var(--danger); font-size: 0.84rem; }
.has-error .form-control, .form-control.is-invalid { border-color: var(--danger); }
.form-check-input { background-color: var(--surface-2); border-color: var(--border-strong); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-check-input:focus { box-shadow: 0 0 0 3px rgba(111, 168, 255, 0.2); }

.field-card { padding: 18px; }
.field-card .form-group:last-of-type { margin-bottom: 0; }

/* =========================================================
   DetailView (key/value)
   ========================================================= */
.detail-view { width: 100%; border-collapse: collapse; }
.detail-view th, .detail-view td {
  text-align: left;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.detail-view tr:last-child th, .detail-view tr:last-child td { border-bottom: 0; }
.detail-view th {
  color: var(--text-faint);
  font-weight: 550;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: 38%;
  white-space: nowrap;
}
.detail-view td { color: var(--text); font-weight: 500; }

/* =========================================================
   Stats (dashboard)
   ========================================================= */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.stat__label { color: var(--text-muted); font-size: 0.82rem; font-weight: 550; }
.stat__value { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; }

/* =========================================================
   Empty state
   ========================================================= */
.empty {
  text-align: center;
  padding: 40px 22px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r);
  color: var(--text-muted);
}
.empty__icon { color: var(--text-faint); margin-bottom: 12px; }
.empty__title { color: var(--text); font-weight: 650; margin-bottom: 4px; }

/* =========================================================
   Pagination
   ========================================================= */
.pagination { gap: 6px; flex-wrap: wrap; }
.pagination .page-link {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--r-sm) !important;
  min-width: 42px;
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pagination .page-link:hover { background: var(--surface-2); color: var(--text); }
.pagination .active .page-link { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.pagination .disabled .page-link { opacity: 0.4; }

/* =========================================================
   Login
   ========================================================= */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(227, 32, 42, 0.16), transparent 60%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 30px 26px;
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-card .brand { text-align: center; margin-bottom: 26px; }
.login-card .brand img { width: 200px; max-width: 70%; }

/* =========================================================
   Entrance motion (subtle, list stagger)
   ========================================================= */
@keyframes row-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.list-row { animation: row-in 360ms var(--ease) both; }
.list-row:nth-child(2) { animation-delay: 30ms; }
.list-row:nth-child(3) { animation-delay: 60ms; }
.list-row:nth-child(4) { animation-delay: 90ms; }
.list-row:nth-child(5) { animation-delay: 120ms; }
.list-row:nth-child(n+6) { animation-delay: 150ms; }

/* =========================================================
   Desktop (>=992px): fixed sidebar, no topbar/bottom-nav
   ========================================================= */
@media (min-width: 992px) {
  .topbar, .bottom-nav, .fab { display: none; }

  .app-shell { display: flex; }

  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    padding: 22px 14px;
    background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .sidebar .brand { padding: 6px 10px 22px; }
  .sidebar .brand img { width: 100%; max-width: 168px; }
  .sidebar .nav-link-item {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    padding: 11px 14px;
    border-radius: var(--r-sm);
    font-weight: 550;
    transition: background 140ms var(--ease), color 140ms var(--ease);
  }
  .sidebar .nav-link-item svg { width: 20px; height: 20px; }
  .sidebar .nav-link-item:hover { background: var(--surface-2); color: var(--text); }
  .sidebar .nav-link-item.active { background: var(--brand); color: var(--on-brand); box-shadow: 0 4px 14px rgba(227,32,42,0.28); }
  .sidebar .sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

  .content {
    margin-left: var(--sidebar-w);
    padding: 30px 36px 48px;
    max-width: calc(var(--sidebar-w) + 1080px);
  }
  h1 { font-size: 1.85rem; }
}

/* =========================================================
   Reduced motion
   ========================================================= */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .list-row { animation: none; }
}

/* ---- "Mais" sheet (mobile overflow menu) ---- */
.sheet {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(0, 0, 0, 0.5);
  display: none;
}
.sheet.open { display: block; }
.sheet__panel {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--bottomnav-h) + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 10px;
  box-shadow: var(--shadow-lg);
}
.sheet__item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; background: none; border: 0; cursor: pointer;
  color: var(--text); font: inherit; font-weight: 550;
  padding: 14px 14px; border-radius: var(--r-sm); text-align: left;
}
.sheet__item svg { width: 22px; height: 22px; color: var(--text-faint); }
.sheet__item:hover { background: var(--surface-2); }
.sheet__item.active { color: var(--brand); }
.sheet__item.active svg { color: var(--brand); }
.sheet form { margin: 0; }
@media (min-width: 992px) { .sheet { display: none !important; } }

/* =========================================================
   Filtros recolhíveis (mobile-first)
   ========================================================= */
.filters { border: 0; }
.filters__toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  list-style: none; cursor: pointer; user-select: none;
  padding: 11px 14px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r); color: var(--text); font-weight: 550;
}
.filters__toggle::-webkit-details-marker { display: none; }
.filters__toggle:hover { background: var(--surface-3); }
.filters__label { display: inline-flex; align-items: center; gap: 8px; }
.filters__label svg { color: var(--text-faint); }
.filters__badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  background: var(--brand); color: var(--on-brand);
  border-radius: 999px; font-size: 12px; font-weight: 700; line-height: 1;
}
.filters__chevron { color: var(--text-faint); transition: transform 0.18s ease; flex: none; }
.filters[open] .filters__chevron { transform: rotate(180deg); }
.filters__panel { margin-top: 8px; }
