/* =========================================================================
   SPF Garage Widget
   Dark KTM-Theme. Alle Farben über CSS-Variablen überschreibbar (Theme/Bricks).
   Layouts: data-garage-layout="full" (Mainpage, zwei Spalten) | "compact"
   (Header/Kategorie/Produkt, Popover). Zustände: data-garage-state=
   "collapsed" (nur aktives Fahrzeug) | "expanded" (Auswahl + Garage).
   ========================================================================= */

.spf-garage {
    /* Markenfarbe statt festem Orange (11.08.2026). */
    --spf-acc: var(--brand-accent,#ff6600);
    --spf-acc-press: var(--brand-accent-dark,#e25c00);
    --spf-bg: #0e0e0e;
    --spf-bg-2: #1a1a1a;
    --spf-bg-3: #232323;
    --spf-line: rgba(255, 255, 255, 0.08);
    --spf-line-strong: rgba(255, 255, 255, 0.14);
    --spf-text: #ffffff;
    --spf-muted: #9a9a9a;
    --spf-radius: 20px;
    --spf-radius-inner: 12px;
    --spf-ease: cubic-bezier(0.2, 0, 0, 1);

    position: relative;
    color: var(--spf-text);
    background: var(--spf-bg);
    border-radius: var(--spf-radius);
    box-shadow:
        0 0 0 1px var(--spf-line),
        0 1px 2px rgba(0, 0, 0, 0.4),
        0 12px 32px rgba(0, 0, 0, 0.35);
    font-size: 15px;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.spf-garage *,
.spf-garage *::before,
.spf-garage *::after { box-sizing: border-box; }

/* ----- Zustands-Sichtbarkeit -------------------------------------------- */

.spf-garage[data-garage-state="expanded"] .spf-garage-summary { display: none; }

/* Panel wird über das Grid-Rows-Verfahren weich auf-/zugeklappt (interruptibel). */
.spf-garage-reveal {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.32s var(--spf-ease), opacity 0.24s ease;
}
.spf-garage-panel-inner { overflow: hidden; }

.spf-garage[data-garage-state="collapsed"] .spf-garage-reveal {
    grid-template-rows: 0fr;
    opacity: 0;
}

/* ----- Zusammenfassung (eingeklappt) ------------------------------------ */

.spf-garage-summary {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
}

.spf-garage-summary-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1 1 auto;
}
.spf-garage-summary-label {
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--spf-muted);
}
.spf-garage-summary-name {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.spf-garage-summary-meta { font-size: 13px; color: var(--spf-muted); }

.spf-garage-switch {
    flex: 0 0 auto;
    background: transparent;
    color: var(--spf-acc);
    border: 1px solid var(--spf-line-strong);
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    min-height: 40px;
    transition: transform 0.12s var(--spf-ease), background-color 0.2s ease, border-color 0.2s ease;
}
@media (hover:hover){
.spf-garage-switch:hover{ background: var(--spf-bg-2); border-color: var(--spf-acc); }}
.spf-garage-switch:active { transform: scale(0.96); }

/* ----- Zwei-Spalten-Panel ----------------------------------------------- */

.spf-garage-panel-inner {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 16px;
    padding: 16px;
}

.spf-garage-col {
    background: var(--spf-bg-2);
    border-radius: var(--spf-radius-inner);
    padding: 16px;
    /* Gestaffeltes Enter: interruptible Transition, kein keyframe. */
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.3s ease, transform 0.3s var(--spf-ease);
}
.spf-garage[data-garage-state="expanded"] .spf-garage-col { opacity: 1; transform: none; }
.spf-garage[data-garage-state="expanded"] .spf-garage-col--select { transition-delay: 0.05s; }
.spf-garage[data-garage-state="expanded"] .spf-garage-col--list { transition-delay: 0.13s; }

.spf-garage-col-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.spf-garage-col-title {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--spf-muted);
    text-wrap: balance;
}
.spf-garage-col--list .spf-garage-col-title { margin-bottom: 12px; }

.spf-garage-close {
    position: relative;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--spf-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: 8px;
    transition: transform 0.12s var(--spf-ease), color 0.2s ease, background-color 0.2s ease;
}
@media (hover:hover){
.spf-garage-close:hover{ color: var(--spf-text); background: var(--spf-bg-3); }}
.spf-garage-close:active { transform: scale(0.96); }
/* Hit-Area auf min. 40x40 erweitern. */
.spf-garage-close::after {
    content: "";
    position: absolute;
    inset: -6px;
}

/* ----- Tabs (schräg, KTM-Optik) ----------------------------------------- */

.spf-garage-tabs { display: flex; gap: 2px; margin-bottom: 12px; }

.spf-garage-tab {
    background: var(--spf-bg-3);
    color: var(--spf-muted);
    border: none;
    padding: 11px 26px 11px 18px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 100%, 0 100%);
    transition: transform 0.12s var(--spf-ease), background-color 0.2s ease, color 0.2s ease;
}
.spf-garage-tab.is-active { background: var(--spf-acc); color: #fff; }
@media (hover:hover){
.spf-garage-tab:not(.is-active):hover{ color: var(--spf-text); background: #2c2c2c; }}
.spf-garage-tab:active { transform: scale(0.96); }

/* ----- Eingaben --------------------------------------------------------- */

.spf-garage-pane { display: block; }

.spf-garage-vin-label {
    display: block;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--spf-muted);
    margin-bottom: 6px;
}
.spf-garage-vin-row { display: flex; gap: 8px; }

.spf-garage-vin,
.spf-garage-select {
    width: 100%;
    background: #000;
    color: var(--spf-text);
    border: 1px solid var(--spf-line-strong);
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 14px;
    min-height: 44px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.spf-garage-vin { text-transform: uppercase; letter-spacing: 0.04em; }
.spf-garage-vin::placeholder { color: #6a6a6a; text-transform: none; letter-spacing: normal; }
.spf-garage-vin:focus-visible,
.spf-garage-select:focus-visible {
    outline: none;
    border-color: var(--spf-acc);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-accent,#ff6600) 25%, transparent);
}
.spf-garage-select { margin-bottom: 8px; cursor: pointer; }
.spf-garage-select:disabled { color: #6a6a6a; background: #151515; cursor: not-allowed; }

/* ----- Buttons (VIN-Suche / Speichern) ---------------------------------- */

.spf-garage-vin-search,
.spf-garage-save {
    background: var(--spf-acc);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.03em;
    cursor: pointer;
    min-height: 44px;
    transition: transform 0.12s var(--spf-ease), background-color 0.2s ease, opacity 0.2s ease;
}
.spf-garage-vin-search { flex: 0 0 auto; padding: 12px 18px 12px 20px; }
.spf-garage-save { width: 100%; margin-top: 12px; }
@media (hover:hover){
.spf-garage-vin-search:hover,
.spf-garage-save:hover{ background: var(--spf-acc-press); }}
.spf-garage-vin-search:active,
.spf-garage-save:active { transform: scale(0.96); }
.spf-garage-save[disabled],
.spf-garage-vin-search[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }

.spf-garage-message {
    min-height: 1.25em;
    margin-top: 8px;
    font-size: 13px;
    color: var(--spf-muted);
    text-wrap: pretty;
}
.spf-garage-message[data-type="error"] { color: #ff6b6b; }
.spf-garage-message[data-type="success"] { color: #4ade80; }

/* ----- Fahrzeugliste ---------------------------------------------------- */

.spf-garage-vehicles { display: flex; flex-direction: column; gap: 8px; }

.spf-garage-vehicle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 4px 4px 6px;
    border-radius: 8px;
    background: var(--spf-bg-3);
    box-shadow: inset 0 0 0 1px var(--spf-line);
    transition: box-shadow 0.2s ease, background-color 0.2s ease;
}
.spf-garage-vehicle.is-active {
    background: #241a12;
    box-shadow: inset 0 0 0 1px var(--spf-acc);
}

.spf-garage-activate {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
    border: none;
    color: inherit;
    text-align: left;
    cursor: pointer;
    padding: 8px;
    min-height: 40px;
    border-radius: 6px;
    transition: transform 0.12s var(--spf-ease), background-color 0.2s ease;
}
@media (hover:hover){
.spf-garage-activate:not([disabled]):hover{ background: rgba(255, 255, 255, 0.04); }}
.spf-garage-activate:not([disabled]):active { transform: scale(0.98); }
.spf-garage-activate[disabled] { cursor: default; }

.spf-garage-dot {
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 2px var(--spf-muted);
    transition: box-shadow 0.2s ease, background-color 0.2s ease;
}
.spf-garage-vehicle.is-active .spf-garage-dot {
    background: var(--spf-acc);
    box-shadow: inset 0 0 0 2px var(--spf-acc), 0 0 0 3px color-mix(in srgb, var(--brand-accent,#ff6600) 20%, transparent);
}

.spf-garage-vehicle-text { display: flex; flex-direction: column; min-width: 0; }
.spf-garage-vehicle-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.spf-garage-vehicle-meta { font-size: 12px; color: var(--spf-muted); }

.spf-garage-vehicle-remove {
    position: relative;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--spf-muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    transition: transform 0.12s var(--spf-ease), color 0.2s ease, background-color 0.2s ease;
}
@media (hover:hover){
.spf-garage-vehicle-remove:hover{ color: #ff6b6b; background: rgba(255, 107, 107, 0.1); }}
.spf-garage-vehicle-remove:active { transform: scale(0.96); }
/* Hit-Area auf min. 40x40 erweitern, ohne Layout zu verschieben. */
.spf-garage-vehicle-remove::after { content: ""; position: absolute; inset: -4px; }

.spf-garage-empty { color: var(--spf-muted); font-size: 14px; }

/* ----- Layout "compact": Header / Kategorie / Produkt ------------------- */

.spf-garage[data-garage-layout="compact"] { box-shadow: 0 0 0 1px var(--spf-line); }
.spf-garage[data-garage-layout="compact"] .spf-garage-summary { padding: 10px 12px; gap: 10px; }
.spf-garage[data-garage-layout="compact"] .spf-garage-summary-name { font-size: 14px; }

/* Aufgeklappt als Popover über den Inhalt legen, statt ihn zu verschieben. */
.spf-garage[data-garage-layout="compact"] .spf-garage-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    z-index: 60;
    background: var(--spf-bg);
    border-radius: var(--spf-radius);
    box-shadow:
        0 0 0 1px var(--spf-line),
        0 8px 24px rgba(0, 0, 0, 0.5),
        0 2px 6px rgba(0, 0, 0, 0.4);
}
.spf-garage[data-garage-layout="compact"] .spf-garage-panel-inner { grid-template-columns: 1fr; }
.spf-garage[data-garage-layout="compact"][data-garage-state="collapsed"] .spf-garage-panel { display: none; }

/* ----- Responsiv -------------------------------------------------------- */

@media (max-width: 680px) {
    .spf-garage-panel-inner { grid-template-columns: 1fr; }
    .spf-garage-tab { padding-right: 22px; }
    /* 16px gegen den iOS-Fokus-Zoom: Safari zoomt beim Antippen in jedes Feld
       unter 16px und faehrt danach nicht von selbst zurueck. Hoehe steht per
       min-height:44px fest, die Zeile springt also nicht. Desktop bleibt 14px. */
    .spf-garage-vin,
    .spf-garage-select { font-size: 16px; }
}

/* ----- Reduced Motion --------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    .spf-garage *,
    .spf-garage *::before,
    .spf-garage *::after {
        transition-duration: 0.01ms !important;
        transition-delay: 0ms !important;
    }
}
