/* ─── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:           #07080f;
  --surface:      #0e1117;
  --surface-2:    #161b27;
  --surface-3:    #1e2436;
  --border:       rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.14);
  color-scheme: dark;

  --primary:      #f97316;
  --primary-dark: #ea6c0a;
  --primary-glow: rgba(249,115,22,0.18);
  --primary-text: #fff7ed;

  --success:      #22c55e;
  --success-bg:   rgba(34,197,94,0.12);
  --error:        #f87171;
  --error-bg:     rgba(248,113,113,0.12);
  --warning:      #fbbf24;

  --text:         #f1f5f9;
  --text-muted:   #94a3b8;
  --text-subtle:  #4b5563;

  --radius:       14px;
  --radius-sm:    8px;
  --radius-xs:    6px;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.6);
  --transition:   0.18s cubic-bezier(0.4,0,0.2,1);
}

/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}

/* ─── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ─── Navbar ───────────────────────────────────────────────────────────────── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 62px;
  background: rgba(14,17,23,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.nav-brand svg { color: var(--primary); flex-shrink: 0; }

.nav-brand span {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Nav center — scrollable page links */
.nav-center {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-center::-webkit-scrollbar { display: none; }

/* Nav right — always visible, never shrinks */
.nav-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

#logoutBtn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: var(--radius-xs);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  font-family: inherit;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}
#logoutBtn:hover {
  background: var(--error-bg);
  color: var(--error);
  border-color: rgba(248,113,113,0.3);
}

#userPill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
  flex-shrink: 0;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-glow); color: var(--primary); }

/* ─── Page Layout ──────────────────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.page-header { margin-bottom: 2rem; }

.page-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 4px;
}

.page-header p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ─── Content Grid ─────────────────────────────────────────────────────────── */
.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* ─── Wide form (2-col grid inside the card) ───────────────────────────────── */
.form-wide {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0 1.5rem;
}
.form-wide .form-row,
.form-wide .form-actions { grid-column: 1 / -1; }

/* ─── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title svg { color: var(--primary); }

/* ─── Form Elements ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.form-control:hover { border-color: var(--border-hover); }

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: var(--surface-3);
}

.form-control::placeholder { color: var(--text-subtle); }

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2394a3b8' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
  padding-right: 40px;
  cursor: pointer;
}

select.form-control option {
  background: var(--surface-2);
  color: var(--text);
}

.form-control:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ─── Inline brand input ────────────────────────────────────────────────────── */
.inline-add {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.inline-add .form-control { flex: 1; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
  white-space: nowrap;
  outline: none;
}

.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
  padding: 13px;
  font-size: 0.9rem;
  box-shadow: 0 2px 12px rgba(249,115,22,0.3);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: 0 4px 20px rgba(249,115,22,0.4);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--error-bg);
  color: var(--error);
  padding: 7px 12px;
  font-size: 0.8rem;
  border: 1px solid rgba(248,113,113,0.2);
}
.btn-danger:hover:not(:disabled) { background: rgba(248,113,113,0.2); }

.btn-sm { padding: 7px 14px; font-size: 0.8rem; }

.btn-icon {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 7px 10px;
  border-radius: var(--radius-xs);
}
.btn-icon:hover { background: var(--surface-3); color: var(--primary); border-color: var(--border-hover); }

/* ─── Table ────────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

thead tr {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

th {
  padding: 11px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
  white-space: nowrap;
}

td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  vertical-align: middle;
}

td:first-child { color: var(--text); font-weight: 500; }

tr:last-child td { border-bottom: none; }

tbody tr {
  transition: background var(--transition);
}
tbody tr:hover { background: rgba(255,255,255,0.025); }

/* ─── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: rgba(251,191,36,0.12); color: var(--warning); }
.badge-muted   { background: var(--surface-3); color: var(--text-muted); }

/* ─── Empty State ──────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-subtle);
  gap: 12px;
  text-align: center;
}

.empty-state svg { opacity: 0.35; }

.empty-state p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ─── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  color: var(--text);
  min-width: 260px;
  max-width: 360px;
  animation: slideIn 0.25s ease forwards;
  pointer-events: auto;
  transition: opacity 0.3s;
}

.toast-item.toast-success { border-left: 3px solid var(--success); }
.toast-item.toast-error   { border-left: 3px solid var(--error); }

@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ─── Loading Spinner ──────────────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Divider ──────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 1.5rem 0;
}

/* ─── Centered page layout (modelos page) ───────────────────────────────────── */
.page-centered {
  max-width: 560px;
  margin: 0 auto;
}

.models-list { margin-top: 2rem; }

/* ─── Stats row ────────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1;
}

.stat-value span { color: var(--primary); }

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ─── Search bar ───────────────────────────────────────────────────────────── */
.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-row .search-main   { flex: 1; min-width: 160px; }
.search-row .search-filter { width: 150px; flex-shrink: 0; }
.search-row .form-control  { max-width: none; }

/* ─── Form actions row (submit + clear) ────────────────────────────────────── */
.form-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-top: 0.25rem;
}
.form-actions .btn-primary { flex: 1; }
.form-actions .btn-ghost   { flex-shrink: 0; white-space: nowrap; }

/* ─── Pagination ───────────────────────────────────────────────────────────── */
#pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pg-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.pg-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); border-color: var(--border-hover); }
.pg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pg-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.pg-ellipsis {
  font-size: 0.82rem;
  color: var(--text-subtle);
  padding: 0 4px;
  line-height: 36px;
}

.pg-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 8px;
  line-height: 36px;
  white-space: nowrap;
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .navbar { padding: 0 0.75rem; gap: 6px; }
  .nav-brand span { display: none; }
  .container { padding: 1rem 0.75rem 3rem; }
  .card { padding: 1.1rem; }
  .page-header { margin-bottom: 1.25rem; }
  .page-header h1 { font-size: 1.25rem; }
  .page-header p  { font-size: 0.82rem; }
  th, td { padding: 10px 8px; }

  /* Hide less critical columns on small screens */
  table th.col-nf, table td.col-nf,
  table th.col-entrada, table td.col-entrada,
  table th.col-loja, table td.col-loja { display: none; }

  .search-row .search-main,
  .search-row .search-filter { width: 100%; flex-shrink: 1; }

  .form-row { grid-template-columns: 1fr; }
  .form-wide { grid-template-columns: 1fr; }

  .modal { max-width: 100%; border-radius: var(--radius) var(--radius) 0 0; margin-top: auto; }
  .modal-overlay { align-items: flex-end; }

  .stats-row { gap: 0.6rem; }
  .stat-card  { padding: 0.85rem 1rem; }
  .stat-value { font-size: 1.4rem; }

  #toast { left: 0.75rem; right: 0.75rem; bottom: 1rem; }
  .toast-item { min-width: 0; max-width: 100%; }

  #pagination { gap: 3px; }
  .pg-btn { min-width: 32px; height: 32px; font-size: 0.78rem; }
  .pg-info { display: none; }
}

@media (max-width: 400px) {
  #userPill span:first-child { display: none; }
}

/* ─── Light Mode ───────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --surface-3:    #e8edf2;
  --border:       rgba(0,0,0,0.08);
  --border-hover: rgba(0,0,0,0.15);
  --primary-glow: rgba(249,115,22,0.12);
  --success-bg:   rgba(34,197,94,0.1);
  --error-bg:     rgba(248,113,113,0.1);
  --text:         #0f172a;
  --text-muted:   #475569;
  --text-subtle:  #94a3b8;
  --shadow:       0 2px 12px rgba(0,0,0,0.07);
  --shadow-lg:    0 8px 30px rgba(0,0,0,0.14);
  color-scheme: light;
}

[data-theme="light"] .navbar {
  background: rgba(255,255,255,0.88);
}

[data-theme="light"] select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23475569' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px 8px;
}

[data-theme="light"] .toast-item {
  background: #ffffff;
  color: var(--text);
}

/* ─── Theme Toggle Button ──────────────────────────────────────────────────── */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-hover); }

/* ─── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.15s ease;
}

.modal-overlay[hidden] { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.2s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.modal-close {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--radius-xs);
  border: none;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  transition: background var(--transition), color var(--transition);
}
.modal-close:hover { background: var(--surface-3); color: var(--text); }

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-body .form-group { margin-bottom: 0.9rem; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  gap: 0.75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.modal-photo-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-xs);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  cursor: pointer;
}
.btn-link:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-hover); }
.btn-link:not([href]), .btn-link[href="#"] { opacity: 0.4; pointer-events: none; }

/* Row clickable */
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: rgba(249,115,22,0.05); }
