/* ============================================
   AutoReg Admin - Legacy Professional System
   Full-width, utilitarian design
   ============================================ */

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #cccccc;
  --border-dark: #999999;
  --text-primary: #000000;
  --text-secondary: #666666;
  --text-muted: #999999;
  --primary: #0066cc;
  --primary-hover: #0052a3;
  --danger: #cc0000;
  --danger-hover: #990000;
  --success: #006600;
  --topbar-bg: #ffffff;
  --topbar-border: #cccccc;
}

/* ============================================
   Reset & Base
   ============================================ */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  font-family:
    "Segoe UI",
    Tahoma,
    Geneva,
    Verdana,
    sans-serif;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--bg);
}

code {
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  background: #f0f0f0;
  padding: 2px 4px;
  border: 1px solid #e0e0e0;
}

/* ============================================
   Utilities
   ============================================ */

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 11px;
}

/* ============================================
   Layout - Full Width
   ============================================ */

.container {
  padding: 0;
  margin: 0;
  width: 100%;
}

.section-spacing {
  margin-bottom: 0;
  border-bottom: 2px solid var(--border);
}

/* ============================================
   Topbar
   ============================================ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--topbar-bg);
  border-bottom: 2px solid var(--topbar-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand__mark {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #ffffff;
  background: #000000;
  border: 1px solid #000000;
}

.brand__text {
  display: flex;
  flex-direction: column;
}

.brand__title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
  color: var(--text-primary);
}

.brand__sub {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================
   Typography
   ============================================ */

.h1 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ============================================
   Card - Full Width Sections
   ============================================ */

.card {
  background: var(--surface);
  border: none;
  border-radius: 0;
  padding: 16px;
  box-shadow: none;
}

.card--inner {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
}

/* ============================================
   Grid (for auth forms only)
   ============================================ */

.grid {
  display: grid;
  gap: 12px;
}

.grid--auth {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  max-width: 900px;
}

/* ============================================
   Flexbox Utilities
   ============================================ */

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.row--space {
  justify-content: space-between;
}

/* ============================================
   Forms
   ============================================ */

.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
  max-width: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field__label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.input,
.textarea {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  outline: none;
}

.input:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.search-input {
  flex: 1;
  max-width: 400px;
}

.editor-layout {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 520px;
  gap: 16px;
  align-items: start;
}

.editor-left {
  min-width: 0;
}

.editor-right {
  position: sticky;
  top: 64px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.sheet-section {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 12px;
}

.sheet-section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}

.sheet-section__title {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.sheet-preview {
  position: relative;
  height: 420px;
  border: 1px solid var(--border);
  background: #fff;
}

.sheet-preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.sheet-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  text-align: center;
}

@media (max-width: 1100px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .editor-right {
    position: static;
  }
}

.textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.4;
  font-family: monospace;
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  color: var(--text-primary);
  background: #e0e0e0;
  border: 1px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.btn:hover {
  background: #d0d0d0;
  border-color: var(--border-dark);
}

.btn:active {
  background: #c0c0c0;
}

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

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

.btn--primary:active {
  background: #003d7a;
}

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

.btn--danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn--danger:active {
  background: #660000;
}

.btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-primary);
}

.btn--ghost:hover {
  background: #e0e0e0;
}

/* ============================================
   Checkbox
   ============================================ */

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.checkbox input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* ============================================
   Field Sections (Category containers)
   ============================================ */

.fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
}

.section__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.section__title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.section__actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.iconbtn {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  background: #e0e0e0;
  border: 1px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  text-transform: uppercase;
}

.iconbtn:hover {
  background: #d0d0d0;
  border-color: var(--border-dark);
}

.iconbtn--danger:hover {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.section__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

/* Make long-form text areas span the full width of the category box. */
.section__grid .field:has(textarea.textarea) {
  grid-column: 1 / -1;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  /* Match the visual height of text fields (label + input). */
  min-height: 56px;
}

.toggle__label {
  font-size: 12px;
  color: var(--text-primary);
}

.toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.boolfield__box {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  outline: none;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.boolfield__box input[type="checkbox"] {
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* ============================================
   Image Upload Section
   ============================================ */

.images-section {
  margin-top: 16px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.images-section__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.images-section__title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.image-url-field {
  margin-top: 10px;
}

.image-url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.image-url-input {
  min-height: 84px;
  resize: vertical;
}

/* Main Image Viewer */
.main-image-viewer {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #000000;
  border: 1px solid var(--border);
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.main-image-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.main-image-container img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 0;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-nav:hover {
  background: rgba(0, 0, 0, 0.8);
}

.image-nav--prev {
  left: 10px;
}

.image-nav--next {
  right: 10px;
}

.image-status-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.7);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

/* Thumbnail Grid */
.images-thumbnails {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.image-thumb {
  position: relative;
  aspect-ratio: 4/3;
  background: var(--surface);
  border: 2px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: opacity 0.2s, border-color 0.2s;
}

.image-thumb:hover {
  border-color: var(--primary);
}

.image-thumb.active {
  border-color: var(--primary);
  border-width: 3px;
}

.image-thumb.marked-delete {
  opacity: 0.4;
  border-color: var(--danger);
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-thumb__badge {
  position: absolute;
  top: 4px;
  left: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  background: var(--primary);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.image-thumb__badge--remote {
  background: #444444;
}

.image-thumb__remove {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  color: #ffffff;
  background: var(--danger);
  border: 1px solid var(--danger-hover);
  cursor: pointer;
}

.image-thumb__remove:hover {
  background: var(--danger-hover);
}

/* ============================================
   Cars Grid - Full Width
   ============================================ */

.cars {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  /* Keep the cars area compact: show up to ~3 rows then scroll vertically. */
  grid-auto-rows: 78px;
  max-height: 238px; /* (3 * 78) + small border/gap allowance */
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
}

.tile {
  padding: 10px;
  background: var(--surface);
  border: none;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.tile:hover {
  background: #ffffcc;
}

.tile__title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.tile__meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--text-secondary);
}

/* ============================================
   Badges
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: #e0e0e0;
  border: 1px solid var(--border);
  border-radius: 0;
}

.badge--hidden {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.badge--ok {
  color: #ffffff;
  background: var(--success);
  border-color: var(--success);
}

/* ============================================
   Alerts
   ============================================ */

.alert {
  margin: 0;
  padding: 10px 16px;
  background: #ffffcc;
  border: none;
  border-bottom: 2px solid #ffcc00;
  border-radius: 0;
  font-weight: 700;
}

.alert--error {
  color: #ffffff;
  background: var(--danger);
  border-bottom-color: var(--danger-hover);
}

.alert--ok {
  color: #ffffff;
  background: var(--success);
  border-bottom-color: #004400;
}

/* ============================================
   Details / Accordion
   ============================================ */

.details {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.details summary {
  padding: 6px 0;
  font-weight: 700;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.details summary:hover {
  color: var(--primary);
}

/* ============================================
   Pre / Code Block
   ============================================ */

.pre {
  margin: 10px 0 0;
  padding: 10px;
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-primary);
  background: #f0f0f0;
  border: 1px solid var(--border);
  border-radius: 0;
  overflow: auto;
  max-height: 300px;
}

/* ============================================
   Dialog
   ============================================ */

.dialog {
  border: 2px solid var(--border);
  padding: 0;
  border-radius: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.dialog__card {
  width: min(500px, calc(100vw - 32px));
  margin: 10vh auto 0;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    gap: 6px;
  }

  .topbar__actions {
    width: 100%;
    justify-content: flex-end;
  }

  .cars {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .section__grid {
    grid-template-columns: 1fr;
  }

  .form {
    max-width: 100%;
  }
}
