:root {
  --pearl: #f8fafd;
  --pearl-deep: #f0f4fa;
  --pearl-card: #ffffff;
  --brand-blue: #2563eb;
  --brand-blue-mid: #3b82f6;
  --brand-blue-soft: #dbeafe;
  --brand-blue-faint: rgba(37, 99, 235, 0.08);
  --brand-blue-edge: rgba(37, 99, 235, 0.12);
  --accent: #65a30d;
  --text: #1e293b;
  --text-soft: #334155;
  --muted: #64748b;
  --border: rgba(37, 99, 235, 0.12);
  --border-strong: rgba(37, 99, 235, 0.22);
  --shadow: 0 8px 32px rgba(37, 99, 235, 0.08);
  --bg: var(--pearl);
  --bg2: var(--pearl-deep);
  --bg3: var(--pearl-card);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  color: var(--text);
  min-height: 100vh;
  background:
    radial-gradient(ellipse 90% 70% at 0% 0%, var(--brand-blue-edge) 0%, transparent 55%),
    radial-gradient(ellipse 85% 65% at 100% 0%, rgba(59, 130, 246, 0.1) 0%, transparent 52%),
    radial-gradient(ellipse 80% 60% at 0% 100%, rgba(37, 99, 235, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse 85% 65% at 100% 100%, var(--brand-blue-edge) 0%, transparent 55%),
    linear-gradient(165deg, #fcfdfe 0%, var(--pearl) 35%, #f4f7fc 70%, #eef3fa 100%);
  background-attachment: fixed;
}

.admin-body { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background:
    radial-gradient(ellipse at 0% 0%, rgba(37, 99, 235, 0.06) 0%, transparent 60%),
    rgba(255, 255, 255, 0.92);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px rgba(37, 99, 235, 0.05);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.sidebar-brand { display: flex; align-items: center; gap: .5rem; margin-bottom: 1.5rem; color: var(--text); font-weight: 600; }
.sidebar-brand img { height: 40px; }
.sidebar-brand .logo-circle-sm { width: 44px; height: 44px; flex-shrink: 0; }
.sidebar-brand .logo-circle-sm img { height: auto; }

.sidebar nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.sidebar nav a {
  color: var(--muted);
  padding: .5rem .75rem;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 500;
}
.sidebar nav a:hover {
  background: var(--brand-blue-soft);
  color: var(--brand-blue);
}

.sidebar-foot { font-size: .85rem; color: var(--muted); }
.sidebar-foot a { color: var(--brand-blue); }

.admin-main {
  flex: 1;
  padding: 1.5rem 2rem;
  overflow: auto;
  background: transparent;
}

.table { width: 100%; border-collapse: collapse; margin: 1rem 0; }
.table th, .table td {
  border-bottom: 1px solid var(--border);
  padding: .6rem;
  text-align: left;
  font-size: .9rem;
}
.table th { color: var(--text-soft); font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; margin: 1rem 0; }

.stat-card {
  background: rgba(255, 255, 255, 0.92);
  padding: 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.stat-card span { display: block; color: var(--muted); font-size: .8rem; }
.stat-card strong { font-size: 1.5rem; color: var(--brand-blue); }

.btn {
  display: inline-block;
  padding: .5rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand-blue) 0%, var(--brand-blue-mid) 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-outline {
  background: #fff;
  border: 1px solid var(--border-strong);
  color: var(--brand-blue);
}

.btn-sm { padding: .35rem .65rem; font-size: .85rem; }
.btn-block { width: 100%; }

.form-admin label { display: block; margin-bottom: .75rem; color: var(--text-soft); font-weight: 500; }

.form-admin input,
.form-admin select,
.form-admin textarea {
  width: 100%;
  padding: .5rem;
  margin-top: .25rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.card-admin {
  background: rgba(255, 255, 255, 0.95);
  padding: 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.alert { padding: .75rem; border-radius: 8px; margin-bottom: 1rem; }
.alert.ok { background: rgba(132, 204, 22, 0.12); border: 1px solid rgba(101, 163, 13, 0.35); color: #3f6212; }
.alert.err { background: rgba(239, 68, 68, 0.08); border: 1px solid rgba(239, 68, 68, 0.35); color: #b91c1c; }

.badge {
  background: var(--brand-blue-soft);
  color: var(--brand-blue);
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: rgba(255, 255, 255, 0.95);
  padding: 2rem;
  border-radius: 16px;
  width: min(380px, 90vw);
  border: 1px solid var(--border);
  box-shadow: 0 16px 48px rgba(37, 99, 235, 0.12);
}

.login-logo-circle { width: 80px; height: 80px; margin: 0 auto 1rem; display: flex; }

.login-box input {
  width: 100%;
  margin-bottom: .75rem;
  padding: .6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.login-box h1 { color: var(--text); text-transform: none; }
.error { color: #dc2626; }
.hint { font-size: .85rem; color: var(--muted); text-align: center; }

.chat-admin-grid { display: grid; grid-template-columns: 280px 1fr; gap: 1.5rem; }

.chat-window {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 12px;
  padding: 1rem;
  min-height: 320px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.chat-messages { max-height: 260px; overflow-y: auto; margin-bottom: .75rem; }
.chat-msg { padding: .4rem .6rem; margin-bottom: .4rem; border-radius: 6px; font-size: .9rem; }
.chat-msg.cliente { background: var(--brand-blue-soft); }
.chat-msg.vendedor, .chat-msg.sistema { background: var(--pearl-deep); }

.chat-input-row { display: flex; gap: .5rem; }
.chat-input-row input {
  flex: 1;
  padding: .5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.foto-preview img { margin-right: 4px; border-radius: 4px; }
.form-inline label { display: inline-block; margin-right: 1rem; }
.form-aprovar label { display: inline-block; margin-right: 1rem; margin-bottom: .5rem; }
.admin-main .hint { font-size: .85rem; color: var(--muted); margin: .5rem 0 1rem; text-align: left; }
.admin-main h1, .admin-main h2 { text-transform: none; letter-spacing: normal; }

.badge-vendido { background: rgba(239, 68, 68, 0.12); color: #dc2626; }
.badge-publicado { background: rgba(132, 204, 22, 0.15); color: #4d7c0f; }
.badge-pendente { background: rgba(251, 191, 36, 0.2); color: #b45309; }
.badge-inativo { background: rgba(100, 116, 139, 0.15); color: #475569; }
.badge-vendido { background: rgba(239, 68, 68, 0.12); color: #dc2626; }

.btn-danger {
  background: #fff;
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #dc2626;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.06); }

.filter-tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }
.filter-tab {
  padding: .4rem .85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 600;
}
.filter-tab.active, .filter-tab:hover {
  background: var(--brand-blue-soft);
  color: var(--brand-blue);
  border-color: var(--border-strong);
}

.actions-cell { white-space: nowrap; }
.actions-cell .inline-form { display: inline; }
.inline-form { display: inline-block; margin: 0 .15rem; vertical-align: middle; }

.action-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; }
.action-bar-btns { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

.venda-inline { display: inline-block; vertical-align: middle; position: relative; }
.venda-inline summary { list-style: none; cursor: pointer; }
.venda-inline summary::-webkit-details-marker { display: none; }
.venda-form {
  position: absolute;
  z-index: 10;
  right: 0;
  top: 100%;
  margin-top: .35rem;
  min-width: 220px;
  padding: .75rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.venda-form label { font-size: .85rem; margin-bottom: .5rem; }
.venda-form select { font-size: .85rem; }

code { font-size: .85em; color: var(--brand-blue); background: var(--brand-blue-faint); padding: .1rem .35rem; border-radius: 4px; }
.meta-list { list-style: none; padding: 0; margin: 0; }
.meta-list li { padding: .35rem 0; border-bottom: 1px solid var(--border); }
.req { color: #dc2626; }

.muted { color: var(--muted); }

/* Miniatura circular — dashboard veículos */
.veiculo-cell {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-width: 0;
}
.veiculo-thumb-circle {
  width: 52px;
  height: 52px;
  min-width: 52px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--pearl-deep);
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--brand-blue-soft);
}
.veiculo-thumb-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  transform: scale(1.22);
}
.veiculo-thumb-empty {
  background: linear-gradient(135deg, var(--pearl-deep), var(--brand-blue-soft));
}
.veiculo-cell-link {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  line-height: 1.25;
}
.veiculo-cell-link:hover { color: var(--brand-blue); }
.veiculo-cell-label { font-weight: 600; line-height: 1.25; }
.table td:first-child .veiculo-cell { max-width: 280px; }

/* ── Menu mobile admin ── */
.admin-nav-toggle {
  display: none;
  position: fixed;
  top: max(10px, env(safe-area-inset-top, 0px));
  right: max(10px, env(safe-area-inset-right, 0px));
  z-index: 200;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.admin-nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  margin: 0 auto;
  background: var(--brand-blue);
  border-radius: 2px;
  transition: transform .2s, opacity .2s;
}

body.admin-nav-open .admin-nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
body.admin-nav-open .admin-nav-toggle span:nth-child(2) { opacity: 0; }
body.admin-nav-open .admin-nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
}

.table-responsive .table { margin: 0; min-width: 640px; }

@media (max-width: 992px) {
  .admin-main { padding: 1.25rem 1rem; padding-top: 3.5rem; }
  .chat-admin-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .action-bar { flex-direction: column; align-items: stretch; }
  .action-bar-btns { width: 100%; }
  .action-bar-btns .btn { flex: 1; text-align: center; min-height: 44px; }
}

@media (max-width: 768px) {
  .admin-nav-toggle { display: flex; }

  .admin-body { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(280px, 88vw);
    height: 100vh;
    height: 100dvh;
    z-index: 150;
    transform: translateX(-105%);
    transition: transform .25s ease;
    overflow-y: auto;
    padding-top: max(3.5rem, calc(3.5rem + env(safe-area-inset-top, 0px)));
    box-shadow: 8px 0 32px rgba(37, 99, 235, 0.12);
  }

  body.admin-nav-open .sidebar { transform: translateX(0); }

  body.admin-nav-open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 140;
  }

  .grid2 { grid-template-columns: 1fr; }

  .form-admin input,
  .form-admin select,
  .form-admin textarea { min-height: 44px; font-size: 16px; }

  .login-box { padding: 1.5rem; }

  .venda-form {
    position: static;
    margin-top: .5rem;
    width: 100%;
    min-width: 0;
  }

  .filter-tabs { gap: .35rem; }
  .filter-tab { min-height: 40px; display: inline-flex; align-items: center; }

  .inline-form { display: block; margin: .25rem 0; }
  .actions-cell { white-space: normal; }
}

@media (max-width: 480px) {
  .stat-card strong { font-size: 1.25rem; }
  .table th, .table td { padding: .45rem; font-size: .82rem; }
  .veiculo-thumb-circle { width: 44px; height: 44px; min-width: 44px; }
}
