@import url("./variables.css");

* { box-sizing: border-box; }

html {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  padding: 0 0 74px;
  overflow-x: hidden;
}

body:not(.auth-page):not(.session-ready) .topbar,
body:not(.auth-page):not(.session-ready) .app-shell,
body:not(.auth-page):not(.session-ready) .bottom-nav {
  visibility: hidden;
}

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

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

button {
  text-align: center;
}

code {
  overflow-wrap: anywhere;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px;
  overflow: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 249, .92);
  backdrop-filter: blur(14px);
}

.topbar > * {
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 750;
}

.brand img { width: 34px; height: 34px; }

.desktop-nav {
  display: none;
  gap: 6px;
  color: var(--muted);
}

.desktop-nav a,
.bottom-nav a {
  border-radius: var(--radius);
}

.desktop-nav a {
  padding: 9px 12px;
}

.desktop-nav a.active,
.bottom-nav a.active {
  color: var(--primary-strong);
  background: #e2f2ee;
}

.user-pill {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: .9rem;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(14px);
}

.bottom-nav a {
  display: grid;
  place-items: center;
  min-height: 46px;
  color: var(--muted);
  font-size: .78rem;
}

.page-title {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin: 18px 0;
}

.page-title > div:first-child {
  min-width: 0;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 2rem; }
h2 { font-size: 1.1rem; }
p { color: var(--muted); line-height: 1.5; }

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

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

.panel,
.card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel { padding: 16px; }
.card { padding: 14px; }

.stat strong {
  display: block;
  margin-top: 6px;
  font-size: 1.55rem;
}

.vehicle-photo {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin: 0 0 14px;
  background: var(--surface-soft);
}

.muted { color: var(--muted); }
.is-hidden { display: none !important; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  max-width: 100%;
}

.btn.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.btn.danger {
  border-color: #f0d2d2;
  color: var(--danger);
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .9rem;
}

input, select, textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}

select[multiple] {
  min-height: 128px;
}

table {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

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

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

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.row > * {
  min-width: 0;
}

.row > :first-child {
  flex: 1 1 220px;
}

.row > .actions {
  flex: 0 1 auto;
  justify-content: flex-end;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: .78rem;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.auth-card {
  width: min(420px, 100%);
  padding: 22px;
}

.empty {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  background: rgba(255,255,255,.55);
}

.state {
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}

.state.loading {
  color: var(--muted);
}

.state.error {
  border-color: #f0d2d2;
  background: #fff8f8;
  color: var(--danger);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 86px;
  z-index: 30;
  max-width: calc(100vw - 32px);
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  box-shadow: var(--shadow);
}

@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .desktop-nav { display: flex; }
  .bottom-nav { display: none; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .full { grid-column: 1 / -1; }
}

@media (min-width: 1040px) {
  .stats { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .app-shell { padding: 14px; }
  .topbar { align-items: flex-start; flex-wrap: wrap; padding: 10px 14px; }
  .brand { min-height: 40px; }
  .user-pill { max-width: 100%; flex: 1 1 100%; }
  .user-pill [data-user-name] {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .page-title { align-items: stretch; }
  .page-title > * { width: 100%; }
  .actions, .row > .actions { width: 100%; justify-content: stretch; }
  .btn, .actions select { flex: 1 1 100%; white-space: normal; }
  .card, .panel { padding: 12px; }
  h1 { font-size: 1.7rem; }
  .stats { grid-template-columns: 1fr; }
}
