/* Hide elements until Alpine.js initializes - prevents FOUC */
[x-cloak] {
    display: none !important;
}

:root {
    --slate-950: #0a0a0b;
    --slate-900: #111113;
    --slate-800: #1e1e21;
    --slate-700: #2d2d31;
    --slate-600: #4a4a50;
    --slate-500: #6b7280;
    --slate-400: #9ca3af;
    --slate-300: #c9cdd4;
    --slate-200: #e2e8f0;
    --slate-50: #f8fafc;
    --emerald-500: #10b981;
    --emerald-400: #34d399;
    --sky-500: #0ea5e9;
    --sky-400: #38bdf8;
    --violet-500: #8b5cf6;
    --violet-400: #a78bfa;
    --amber-500: #f59e0b;
    --rose-500: #f43f5e;
    --rose-400: #fb7185;
    --font-sans: 'Geist', 'Noto Sans SC', system-ui, sans-serif;
    --font-mono: 'Geist Mono', 'SFMono-Regular', Consolas, monospace;
    --radius-sm: 2px;
    --radius-md: 4px;
}

body {
    font-family: var(--font-sans);
    background: var(--slate-950);
    color: var(--slate-50);
}

.row-overpick {
    background: repeating-linear-gradient(
        -45deg,
        rgb(254 205 211 / 0.1) 0px,
        rgb(254 205 211 / 0.1) 4px,
        transparent 4px,
        transparent 8px
    );
    border-left: 3px solid var(--rose-500);
}

.badge-finished {
    background: rgb(139 92 246 / 0.2);
    color: var(--violet-400);
    border: 1px solid rgb(139 92 246 / 0.3);
}

.badge-self-made {
    background: rgb(16 185 129 / 0.2);
    color: var(--emerald-400);
    border: 1px solid rgb(16 185 129 / 0.3);
}

.badge-purchased {
    background: rgb(14 165 233 / 0.2);
    color: var(--sky-400);
    border: 1px solid rgb(14 165 233 / 0.3);
}

.glow-emerald:focus {
    box-shadow: 0 0 0 2px var(--slate-950), 0 0 0 4px var(--emerald-500);
}

/* === Column Resize Handles === */
.resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.15s ease;
    z-index: 30;
}

.resize-handle:hover,
.resize-handle.active {
    background: var(--emerald-500);
}

.resize-handle::after {
    content: '';
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 16px;
    background: var(--slate-600);
    border-radius: 1px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.resize-handle:hover::after {
    opacity: 1;
    background: var(--emerald-400);
}

th.resizable {
    position: relative;
}

/* === Filter Chips === */
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
}

.filter-chip-active {
    background: rgb(16 185 129 / 0.15);
    color: var(--emerald-400);
    border-color: rgb(16 185 129 / 0.3);
}

.filter-chip-inactive {
    background: var(--slate-800);
    color: var(--slate-500);
    border-color: var(--slate-700);
}

.filter-chip-inactive:hover {
    background: var(--slate-700);
    color: var(--slate-400);
}

.filter-chip-finished.filter-chip-active {
    background: rgb(139 92 246 / 0.15);
    color: var(--violet-400);
    border-color: rgb(139 92 246 / 0.3);
}

.filter-chip-self-made.filter-chip-active {
    background: rgb(16 185 129 / 0.15);
    color: var(--emerald-400);
    border-color: rgb(16 185 129 / 0.3);
}

.filter-chip-purchased.filter-chip-active {
    background: rgb(14 165 233 / 0.15);
    color: var(--sky-400);
    border-color: rgb(14 165 233 / 0.3);
}

/* === Sort Indicators === */
.sort-indicator {
    display: inline-flex;
    flex-direction: column;
    gap: -2px;
    opacity: 0.4;
    transition: opacity 0.15s ease;
}

.sort-indicator.active {
    opacity: 1;
}

.sort-indicator svg {
    width: 12px;
    height: 12px;
}

.sortable-header {
    cursor: pointer;
    user-select: none;
}

.sortable-header:hover {
    background: var(--slate-800);
}

.sortable-header:hover .sort-indicator {
    opacity: 0.7;
}

/* === Dropdown Menus === */
.dropdown-menu {
    position: absolute;
    right: 0;
    margin-top: 0.5rem;
    background: var(--slate-800);
    border: 1px solid var(--slate-700);
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    z-index: 50;
    min-width: 200px;
    max-height: 320px;
    overflow-y: auto;
}

.dropdown-header {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    color: var(--slate-500);
    border-bottom: 1px solid var(--slate-700);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--slate-300);
    cursor: pointer;
    transition: background 0.15s ease;
}

.dropdown-item:hover {
    background: var(--slate-700);
}

.dropdown-item-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dropdown-divider {
    height: 1px;
    background: var(--slate-700);
    margin: 0.25rem 0;
}

/* === Filter Toolbar === */
.filter-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--slate-800);
    border-bottom: 1px solid var(--slate-700);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-label {
    font-size: 0.75rem;
    color: var(--slate-500);
    white-space: nowrap;
}

.filter-search {
    flex: 1;
    min-width: 180px;
    max-width: 280px;
}

.filter-search input {
    width: 100%;
    padding: 0.375rem 0.75rem;
    padding-left: 2rem;
    background: var(--slate-900);
    border: 1px solid var(--slate-700);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    color: var(--slate-300);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.filter-search input:focus {
    outline: none;
    border-color: var(--emerald-500);
    box-shadow: 0 0 0 2px rgb(16 185 129 / 0.2);
}

.filter-search input::placeholder {
    color: var(--slate-600);
}

.filter-search-icon {
    position: absolute;
    left: 0.625rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--slate-500);
    pointer-events: none;
}

/* === Search History Dropdown === */
.search-history {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.25rem;
    background: var(--slate-800);
    border: 1px solid var(--slate-700);
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
    z-index: 50;
    max-height: 15rem;
    overflow-y: auto;
}

.search-history-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    font-family: var(--font-mono);
    color: var(--slate-300);
    cursor: pointer;
    transition: background 0.15s ease;
}

.search-history-item:hover {
    background: var(--slate-700);
}

.search-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--slate-700);
}

/* === Column Settings Panel === */
.column-settings {
    min-width: 220px;
}

.column-settings-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.column-settings-item:hover:not(.column-settings-item-locked) {
    background: var(--slate-700);
}

.column-settings-item-locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.column-settings-checkbox {
    width: 1rem;
    height: 1rem;
    border-radius: 0.25rem;
    border: 1px solid var(--slate-600);
    background: var(--slate-800);
    appearance: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.column-settings-checkbox:checked {
    background: var(--emerald-500);
    border-color: var(--emerald-500);
}

.column-settings-checkbox:checked::after {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E") center/60% no-repeat;
}

.column-settings-checkbox:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.bg-dots {
    background-image: radial-gradient(rgb(255 255 255 / 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
}

.skeleton {
    background: linear-gradient(90deg, var(--slate-800) 25%, var(--slate-700) 50%, var(--slate-800) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }
    20%,
    60% {
        transform: translateX(-6px);
    }
    40%,
    80% {
        transform: translateX(6px);
    }
}

.animate-shake {
    animation: shake 0.4s ease-in-out;
}

.tree-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.tree-node {
    background: var(--slate-900);
    border: 1px solid var(--slate-700);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 180px;
}

.tree-label {
    font-size: 0.75rem;
    color: var(--slate-400);
    letter-spacing: 0.04em;
}

.tree-value {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    color: var(--slate-50);
}

.tree-root {
    border-color: var(--emerald-500);
    background: rgb(16 185 129 / 0.08);
    box-shadow: 0 0 0 1px rgb(16 185 129 / 0.25);
}

.tree-sales {
    border-color: var(--violet-500);
}

.tree-production {
    border-color: var(--sky-500);
}

.tree-purchase {
    border-color: var(--amber-500);
}

.tree-doc {
    background: rgb(15 23 42 / 0.4);
}

.tree-children {
    margin-left: 1.5rem;
    padding-left: 1.5rem;
    border-left: 1px solid var(--slate-700);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.tree-branch {
    position: relative;
    padding-left: 1.5rem;
}

.tree-branch::before {
    content: '';
    position: absolute;
    left: 0;
    top: 1.2rem;
    width: 1.5rem;
    height: 1px;
    background: var(--slate-700);
}

@media print {
    body {
        background: white;
        color: black;
    }

    .no-print {
        display: none !important;
    }
}

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

@media (max-width: 767px) {
    .bom-table {
        display: none;
    }

    .bom-cards {
        display: block;
    }

    .bom-card {
        background: var(--slate-900);
        border: 1px solid var(--slate-800);
        border-radius: var(--radius-md);
        padding: 1rem;
        margin-bottom: 0.75rem;
    }

    .bom-card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 0.75rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid var(--slate-800);
    }

    .bom-card-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .bom-card-item {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

    .bom-card-label {
        font-size: 0.75rem;
        color: var(--slate-500);
    }

    .bom-card-value {
        font-size: 0.875rem;
        color: var(--slate-200);
        font-variant-numeric: tabular-nums;
    }

    .touch-target {
        min-height: 44px;
        min-width: 44px;
    }

    .tree-node {
        min-width: 0;
    }

    .tree-children {
        margin-left: 1rem;
        padding-left: 1rem;
    }

    .tree-branch {
        padding-left: 1rem;
    }

    .tree-branch::before {
        width: 1rem;
    }
}

@media (min-width: 768px) {
    .bom-table {
        display: block;
    }

    .bom-cards {
        display: none;
    }
}

/* === Filter Toolbar Mobile === */
@media (max-width: 767px) {
    .filter-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .filter-group {
        flex-wrap: wrap;
    }

    .filter-search {
        max-width: none;
        width: 100%;
    }

    .filter-chip {
        padding: 0.5rem 0.875rem;
    }
}
