/* ============================================================
   TactiPrint3D — Foundation Layer (v58 · professional overhaul)
   Tokens, base, navigation, buttons, inputs, cards, tables,
   badges, modals, notifications, empty states, loading, theme.
   Identity/refinement rules live in design-system.css (loads after).
   No JS behavior changes. All existing element IDs preserved.
   ============================================================ */

/* ---- Design tokens ---- */
:root {
    /* surfaces */
    --bg-primary: #000000;
    --bg-secondary: #1C1C1E;
    --bg-tertiary: #2C2C2E;
    --bg-input: #0F0F10;
    --border-color: #38383A;
    --border-strong: #48484C;

    /* text */
    --text-primary: #FFFFFF;
    --text-secondary: #98989F;
    --text-tertiary: #7C7C84;

    /* brand accent (TactiPrint3D navy/blue) */
    --accent-primary: #42639C;
    --accent-text: #6A8CCE;
    --accent-hover: #4E70AE;
    --accent-tint: rgba(106, 140, 206, 0.14);
    --accent-ring: rgba(106, 140, 206, 0.22);

    /* status */
    --success: #30D158;
    --warning: #FF9F0A;
    --danger: #FF453A;

    /* chrome */
    --nav-bg: rgba(18, 18, 20, 0.82);
    --chart-text: #98989F;
    --chart-grid: #2C2C2E;

    /* spacing scale (4px base) */
    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
    --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;

    /* radius scale: one rule everywhere */
    --radius-xs: 8px;   /* chips, small controls */
    --radius-sm: 10px;  /* buttons, inputs */
    --radius-md: 14px;  /* cards, panels */
    --radius-lg: 18px;  /* modals */
    --radius-pill: 999px;

    --ease-premium: cubic-bezier(0.22, 1, 0.36, 1);
}
:root[data-theme="light"] {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F5F5F8;
    --bg-tertiary: #E9E9EE;
    --bg-input: #FFFFFF;
    --border-color: #DADAE0;
    --border-strong: #C2C2CB;
    --text-primary: #000000;
    --text-secondary: #55555E;
    --text-tertiary: #6D6D76;
    --accent-primary: #1A2B4A;
    --accent-text: #1A2B4A;
    --accent-hover: #0F1D33;
    --accent-tint: rgba(26, 43, 74, 0.07);
    --accent-ring: rgba(26, 43, 74, 0.16);
    --nav-bg: rgba(255, 255, 255, 0.85);
    --chart-text: #6D6D76;
    --chart-grid: #E9E9EE;
    --success: #34C759;
    --warning: #FF9500;
    --danger: #FF3B30;
}

/* ---- Reset & base ---- */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { width: 100%; }
body {
    font-family: 'Schibsted Grotesk', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    transition: background-color 0.3s ease, color 0.3s ease;
}
.hidden { display: none !important; }

/* ---- Icon system: ONE sprite, ONE stroke weight ----
   Every icon in the app is a <svg class="ic"><use href="#i-*"/></svg>
   reference to the single sprite defined in index.html. */
.ic {
    width: 18px; height: 18px; flex-shrink: 0;
    fill: none; stroke: currentColor; stroke-width: 1.75;
    stroke-linecap: round; stroke-linejoin: round;
}
.ic-nav { width: 16px; height: 16px; }
.ic-sm { width: 15px; height: 15px; }
.ic-xs { width: 12px; height: 12px; stroke-width: 2; }
.ic-lg { width: 22px; height: 22px; }

/* ---- Navbar ---- */
.navbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; height: 64px; width: 100%;
    background-color: var(--nav-bg);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky; top: 0; z-index: 1000;
}
.nav-left { display: flex; align-items: center; gap: 6px; }
.nav-brand { display: flex; align-items: center; gap: 12px; }
.brand-text { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text-primary); }
.accent-text { color: var(--accent-text); }
.nav-actions { display: flex; gap: 6px; align-items: center; }
.top-nav-links { display: flex; gap: 2px; flex: 1; justify-content: center; }
.nav-link {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 13px; border-radius: var(--radius-xs);
    color: var(--text-secondary); text-decoration: none;
    font-size: 0.875rem; font-weight: 500; cursor: pointer;
    transition: color 0.18s ease, background-color 0.18s ease;
    background: transparent; border: none; font-family: inherit; white-space: nowrap;
}
.nav-link .ic { color: var(--text-tertiary); transition: color 0.18s ease; }
.nav-link:hover { color: var(--text-primary); background-color: var(--bg-tertiary); }
.nav-link:hover .ic { color: var(--text-secondary); }
.nav-link.active { color: var(--accent-text); font-weight: 600; background-color: var(--accent-tint); }
.nav-link.active .ic { color: var(--accent-text); }

/* ---- Mobile drawer: hamburger navigation, phone-sized screens only ---- */
.btn-icon.hamburger-btn { display: none; }
.menu-overlay {
    position: fixed; inset: 0; z-index: 1500;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    opacity: 0; visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}
.menu-overlay.open { opacity: 1; visibility: visible; }
.menu-drawer {
    position: absolute; top: 0; left: 0; height: 100%; width: min(80vw, 300px);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    transform: translateX(-100%); transition: transform 0.26s var(--ease-premium);
    display: flex; flex-direction: column;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
}
.menu-overlay.open .menu-drawer { transform: translateX(0); }
.menu-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border-color); }
.menu-links { display: flex; flex-direction: column; padding: 10px; gap: 2px; overflow-y: auto; }
.menu-link {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; min-height: 48px; border-radius: var(--radius-sm);
    background: transparent; border: none; text-align: left;
    color: var(--text-primary); font-size: 0.95rem; font-weight: 550;
    font-family: inherit; cursor: pointer; width: 100%;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.menu-link .ic { color: var(--text-secondary); }
.menu-link:hover, .menu-link:active { background-color: var(--bg-tertiary); }
.menu-link.active { color: var(--accent-text); background-color: var(--accent-tint); }
.menu-link.active .ic { color: var(--accent-text); }

/* ---- Responsive top navigation: primary at every width ---- */
/* Tablet: compact icon-only center links (tooltips + aria-labels carry the names) */
@media (max-width: 1180px) {
    .nav-link span { display: none; }
    .nav-link { padding: 9px 11px; }
}

/* ---- Page shell ---- */
.main-content { max-width: 1280px; margin: 0 auto; padding: 28px 32px 88px; }
.page { display: none; animation: fadeIn 0.3s var(--ease-premium); }
.page.active { display: block; }
.page-title { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 22px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- Cards & grids ---- */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    display: flex; flex-direction: column;
    transition: border-color 0.2s ease, background-color 0.3s ease;
    min-width: 0;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; }
.card-header h3 { font-size: 0.72rem; color: var(--text-tertiary); font-weight: 650; text-transform: uppercase; letter-spacing: 0.07em; }
.card-body { flex-grow: 1; }

/* Stats */
.big-stat { font-size: 2.25rem; font-weight: 680; letter-spacing: -0.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.8rem; color: var(--text-tertiary); margin-top: 4px; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px; min-height: 40px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.875rem; font-weight: 600; font-family: inherit;
    cursor: pointer; text-decoration: none; white-space: nowrap;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
}
.btn .ic { width: 16px; height: 16px; }
.btn-primary {
    background-color: var(--accent-primary); color: #FFFFFF;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 1px 2px rgba(0, 0, 0, 0.18);
}
.btn-primary:hover { background-color: var(--accent-hover); }
.btn-secondary { background-color: var(--bg-tertiary); color: var(--text-primary); border-color: var(--border-color); }
.btn-secondary:hover { background-color: var(--border-color); }
.btn-ghost { background-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background-color: var(--bg-secondary); color: var(--text-primary); }
.btn-danger { background-color: transparent; color: var(--danger); border-color: rgba(255, 69, 58, 0.35); }
.btn-danger:hover { background-color: rgba(255, 69, 58, 0.1); }
.btn-large { width: 100%; min-height: 46px; padding: 11px 16px; font-size: 0.95rem; margin-top: 4px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn-row { display: flex; gap: 10px; align-items: center; }

.btn-icon {
    background: transparent; border: none; color: var(--text-secondary);
    cursor: pointer; padding: 8px; border-radius: var(--radius-xs);
    display: inline-flex; align-items: center; justify-content: center;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
}
.btn-icon:hover { color: var(--text-primary); background-color: var(--bg-tertiary); }
.btn-icon:active { transform: scale(0.94); }
.btn-icon svg { width: 20px; height: 20px; display: block; }
.modal-close-btn {
    background-color: var(--bg-tertiary); border: 1px solid var(--border-color);
    border-radius: 50%; width: 34px; height: 34px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
}
.modal-close-btn svg { width: 16px; height: 16px; }
.btn-export { padding: 6px; border-radius: var(--radius-xs); flex-shrink: 0; }
.btn-export svg { width: 17px; height: 17px; }
.btn-export:hover { color: var(--accent-text); }

/* Row-level action buttons (tables, spool cards) */
.btn-remove-spool, .btn-delete-row, .btn-edit-row {
    padding: 5px 10px; font-size: 0.75rem; font-weight: 600; font-family: inherit;
    border: 1px solid transparent; background: transparent; cursor: pointer;
    border-radius: var(--radius-xs); white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn-remove-spool, .btn-delete-row { color: var(--danger); border-color: rgba(255, 69, 58, 0.3); }
.btn-remove-spool:hover, .btn-delete-row:hover { background: rgba(255, 69, 58, 0.1); border-color: rgba(255, 69, 58, 0.55); }
.btn-edit-row { color: var(--accent-text); border-color: var(--accent-ring); background: var(--accent-tint); }
.btn-edit-row:hover { border-color: var(--accent-text); }
.btn-remove-spool:active, .btn-delete-row:active, .btn-edit-row:active { transform: scale(0.94); }
.row-actions { display: flex; gap: 6px; white-space: nowrap; }

/* ---- Inputs ---- */
.select-input, .search-input {
    width: 100%; min-height: 42px;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 12px; border-radius: var(--radius-sm);
    font-size: 0.925rem; font-family: inherit; outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.select-input:hover, .search-input:hover { border-color: var(--border-strong); }
.select-input:focus, .search-input:focus { border-color: var(--accent-text); box-shadow: 0 0 0 3px var(--accent-ring); }
.select-input:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---- Toolbars ---- */
.toolbar { margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar .search-input { flex: 1 1 220px; max-width: 440px; }
.toolbar .btn { flex-shrink: 0; }
.toolbar h3 { font-size: 1rem; font-weight: 650; letter-spacing: -0.01em; }

/* ---- Tables ---- */
.table-container {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left; padding: 10px 14px;
    font-size: 0.68rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-color); white-space: nowrap;
}
.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border-color); font-size: 0.875rem; white-space: nowrap; color: var(--text-secondary); }
.data-table td strong, .data-table td:first-child { color: var(--text-primary); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background-color 0.15s ease; }
.data-table tbody tr:hover td { background-color: color-mix(in srgb, var(--text-primary) 3%, transparent); }
/* numeric columns align right (fixed column orders per table) */
#inventoryTableBody td:nth-child(4), #inventoryTableBody td:nth-child(5), #inventoryTableBody td:nth-child(8),
#incomeTableBody td:nth-child(3), #expensesTableBody td:nth-child(4) { text-align: right; font-variant-numeric: tabular-nums; }
.data-table th:nth-child(4):not(:first-child) { text-align: left; }
.warning-text { color: var(--warning); display: flex; align-items: center; gap: 6px; }
#inventoryTableBody td.warning-text { justify-content: flex-end; }

/* ---- Badges & status ---- */
.status-badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: var(--radius-pill);
    font-size: 0.7rem; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap;
}
.status-active { background-color: rgba(48, 209, 88, 0.15); color: var(--success); }
.status-inactive { background-color: rgba(120, 120, 128, 0.16); color: var(--text-tertiary); }
.status-instock { background-color: rgba(48, 209, 88, 0.15); color: var(--success); }
.status-lowstock { background-color: rgba(255, 159, 10, 0.15); color: var(--warning); }
.status-outofstock { background-color: rgba(255, 69, 58, 0.14); color: var(--danger); }
.alert-list { display: flex; flex-direction: column; gap: 2px; }
.alert-item {
    font-size: 0.85rem; color: var(--text-secondary);
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 0; border-bottom: 1px solid var(--border-color); gap: 10px;
}
.alert-item:last-child { border-bottom: none; }
.alert-item strong { color: var(--text-primary); font-weight: 550; }
.alert-badge { padding: 3px 9px; border-radius: var(--radius-pill); font-size: 0.68rem; font-weight: 650; white-space: nowrap; }
.alert-badge.out { background: rgba(255, 69, 58, 0.14); color: var(--danger); }
.alert-badge.low { background: rgba(255, 159, 10, 0.15); color: var(--warning); }

/* PRO treatments */
.pro-badge {
    background: var(--accent-primary); color: #fff;
    font-size: 0.62rem; font-weight: 700; letter-spacing: 0.1em;
    padding: 3px 8px; border-radius: 6px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
.pro-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: var(--radius-pill);
    background: var(--accent-tint); color: var(--accent-text);
    border: 1px solid var(--accent-ring);
    font-size: 0.68rem; font-weight: 650; letter-spacing: 0.03em;
}

/* ---- Progress ---- */
.progress-track { width: 100%; height: 6px; background: var(--bg-tertiary); border-radius: var(--radius-pill); margin-top: 10px; margin-bottom: 10px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent-primary); border-radius: var(--radius-pill); transition: width 0.3s ease; }
.progress-fill.low { background: var(--danger); }

/* ---- Spool cards ---- */
.spool-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px; position: relative; min-width: 0;
}
.spool-color-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border-strong); margin-bottom: 10px; }
.spool-info { font-size: 0.825rem; color: var(--text-tertiary); margin-bottom: 4px; display: flex; justify-content: space-between; gap: 10px; }
.spool-info strong { color: var(--text-primary); font-weight: 550; text-align: right; }

/* ---- Filament grids ---- */
.active-spools-section { background-color: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 20px; margin-bottom: 20px; }
.active-spools-section h3 { margin-bottom: 14px; font-size: 0.95rem; font-weight: 650; }
.active-spools-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
.filament-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-top: 0; }

/* ---- Finance / form layouts ---- */
.form-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; margin-bottom: 16px; }
.stats-row-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.finance-charts-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; margin-bottom: 16px; align-items: stretch; }
.finance-tables { display: flex; flex-direction: column; gap: 16px; }
.form-card { background-color: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 20px; width: 100%; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 6px; font-weight: 550; }
.form-group small { display: block; margin-top: 6px; color: var(--text-tertiary); font-size: 0.75rem; line-height: 1.5; }
.status-card { background-color: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 20px; width: 100%; }
.status-item {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 11px 0; border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem; color: var(--text-tertiary);
}
.status-item:last-child { border-bottom: none; }
.status-item strong { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.status-item.status-item-emph { color: var(--text-secondary); }
.status-item.status-item-emph strong { color: var(--success); }

.success-state {
    margin-top: 12px; padding: 12px 14px;
    background-color: rgba(48, 209, 88, 0.09);
    border: 1px solid rgba(48, 209, 88, 0.3);
    border-radius: var(--radius-sm); text-align: center;
}
.success-state p { color: var(--text-primary); margin-bottom: 10px; font-size: 0.875rem; }

/* ---- Modals ---- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    display: flex; z-index: 1000; padding: 16px;
    overflow-y: auto; -webkit-overflow-scrolling: touch;
    animation: fadeIn 0.2s ease;
}
.modal-content {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%; max-width: 460px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
    animation: modalIn 0.28s var(--ease-premium);
    margin: auto; display: flex; flex-direction: column;
    max-height: calc(100vh - 2rem); max-height: calc(100dvh - 2rem);
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.96) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-header, .modal-footer { padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.modal-header { border-bottom: 1px solid var(--border-color); }
.modal-header h3 { font-size: 1rem; font-weight: 650; letter-spacing: -0.01em; }
.modal-footer { border-top: 1px solid var(--border-color); justify-content: flex-end; gap: 8px; }
.modal-body { padding: 18px 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---- Notifications ---- */
.notification-container {
    position: fixed; bottom: 20px; right: 20px; z-index: 2000;
    display: flex; flex-direction: column; gap: 8px;
    max-width: calc(100vw - 40px);
}
.notification {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: 11px 16px; border-radius: var(--radius-sm);
    font-size: 0.85rem; box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
    animation: slideIn 0.28s var(--ease-premium);
}
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

/* ---- Empty states ---- */
.empty-state-graphic { text-align: center; padding: 40px 24px; color: var(--text-tertiary); grid-column: 1 / -1; }
.empty-state-graphic .empty-state-icon { display: flex; justify-content: center; margin-bottom: 14px; }
.empty-state-graphic svg { width: 26px; height: 26px; color: var(--text-tertiary); opacity: 0.75; }
.empty-state-graphic .empty-state-title { font-size: 0.95rem; font-weight: 600; color: var(--text-secondary); }
.empty-state-graphic .empty-state-subtitle { font-size: 0.825rem; margin-top: 4px; line-height: 1.5; }
.empty-state-cta { margin-top: 16px; display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }

/* ---- Charts / printer frame ---- */
.chart-container { height: 260px; width: 100%; max-width: 100%; position: relative; overflow: hidden; }
.printer-container { height: 350px; width: 100%; border-radius: var(--radius-sm); overflow: hidden; background: #000; }
.printer-iframe { width: 100%; height: 100%; border: none; }
.printer-actions-row { padding: 14px 16px 16px; display: flex; gap: 10px; }

/* ---- Theme toggle ---- */
.theme-toggle-container { display: flex; align-items: center; gap: 12px; padding: 4px 0; color: var(--text-secondary); font-size: 0.875rem; }
.ios-switch { position: relative; display: inline-block; width: 51px; height: 31px; }
.ios-switch input { opacity: 0; width: 0; height: 0; }
.ios-switch .slider {
    position: absolute; cursor: pointer; inset: 0;
    background-color: var(--bg-tertiary); border: 1px solid var(--border-color);
    transition: 0.3s; border-radius: var(--radius-pill);
}
.ios-switch .slider:before {
    position: absolute; content: ""; height: 25px; width: 25px; left: 2px; bottom: 2px;
    background-color: white; transition: 0.3s; border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}
.ios-switch input:checked + .slider { background-color: var(--success); border-color: var(--success); }
.ios-switch input:checked + .slider:before { transform: translateX(20px); }

/* ---- Landing / sign-in shell (visual refinement lives in index.html <style>) ---- */
.onboarding-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--bg-primary); z-index: 3000;
    display: flex; align-items: center; justify-content: center; padding: 24px;
    overflow-y: auto; align-items: flex-start;
}
.onboarding-content { max-width: 400px; width: 100%; text-align: center; }

/* ---- Loading / error ---- */
.loading-overlay {
    position: fixed; inset: 0; z-index: 3000;
    background-color: var(--bg-primary);
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.3s ease;
}
.loading-overlay.hidden { display: none !important; }
.loading-content { text-align: center; padding: 32px; }
.spinner {
    width: 42px; height: 42px; margin: 0 auto 18px;
    border: 3px solid var(--bg-tertiary); border-top-color: var(--accent-text);
    border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text-secondary); font-size: 0.95rem; }
.loading-error { margin-top: 8px; }
.loading-error p { color: var(--text-primary); font-size: 0.95rem; margin-bottom: 16px; line-height: 1.5; }
.loading-error .btn { min-width: 140px; }

/* ---- Grid min-width guards (prevent overflow) ---- */
.form-container > .card, .stats-row-grid > .card, .finance-charts-grid > .card, .finance-tables > .card, .dashboard-grid > .card { min-width: 0; }
html, body { overscroll-behavior: none; }
.table-container { touch-action: pan-x; overscroll-behavior-x: contain; overscroll-behavior-y: contain; }
.modal-body, .menu-links { overscroll-behavior: contain; }

/* iOS date input fix */
input[type="date"].select-input { -webkit-appearance: none; appearance: none; display: block; width: 100%; min-width: 0; max-width: 100%; text-align: left; }
input[type="date"].select-input::-webkit-date-and-time-value { min-height: 1.5em; padding: 0; margin: 0; text-align: left; }

.navbar-logo { height: 38px; width: auto; display: block; border-radius: 8px; }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
    .main-content { padding: 24px 24px 72px; }
    .finance-charts-grid { grid-template-columns: 1fr; }
    .active-spools-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .navbar { padding: 0 14px; height: 62px; }
    .navbar-logo { height: 36px; }
    .brand-text { display: none; }
    .btn-icon.hamburger-btn { display: inline-flex; align-items: center; justify-content: center; }
    .top-nav-links { display: none; }
    .btn-icon { padding: 11px; }
    .btn-icon svg { width: 22px; height: 22px; }
    .main-content { padding: 18px 16px calc(36px + env(safe-area-inset-bottom)); }
    .page-title { font-size: 1.45rem; margin-bottom: 16px; }
    .dashboard-grid, .active-spools-grid, .filament-grid, .form-container, .stats-row-grid, .finance-charts-grid, .finance-tables { grid-template-columns: 1fr !important; display: grid !important; }
    .span-2, .span-3 { grid-column: span 1 !important; }
    .big-stat { font-size: 2rem; }
    .card { padding: 18px 16px; }
    .status-item { font-size: 0.95rem; padding: 12px 0; }
    .alert-item { font-size: 0.9rem; }
    .spool-info { font-size: 0.875rem; }
    .btn { min-height: 46px; padding: 12px 16px; font-size: 0.95rem; }
    .btn-large { min-height: 50px; }
    .btn-remove-spool, .btn-delete-row, .btn-edit-row { padding: 9px 13px; font-size: 0.85rem; }
    .select-input, .search-input { min-height: 46px; padding: 12px 14px; font-size: 1rem; }
    .chart-container { height: 240px !important; }
    .printer-container { height: 240px; }
    .notification-container { bottom: calc(16px + env(safe-area-inset-bottom)); left: 16px; right: 16px; max-width: none; }
    .btn-export { padding: 8px; }
    .btn-export svg { width: 19px; height: 19px; }
    .empty-state-graphic { padding: 32px 16px; }
    .toolbar { gap: 10px; }
    .toolbar .search-input { max-width: none; flex-basis: 100%; }
    .toolbar .btn { flex: 1; }
}
@media (max-width: 400px) {
    .active-spools-grid { grid-template-columns: 1fr; }
    .stats-row-grid { gap: 12px; }
    .btn { white-space: normal; }
}
