/* ============================================================================
 *  ui.css  —  shared design-system components
 *  Buttons · theme picker · toasts · confirm dialog · empty states.
 *  Global (loaded in base.html). Colour from theme.css tokens only.
 * ==========================================================================*/

/* ---------------------------------------------------------------------------
 *  Buttons — words + icon, never icon-only for primary actions.
 * ------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);

    min-height: 44px;
    padding: 0 var(--space-4);

    font-family: var(--font-sans);
    font-size: var(--fs-base);
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;

    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    cursor: pointer;

    transition: background-color 0.15s ease, border-color 0.15s ease,
                color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 1.25em; height: 1.25em; flex: 0 0 auto; }

.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
    box-shadow: var(--shadow-1);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

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

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

/* Solid danger — only inside the confirm dialog. */
.btn-danger-solid {
    background: var(--danger);
    color: var(--danger-text);
    border-color: var(--danger);
}
.btn-danger-solid:hover { filter: brightness(1.08); }

/* A big, obvious primary action (e.g. "＋ Add Part"). */
.btn-lg {
    min-height: 48px;
    padding: 0 var(--space-5);
    font-size: var(--fs-lg);
    border-radius: var(--radius-md);
}

/* ---------------------------------------------------------------------------
 *  Theme picker — <details class="theme-picker"> in the navbar.
 * ------------------------------------------------------------------------- */
.theme-picker { position: relative; flex: 0 0 auto; }

.theme-picker > summary {
    list-style: none;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 0 var(--space-3);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: var(--fs-base);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}
.theme-picker > summary::-webkit-details-marker { display: none; }
.theme-picker > summary:hover { background: var(--surface-hover); }
.theme-picker .theme-caret { color: var(--text-muted); font-size: 0.8em; transition: transform 0.15s ease; }
.theme-picker[open] .theme-caret { transform: rotate(180deg); }

.theme-swatch {
    display: inline-block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--border-strong);
    flex: 0 0 auto;
}
/* Summary swatch reflects the ACTIVE theme (pure CSS). */
:root[data-theme="light"]       .theme-picker > summary .theme-swatch { background: var(--swatch-light); }
:root[data-theme="dark"]        .theme-picker > summary .theme-swatch { background: var(--swatch-dark); }
:root[data-theme="glass-light"] .theme-picker > summary .theme-swatch { background: var(--swatch-glass-light); }
:root[data-theme="glass-dark"]  .theme-picker > summary .theme-swatch { background: var(--swatch-glass-dark); }

.theme-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 1200;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-2);
}

.theme-option {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: 44px;
    padding: 0 var(--space-3);
    background: transparent;
    color: var(--text);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    text-align: left;
    cursor: pointer;
}
.theme-option:hover { background: var(--surface-hover); }
.theme-option .theme-swatch { width: 20px; height: 20px; border-radius: var(--radius-sm); }
.theme-option[data-theme-value="light"]       .theme-swatch { background: var(--swatch-light); }
.theme-option[data-theme-value="dark"]        .theme-swatch { background: var(--swatch-dark); }
.theme-option[data-theme-value="glass-light"] .theme-swatch { background: var(--swatch-glass-light); }
.theme-option[data-theme-value="glass-dark"]  .theme-swatch { background: var(--swatch-glass-dark); }
.theme-option .theme-check { margin-left: auto; color: var(--accent); opacity: 0; font-weight: 700; }

/* Highlight the option matching the active theme (pure CSS, no JS reflection). */
:root[data-theme="light"]       .theme-option[data-theme-value="light"],
:root[data-theme="dark"]        .theme-option[data-theme-value="dark"],
:root[data-theme="glass-light"] .theme-option[data-theme-value="glass-light"],
:root[data-theme="glass-dark"]  .theme-option[data-theme-value="glass-dark"] {
    background: var(--accent-soft);
    border-color: var(--border);
    font-weight: 700;
}
:root[data-theme="light"]       .theme-option[data-theme-value="light"] .theme-check,
:root[data-theme="dark"]        .theme-option[data-theme-value="dark"] .theme-check,
:root[data-theme="glass-light"] .theme-option[data-theme-value="glass-light"] .theme-check,
:root[data-theme="glass-dark"]  .theme-option[data-theme-value="glass-dark"] .theme-check {
    opacity: 1;
}

/* ---------------------------------------------------------------------------
 *  Toasts — bottom-centre pill, icon + short text, auto-dismiss.
 * ------------------------------------------------------------------------- */
.toast-container {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    pointer-events: none;
}
.toast {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    max-width: min(90vw, 460px);
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-2);
    font-size: var(--fs-base);
    font-weight: 600;
    pointer-events: auto;
    animation: toast-in 0.2s ease both;
}
.toast.toast--out { animation: toast-out 0.2s ease both; }
.toast .toast-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
}
.toast--success .toast-icon { color: var(--success); }
.toast--error   .toast-icon { color: var(--danger); }
.toast--info    .toast-icon { color: var(--accent); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(12px); }
}

/* ---------------------------------------------------------------------------
 *  Confirm dialog — plain-language, forgiving.
 * ------------------------------------------------------------------------- */
.confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: var(--backdrop);
}
.confirm-modal.open { display: flex; }
:root[data-theme^="glass"] .confirm-modal {
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}
.confirm-card {
    width: 100%;
    max-width: 460px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-2);
    padding: var(--space-5);
}
.confirm-card h3 {
    margin: 0 0 var(--space-3);
    font-size: var(--fs-xl);
    color: var(--text);
}
.confirm-card p {
    margin: 0 0 var(--space-5);
    font-size: var(--fs-base);
    line-height: 1.5;
    color: var(--text-muted);
}
.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    flex-wrap: wrap;
}

/* ---------------------------------------------------------------------------
 *  Placeholder / landing page bodies
 * ------------------------------------------------------------------------- */
.page-body {
    padding: var(--space-5);
    max-width: 1100px;
}
.page-body h2 {
    font-size: var(--fs-title);
    margin: 0 0 var(--space-2);
    color: var(--text);
}
.page-intro {
    color: var(--text-muted);
    font-size: var(--fs-lg);
    margin: 0 0 var(--space-5);
}
.quick-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: var(--space-4);
}
.quick-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
    text-decoration: none;
    font-size: var(--fs-lg);
    font-weight: 600;
    transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}
.quick-link:hover { background: var(--surface-hover); box-shadow: var(--shadow-2); }
.quick-link:active { transform: translateY(1px); }
.quick-link .quick-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    border-radius: var(--radius-md);
    background: var(--accent-soft);
    color: var(--accent);
}
.quick-link .quick-icon svg { width: 24px; height: 24px; }

/* ---------------------------------------------------------------------------
 *  Dashboard: stat tiles + recent activity
 * ------------------------------------------------------------------------- */
.dashboard .page-intro { margin-bottom: var(--space-5); }

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}
.stat-tile {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
}
.stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    flex: 0 0 auto;
    border-radius: var(--radius-md);
    background: var(--accent-soft);
    color: var(--accent);
}
.stat-icon svg { width: 26px; height: 26px; }
.stat-meta { display: flex; flex-direction: column; min-width: 0; }
.stat-value {
    font-size: var(--fs-title);
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}
.stat-label { font-size: var(--fs-sm); color: var(--text-muted); }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-5);
    align-items: start;
}
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

.section-title {
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text);
    margin: 0 0 var(--space-3);
}

.activity-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-1);
    overflow: hidden;
}
.activity-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}
.activity-row:last-child { border-bottom: none; }
.activity-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    border-radius: var(--radius-md);
    background: var(--accent-soft);
    color: var(--accent);
}
.activity-icon svg { width: 18px; height: 18px; }
.activity-icon--add { background: var(--success-soft); color: var(--success); }
.activity-icon--delete { background: var(--danger-soft); color: var(--danger); }
.activity-icon--update { background: var(--accent-soft); color: var(--accent); }
.activity-text { flex: 1; min-width: 0; }
.activity-title { color: var(--text); font-weight: 600; }
.activity-meta { color: var(--text-faint); font-size: var(--fs-sm); }
.activity-empty { padding: var(--space-5); text-align: center; color: var(--text-muted); }

/* ---------------------------------------------------------------------------
 *  Empty state — friendly, with a call to action.
 * ------------------------------------------------------------------------- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-6) var(--space-4);
    text-align: center;
    color: var(--text-muted);
}
.empty-state .empty-icon { color: var(--text-faint); }
.empty-state .empty-icon svg { width: 56px; height: 56px; }
.empty-state .empty-title {
    font-size: var(--fs-lg);
    font-weight: 700;
    color: var(--text);
}
.empty-state .empty-sub { font-size: var(--fs-base); }
