/* cars — vehicle maintenance PWA styles.
   Pico CSS v2 (dark theme) does the heavy lifting; this file adds the
   app-shell chrome (sticky nav, full-screen dialogs, tab segments) and
   the domain widgets (status badges, vehicle cards, receipt grids).
   Mobile-first: the primary target is a phone (≤480px) installed as a PWA. */

/* Alpine.js cloak — hide templates until Alpine boots */
[x-cloak],
[hidden] {
    display: none !important;
}

.text-muted {
    opacity: 0.7;
}

/* ---------------------------------------------------------------
   App-like sticky top bar
   --------------------------------------------------------------- */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--pico-background-color);
    /* Keep the bar clear of the notch/status bar when installed. */
    padding-top: env(safe-area-inset-top);
}

.top-nav .nav-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.top-nav .nav-title strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-nav .back-btn {
    margin: 0;
    padding: 0.25rem 0.6rem;
    background: none;
    border: none;
    box-shadow: none;
    color: var(--pico-color);
    font-size: 1.3rem;
    line-height: 1;
}

/* Sync status dot (top bar) */
.sync-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--pico-muted-color);
    flex-shrink: 0;
}

.sync-dot.sync-paused {
    background: #2ecc71;
}

.sync-dot.sync-active {
    background: #f1c40f;
}

.sync-dot.sync-error {
    background: #e74c3c;
}

/* Slim offline / queued-changes banner under the top bar */
.sync-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    background: #7a5c1e;
    color: #fff;
}

.sync-banner.banner-error {
    background: var(--pico-del-color, #d9534f);
}

.sync-banner button {
    margin: 0;
    padding: 0.2rem 0.6rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

/* Main content: leave room for the safe area at the bottom */
main.container {
    padding-bottom: calc(2rem + env(safe-area-inset-bottom));
}

/* ---------------------------------------------------------------
   Status badges — maintenance due states
   --------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    color: #fff;
}

.badge-overdue {
    background: #c0392b;
}

.badge-due-soon {
    background: #b9770e;
}

.badge-ok {
    background: #1e8449;
}

.badge-unknown {
    background: #566573;
}

/* ---------------------------------------------------------------
   Garage — vehicle cards
   --------------------------------------------------------------- */
.vehicle-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

@media (min-width: 640px) {
    .vehicle-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.vehicle-card {
    margin: 0;
    padding: 1rem;
    cursor: pointer;
    border: 1px solid var(--pico-form-element-border-color);
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-background-color);
    transition: box-shadow 0.15s ease;
}

.vehicle-card:hover {
    box-shadow: var(--pico-card-box-shadow);
}

.vehicle-card .vehicle-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.vehicle-card .vehicle-card-meta {
    margin: 0;
    font-size: 0.85rem;
    color: var(--pico-muted-color);
}

.vehicle-card .vehicle-card-counts {
    margin: 0.4rem 0 0;
    font-size: 0.8rem;
}

/* ---------------------------------------------------------------
   Vehicle detail — tab rows (segmented control)
   --------------------------------------------------------------- */
.tab-buttons {
    display: flex;
    width: 100%;
    max-width: 480px;
    gap: 2px;
    padding: 3px;
    background: var(--pico-form-element-background-color);
    border: 1px solid var(--pico-form-element-border-color);
    border-radius: 10px;
    margin-bottom: 1.25rem;
}

.tab-buttons button,
.tab-buttons button.outline,
.tab-buttons button.secondary {
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 0.45rem 0.4rem;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    background: transparent;
    border: none;
    border-radius: 7px;
    box-shadow: none;
    color: var(--pico-muted-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s ease, color 0.15s ease;
}

.tab-buttons button.outline:hover {
    color: var(--pico-color);
}

/* Active segment = the button without the outline/secondary marker */
.tab-buttons button:not(.outline):not(.secondary) {
    background: var(--pico-primary);
    color: var(--pico-primary-inverse);
}

/* ---------------------------------------------------------------
   Due list / schedule / history rows
   --------------------------------------------------------------- */
.due-row,
.schedule-row,
.log-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.25rem;
    border-bottom: 1px solid var(--pico-form-element-border-color);
}

.due-row:last-child,
.schedule-row:last-child,
.log-row:last-child {
    border-bottom: none;
}

.due-row .due-main,
.schedule-row .schedule-main,
.log-row .log-main {
    flex: 1;
    min-width: 0;
}

.due-row .due-name,
.schedule-row .schedule-name {
    font-weight: 500;
}

.due-row .due-detail,
.schedule-row .schedule-detail,
.log-row .log-detail {
    margin: 0;
    font-size: 0.8rem;
    color: var(--pico-muted-color);
}

.schedule-row.schedule-disabled .schedule-main {
    opacity: 0.45;
}

.log-row .log-cost {
    font-weight: 600;
    white-space: nowrap;
}

/* Compact icon-ish action buttons on rows */
.row-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

.row-actions button {
    margin: 0;
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
}

/* Quick odometer update strip */
.odo-quick {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1.25rem;
}

.odo-quick input {
    margin: 0;
    flex: 1;
}

.odo-quick button {
    margin: 0;
    white-space: nowrap;
}

/* Cost stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin: 1rem 0;
}

.stat-card {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--pico-form-element-border-color);
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-background-color);
}

.stat-card .stat-label {
    margin: 0;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--pico-muted-color);
}

.stat-card .stat-value {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
}

/* ---------------------------------------------------------------
   Receipt / document thumbnails
   --------------------------------------------------------------- */
.receipt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.receipt-thumb {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    margin: 0;
    border: 1px solid var(--pico-form-element-border-color);
    border-radius: var(--pico-border-radius);
    overflow: hidden;
    background: var(--pico-card-background-color);
    cursor: pointer;
}

.receipt-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.receipt-thumb .receipt-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.15rem 0.35rem;
    font-size: 0.65rem;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Full-size receipt viewer */
.receipt-viewer img {
    max-width: 100%;
    max-height: 70vh;
    display: block;
    margin: 0 auto;
    border-radius: var(--pico-border-radius);
}

/* ---------------------------------------------------------------
   Dialogs — full-screen overlay style (roomier on phones than
   Pico's centered card; forms get the whole viewport)
   --------------------------------------------------------------- */
dialog {
    max-width: 100%;
    max-height: 100%;
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: var(--pico-background-color) !important;
    opacity: 1 !important;
    z-index: 1100;
}

dialog::backdrop {
    background: transparent !important;
    opacity: 0 !important;
}

dialog article {
    width: 100%;
    height: 100vh;
    max-height: 100vh;
    margin: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    background: var(--pico-background-color);
    padding-top: env(safe-area-inset-top);
}

/* Dialog header with native-app back button */
dialog article header {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
    margin: 0;
}

dialog article header a {
    font-size: 1.5rem;
    text-decoration: none;
    color: var(--pico-color);
}

dialog article header a:hover {
    opacity: 0.8;
}

dialog article header h3 {
    margin: 0;
    font-size: 1.1rem;
}

/* Scrollable form body between sticky header and footer */
dialog article .dialog-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--pico-spacing);
}

/* Dialog footer buttons */
dialog article footer {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: var(--pico-card-background-color);
    border-top: 1px solid var(--pico-form-element-border-color);
    padding: var(--pico-spacing);
    padding-bottom: calc(var(--pico-spacing) + env(safe-area-inset-bottom));
    margin: 0;
}

dialog article footer button {
    flex: 1;
    margin: 0;
}

/* Service-item multi-select (checkbox list) in the log form */
.service-selector {
    max-height: 40vh;
    overflow-y: auto;
    border: 1px solid var(--pico-form-element-border-color);
    border-radius: var(--pico-border-radius);
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
}

.service-selector label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--pico-form-element-border-color);
}

.service-selector label:last-child {
    border-bottom: none;
}

/* Catalog picker rows */
.catalog-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.25rem;
    border-bottom: 1px solid var(--pico-form-element-border-color);
}

.catalog-row:last-child {
    border-bottom: none;
}

.catalog-row .catalog-meta {
    margin: 0;
    font-size: 0.8rem;
    color: var(--pico-muted-color);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--pico-muted-color);
}

/* Section headings with a trailing action button */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.section-head h3,
.section-head h4 {
    margin: 0;
}

.section-head button {
    margin: 0;
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* ---------------------------------------------------------------
   Mobile (≤480px is the primary target)
   --------------------------------------------------------------- */
@media (max-width: 480px) {
    :root {
        --pico-font-size: 100%;
    }

    main.container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    dialog article footer button {
        min-height: 44px;
    }
}

/* PWA touch targets */
@media (hover: none) and (pointer: coarse) {
    button,
    [role="button"] {
        min-height: 42px;
    }

    .row-actions button,
    .section-head button,
    .sync-banner button {
        min-height: 34px;
    }
}

/* ------------------------------------------------------------------ */
/* Parts (log modal repeater + re-order links)                        */
/* ------------------------------------------------------------------ */
.part-row {
    border: 1px solid var(--pico-muted-border-color, #333);
    border-radius: var(--pico-border-radius, 6px);
    padding: 0.5rem;
    margin-bottom: 0.5rem;
}
.part-row input {
    margin-bottom: 0.4rem;
}
.part-row-meta {
    display: grid;
    grid-template-columns: 1fr 1fr 0.7fr auto;
    gap: 0.4rem;
    align-items: center;
}
.part-row-meta input {
    margin-bottom: 0;
}
.part-row-del {
    margin: 0;
    padding: 0.25rem 0.6rem;
    line-height: 1;
}
/* Re-order links under a history log entry */
.part-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.35rem;
}
.part-link {
    font-size: 0.8rem;
    padding: 0.1rem 0.5rem;
    border: 1px solid var(--pico-primary, #3b82f6);
    border-radius: 999px;
    text-decoration: none;
    white-space: nowrap;
}
