/* ============================================================
   MotorFlow — Design System
   Tailwise Dagger style fidelity pass (light mode only)
   ============================================================ */

/* ----- Theme variables (Dagger exact tokens) ----- */
:root {
  /* Primary: Dagger default theme-1 (#03045e) */
  --color-primary: #03045e;
  --color-primary-hover: #0c4a6e;      /* theme-2 */
  --color-primary-ring: rgb(3 4 94 / 0.2);
  --color-theme-2: #0c4a6e;

  --color-surface: #ffffff;
  --color-surface-alt: #f8fafc;        /* slate-50 */
  --color-border: #e2e8f0;             /* slate-200 */
  --color-border-light: rgba(226, 232, 240, 0.7);
  --color-text: #475569;               /* slate-600 */
  --color-text-muted: #94a3b8;         /* slate-400 */
  --color-text-heading: #1e293b;       /* slate-800 */
  --color-backdrop: rgba(15, 23, 42, 0.6);
  --color-danger: #b91c1c;             /* red-700 (Tailwise) */
  --color-success: #0d9488;            /* teal-600 (Tailwise) */
  --color-warning: #ca8a04;            /* yellow-600 (Tailwise) */
  --color-info: #0891b2;               /* cyan-600 (Tailwise) */
}

/* ----- Global base (Tailwise Dagger body styles) ----- */
body {
  font-family: 'Public Sans', ui-sans-serif, system-ui, sans-serif;
  font-size: 0.875rem;
  line-height: 1.25rem;
  letter-spacing: 0.025em;
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Page background gradient (Dagger: from-slate-100 to-slate-50) */
.page-bg::before {
  content: "";
  position: fixed;
  inset: 0;
  background: linear-gradient(to bottom, #f1f5f9, #f8fafc);
  z-index: -1;
}

/* ============================================================
   @layer components — Dagger-aligned replacements
   ============================================================ */
@layer components {

  /* ----- Box (card surface, exact Tailwise .box) ----- */
  .box {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.6rem;
    position: relative;
    box-shadow: 0px 3px 5px #0000000b;
  }

  /* ----- Buttons (exact Tailwise compiled styles) ----- */
  .btn-mf {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25rem;
    cursor: pointer;
    transition: all 200ms ease;
    white-space: nowrap;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  }
  .btn-mf:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px var(--color-primary-ring);
  }
  .btn-mf:disabled {
    opacity: 0.7;
    cursor: not-allowed;
  }

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

  .btn-mf-ghost {
    background-color: transparent;
    border-color: transparent;
    color: var(--color-text);
    box-shadow: none;
  }
  .btn-mf-ghost:hover:not(:disabled) {
    background-color: var(--color-surface-alt);
  }

  .btn-mf-danger {
    background-color: var(--color-danger);
    color: #ffffff;
    border-color: var(--color-danger);
  }
  .btn-mf-danger:hover:not(:disabled) {
    background-color: #991b1b;
    border-color: #991b1b;
  }

  .btn-mf-success {
    background-color: var(--color-success);
    color: #ffffff;
    border-color: var(--color-success);
  }
  .btn-mf-success:hover:not(:disabled) {
    background-color: #0f766e;
    border-color: #0f766e;
  }

  .btn-mf-outline {
    background-color: transparent;
    border-color: var(--color-border);
    color: var(--color-text);
    box-shadow: none;
  }
  .btn-mf-outline:hover:not(:disabled) {
    background-color: var(--color-surface-alt);
  }

  .btn-mf-soft {
    background-color: rgb(3 4 94 / 0.08);
    border-color: transparent;
    color: var(--color-primary);
    box-shadow: none;
  }
  .btn-mf-soft:hover:not(:disabled) {
    background-color: rgb(3 4 94 / 0.14);
  }

  /* Button sizes */
  .btn-mf-sm {
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
  }
  .btn-mf-xs {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }
  .btn-mf-circle {
    border-radius: 9999px;
    padding: 0.375rem;
  }

  /* ----- Form inputs (Tailwise compiled style) ----- */
  .input-mf {
    display: block;
    width: 100%;
    border-radius: 0.375rem;
    border: 1px solid var(--color-border);
    background-color: var(--color-surface);
    color: var(--color-text-heading);
    font-size: 0.875rem;
    padding: 0.4375rem 0.75rem;
    transition: border-color 200ms ease, box-shadow 200ms ease;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  }
  .input-mf:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px var(--color-primary-ring);
  }
  .input-mf:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
  .input-mf::placeholder {
    color: var(--color-text-muted);
  }

  .input-mf-ghost {
    border-color: transparent;
    background-color: transparent;
    box-shadow: none;
  }
  .input-mf-ghost:focus {
    border-color: var(--color-primary);
  }

  .input-mf-sm {
    padding: 0.3125rem 0.625rem;
    font-size: 0.8125rem;
  }

  /* Select styling */
  select.input-mf {
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.25rem 1.25rem;
    appearance: none;
  }

  /* Checkbox — Tailwise-style custom appearance */
  .checkbox-mf {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    border-radius: 0.25rem;
    border: 1px solid var(--color-border);
    background-color: var(--color-surface);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    cursor: pointer;
    appearance: none;
    transition: background-color 100ms ease-in-out, border-color 100ms ease-in-out;
    background-image: none;
  }
  .checkbox-mf:checked {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
  }
  .checkbox-mf:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-ring);
  }
  .checkbox-mf-xs {
    width: 0.75rem;
    height: 0.75rem;
  }

  .radio-mf {
    width: 1rem;
    height: 1rem;
    accent-color: var(--color-primary);
    cursor: pointer;
  }
  .radio-mf-sm {
    width: 0.875rem;
    height: 0.875rem;
  }

  /* ----- Tables (Tailwise Dagger exact) ----- */
  .table-mf {
    width: 100%;
    text-align: left;
    font-size: 0.875rem;
  }
  .table-mf th {
    font-weight: 500;
    color: var(--color-text-heading);
    padding: 0.75rem 1.25rem;
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
  }
  .table-mf td {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
  }
  .table-mf tbody tr:hover {
    background-color: var(--color-surface-alt);
  }
  .table-mf-sm th,
  .table-mf-sm td {
    padding: 0.5rem 0.75rem;
  }
  .table-mf-xs th,
  .table-mf-xs td {
    padding: 0.375rem 0.625rem;
  }
  .table-mf-zebra tbody tr:nth-child(even) {
    background-color: var(--color-surface-alt);
  }

  /* ----- Badge ----- */
  .badge-mf {
    display: inline-flex;
    align-items: center;
    border-radius: 0.375rem;
    border: 1px solid var(--color-border);
    padding: 0.0625rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1.25rem;
    white-space: nowrap;
  }
  .badge-mf-outline {
    background-color: transparent;
  }
  .badge-mf-success {
    color: #0d9488;
    border-color: #0d9488;
    background-color: rgba(13, 148, 136, 0.08);
  }
  .badge-mf-error {
    color: #b91c1c;
    border-color: #b91c1c;
    background-color: rgba(185, 28, 28, 0.08);
  }
  .badge-mf-warning {
    color: #ca8a04;
    border-color: #ca8a04;
    background-color: rgba(202, 138, 4, 0.08);
  }

  /* ----- Alerts & toasts ----- */
  .alert-mf {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  }
  .alert-mf-success {
    background-color: #0d9488;
    color: #ffffff;
  }
  .alert-mf-error {
    background-color: #b91c1c;
    color: #ffffff;
  }
  .alert-mf-warning {
    background-color: #ca8a04;
    color: #ffffff;
  }

  /* ----- Modal / Dialog ----- */
  dialog.modal-mf {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: transparent;
    border: none;
    max-width: 100vw;
    max-height: 100vh;
    width: 100%;
    height: 100%;
  }
  dialog.modal-mf::backdrop {
    background: var(--color-backdrop);
  }
  dialog.modal-mf:not([open]) {
    display: none;
  }
  .modal-mf-box {
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.75rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    padding: 1.5rem;
    width: 100%;
    max-width: 32rem;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
  }
  .modal-mf-box-lg {
    max-width: 48rem;
  }
  .modal-mf-box-xl {
    max-width: 64rem;
  }
  .modal-mf-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding-top: 1rem;
    margin-top: 1rem;
    border-top: 1px solid var(--color-border-light);
  }

  /* ----- Sidebar nav (Dagger exact) ----- */
  .sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: 0.6rem;
    border: 1px solid transparent;
    padding: 0.75rem 0.875rem;
    font-size: 0.875rem;
    font-weight: 400;
    color: #64748b; /* slate-500 */
    transition: all 200ms ease;
  }
  .sidebar-link:hover {
    background-color: rgba(255, 255, 255, 0.8);
    border-color: rgba(226, 232, 240, 0.8);
    box-shadow: 0px 2px 3px #0000000b;
    color: var(--color-text-heading);
  }
  .sidebar-link-active:hover {
    color: #ffffff;
  }
  .sidebar-link svg {
    flex: none;
    opacity: 0.8;
    stroke: var(--color-primary);
    fill: rgb(3 4 94 / 0.1);
  }
  .sidebar-link-active {
    color: #ffffff;
    font-weight: 500;
    background: linear-gradient(to right, rgb(3 4 94 / 0.95), rgb(12 74 110 / 0.95));
    border-color: #ffffff;
    box-shadow: 0px 2px 3px #0000000b;
  }
  .sidebar-link-active:hover {
    background: linear-gradient(to right, rgb(3 4 94 / 0.95), rgb(12 74 110 / 0.95));
    border-color: #ffffff;
    color: #ffffff;
  }
  .sidebar-link-active svg {
    stroke: #ffffff;
    fill: rgb(255 255 255 / 0.1);
    opacity: 1;
  }

  /* Sidebar dashed divider (Dagger exact) */
  .sidebar-divider {
    position: relative;
  }
  .sidebar-divider::before {
    content: "";
    display: none;
    position: absolute;
    right: 0;
    top: 16.666667%;
    bottom: 16.666667%;
    border-right: 1px dashed rgba(203, 213, 225, 0.7);
  }
  @media (min-width: 1280px) {
    .sidebar-divider::before {
      display: block;
    }
  }

  /* ----- Page header (sticky below top bar) ----- */
  .page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
  }
  .page-header-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text-heading);
  }

  /* Fixed section header — pinned below the fixed top bar */
  .section-header {
    position: sticky;
    top: 65px;
    z-index: 10;
    background: #f1f5f9;
    padding: 0.75rem 0.25rem;
  }

  /* ----- Empty state ----- */
  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1rem;
    color: var(--color-text-muted);
    text-align: center;
  }
  .empty-state svg {
    width: 2.5rem;
    height: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
  }

  /* ----- Fieldset ----- */
  .fieldset-mf {
    border: 1px solid var(--color-border-light);
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
  }
  .fieldset-mf-legend {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    padding: 0 0.375rem;
  }

  /* ----- Menu (settings sidebar) ----- */
  .menu-mf {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
  }
  .menu-mf a {
    display: block;
    padding: 0.4375rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    color: var(--color-text);
    transition: all 150ms ease;
  }
  .menu-mf a:hover {
    background-color: var(--color-surface-alt);
    color: var(--color-text-heading);
  }
  .menu-mf a.active {
    background-color: rgb(3 4 94 / 0.08);
    color: var(--color-primary);
    font-weight: 500;
  }
}

/* ============================================================
   Existing functional CSS — preserved as-is
   ============================================================ */

/* Spinner styles */
.spinner {
  width: 50px;
  aspect-ratio: 1;
  display: grid;
  border-radius: 50%;
  background:
    linear-gradient(0deg, rgb(0 0 0/50%) 30%, #0000 0 70%, rgb(0 0 0/100%) 0)
      50%/8% 100%,
    linear-gradient(90deg, rgb(0 0 0/25%) 30%, #0000 0 70%, rgb(0 0 0/75%) 0)
      50%/100% 8%;
  background-repeat: no-repeat;
  animation: s3 1s infinite steps(12);
}
.spinner::before,
.spinner::after {
  content: "";
  grid-area: 1/1;
  border-radius: 50%;
  background: inherit;
  opacity: 0.915;
  transform: rotate(30deg);
}
.spinner::after {
  opacity: 0.83;
  transform: rotate(60deg);
}

@keyframes s3 {
  100% {
    transform: rotate(1turn);
  }
}

.spinner-sm {
  width: 16px;
}

.spinner .htmx-request {
  opacity: 1;
}

.spinner.htmx-request {
  opacity: 1;
}

.image-container {
  position: relative;
  display: inline-block;
}

.image-container img {
  display: block;
  width: 100%;
  height: auto;
}

.button-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-container:hover .button-overlay {
  opacity: 1;
}

.button-overlay button {
  margin: 0 5px;
  padding: 10px 20px;
  background-color: #ffffff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.button-overlay button:hover {
  background-color: #f0f0f0;
}

.no-animation-checkbox {
  transition: none !important;
  animation: none !important;
}

tr.htmx-swapping td {
  opacity: 0;
  transition: opacity 1s ease-out;
}

/* HTMX indicator: hidden by default, shown during request */
.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
}

/* Dropdown action menu (three-dots, Hyperscript-positioned) */
.dropdown-action {
  display: inline-block;
}
/* Allow Tailwind responsive utilities (e.g. md:hidden) to override */
@media (min-width: 768px) {
  .dropdown-action.md\:hidden {
    display: none;
  }
}
.dropdown-action-menu {
  position: fixed;
  z-index: 9999;
  min-width: 9rem;
  padding: 0.25rem;
  border-radius: 0.375rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.12);
}
.dropdown-action-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4rem 0.6rem;
  border-radius: 0.25rem;
  font-size: 0.8125rem;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  transition: background 150ms;
  white-space: nowrap;
}
.dropdown-action-item:hover {
  background: var(--color-surface-alt, oklch(0.97 0 0));
}
.dropdown-action-item.danger {
  color: var(--color-danger);
}

/* Ad items: dim unselected images */
.image-container[data-selected="false"] {
  opacity: 0.35;
  border: 2px dashed oklch(50% 0.01 270);
  border-radius: 0.75rem;
}

/* Ad features/options: dim unchecked rows */
#ad-features > div:has(> input[type="checkbox"]:not(:checked)),
#ad-options > li:has(> input[type="checkbox"]:not(:checked)) {
  opacity: 0.45;
}
