/* ==========================================================================
   Admin panel styles (loaded after styles.css)
   ========================================================================== */

[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
}
.login-card { width: 100%; max-width: 380px; padding: 32px 28px; box-shadow: var(--shadow-lg); }
.login-card h1 { text-align: center; font-size: 24px; margin-bottom: 8px; }
.login-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.login-logo .logo-mark { width: 52px; height: 52px; border-radius: 12px; }
.login-logo .logo-mark svg { width: 30px; height: 30px; }

/* ---------- Header ---------- */
.admin-nav { display: flex; gap: 4px; }
.admin-nav .btn-ghost { color: rgba(255, 255, 255, .85); }
.admin-nav .btn-ghost:hover { color: #fff; background: rgba(255, 255, 255, .1); }

.admin-main { padding-top: 28px; padding-bottom: 56px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 32px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
}
.stat span { display: block; font-size: 13px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat strong { font-size: 28px; color: var(--primary); line-height: 1.3; }

/* ---------- Toolbar & table ---------- */
.admin-toolbar { display: flex; gap: 12px; margin-bottom: 16px; }
.admin-toolbar .input { max-width: 360px; height: 42px; }
.admin-toolbar .select { width: auto; min-width: 170px; height: 42px; }

.table-card { padding: 0; overflow: hidden; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table thead th {
  background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); font-weight: 700;
}
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover { background: #fafbfd; }
.admin-table .vehicle-cell { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.admin-table .vehicle-cell img { width: 76px; height: 48px; object-fit: cover; border-radius: 4px; background: #e8edf3; flex-shrink: 0; }
.admin-table .vehicle-cell strong { display: block; color: var(--text); }
.admin-table .vehicle-cell small { color: var(--text-muted); }
.admin-table .price { font-size: 16px; }
.admin-table .actions-col, .admin-table .row-actions { text-align: right; white-space: nowrap; }
.row-actions .btn { padding: 7px 9px; }
.row-actions .btn svg { width: 17px; height: 17px; }
.row-actions .btn-delete:hover { color: var(--danger); background: #fbe4e1; }
.status-select { height: 34px; padding: 4px 30px 4px 10px; font-size: 13px; font-weight: 600; width: auto; }
.status-select.s-available { color: var(--success); }
.status-select.s-reserved { color: var(--warning); }
.status-select.s-sold { color: var(--danger); }
.star { color: var(--accent); display: inline-flex; vertical-align: -2px; margin-left: 4px; }
.star svg { width: 15px; height: 15px; fill: currentColor; }

.data-tools { margin-top: 24px; }
.data-tools summary { cursor: pointer; font-weight: 600; color: var(--primary); }
.data-tools[open] summary { margin-bottom: 16px; }
.password-form { max-width: 360px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(5, 14, 26, .6); }
.modal-panel {
  position: relative; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 820px; max-height: calc(100vh - 40px); display: flex; flex-direction: column;
}
.modal-sm { max-width: 420px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 20px; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--border); background: #f8fafc;
  border-radius: 0 0 var(--radius) var(--radius);
}
.modal-footer .form-error { margin: 0 auto 0 0; }
body.modal-open { overflow: hidden; }

fieldset { border: 0; padding: 0; margin: 0 0 24px; }
legend { font-weight: 700; color: var(--primary); font-size: 16px; margin-bottom: 12px; padding: 0; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.input.invalid, .select.invalid { border-color: var(--danger); }

/* ---------- Image manager ---------- */
.image-manager { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.image-manager:empty { display: none; }
.image-tile {
  position: relative; aspect-ratio: 16 / 10; border-radius: var(--radius-sm); overflow: hidden;
  background: #e8edf3; border: 2px solid transparent; cursor: grab;
}
.image-tile.dragging { opacity: .4; }
.image-tile.drop-target { border-color: var(--primary-light); }
.image-tile:first-child { border-color: var(--accent); }
.image-tile:first-child::after {
  content: 'Cover'; position: absolute; left: 6px; bottom: 6px;
  background: var(--accent); color: var(--primary-dark); font-size: 11px; font-weight: 700;
  padding: 2px 6px; border-radius: 3px;
}
.image-tile img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.image-tile .tile-actions { position: absolute; top: 4px; right: 4px; display: flex; gap: 4px; }
.image-tile .tile-actions button {
  width: 26px; height: 26px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(10, 29, 52, .75); color: #fff; display: grid; place-items: center;
}
.image-tile .tile-actions button:hover { background: var(--primary-dark); }
.image-tile .tile-actions button.remove:hover { background: var(--danger); }
.image-tile .tile-actions svg { width: 14px; height: 14px; }

.upload-drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  border: 2px dashed #c3cfdc; border-radius: var(--radius); padding: 22px; cursor: pointer;
  color: var(--text-muted); transition: border-color .15s, background .15s;
}
.upload-drop:hover, .upload-drop.dragover { border-color: var(--primary-light); background: #f3f7fb; }
.upload-drop svg { width: 30px; height: 30px; color: var(--primary-light); }
.upload-drop strong { color: var(--primary); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: repeat(2, 1fr); }

  /* Table → stacked cards */
  .admin-table thead { display: none; }
  .admin-table, .admin-table tbody, .admin-table tr, .admin-table td { display: block; width: 100%; }
  .admin-table tr { padding: 14px 16px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; }
  .admin-table tbody tr:last-child { border-bottom: 0; }
  .admin-table td { padding: 0; border: 0; }
  .admin-table td.vehicle-td { grid-column: 1 / -1; }
  .admin-table td[data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; text-transform: uppercase;
    letter-spacing: .4px; color: var(--text-muted); font-weight: 700;
  }
  .admin-table td.updated-td { display: none; }
  .admin-table .row-actions { grid-column: 1 / -1; text-align: left; border-top: 1px dashed var(--border); padding-top: 8px; }
}

@media (max-width: 600px) {
  .hide-sm { display: none; }
  .admin-main { padding-top: 20px; }
  .stats { gap: 10px; margin-bottom: 24px; }
  .stat { padding: 14px; }
  .stat strong { font-size: 22px; }
  .admin-toolbar { flex-direction: column; }
  .admin-toolbar .input, .admin-toolbar .select { max-width: none; width: 100%; }
  .section-head .btn { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { padding: 0; align-items: stretch; }
  .modal-panel { max-height: 100vh; height: 100%; border-radius: 0; }
  .modal-sm { height: auto; margin: auto 16px; border-radius: var(--radius); }
  .modal-footer { border-radius: 0; flex-wrap: wrap; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal-footer .form-error { flex-basis: 100%; }
  .modal-footer .btn { flex: 1; }
}

.admin-nav { align-items: center; }
.admin-user { color: rgba(255, 255, 255, .6); font-size: 14px; padding: 0 6px; }
/* --- Dealer profile photo as logo mark --- */
.logo-mark { overflow: hidden; padding: 0; }
.logo-mark .logo-img {
  width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 50%;
  display: block;
}
