/* =====================================================================
   components.css
   Shared building blocks, loaded by every page after base.css:
   buttons, badges, cards, forms, tables, alerts, toasts, modals, tabs,
   accordions, dropdowns, list groups, pagination, breadcrumbs, progress,
   spinners, empty states, order status timeline.
   Colours come only from the semantic tokens in base.css.
   ===================================================================== */

/* ---------------------------------------------------------------------
   Buttons
   .btn + one variant: btn-primary (filled dark), btn-secondary
   (outlined), btn-danger, btn-ghost (text only), btn-inverse (white,
   for use on photos/dark panels). Sizes: btn-sm, btn-lg. btn-block
   fills its container. btn-icon is a square icon-only button and must
   carry an aria-label.
   --------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--control-height);
    padding: 0 var(--space-3);
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: background-color var(--duration-fast) var(--ease),
                border-color var(--duration-fast) var(--ease),
                color var(--duration-fast) var(--ease),
                transform var(--duration-fast) var(--ease);
}

.btn:hover {
    text-decoration: none;
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled,
.btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primary {
    background: var(--action);
    border-color: var(--action);
    color: var(--text-inverse);
}

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

.btn-secondary {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--surface-muted);
    border-color: var(--gray-400);
    color: var(--text);
}

.btn-danger {
    background: var(--red-600);
    border-color: var(--red-600);
    color: var(--text-inverse);
}

.btn-danger:hover {
    background: var(--red-700);
    border-color: var(--red-700);
    color: var(--text-inverse);
}

.btn-ghost {
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--surface-sunken);
    color: var(--text);
}

.btn-inverse {
    background: var(--gray-0);
    border-color: var(--gray-0);
    color: var(--gray-900);
}

.btn-inverse:hover {
    background: var(--gray-100);
    border-color: var(--gray-100);
    color: var(--gray-900);
}

.btn-sm {
    min-height: var(--control-height-sm);
    padding: 0 var(--space-2);
    font-size: var(--text-xs);
}

.btn-lg {
    min-height: 46px;
    padding: 0 var(--space-4);
    font-size: var(--text-base);
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-icon {
    width: var(--control-height);
    padding: 0;
}

.btn-icon.btn-sm {
    width: var(--control-height-sm);
}

/* A row of buttons that touch (period filters, segmented choices) */
.btn-group {
    display: inline-flex;
}

.btn-group > .btn {
    border-radius: 0;
}

.btn-group > .btn:not(:first-of-type) {
    margin-left: -1px;
}

.btn-group > .btn:first-of-type {
    border-radius: var(--radius) 0 0 var(--radius);
}

.btn-group > .btn:last-of-type {
    border-radius: 0 var(--radius) var(--radius) 0;
}

.btn-group > .btn.active {
    position: relative;
    background: var(--action);
    border-color: var(--action);
    color: var(--text-inverse);
}

/* Visually hidden radio that drives a .btn next to it */
.btn-check {
    position: absolute;
    clip: rect(0, 0, 0, 0);
    pointer-events: none;
}

.btn-check:checked + .btn {
    background: var(--action);
    border-color: var(--action);
    color: var(--text-inverse);
}

.btn-check:focus-visible + .btn {
    outline: 2px solid var(--blue-600);
    outline-offset: 2px;
}

/* Plain icon button used inside rows and cards (edit, delete, close) */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    text-decoration: none;
    transition: background-color var(--duration-fast) var(--ease),
                color var(--duration-fast) var(--ease);
}

.icon-btn:hover {
    background: var(--surface-sunken);
    color: var(--text);
    text-decoration: none;
}

.icon-btn-danger:hover {
    background: var(--danger-bg);
    color: var(--danger-text);
}

/* Close button for modals, toasts and drawers */
.btn-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.125rem;
    transition: background-color var(--duration-fast) var(--ease),
                color var(--duration-fast) var(--ease);
}

.btn-close:hover {
    background: var(--surface-sunken);
    color: var(--text);
}

/* Inline text link styled as a button (no box) */
.link-button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-link);
    font-size: inherit;
}

.link-button:hover {
    text-decoration: underline;
}

/* ---------------------------------------------------------------------
   Badges
   One size everywhere. Neutral by default; a tone only when the badge
   carries a meaning (paid, failed, low stock ...).
   --------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    height: 22px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface-muted);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1;
    white-space: nowrap;
    vertical-align: middle;
}

.badge-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.badge-warning {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning-text);
}

.badge-danger {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger-text);
}

.badge-info {
    background: var(--info-bg);
    border-color: var(--info-border);
    color: var(--info-text);
}

.badge-dark {
    background: var(--gray-900);
    border-color: var(--gray-900);
    color: var(--text-inverse);
}

/* Product tag: neutral badge with a dot in the tag's own colour
   (the colour comes from the database via --tag-color) */
.tag-badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tag-color, var(--gray-400));
}

/* Order, payment and application status: the one place a status value
   is mapped to a tone. Templates write class="badge status-{{ x.status }}".
   Values not listed here stay neutral (refunded, voided, overpaid ...). */
.status-pending,
.status-unpaid,
.status-partially_paid {
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning-text);
}

.status-processing,
.status-confirmed,
.status-shipped {
    background: var(--info-bg);
    border-color: var(--info-border);
    color: var(--info-text);
}

.status-delivered,
.status-completed,
.status-paid,
.status-approved {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.status-cancelled,
.status-failed,
.status-payment_failed,
.status-rejected {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger-text);
}

/* Small coloured dot in front of a status word */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-400);
}

.status-dot-success { background: var(--success-text); }
.status-dot-warning { background: #c98a12; }
.status-dot-danger { background: var(--danger-text); }

/* ---------------------------------------------------------------------
   Cards
   --------------------------------------------------------------------- */
.card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--border);
}

.card-header h1,
.card-header h2,
.card-header h3,
.card-header h4,
.card-header h5,
.card-header h6,
.card-title {
    margin: 0;
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
}

.card-body {
    flex: 1 1 auto;
    padding: var(--space-3);
}

.card-footer {
    padding: var(--space-3);
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

@media (min-width: 768px) {
    .card-header,
    .card-body,
    .card-footer {
        padding-inline: var(--space-4);
    }
}

/* Muted panel for summaries and hints inside a page */
.panel-muted {
    padding: var(--space-3);
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */
.form-label {
    display: block;
    margin-bottom: var(--space-1);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text);
}

.form-control,
.form-select,
form select:not([class]),
.form-field input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]),
.form-field select,
.form-field textarea {
    display: block;
    width: 100%;
    min-height: var(--control-height);
    padding: 0.4375rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background-color: var(--surface);
    color: var(--text);
    font-size: var(--text-base);
    line-height: 1.4;
    transition: border-color var(--duration-fast) var(--ease),
                box-shadow var(--duration-fast) var(--ease);
}

.form-control::placeholder {
    color: var(--gray-400);
}

.form-control:focus,
.form-select:focus,
form select:not([class]):focus,
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    border-color: var(--blue-600);
    box-shadow: var(--focus-ring);
    outline: none;
}

.form-control:disabled,
.form-control[readonly],
.form-select:disabled {
    background-color: var(--surface-muted);
    color: var(--text-secondary);
}

textarea.form-control {
    min-height: 96px;
    resize: vertical;
}

input[type="color"].form-control {
    width: 56px;
    padding: 4px;
}

input[type="file"].form-control {
    padding: 0.375rem 0.5rem;
    font-size: var(--text-sm);
}

.form-select,
form select:not([class]) {
    padding-right: 2.25rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a7771' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.625rem center;
    background-size: 16px;
}

.form-select[multiple] {
    padding-right: 0.75rem;
    background-image: none;
}

.form-control-sm,
.form-select-sm {
    min-height: var(--control-height-sm);
    padding-block: 0.25rem;
    font-size: var(--text-sm);
}

.form-text {
    display: block;
    margin-top: var(--space-1);
    font-size: var(--text-sm);
    color: var(--text-muted);
}

/* Error state set by Django forms or JS validation */
.form-field.has-error input,
.form-field.has-error select,
.form-field.has-error textarea,
.is-invalid,
.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--red-600);
}

.invalid-feedback,
.errorlist {
    display: block;
    margin: var(--space-1) 0 0;
    padding: 0;
    list-style: none;
    font-size: var(--text-sm);
    color: var(--danger-text);
}

/* Required-field marker */
.required {
    color: var(--danger-text);
}

/* Checkbox / radio row */
.form-check {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    min-height: 1.5rem;
}

.form-check-input,
.form-field.form-check input {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    margin: 0.2rem 0 0;
    accent-color: var(--gray-900);
    cursor: pointer;
}

.form-check-label {
    font-size: var(--text-base);
    cursor: pointer;
}

/* Toggle switch: a checkbox drawn as a track and knob */
.form-switch .form-check-input {
    appearance: none;
    width: 2.25rem;
    height: 1.25rem;
    margin-top: 0.1rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-full);
    background: var(--gray-200);
    position: relative;
    transition: background-color var(--duration) var(--ease);
}

.form-switch .form-check-input::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--gray-0);
    box-shadow: var(--shadow-sm);
    transition: transform var(--duration) var(--ease);
}

.form-switch .form-check-input:checked {
    background: var(--gray-900);
    border-color: var(--gray-900);
}

.form-switch .form-check-input:checked::after {
    transform: translateX(1rem);
}

/* Input with a fixed label or button glued to one side */
.input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.input-group > .form-control,
.input-group > .form-select {
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
}

.input-group > :not(:first-child) {
    margin-left: -1px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.input-group > :not(:last-child) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-muted);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    white-space: nowrap;
}

/* A titled block of fields inside a long form */
.form-section {
    padding-bottom: var(--space-4);
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}

.form-section:last-child {
    padding-bottom: 0;
    margin-bottom: 0;
    border-bottom: 0;
}

/* Character counter under a text field */
.character-count {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.character-count.warning { color: var(--warning-text); }
.character-count.danger { color: var(--danger-text); }

/* ---------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------- */
.table-responsive {
    position: relative; /* keeps visually-hidden cells inside the scroll box */
    width: 100%;
    min-width: 0; /* lets a wide table scroll inside a flex parent (cards) */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    margin-bottom: 0;
    font-size: var(--text-sm);
    color: var(--text);
}

.table th,
.table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table thead th {
    background: var(--surface-muted);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.table tbody tr:last-child > th,
.table tbody tr:last-child > td {
    border-bottom: 0;
}

.table-hover tbody tr {
    transition: background-color var(--duration-fast) var(--ease);
}

.table-hover tbody tr:hover {
    background: var(--gray-25);
}

.table-sm th,
.table-sm td {
    padding: 0.4rem 0.5rem;
}

.table-borderless th,
.table-borderless td {
    border-bottom: 0;
}

.table-borderless thead th {
    background: none;
}

/* Label column of a two-column key/value table */
.spec-label {
    width: 35%;
    color: var(--text-secondary);
    font-weight: var(--weight-medium);
}

/* Row the user can click (opens a detail page) */
.row-link {
    cursor: pointer;
}

/* ---------------------------------------------------------------------
   Alerts: inline messages that stay on the page
   --------------------------------------------------------------------- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: 0.75rem var(--space-3);
    margin-bottom: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-muted);
    color: var(--text);
    font-size: var(--text-sm);
}

.alert > .icon {
    margin-top: 0.2em;
}

.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.alert-danger  { background: var(--danger-bg);  border-color: var(--danger-border);  color: var(--danger-text); }
.alert-info    { background: var(--info-bg);    border-color: var(--info-border);    color: var(--info-text); }

/* ---------------------------------------------------------------------
   Toasts: Django messages and JS notices (ui.js shows and dismisses)
   --------------------------------------------------------------------- */
.toast-region {
    position: fixed;
    top: var(--space-3);
    right: var(--space-3);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: min(360px, calc(100vw - 2rem));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: 0.75rem 0.75rem 0.75rem var(--space-3);
    border: 1px solid var(--border);
    border-left-width: 3px;
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--text);
    font-size: var(--text-sm);
    pointer-events: auto;
    animation: toast-in var(--motion-enter) var(--ease-out);
}

.toast.is-leaving {
    opacity: 0;
    transform: translateX(16px);
    transition: opacity var(--motion-exit) var(--ease), transform var(--motion-exit) var(--ease);
}

.toast-body {
    flex: 1;
    padding-top: 0.3rem;
}

.toast .btn-close {
    width: 28px;
    height: 28px;
}

.toast-success { border-left-color: var(--success-text); }
.toast-warning { border-left-color: #c98a12; }
.toast-error,
.toast-danger  { border-left-color: var(--danger-text); }
.toast-info    { border-left-color: var(--blue-600); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(16px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ---------------------------------------------------------------------
   Modal: a native <dialog class="modal"> opened by ui.js
   --------------------------------------------------------------------- */
.modal {
    width: min(500px, calc(100vw - 2rem));
    max-height: calc(100vh - 2rem);
    padding: 0;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal[open] {
    display: flex;
    flex-direction: column;
    animation: modal-in var(--motion-enter) var(--ease-out);
}

.modal::backdrop {
    background: rgba(28, 27, 25, 0.45);
    animation: fade-in var(--motion-enter) var(--ease-out);
}

/* ui.js adds .is-closing, waits for this animation, then closes the dialog */
.modal.is-closing {
    animation: modal-out var(--motion-exit) var(--ease) forwards;
}

.modal.is-closing::backdrop {
    animation: fade-out var(--motion-exit) var(--ease) forwards;
}

.modal-sm { width: min(380px, calc(100vw - 2rem)); }
.modal-lg { width: min(800px, calc(100vw - 2rem)); }
.modal-xl { width: min(1140px, calc(100vw - 2rem)); }

.modal-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: calc(100vh - 2rem);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}

.modal-title {
    margin: 0;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
}

.modal-body {
    flex: 1 1 auto;
    padding: var(--space-4);
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(calc(var(--motion-rise) * 0.75)) scale(0.97); }
    to   { opacity: 1; transform: none; }
}

@keyframes modal-out {
    from { opacity: 1; transform: none; }
    to   { opacity: 0; transform: translateY(calc(var(--motion-rise) * 0.4)) scale(0.98); }
}

/* .modal-sheet: a panel docked to the right edge (filters, carts, settings).
   On phones it becomes a bottom sheet. Same open/close flow as any modal. */
.modal.modal-sheet {
    width: min(420px, 100vw);
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0 0 0 auto;
    border-radius: 0;
}

.modal-sheet .modal-content {
    height: 100%;
    max-height: none;
}

.modal-sheet[open] {
    animation: sheet-in-right var(--motion-enter) var(--ease-out);
}

.modal-sheet.is-closing {
    animation: sheet-out-right var(--motion-exit) var(--ease) forwards;
}

@keyframes sheet-in-right {
    from { transform: translateX(100%); }
}

@keyframes sheet-out-right {
    to { transform: translateX(100%); }
}

@keyframes sheet-in-up {
    from { transform: translateY(100%); }
}

@keyframes sheet-out-down {
    to { transform: translateY(100%); }
}

@media (max-width: 575.98px) {
    .modal.modal-sheet {
        width: 100vw;
        height: auto;
        max-height: 88dvh;
        margin: auto 0 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    .modal-sheet .modal-content {
        max-height: 88dvh;
    }

    .modal-sheet[open] {
        animation-name: sheet-in-up;
    }

    .modal-sheet.is-closing {
        animation-name: sheet-out-down;
    }
}

/* ---------------------------------------------------------------------
   Tabs: .tabs > button.tab, panels .tab-panel (ui.js switches them)
   --------------------------------------------------------------------- */
.tabs {
    display: flex;
    gap: var(--space-1);
    margin: 0 0 var(--space-3);
    padding: 0;
    border-bottom: 1px solid var(--border);
    list-style: none;
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    position: relative;
    flex-shrink: 0;
    padding: 0.625rem var(--space-3);
    border: 0;
    background: none;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    white-space: nowrap;
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease);
}

.tab::after {
    content: "";
    position: absolute;
    left: var(--space-3);
    right: var(--space-3);
    bottom: -1px;
    height: 2px;
    background: var(--gray-900);
    transform: scaleX(0);
    transition: transform var(--duration) var(--ease);
}

.tab:hover {
    color: var(--text);
    text-decoration: none;
}

.tab.active {
    color: var(--text);
}

.tab.active::after {
    transform: scaleX(1);
}

.tab-panel {
    animation: fade-in var(--motion-enter) var(--ease-out);
}

/* ---------------------------------------------------------------------
   Accordion: built on <details>/<summary>, no JS needed
   --------------------------------------------------------------------- */
.accordion-item {
    border-bottom: 1px solid var(--border);
}

.accordion-item:last-child {
    border-bottom: 0;
}

.accordion-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 0.75rem 0;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text);
    cursor: pointer;
    list-style: none;
}

.accordion-button::-webkit-details-marker {
    display: none;
}

.accordion-button::after {
    content: "";
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b5954' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e") no-repeat center / 16px;
    transition: transform var(--duration) var(--ease);
}

details[open] > .accordion-button::after {
    transform: rotate(180deg);
}

.accordion-body {
    padding: 0 0 var(--space-3);
}

/* ---------------------------------------------------------------------
   Dropdown: <details class="dropdown"> with a .dropdown-menu panel
   (ui.js closes it on outside click and Escape)
   --------------------------------------------------------------------- */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown > summary {
    list-style: none;
}

.dropdown > summary::-webkit-details-marker {
    display: none;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: var(--z-dropdown);
    min-width: 200px;
    padding: var(--space-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    animation: dropdown-in var(--motion-enter) var(--ease-out);
}

.dropdown-menu-end {
    left: auto;
    right: 0;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font-size: var(--text-sm);
    text-align: left;
    text-decoration: none;
}

.dropdown-item:hover {
    background: var(--surface-muted);
    text-decoration: none;
}

.dropdown-item.active {
    font-weight: var(--weight-semibold);
}

.dropdown-divider {
    height: 0;
    margin: var(--space-1) 0;
    border-top: 1px solid var(--border);
    list-style: none;
}

@keyframes dropdown-in {
    from { opacity: 0; transform: translateY(calc(var(--motion-rise) * -0.5)); }
    to   { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------------
   List group
   --------------------------------------------------------------------- */
.list-group {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    list-style: none;
    overflow: hidden;
}

.list-group-flush {
    border: 0;
    border-radius: 0;
}

.list-group-item {
    display: block;
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.list-group-item:last-child {
    border-bottom: 0;
}

.list-group-item-action {
    width: 100%;
    text-align: left;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease);
}

.list-group-item-action:hover {
    background: var(--surface-muted);
    text-decoration: none;
}

.list-group-item.active {
    background: var(--surface-sunken);
    font-weight: var(--weight-semibold);
}

/* ---------------------------------------------------------------------
   Pagination and breadcrumbs
   --------------------------------------------------------------------- */
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
}

.page-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 0.625rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: var(--text-sm);
    text-decoration: none;
    transition: background-color var(--duration-fast) var(--ease);
}

.page-link:hover {
    background: var(--surface-muted);
    text-decoration: none;
}

.page-item.active .page-link {
    background: var(--gray-900);
    border-color: var(--gray-900);
    color: var(--text-inverse);
}

.page-item.disabled .page-link {
    color: var(--gray-400);
    pointer-events: none;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    margin: 0 0 var(--space-3);
    padding: 0;
    list-style: none;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.breadcrumb-item + .breadcrumb-item::before {
    content: "/";
    padding: 0 var(--space-2);
    color: var(--gray-400);
}

.breadcrumb-item a {
    color: var(--text-secondary);
}

.breadcrumb-item.active {
    color: var(--text);
}

/* ---------------------------------------------------------------------
   Star rating: display (includes/stars.html) and picker (includes/star_input.html)
   --------------------------------------------------------------------- */
.stars {
    display: inline-flex;
    gap: 1px;
    color: var(--gray-300);
    vertical-align: middle;
}

.stars svg {
    fill: currentColor;
}

.star.is-filled {
    color: var(--gray-900);
}

.star-input {
    display: inline-flex;
    flex-direction: row-reverse;
    justify-content: flex-end;
    gap: 2px;
}

.star-input label {
    color: var(--gray-300);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease);
}

.star-input svg {
    fill: currentColor;
}

.star-input input:checked ~ label,
.star-input label:hover,
.star-input label:hover ~ label {
    color: var(--gray-900);
}

.star-input input:focus-visible + label {
    border-radius: var(--radius);
    box-shadow: var(--focus-ring);
}

/* ---------------------------------------------------------------------
   Progress, spinner
   --------------------------------------------------------------------- */
.progress {
    display: flex;
    height: 8px;
    overflow: hidden;
    border-radius: var(--radius-full);
    background: var(--surface-sunken);
}

.progress-sm {
    height: 5px;
}

.progress-bar {
    height: 100%;
    background: var(--gray-900);
    transition: width var(--duration-slow) var(--ease);
}

.progress-bar-success { background: var(--success-text); }
.progress-bar-warning { background: #c98a12; }
.progress-bar-danger  { background: var(--danger-text); }

.spinner {
    display: inline-block;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    vertical-align: -0.125em;
    animation: spin 0.7s linear infinite;
}

.spinner-lg {
    width: 2rem;
    height: 2rem;
    border-width: 3px;
}

/* Centred loading placeholder for panels filled by fetch() */
.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 80px;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------------
   Empty state: one look for "nothing here yet"
   --------------------------------------------------------------------- */
/* Placeholder blocks while content loads (quick view and any async panel) */
.skeleton {
    display: block;
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    animation: skeleton-pulse 1.4s var(--ease) infinite;
}

.skeleton-line { height: 0.875rem; }
.skeleton-title { height: 1.5rem; width: 70%; }
.skeleton-short { width: 35%; }
.skeleton-block { height: 3rem; margin-top: auto; }

@keyframes skeleton-pulse {
    50% { opacity: 0.55; }
}

.empty-state {
    padding: var(--space-5) var(--space-3);
    text-align: center;
    color: var(--text-muted);
}

.empty-state > .icon {
    margin-bottom: var(--space-3);
    font-size: 2.5rem;
    color: var(--gray-300);
}

.empty-state h2,
.empty-state h3,
.empty-state h4,
.empty-state h5 {
    margin-bottom: var(--space-1);
    color: var(--text);
}

.empty-state p {
    max-width: 420px;
    margin-inline: auto;
}

/* ---------------------------------------------------------------------
   Thumbnails: small product/order images and their placeholders
   --------------------------------------------------------------------- */
.thumb {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    object-fit: cover;
    background: var(--surface-muted);
}

.thumb-sm { width: 40px; height: 40px; }
.thumb-lg { width: 64px; height: 64px; }

.thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    color: var(--gray-400);
}

/* ---------------------------------------------------------------------
   Key/value list (order summaries, customer details)
   --------------------------------------------------------------------- */
.detail-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin: 0;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
}

.detail-row dt,
.detail-row > span:first-child {
    color: var(--text-secondary);
    font-weight: var(--weight-normal);
}

.detail-row-total {
    padding-top: var(--space-2);
    border-top: 1px solid var(--border);
    font-weight: var(--weight-semibold);
}

/* ---------------------------------------------------------------------
   Order progress steps and timeline (customer and admin order pages)
   --------------------------------------------------------------------- */
.order-progress-steps {
    position: relative;
    display: flex;
    justify-content: space-between;
    margin: var(--space-3) 0;
}

.order-progress-steps::before {
    content: "";
    position: absolute;
    top: 15px;
    left: 8%;
    right: 8%;
    height: 2px;
    background: var(--border);
}

.order-step {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.order-step-dot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 2px solid var(--border-strong);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.order-step.completed .order-step-dot,
.order-step.active .order-step-dot {
    border-color: var(--gray-900);
    background: var(--gray-900);
    color: var(--text-inverse);
}

.order-step-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-align: center;
}

.order-step.completed .order-step-label,
.order-step.active .order-step-label {
    color: var(--text);
    font-weight: var(--weight-medium);
}

.timeline {
    position: relative;
    margin: 0;
    padding: 0 0 0 1.25rem;
    list-style: none;
}

.timeline-item {
    position: relative;
    padding-bottom: var(--space-3);
}

.timeline-item:not(:last-child)::before {
    content: "";
    position: absolute;
    top: 14px;
    bottom: 0;
    left: -15px;
    width: 1px;
    background: var(--border);
}

.timeline-marker {
    position: absolute;
    top: 6px;
    left: -19px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--gray-400);
    box-shadow: 0 0 0 3px var(--surface);
}

.timeline-marker-delivered,
.timeline-marker-paid { background: var(--success-text); }
.timeline-marker-cancelled,
.timeline-marker-failed { background: var(--danger-text); }
.timeline-marker-pending { background: #c98a12; }
.timeline-marker-processing,
.timeline-marker-shipped { background: var(--blue-600); }

.timeline-content {
    font-size: var(--text-sm);
}

/* ---------------------------------------------------------------------
   Lightbox (product images, file previews)
   --------------------------------------------------------------------- */
.lightbox {
    background: #000;
}

.lightbox .modal-body {
    position: relative;
    padding: 0;
    background: #000;
}

.lightbox img {
    display: block;
    width: 100%;
    max-height: 85vh;
    object-fit: contain;
}

.lightbox .btn-close {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    z-index: 1;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.lightbox .btn-close:hover {
    background: rgba(255, 255, 255, 0.3);
    color: #fff;
}

.tabs-center {
    justify-content: center;
}
