/* Pedal Inventory — Workshop palette
   Mood: well-lit workbench at night. Dark pegboard surface,
   warm overhead lamp, amber pilot lights, cool blue LED readouts.
   Strategy: Restrained dark — tinted neutrals + two accents under 15% */

:root {
    /* Core palette — OKLCH */
    --bg: oklch(0.16 0.01 250);
    --surface: oklch(0.21 0.012 250);
    --surface-hover: oklch(0.25 0.014 250);
    --surface-alt: oklch(0.19 0.011 250);
    --border: oklch(0.30 0.012 250);
    --border-subtle: oklch(0.25 0.008 250);

    --ink: oklch(0.92 0.01 80);
    --muted: oklch(0.75 0.012 80);

    /* Primary — shifted from seed 200° toward a warmer teal, workshop pilot-light feel */
    --primary: oklch(0.68 0.12 195);
    --primary-hover: oklch(0.60 0.11 195);
    --primary-subtle: oklch(0.25 0.04 195);
    --primary-glow: oklch(0.68 0.12 195 / 0.15);

    /* Accent — amber, like a tube amp pilot light */
    --accent: oklch(0.72 0.14 70);
    --accent-subtle: oklch(0.25 0.04 70);

    /* Semantic */
    --good: oklch(0.68 0.14 155);
    --warning: oklch(0.72 0.14 70);
    --danger: oklch(0.65 0.16 25);

    /* Spacing scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 0.75rem;
    --space-lg: 1.25rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4.5rem;

    /* Type */
    --font: "Inter", system-ui, -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", monospace;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.9375rem;
    --text-lg: 1.0625rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 2rem;

    /* Radii */
    --radius-sm: 4px;
    --radius: 6px;
    --radius-lg: 10px;
    --radius-round: 50px;

    /* Shadows */
    --shadow-sm: 0 1px 3px oklch(0 0 0 / 0.3);
    --shadow: 0 2px 8px oklch(0 0 0 / 0.4);
    --shadow-lg: 0 8px 24px oklch(0 0 0 / 0.5);
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font);
    font-size: var(--text-base);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    /* Subtle noise texture like pegboard */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.015'/%3E%3C/svg%3E");
}

/* Navigation */
.nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: var(--space-md) var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-xl);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.nav-brand {
    font-size: var(--text-lg);
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--ink);
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: -0.02em;
}

.nav-links {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
}

.nav-link {
    color: var(--muted);
    text-decoration: none;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: color 0.12s, background 0.12s;
}

.nav-link:hover {
    background: var(--surface-hover);
    color: var(--ink);
}

.nav-link[aria-current="page"],
.nav-link.active {
    color: var(--ink);
    background: var(--surface-hover);
}

/* Layout */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
}

/* Typography */
h1 {
    font-size: var(--text-2xl);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-lg);
    color: var(--ink);
}

h2 {
    font-size: var(--text-xl);
    font-weight: 600;
    font-family: var(--font-mono);
    letter-spacing: -0.01em;
    margin-bottom: var(--space-md);
    color: var(--ink);
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
    flex-wrap: wrap;
}

.page-header h1 {
    margin-bottom: 0;
}

.page-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-2xl);
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-top: 2px solid var(--primary);
    border-radius: var(--radius-lg);
    padding: var(--space-lg) var(--space-lg) var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.stat-value {
    font-size: var(--text-3xl);
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--primary);
    letter-spacing: -0.03em;
    text-shadow: 0 0 20px var(--primary-glow);
}

.stat-label {
    font-size: var(--text-sm);
    color: var(--muted);
    font-weight: 500;
}

/* Quick actions */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-2xl);
}

.quick-action {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--ink);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: border-color 0.12s, background 0.12s;
}

.quick-action:hover {
    border-color: var(--primary);
    background: var(--surface-hover);
}

.quick-action-icon {
    font-size: var(--text-xl);
}

/* Sections */
.section {
    margin-bottom: var(--space-2xl);
}

.subtitle {
    color: var(--muted);
    margin-bottom: var(--space-lg);
    font-size: var(--text-sm);
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
    background: var(--surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

th, td {
    padding: var(--space-sm) var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

th {
    background: oklch(0.18 0.01 250);
    font-weight: 600;
    color: var(--muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

tbody tr {
    transition: background 0.1s;
}

tbody tr:nth-child(even) {
    background: var(--surface-alt);
}

tbody tr:hover {
    background: var(--surface-hover);
}

tr:last-child td {
    border-bottom: none;
}

.value-cell {
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--ink);
}

/* Stock indicators */
.stock-good {
    color: var(--good);
    font-weight: 600;
    font-family: var(--font-mono);
}

.stock-low {
    color: var(--warning);
    font-weight: 600;
    font-family: var(--font-mono);
}

.stock-out {
    color: var(--danger);
    font-weight: 600;
    font-family: var(--font-mono);
}

/* Quantity columns */
.qty-total {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--ink);
}

.qty-reserved {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
}

.qty-none {
    color: var(--muted);
    opacity: 0.5;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 3px var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.01em;
}

/* Component category badges — muted tones that don't fight for attention */
.badge-resistor { background: oklch(0.25 0.04 155); color: oklch(0.75 0.10 155); }
.badge-capacitor { background: oklch(0.25 0.04 70); color: oklch(0.78 0.10 70); }
.badge-transistor { background: oklch(0.25 0.04 220); color: oklch(0.75 0.10 220); }
.badge-diode { background: oklch(0.25 0.04 340); color: oklch(0.75 0.10 340); }
.badge-ic { background: oklch(0.25 0.04 290); color: oklch(0.75 0.10 290); }
.badge-potentiometer { background: oklch(0.25 0.04 40); color: oklch(0.78 0.10 40); }
.badge-switch { background: oklch(0.25 0.03 195); color: oklch(0.75 0.08 195); }
.badge-inductor { background: oklch(0.25 0.04 130); color: oklch(0.75 0.10 130); }
.badge-other { background: oklch(0.22 0.005 250); color: oklch(0.60 0.01 250); }

/* Build status badges */
.badge-status-planned { background: var(--primary-subtle); color: var(--primary); }
.badge-status-in_progress { background: var(--accent-subtle); color: var(--accent); }
.badge-status-completed { background: oklch(0.25 0.04 155); color: var(--good); }
.badge-status-abandoned { background: oklch(0.22 0.005 250); color: var(--muted); }

.badge-lg {
    padding: var(--space-xs) var(--space-md);
    font-size: var(--text-sm);
}

/* Transaction type badges */
.badge-txn-restock { background: oklch(0.25 0.04 155); color: var(--good); }
.badge-txn-used_in_build { background: oklch(0.25 0.04 340); color: oklch(0.75 0.10 340); }
.badge-txn-manual_adjustment { background: var(--primary-subtle); color: var(--primary); }
.badge-txn-build_reversed { background: var(--accent-subtle); color: var(--accent); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s, transform 0.08s;
    white-space: nowrap;
    min-height: 36px;
}

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

.btn:active {
    transform: scale(0.97);
}

.btn:disabled, .btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: oklch(0.98 0 0);
}

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

.btn-good {
    background: var(--good);
    border-color: var(--good);
    color: oklch(0.98 0 0);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: oklch(0.98 0 0);
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-xs);
    min-height: 30px;
    min-width: 30px;
    border-radius: var(--radius-round);
}

/* Forms */
.form {
    max-width: 800px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-lg);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
}

.form-group label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--muted);
}

.input {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--ink);
    font-size: var(--text-sm);
    font-family: var(--font);
    transition: border-color 0.12s, box-shadow 0.12s;
    min-height: 36px;
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.input::placeholder {
    color: var(--muted);
    opacity: 0.6;
}

.input-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-xs);
    min-height: 28px;
}

textarea.input {
    resize: vertical;
    font-family: var(--font);
    line-height: 1.5;
}

textarea.mono {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    line-height: 1.6;
}

select.input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239999bb' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: var(--text-sm);
    cursor: pointer;
    color: var(--muted);
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

/* Filters */
.filters {
    display: flex;
    gap: var(--space-md);
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: var(--space-xl);
    padding: var(--space-md) var(--space-lg);
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
}

/* Builds */
.builds-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-lg);
}

.build-card {
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    text-decoration: none;
    color: var(--ink);
    transition: border-color 0.12s, background 0.12s, box-shadow 0.15s;
}

.build-card:hover {
    border-color: var(--primary);
    background: var(--surface-hover);
    box-shadow: var(--shadow-sm);
}

.build-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.build-card h3 {
    font-size: var(--text-lg);
    font-weight: 600;
    letter-spacing: -0.01em;
}

.build-meta {
    font-size: var(--text-sm);
    color: var(--muted);
    margin-top: var(--space-xs);
}

.build-actions {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    margin-bottom: var(--space-xl);
}

.inline-form {
    display: inline;
}

.bom-summary {
    display: flex;
    gap: var(--space-xl);
    margin-bottom: var(--space-xl);
    font-size: var(--text-base);
    font-weight: 600;
}

/* Build progress bar */
.build-progress {
    height: 4px;
    background: var(--border-subtle);
    border-radius: 2px;
    margin-top: var(--space-sm);
    overflow: hidden;
}

.build-progress-fill {
    height: 100%;
    background: var(--good);
    border-radius: 2px;
    transition: width 0.3s ease-out;
}

/* Form inline (for add BOM item) */
.form-inline {
    display: flex;
    gap: var(--space-sm);
    align-items: flex-end;
    flex-wrap: wrap;
}

/* Actions column */
.actions {
    white-space: nowrap;
    display: flex;
    gap: 4px;
}

/* Shopping list */
.search-link {
    display: inline-block;
    margin-right: var(--space-sm);
    font-size: var(--text-xs);
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: var(--space-3xl) var(--space-lg);
    color: var(--muted);
    font-size: var(--text-base);
}

.empty-state a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.empty-state a:hover {
    text-decoration: underline;
}

/* File upload */
.file-upload {
    position: relative;
}

.file-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
}

.file-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xl);
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}

.file-label:hover {
    border-color: var(--primary);
    background: var(--surface);
}

.file-input:focus + .file-label {
    border-color: var(--primary);
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.file-icon {
    font-size: 2rem;
}

.file-text {
    font-size: var(--text-sm);
    color: var(--ink);
    font-weight: 500;
}

.file-hint {
    font-size: var(--text-xs);
    color: var(--muted);
}

.file-name {
    display: block;
    margin-top: var(--space-sm);
    font-size: var(--text-sm);
    color: var(--good);
    font-weight: 600;
    font-family: var(--font-mono);
}

/* Import preview merge indicators */
.merge-indicator {
    color: var(--accent);
    font-weight: 700;
    font-size: var(--text-lg);
}

.new-indicator {
    color: var(--primary);
    font-size: var(--text-sm);
}

.merge-detail {
    color: var(--muted);
    font-size: var(--text-xs);
    font-family: var(--font-mono);
}

/* Quantity flash animation on HTMX update */
@keyframes qty-flash {
    0% { background: var(--primary-subtle); }
    100% { background: transparent; }
}

[id^="qty-"] {
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-weight: 600;
}

.htmx-settling [id^="qty-"] {
    animation: qty-flash 0.6s ease-out;
}

/* Focus-visible for keyboard accessibility */
.nav-link:focus-visible,
.btn:focus-visible,
.build-card:focus-visible,
.input:focus-visible,
.quick-action:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Footer */
.site-footer {
    text-align: center;
    padding: var(--space-2xl) var(--space-lg) var(--space-lg);
    border-top: 1px solid var(--border-subtle);
    margin-top: var(--space-3xl);
}

.coffee-link {
    color: var(--muted);
    font-size: var(--text-xs);
    text-decoration: none;
    transition: color 0.12s;
}

.coffee-link:hover {
    color: var(--accent);
}

/* Responsive */
@media (max-width: 768px) {
    .nav {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
        padding: var(--space-md);
    }

    .nav-links {
        gap: 0;
    }

    .nav-link {
        padding: var(--space-sm);
        font-size: var(--text-sm);
    }

    .container {
        padding: var(--space-lg) var(--space-md);
    }

    h1 {
        font-size: var(--text-xl);
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-md);
    }

    .stat-value {
        font-size: var(--text-2xl);
    }

    .quick-actions {
        grid-template-columns: 1fr;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-inline {
        flex-direction: column;
        align-items: stretch;
    }

    .btn {
        padding: var(--space-md) var(--space-lg);
        min-height: 44px;
    }

    .btn-sm {
        min-height: 36px;
        min-width: 36px;
        padding: var(--space-sm) var(--space-md);
    }

    .build-actions {
        flex-direction: column;
    }

    .bom-summary {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .page-header-right {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* Shopping checklist */
.col-check {
    width: 40px;
    text-align: center;
}

.cart-check {
    width: 18px;
    height: 18px;
    accent-color: var(--good);
    cursor: pointer;
}

.shopping-row.in-cart {
    opacity: 0.45;
    text-decoration: line-through;
    text-decoration-color: var(--muted);
}

.shopping-row.in-cart .stock-out {
    color: var(--muted);
}

.stock-check {
    color: var(--good);
    font-weight: 700;
    font-size: var(--text-lg);
}

.in-stock-row {
    opacity: 0.7;
}

.search-links {
    white-space: nowrap;
}

/* Inline editable fields */
.editable {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    transition: background 0.12s;
    font-size: var(--text-sm);
}

.editable:hover {
    background: var(--surface-hover);
}

/* Auth pages */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-lg);
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-2xl);
    width: 100%;
    max-width: 400px;
}

.auth-brand {
    font-family: var(--font-mono);
    font-size: var(--text-2xl);
    text-align: center;
    margin-bottom: var(--space-xs);
}

.auth-subtitle {
    text-align: center;
    color: var(--muted);
    font-size: var(--text-sm);
    margin-bottom: var(--space-xl);
}

.auth-form .form-group {
    margin-bottom: var(--space-lg);
}

.auth-btn {
    width: 100%;
    margin-top: var(--space-md);
}

.auth-error {
    background: oklch(0.25 0.04 25);
    color: var(--danger);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    margin-bottom: var(--space-lg);
    text-align: center;
}

.auth-switch {
    text-align: center;
    margin-top: var(--space-xl);
    font-size: var(--text-sm);
    color: var(--muted);
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}
