/* =========================================================
           THEME TOKENS
        ========================================================= */
:root[data-theme="dark"] {
    --bg: #0b0d12;
    --surface: #13161f;
    --surface2: #1a1e2b;
    --surface3: #222737;
    --border: #262d3f;
    --border2: #303850;
    --accent: #4f8ef7;
    --accent-hover: #3a7ef5;
    --accent2: #7c5cbf;
    --text: #e8eaf0;
    --text2: #9aa3b8;
    --muted: #5a6278;
    --green: #22c55e;
    --orange: #f59e0b;
    --red: #ef4444;
    --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --modal-bg: rgba(0, 0, 0, 0.75);
    --theme-icon: '☀️';
}

:root[data-theme="light"] {
    --bg: #f0f2f7;
    --surface: #ffffff;
    --surface2: #f5f7fc;
    --surface3: #eaecf4;
    --border: #dde1ee;
    --border2: #c8cde0;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent2: #7c3aed;
    --text: #111827;
    --text2: #4b5563;
    --muted: #9ca3af;
    --green: #16a34a;
    --orange: #d97706;
    --red: #dc2626;
    --card-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    --modal-bg: rgba(0, 0, 0, 0.5);
    --theme-icon: '🌙';
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

.mono {
    font-family: 'Space Mono', monospace;
}



/* Grid bg (dark only) */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 44px 44px;
    opacity: 0.25;
    pointer-events: none;
    transition: opacity 0.3s;
}

[data-theme="light"] body::before {
    opacity: 0.08;
}

.content {
    position: relative;
    z-index: 1;
}

/* NAV */
.nav-tab {
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    color: var(--text2);
}

.nav-tab.active {
    border-bottom-color: var(--accent);
    color: var(--accent);
}

.nav-tab:hover:not(.active) {
    color: var(--text);
    border-bottom-color: var(--border2);
}

/* CARDS */
.spool-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    transition: all 0.22s ease;
    position: relative;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    /* Ensures clicking is possible */
}


.spool-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--card-accent, var(--accent));
    opacity: 0;
    transition: opacity 0.22s;
}

.spool-card:hover {
    transform: translateY(-3px);
    border-color: var(--border2);
}

.spool-card:hover::before {
    opacity: 1;
}

.spool-card.low-stock {
    border-color: rgba(245, 158, 11, 0.35);
}

.spool-card.low-stock::before {
    background: var(--orange);
    opacity: 1;
}

.spool-card.empty {
    border-color: rgba(239, 68, 68, 0.2);
    opacity: 0.55;
}


/* STAT CARDS */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 24px;
    box-shadow: var(--card-shadow);
    transition: background 0.3s, border-color 0.3s;
}

/* BUTTONS */
.btn-primary {
    background: var(--accent);
    color: white;
    border-radius: 10px;
    font-weight: 700;
    font-size: 13px;
    padding: 10px 18px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-ghost {
    background: var(--surface2);
    color: var(--text2);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-weight: 700;
    font-size: 13px;
    padding: 10px 18px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--accent);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: 8px;
    font-weight: 700;
    font-size: 12px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* PROGRESS */
.progress-bg {
    background: var(--surface3);
    border-radius: 99px;
    height: 5px;
}

.progress-fill {
    border-radius: 99px;
    height: 5px;
    transition: width 0.6s ease;
}

/* CHART */
.chart-bar {
    border-radius: 6px 6px 0 0;
    transition: height 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    min-height: 4px;
}

/* TOAST */
#toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 600;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 320px;
    box-shadow: var(--card-shadow);
    color: var(--text);
}

#toast.show {
    transform: translateY(0);
    opacity: 1;
}

#toast.success {
    border-left: 4px solid var(--green);
}

#toast.error {
    border-left: 4px solid var(--red);
}

#toast.info {
    border-left: 4px solid var(--accent);
}

/* MODALS */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--modal-bg);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.open {
    display: flex;
}

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* TABLE */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--surface2);
}

.data-table th {
    padding: 13px 18px;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    text-align: left;
}

.data-table td {
    padding: 13px 18px;
    font-size: 14px;
    border-top: 1px solid var(--border);
    color: var(--text);
}

.data-table tr:hover td {
    background: var(--surface2);
}

/* COLOR CHIP */
.color-chip {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 2px solid rgba(128, 128, 128, 0.2);
    display: inline-block;
    flex-shrink: 0;
}

/* BADGE */
.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    font-family: 'Space Mono', monospace;
    letter-spacing: 0.03em;
}

/* SPINNER */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* FADE IN */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(14px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-up {
    animation: fadeUp 0.35s ease forwards;
}

/* HIDDEN */
.hidden {
    display: none !important;
}

/* INPUTS */
input[type=number],
input[type=text],
input[type=url],
select,
textarea {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: 'DM Sans', sans-serif;
    width: 100%;
    transition: border-color 0.2s, background 0.3s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

input::placeholder,
textarea::placeholder {
    color: var(--muted);
}

select option {
    background: var(--surface2);
    color: var(--text);
}

/* THEME TOGGLE */
.theme-toggle {
    width: 44px;
    height: 24px;
    background: var(--surface3);
    border: 1px solid var(--border);
    border-radius: 99px;
    cursor: pointer;
    position: relative;
    transition: all 0.3s;
    flex-shrink: 0;
}

.theme-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    transition: transform 0.3s;
}

[data-theme="light"] .theme-toggle::after {
    transform: translateX(20px);
}

/* ACTIONS ROW ON CARD */
.card-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* REORDER BADGE */
.reorder-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--orange);
    display: inline-block;
    animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(0.85);
    }
}

/* SEARCH AUTO INDICATOR */
.auto-link {
    font-size: 10px;
    color: var(--muted);
    font-family: 'Space Mono', monospace;
}

/* SECTION HEADER */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

/* CHECKBOXES */
.row-check {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.card-check-wrap {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.15s;
}

.select-mode .card-check-wrap,
.spool-card:hover .card-check-wrap {
    opacity: 1;
}

.spool-card.card-selected {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 2px rgba(79, 142, 247, 0.25), var(--card-shadow);
}

/* SELECTION TOOLBAR */
.sel-toolbar {
    position: sticky;
    bottom: 20px;
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--surface2);
    border: 1px solid var(--accent);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    margin-top: 20px;
    animation: fadeUp 0.2s ease;
}

/* SCROLLBAR */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 3px;
}