/* ===== CUSTOM FONTS ===== */
@font-face {
    font-family: 'morion-semibold';
    font-weight: 600;
    font-style: normal;
    font-display: swap;
    src: url('fonts/Morion-Semibold.woff2') format('woff2');
}

@font-face {
    font-family: 'acuminprowide-light';
    font-weight: 300;
    font-style: normal;
    font-display: swap;
    src: url('fonts/acuminprowide-light-webfont.woff2') format('woff2'),
        url('fonts/acuminprowide-light-webfont.woff') format('woff');
}

/* ===== DESIGN TOKENS ===== */
:root {
    --bg-dark: #f0eeec;
    --bg-panel: rgba(255, 255, 255, 0.92);
    --border-glass: rgba(0, 0, 0, 0.09);
    --text-main: #0f172a;
    --text-muted: #64748b;
    --accent-primary: #E6530F;
    --accent-gradient: linear-gradient(135deg, #E6530F 0%, #f97316 100%);
    --accent-red: #ef4444;
    --accent-red-hover: #dc2626;
    --card-shadow: 0 4px 24px 0 rgba(0, 0, 0, 0.04);
    --positive: #16a34a;
    --fx-color: #E6530F;
    --sidebar-width: 210px;
    --sidebar-collapsed: 68px;
    --header-height: 90px;
    font-family: 'acuminprowide-light', sans-serif;
}

/* Tabular nums for all dynamic number displays */
[data-calc],
[data-bd],
[data-calc-sheet],
.total-cost-value,
.spreadsheet-cost-cell,
.yarn-final-price,
.cost-val,
.bd-val,
.tier-price,
.calc-header-weight,
.yarn-cost-display strong,
.yarn-weight-info strong,
input[type="number"],
.data-table input[type="text"][readonly] {
    font-variant-numeric: tabular-nums;
}

body.dark-mode {
    --bg-dark: #1a1a1a;
    --bg-panel: rgba(28, 28, 30, 0.92);
    --border-glass: rgba(255, 255, 255, 0.08);
    --text-main: #f5f5f4;
    --text-muted: #a8a29e;
    --accent-primary: #f97316;
    --accent-gradient: linear-gradient(135deg, #f97316 0%, #fb923c 100%);
    --accent-red: #ff4757;
    --accent-red-hover: #ff6b81;
    --card-shadow: 0 4px 24px 0 rgba(0, 0, 0, 0.25);
    --positive: #22c55e;
    --fx-color: #fdba74;
}

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

html {
    overflow-x: hidden;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'acuminprowide-light', sans-serif;
    line-height: 1.5;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

h1,
h2,
h3,
h4 {
    font-family: 'acuminprowide-light', sans-serif;
    letter-spacing: -0.02em;
}

/* Hide number input arrows */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.hidden {
    display: none !important;
}

/* ===== HEADER ===== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 300;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-glass);
    transition: background-color 0.3s;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.3rem 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.header-actions {
    position: absolute;
    right: 2rem;
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-logo {
    height: auto;
    max-height: 80px;
}

/* Light mode: show blue logo */
.nav-logo-light {
    display: none;
}

.nav-logo-dark {
    display: inline;
}

/* Dark mode: show orange logo */
body.dark-mode .nav-logo-light {
    display: inline;
}

body.dark-mode .nav-logo-dark {
    display: none;
}


/* ===== SIDEBAR ===== */
.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: var(--sidebar-width, 240px);
    z-index: 200;
    display: flex;
    flex-direction: column;
    background: #E1D9D1;
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-right: 1px solid var(--border-glass);
    transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        background-color 0.3s;
    overflow-x: clip;
    overflow-y: hidden;
}

body.dark-mode .sidebar {
    background: rgba(22, 22, 24, 0.92);
}

body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed, 68px);
    overflow-x: visible;
}

/* --- Toggle button --- */
.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin: 0.75rem auto 0.5rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.25s;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-main);
}

body.dark-mode .sidebar-toggle {
    background: transparent;
}

body.dark-mode .sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-toggle-icon {
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed .sidebar-toggle-icon {
    transform: rotate(180deg);
}

/* --- Sidebar buttons (shared) --- */
.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: calc(100% - 1rem);
    margin: 2px 0.5rem;
    padding: 0.55rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: 10px;
    color: var(--text-main);
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.95rem;
    font-weight: 400;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
}

.sidebar-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-main);
}

body.dark-mode .sidebar-btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

.sidebar-btn-icon {
    width: 24px;
    height: 24px;
    min-width: 24px;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.sidebar-label {
    opacity: 1;
    transition: opacity 0.2s 0.1s, transform 0.3s;
    transform: translateX(0);
    font-family: 'morion-semibold', 'acuminprowide-light', sans-serif;
    font-weight: 600;
    text-transform: uppercase;
}

body.sidebar-collapsed .sidebar-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
    transition: opacity 0.15s, width 0.2s;
    pointer-events: none;
}

.sidebar-count {
    margin-left: auto;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-secondary, #64748b);
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
    flex-shrink: 0;
}

.sidebar-count:empty {
    display: none;
}

body.dark-mode .sidebar-count {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.6);
}

.sidebar-nav .tab-btn.active .sidebar-count {
    background: #E6530F;
    color: #fff;
}

body.dark-mode .sidebar-nav .tab-btn.active .sidebar-count {
    background: rgba(230, 83, 15, 0.3);
    color: #fb923c;
}

body.sidebar-collapsed .sidebar-count {
    display: none;
}

body.sidebar-collapsed .sidebar-btn {
    justify-content: center;
    gap: 0;
    padding: 0.55rem;
    width: calc(100% - 0.75rem);
    margin: 2px auto;
}

/* Active nav item */
.sidebar-nav .tab-btn.active {
    color: var(--accent-primary);
    background: rgba(230, 83, 15, 0.08);
    font-weight: 500;
}

.sidebar-nav .tab-btn.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    border-radius: 0 3px 3px 0;
    background: var(--accent-primary);
    transition: height 0.2s;
}

body.dark-mode .sidebar-nav .tab-btn.active {
    background: rgba(249, 115, 22, 0.1);
}

body.dark-mode .sidebar-nav .tab-btn img {
    filter: invert(1) hue-rotate(180deg);
}

body.dark-mode .section-header h2 img,
body.dark-mode .section-header h2 lottie-player {
    filter: brightness(0) invert(1);
}

.sidebar-nav .tab-btn.active img {
    filter: none;
}


/* --- Divider --- */
.sidebar-divider {
    height: 1px;
    margin: 0.5rem 1rem;
    background: var(--border-glass);
    flex-shrink: 0;
}

/* --- Sidebar sections --- */
.sidebar-top {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
}

.sidebar-top::-webkit-scrollbar {
    display: none;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.sidebar-bottom {
    flex-shrink: 0;
    padding-bottom: 0.5rem;
}

body.sidebar-collapsed .sidebar-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
}

body.sidebar-collapsed .sidebar-divider {
    align-self: stretch;
}

/* --- Theme toggle icons --- */
.icon-theme-sun {
    display: none;
}

.icon-theme-moon {
    display: block;
}

body.dark-mode .icon-theme-sun {
    display: block;
    filter: invert(1);
}

body.dark-mode .icon-theme-moon {
    display: none;
}

/* --- Sidebar theme button --- */
.sidebar-theme-btn {
    margin-bottom: 4px;
}

.sidebar-theme-btn .sidebar-btn-icon {
    width: 18px;
    height: 18px;
    min-width: 18px;
}

/* Invert black SVG icons in dark mode */
body.dark-mode .btn-section-info img {
    filter: invert(1);
}

body.dark-mode .section-action-bar lottie-player {
    filter: invert(1) hue-rotate(180deg);
}

body.dark-mode .ai-fab lottie-player,
body.dark-mode .sidebar-nav lottie-player {
    filter: invert(1) hue-rotate(180deg);
}

/* --- User section --- */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.6rem 0.75rem;
    margin: 0.25rem 0.5rem 0;
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.2s;
}

body.sidebar-collapsed .sidebar-user {
    justify-content: center;
    padding: 0.55rem;
    margin: 2px 0 0;
    width: 100%;
    gap: 0;
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    opacity: 1;
    transition: opacity 0.2s 0.1s;
}

body.sidebar-collapsed .sidebar-user-info {
    opacity: 0;
    pointer-events: none;
    width: 0;
    transition: opacity 0.15s;
}

.sidebar-user-name {
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-logout-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.82rem;
    letter-spacing: 0.3px;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s;
}

.sidebar-logout-btn:hover {
    color: var(--accent-red);
}

/* --- Admin tabs --- */
.admin-tab {
    display: none;
}

.admin-tab.visible {
    display: flex;
}

/* --- btn-icon-only (still used inside main content) --- */
.btn-icon-only {
    background: transparent;
    border: none;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon-only:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.dark-mode .btn-icon-only:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* ===== MAIN CONTENT ===== */
.app-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
    padding-top: calc(1.5rem + 90px);
    /* account for fixed header */
    margin-left: var(--sidebar-width, 240px);
    transition: margin-left 0.35s cubic-bezier(0.4, 0, 0.2, 1),
        max-width 0.3s;
}

body.sidebar-collapsed .app-main {
    margin-left: var(--sidebar-collapsed, 68px);
}

.app-main.spreadsheet-mode-active {
    max-width: 98%;
}

/* Tab content */
.tab-content {
    display: none;
    animation: fadeIn 0.2s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

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

/* Section headers — now inside action bar */
.section-header {
    display: none;
}

.section-title-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.btn-section-info {
    color: var(--text-muted);
    opacity: 0.6;
    transition: opacity 0.15s, color 0.15s;
    flex-shrink: 0;
}

.btn-section-info:hover {
    opacity: 1;
    color: var(--accent-primary);
}

.section-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Title group inside action bar */
.section-action-bar .section-title-group h2 {
    font-family: 'morion-semibold', 'acuminprowide-light', sans-serif;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

/* Vertical divider between title and buttons */
.action-bar-divider {
    width: 1px;
    align-self: stretch;
    background: var(--border-glass);
    margin: 0.1rem 0.25rem;
    flex-shrink: 0;
}

.section-action-bar .view-toggle-group {
    flex-shrink: 0;
}

/* ===== SECTION ACTION BAR ===== */
.section-action-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 2rem;
    margin-bottom: 1rem;
    background: rgba(240, 238, 236, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-glass);
    position: sticky;
    top: var(--header-height);
    z-index: 150;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    flex-wrap: nowrap;
    white-space: nowrap;
    /* Break out of .app-main max-width to span full viewport width minus sidebar */
    width: calc(100vw - var(--sidebar-width, 240px));
    margin-left: calc(-2rem);
    margin-top: -1.5rem;
}

body.sidebar-collapsed .section-action-bar {
    width: calc(100vw - var(--sidebar-collapsed, 68px));
}

body.dark-mode .section-action-bar {
    background: rgba(28, 28, 30, 0.88);
}

.section-action-bar.hidden {
    display: none;
}

.btn-save-action {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.9rem;
    border-radius: 8px;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid var(--border-glass);
    background: transparent;
    color: var(--text-muted);
    cursor: default;
    transition: all 0.2s;
}

.btn-save-action .icon-save {
    width: 18px;
    height: 18px;
}

.btn-save-action.dirty {
    color: white;
    background: var(--accent-red);
    border-color: var(--accent-red);
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.3);
    cursor: pointer;
    animation: pulseRed 2s infinite;
}

.btn-save-action.dirty:hover {
    background: var(--accent-red-hover);
    transform: translateY(-1px);
}

.view-toggle-group {
    display: flex;
    gap: 2px;
    margin-left: 0.75rem;
    align-items: center;
}

.fabric-code-filter-wrap {
    position: relative;
    margin-left: 0.5rem;
    display: flex;
    align-items: center;
}

.fabric-code-filter {
    padding: 0.3rem 1.6rem 0.3rem 0.5rem;
    border: 1px dashed var(--accent-primary);
    border-radius: 8px;
    background: var(--bg-dark);
    color: var(--text-main);
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.8rem;
    width: 110px;
    outline: none;
}


.fabric-code-filter::placeholder {
    color: #000;
    opacity: 0.5;
}

body.dark-mode .fabric-code-filter::placeholder {
    color: #fff;
    opacity: 0.7;
}

.fabric-code-filter-clear {
    position: absolute;
    right: 6px;
    display: none;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.fabric-code-filter-clear:hover {
    color: var(--accent-primary);
}

.fabric-code-filter-wrap.has-value .fabric-code-filter-clear {
    display: flex;
}

.view-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.view-toggle-btn:hover {
    background: var(--hover-bg, rgba(0, 0, 0, 0.06));
    color: var(--text);
}

.view-toggle-btn.active {
    background: rgba(128, 128, 128, 0.2);
    border-color: var(--text);
    color: var(--text);
}

body.dark-mode .view-toggle-btn.active {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.6);
    color: #fff;
}

/* ===== LOADING ===== */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    color: var(--text-muted);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-glass);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* ===== BUTTONS ===== */
.btn-add-small {
    display: inline-flex;
    align-items: center;
    background: rgba(230, 83, 15, 0.08);
    color: var(--accent-primary);
    border: 1px dashed var(--accent-primary);
    padding: 0.35rem 0.9rem;
    border-radius: 8px;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.01em;
}

.btn-add-small:hover {
    background: var(--accent-primary);
    color: white;
    border-style: solid;
}

.section-action-bar .btn-secondary {
    background: transparent;
}

.btn-secondary {
    background: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--border-glass);
    padding: 0.35rem 0.9rem;
    border-radius: 8px;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.dark-mode .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.06);
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    border: none;
    padding: 0.4rem 0.9rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Save Button (now in sidebar — base styles handled there) */

@keyframes pulseRed {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    70% {
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* ===== GLASS CARD ===== */
.card-glass {
    background: var(--bg-panel);
    border: 1px solid var(--border-glass);
    border-radius: 16px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

/* ===== TABLES ===== */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.data-table th,
.data-table td {
    padding: 0.45rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border-glass);
}

.data-table th {
    background: rgba(0, 0, 0, 0.04);
    font-family: 'acuminprowide-light', sans-serif;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

body.dark-mode .data-table th {
    background: rgba(255, 255, 255, 0.04);
}

.data-table tbody tr:hover {
    background: rgba(0, 0, 0, 0.04);
}

body.dark-mode .data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

.data-table th.sortable:hover {
    background: rgba(0, 0, 0, 0.07);
    color: var(--text-main);
}

body.dark-mode .data-table th.sortable:hover {
    background: rgba(255, 255, 255, 0.06);
}

.sort-icon {
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 4px;
    vertical-align: middle;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    opacity: 0.3;
}

.sortable.asc .sort-icon {
    border-bottom: 5px solid currentColor;
    border-top: none;
    opacity: 1;
}

.sortable.desc .sort-icon {
    border-top: 5px solid currentColor;
    border-bottom: none;
    opacity: 1;
}

.data-table td {
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.9rem;
}

.data-table input {
    background: transparent;
    border: 1px dashed transparent;
    color: var(--text-main);
    padding: 0.1rem 0.2rem;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.9rem;
    width: 60px;
    transition: all 0.15s;
}

.data-table input[data-field="supplier"],
.data-table input[data-field="composition"] {
    width: 140px;
}

.data-table input:hover,
.data-table input:focus {
    border-color: var(--accent-primary);
    background: rgba(0, 0, 0, 0.02);
    border-radius: 4px;
    outline: none;
}

body.dark-mode .data-table input:hover,
body.dark-mode .data-table input:focus {
    background: rgba(255, 255, 255, 0.04);
}

/* ===== FABRIC CARDS ===== */
.fabrics-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    align-items: start;
}

.fabric-card {
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s;
}

.fabric-card:hover {
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.08);
}

body.dark-mode .fabric-card:hover {
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.3);
}

/* Fabric Header — compact summary line */
.fabric-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: stretch;
    padding: 0.5rem 0.7rem;
    gap: 0.8rem;
    cursor: default;
    min-height: 48px;
}

.fabric-header-left {
    display: flex;
    align-items: flex-start;
    align-self: flex-start;
    gap: 0.5rem;
    flex: 0 1 auto;
    min-width: 0;
}

.drag-handle {
    cursor: grab;
    font-size: 1.3rem;
    color: var(--text-muted);
    user-select: none;
    opacity: 0.5;
    transition: opacity 0.2s;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.drag-handle:hover {
    opacity: 1;
}

.drag-handle:active {
    cursor: grabbing;
}

.btn-collapse {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    border-radius: 6px;
    transition: background 0.2s;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
}

.btn-collapse:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.dark-mode .btn-collapse:hover {
    background: rgba(255, 255, 255, 0.08);
}

.icon-chevron {
    transition: transform 0.2s;
}

.fabric-card.closed .icon-chevron {
    transform: rotate(180deg);
}

/* Summary info line */
.fabric-summary-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
}

.fabric-code {
    font-family: 'acuminprowide-light', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent-primary);
}

.fabric-sep {
    color: var(--border-glass);
    font-size: 1.1rem;
}

.fabric-desc {
    font-weight: 500;
    font-size: 0.9rem;
}

.fabric-comp {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.fabric-weight-badge {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-muted);
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    white-space: nowrap;
    margin-left: 0.3rem;
}

body.dark-mode .fabric-weight-badge {
    background: rgba(255, 255, 255, 0.06);
}

.fabric-left-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    flex-shrink: 0;
}

.fabric-nav-btns {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* Header center — cost display */
.fabric-header-center {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-shrink: 0;
    align-self: center;
}

/* Inline editable inputs in the header */
.header-inline-input {
    text-align: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-main);
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.9rem;
    padding: 0.15rem 0.4rem;
    outline: none;
    transition: all 0.15s;
    width: 220px;
    max-width: 100%;
}

.header-inline-input:hover {
    border-color: var(--accent-primary);
    border-style: dashed;
}

.header-inline-input:focus {
    border-color: var(--accent-primary);
    background: rgba(0, 0, 0, 0.03);
}

body.dark-mode .header-inline-input:focus {
    background: rgba(255, 255, 255, 0.04);
}

.header-code {
    font-family: 'acuminprowide-light', sans-serif;
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent-primary);
}

.header-desc {
    font-weight: 500;
}

.header-comp {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.fabric-cost-display {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
    background: rgba(230, 83, 15, 0.06);
    padding: 0.3rem 0.5rem;
    border-radius: 10px;
    border: 1px solid rgba(230, 83, 15, 0.12);
    min-width: 120px;
}

.cost-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    justify-content: flex-start;
}

.cost-row+.cost-row {
    border-left: 1px solid rgba(230, 83, 15, 0.25);
    padding-left: 0.6rem;
}

body.dark-mode .cost-row+.cost-row {
    border-left-color: rgba(249, 115, 22, 0.3);
}

body.dark-mode .fabric-cost-display {
    background: rgba(249, 115, 22, 0.08);
    border-color: rgba(249, 115, 22, 0.15);
}

.meters-input {
    width: 44px;
    background: transparent;
    border: 1px dashed var(--border-glass);
    color: var(--text-main);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1;
    text-align: right;
    -moz-appearance: textfield;
    appearance: textfield;
}

.meters-input:hover {
    border-color: var(--accent-primary);
    border-style: dashed;
}

.meters-input:focus {
    border-color: var(--accent-primary);
    outline: none;
}

.meters-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 0.2rem;
}

.total-cost-value {
    font-family: 'Inter', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent-primary);
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1;
    min-width: 4.5rem;
    display: inline-block;
    text-align: right;
}

.cost-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
}

.fabric-header-btns {
    display: flex;
    gap: 2px;
}

.btn-icon-small {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
}

.btn-icon-small:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.dark-mode .btn-icon-small:hover {
    background: rgba(255, 255, 255, 0.06);
}

.btn-delete-fabric {
    color: var(--accent-red);
}

.btn-delete-fabric:hover {
    background: rgba(239, 68, 68, 0.08) !important;
}

/* ===== FABRIC BODY (expanded) ===== */
.fabric-body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    border-top: 1px solid var(--border-glass);
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Header breakdown wrapper */
.fabric-header-breakdown {
    display: flex;
    align-items: center;
    flex: 1 1 20rem;
    min-width: 0;
    padding: 0;
    overflow-x: auto;
}

/* Cost Breakdown Bar */
.cost-breakdown-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.15rem 0.5rem;
    font-size: 0.75rem;
    font-family: 'acuminprowide-light', sans-serif;
    background: rgba(0, 0, 0, 0.025);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 8px;
    padding: 0.3rem 0.5rem;
    width: 470px;
    flex-shrink: 0;
}

body.dark-mode .cost-breakdown-bar {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.07);
}

.cost-breakdown-bar .bd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.2rem;
    white-space: nowrap;
}

.cost-breakdown-bar .bd-label {
    color: var(--text-muted);
    font-weight: 500;
    font-family: 'acuminprowide-light', sans-serif;
}

.cost-breakdown-bar .bd-val {
    color: var(--accent-primary);
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum' 1;
}

/* Tech Specs */
.tech-spec-header-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 0.5rem;
}

.tech-spec-header-area h4 {
    margin: 0;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 1rem;
    color: var(--text-muted);
}

.edit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
    gap: 0.6rem;
}

.edit-grid .input-group--wide {
    grid-column: span 2;
}

.edit-grid .input-wrapper,
.edit-grid select.input-wrapper {
    border-style: dashed;
}

.edit-grid .input-wrapper:hover,
.edit-grid select.input-wrapper:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(230, 83, 15, 0.08);
}

.edit-grid .input-wrapper input,
.edit-grid .input-wrapper select,
.edit-grid select.input-wrapper {
    font-size: 0.9rem;
}

.edit-grid .input-wrapper input[data-field="warping_mt"],
.edit-grid .input-wrapper input[data-field="weaving_mt"],
.edit-grid .input-wrapper input[data-field="finishing_mt"],
.edit-grid .input-wrapper input[data-field="mending_factor"],
.edit-grid .input-wrapper input[data-field="pinzatura_factor"] {
    font-family: 'acuminprowide-light', sans-serif;
}

.calc-content input[type="number"],
.header-weight-display strong {
    font-family: 'acuminprowide-light', sans-serif;
}

#budget-articles-table .param-input {
    padding: 0.1rem 0.2rem;
    border: 1px dashed #bbb;
    background: transparent;
}

#budget-articles-table .budget-meters-input,
#budget-articles-table .budget-commission-input {
    padding: 0 0.2rem;
    font-size: 0.9rem;
    font-weight: 400;
    font-family: 'acuminprowide-light', sans-serif;
}

#budget-articles-table .param-input:hover,
#budget-articles-table .param-input:focus {
    border-color: var(--accent-primary);
    outline: none;
}

#budget-articles-table .budget-margin-val-cell,
#budget-articles-table .budget-margin-pct-cell,
#budget-articles-table .budget-total-cell {
    font-family: 'acuminprowide-light', sans-serif;
}

/* ===== INPUT GROUPS ===== */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.input-group label {
    font-size: 0.8rem;
    font-family: 'acuminprowide-light', sans-serif;
    color: var(--text-muted);
    font-weight: 500;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    transition: all 0.15s;
}

body.dark-mode .input-wrapper {
    background-color: rgba(255, 255, 255, 0.03);
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(230, 83, 15, 0.12);
}

.input-wrapper input,
.input-wrapper select,
select.input-wrapper {
    background: transparent;
    border: none;
    padding: 0.1rem 0.2rem;
    color: var(--text-main);
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.9rem;
    width: 100%;
    outline: none;
    -moz-appearance: textfield;
    appearance: textfield;
}

select.input-wrapper {
    border: 1px solid var(--border-glass);
}

.input-wrapper select,
select.input-wrapper {
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23666%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 0.6rem auto;
    padding-right: 1.8rem;
    cursor: pointer;
    background-color: rgba(0, 0, 0, 0.02);
}

body.dark-mode .input-wrapper select,
body.dark-mode select.input-wrapper {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23e0e0e0%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-color: rgba(255, 255, 255, 0.04);
}

.input-wrapper select option,
select.input-wrapper option {
    background: var(--bg-dark);
    color: var(--text-main);
}

.input-wrapper .unit {
    color: var(--text-muted);
    font-size: 0.75rem;
    padding-right: 0.7rem;
    user-select: none;
    font-weight: 500;
}

.input-wrapper.disabled {
    opacity: 0.5;
}

.inline-input {
    width: 90px;
}

.param-table .inline-input {
    width: 100%;
}

.inline-input input {
    padding: 0.1rem 0.2rem;
    text-align: right;
}

/* Settings checkboxes */
.settings-checks {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-top: 0.15rem;
}

.check-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.82rem;
    cursor: pointer;
    color: var(--text-main);
}

/* ===== YARN BLOCKS ===== */
#yarns-table input[type="number"],
#yarns-table input[data-field="price_kg"],
#yarns-table .yarn-final-price input,
#yarns-table .yarn-real-s {
    font-family: 'acuminprowide-light', sans-serif;
}

#yarns-table th {
    text-align: center;
}

#yarns-table td:has(input[data-field="price_kg"]),
#yarns-table .yarn-final-price {
    text-align: right;
}

#yarns-table .yarn-final-price input {
    text-align: right;
}

.yarns-master-container {
    background: rgba(0, 0, 0, 0.015);
    border: 1px dashed var(--border-glass);
    border-radius: 12px;
    padding: 1rem;
    margin-top: 0.5rem;
}

body.dark-mode .yarns-master-container {
    background: rgba(255, 255, 255, 0.015);
}

.yarns-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.yarns-header-flex h4 {
    margin: 0;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 1rem;
}


.fabric-yarns-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.yarn-block {
    background: var(--bg-panel);
    border: 1px solid var(--border-glass);
    border-radius: 10px;
    padding: 1rem;
    box-shadow: var(--card-shadow);
}

body.dark-mode .yarn-block {
    background: rgba(255, 255, 255, 0.02);
}

.yarn-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px dashed var(--border-glass);
}

.yarn-selector {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    outline: none;
}

body.dark-mode .yarn-selector {
    background: rgba(255, 255, 255, 0.05);
}

.yarn-selector:focus {
    border-color: var(--accent-primary);
}

.yarn-cost-display {
    font-family: 'acuminprowide-light', sans-serif;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
}

.yarn-cost-display strong {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.yarn-weight-info strong {
    font-size: 1rem;
    color: var(--text-main);
}

.yarn-cost-display .divider {
    color: var(--border-glass);
}

.btn-remove-yarn {
    background: transparent;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
    font-size: 1rem;
}

.btn-remove-yarn:hover {
    opacity: 1;
}

.yarn-calculations-flex {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Calc boxes */
.calc-box {
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--border-glass);
    border-radius: 10px;
    overflow: hidden;
}

body.dark-mode .calc-box {
    background: rgba(0, 0, 0, 0.12);
}

.collapsible-box.closed .icon-chevron {
    transform: rotate(-90deg);
}

.calc-header {
    padding: 0.6rem 1rem;
    font-family: 'acuminprowide-light', sans-serif;
    font-weight: 600;
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    width: 100%;
    border: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    text-align: left;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.02);
    transition: background 0.15s;
}

.calc-header:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.dark-mode .calc-header {
    background: rgba(255, 255, 255, 0.02);
}

body.dark-mode .calc-header:hover {
    background: rgba(255, 255, 255, 0.04);
}

.warp-header {
    color: #6366f1;
}

body.dark-mode .warp-header {
    color: #818cf8;
}

.weft-header {
    color: #ec4899;
}

body.dark-mode .weft-header {
    color: #f472b6;
}

.calc-content {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.calc-content.horizontal-inputs {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
}

.calc-content.horizontal-inputs .input-group {
    flex: 1;
    min-width: 80px;
}

.calc-header-weight {
    font-variant-numeric: tabular-nums;
}

/* ===== PARAMETERS ===== */
.parameters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.25rem;
}

.parameter-card {
    display: flex;
    flex-direction: column;
    overflow: visible;
    transition: all 0.2s;
}

.parameter-card.closed .card-body {
    display: none;
}

.parameter-card .card-body {
    overflow-x: auto;
}

.parameter-card .card-header {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.025);
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border-glass);
}

body.dark-mode .parameter-card .card-header {
    background: rgba(255, 255, 255, 0.025);
}

.parameter-card .card-header h4 {
    margin: 0;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: 0.06em;
}

.param-chevron {
    transition: transform 0.2s;
}

.param-table th,
.param-table td {
    padding: 0.5rem 0.75rem;
    vertical-align: middle;
    font-family: 'acuminprowide-light', sans-serif;
}

.param-table td {
    border-top: 1px solid var(--border-glass);
}

#finishing-table td {
    max-width: 0;
}

#finishing-table .param-input {
    width: calc(100% - 4px);
}

.param-input[type="number"],
#defaultMetersInput {
    font-family: 'acuminprowide-light', sans-serif;
}

.param-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.3rem 0.5rem;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.85rem;
    border: 1px solid var(--border-glass);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.02);
    color: var(--text-main);
    transition: all 0.15s;
}

body.dark-mode .param-input {
    background: rgba(255, 255, 255, 0.04);
}

.param-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(230, 83, 15, 0.1);
}

.param-text {
    min-width: 0;
}

.param-label-bold {
    font-weight: 500;
    color: var(--text-main);
}

/* ===== SPREADSHEET ===== */
.spreadsheet-table {
    border-collapse: collapse;
    width: 100%;
}

.spreadsheet-table td {
    padding: 0.25rem 0.5rem;
    vertical-align: middle;
}

.spreadsheet-table input,
.spreadsheet-table select {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    padding: 0.1rem 0.2rem;
    color: var(--text-main);
    font-size: 0.85rem;
    transition: all 0.15s;
}

.spreadsheet-table input:hover,
.spreadsheet-table select:hover,
.spreadsheet-table input:focus,
.spreadsheet-table select:focus {
    border-color: var(--accent-primary);
    border-style: dashed;
    background: rgba(0, 0, 0, 0.02);
    outline: none;
}

body.dark-mode .spreadsheet-table input:hover,
body.dark-mode .spreadsheet-table select:hover,
body.dark-mode .spreadsheet-table input:focus,
body.dark-mode .spreadsheet-table select:focus {
    background: rgba(255, 255, 255, 0.04);
}

#fabrics-spreadsheet-table input[type="number"],
#fabrics-spreadsheet-table select[data-field="weaving_price_id"],
#fabrics-spreadsheet-table select[data-field="finishing_price_id"] {
    font-family: 'acuminprowide-light', sans-serif;
}

#fabrics-spreadsheet-table th {
    text-align: center;
}

#fabrics-spreadsheet-table td.spreadsheet-cost-cell {
    font-weight: 700;
    font-family: 'acuminprowide-light', sans-serif;
    color: var(--accent-primary);
    font-size: 0.9rem;
    white-space: nowrap;
    text-align: right;
    padding-right: 0.8rem !important;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 1rem 0;
    box-sizing: border-box;
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border-glass);
    border-radius: 14px;
    box-shadow: var(--card-shadow);
    width: 90%;
    max-width: 600px;
    max-height: calc(100vh - 2rem);
    padding: 1.5rem;
    font-family: 'acuminprowide-light', sans-serif;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-glass);
    padding-bottom: 0.75rem;
}

.modal-header h2 {
    font-family: 'acuminprowide-light', sans-serif;
    font-weight: 300;
    font-size: 1.6rem;
    letter-spacing: 0.02em;
}

.modal-body {
    overflow-y: auto;
    flex: 1;
}

.modal-body h3 {
    margin-top: 1.25rem;
    margin-bottom: 0.4rem;
    font-size: 1.15rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: var(--accent-primary);
}

.modal-body ul {
    list-style-type: disc;
    padding-left: 1.5rem;
    color: var(--text-muted);
}

.modal-body li {
    margin-bottom: 0.4rem;
    font-size: 1.05rem;
}

.modal-body code {
    background: rgba(0, 0, 0, 0.04);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.88rem;
    font-weight: 400;
    letter-spacing: 0.01em;
    color: var(--text-main);
}

body.dark-mode .modal-body code {
    background: rgba(255, 255, 255, 0.08);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .yarn-calculations-flex {
        grid-template-columns: 1fr;
    }

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

    .fabric-summary-info {
        font-size: 0.8rem;
    }

    .fabric-cost-display {
        padding: 0.3rem 0.6rem;
    }
}

@media (max-width: 600px) {
    .app-main {
        padding: 1rem;
        padding-top: calc(1rem + 90px);
    }

    .section-action-bar {
        margin-top: -1rem;
        margin-left: -1rem;
    }

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

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

    .fabric-header {
        padding: 0.4rem 0.5rem;
        gap: 0.5rem;
    }

    .fabric-header-left {
        min-width: 0;
        flex: 0 1 auto;
    }

    .header-inline-input {
        width: 140px;
    }

    .fabric-header-center {
        flex: 0 0 auto;
    }

    .fabric-header-breakdown {
        flex: 1 1 auto;
        min-width: 0;
    }

    .cost-breakdown-bar {
        gap: 0.1rem 0.3rem;
        font-size: 0.7rem;
    }
}

/* ===== LOGIN SCREEN ===== */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
    /* Changed from gradient to app bg */
    transition: opacity 0.4s ease, background-color 0.3s;
}

.login-overlay.hidden {
    display: none !important;
}

.login-card {
    position: relative;
    width: 100%;
    max-width: 380px;
    padding: 3rem 2.5rem 2.5rem 2.5rem;
    background: var(--bg-panel);
    border: 2px solid var(--border-glass);
    border-radius: 20px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--card-shadow);
    transition: border-color 0.3s, box-shadow 0.3s;
}

/* Login success: vertical shake then fly up + fade out */
.login-card.login-success {
    animation: loginShakeY 0.4s ease, loginFlyUp 0.5s 0.4s ease forwards;
}

/* Login error: shake only */
.login-card.login-shake {
    animation: loginShake 0.4s ease;
}

/* Fade out the entire overlay on success */
.login-overlay.login-fade-out {
    animation: loginOverlayFade 0.5s 0.5s ease forwards;
}

@keyframes loginShake {

    0%,
    100% {
        transform: translateX(0);
    }

    15% {
        transform: translateX(-12px);
    }

    30% {
        transform: translateX(10px);
    }

    45% {
        transform: translateX(-8px);
    }

    60% {
        transform: translateX(6px);
    }

    75% {
        transform: translateX(-3px);
    }
}

@keyframes loginShakeY {

    0%,
    100% {
        transform: translateY(0);
    }

    15% {
        transform: translateY(-12px);
    }

    30% {
        transform: translateY(10px);
    }

    45% {
        transform: translateY(-8px);
    }

    60% {
        transform: translateY(6px);
    }

    75% {
        transform: translateY(-3px);
    }
}

@keyframes loginFlyUp {
    0% {
        transform: translateY(0);
        opacity: 1;
    }

    100% {
        transform: translateY(-120vh);
        opacity: 0;
    }
}

@keyframes loginOverlayFade {
    0% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        pointer-events: none;
    }
}

.login-theme-btn {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 38px;
    height: 38px;
}

.login-footer {
    position: absolute;
    bottom: 2rem;
    left: 0;
    width: 100%;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.login-logo {
    text-align: center;
    margin-bottom: 1.2rem;
}

/* Light mode defaults */
.login-logo-img {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    max-height: 140px;
}

/* Light mode: show blue */
.login-logo-light {
    display: none;
}

.login-logo-dark {
    display: block;
}

/* Dark mode: show orange */
body.dark-mode .login-logo-light {
    display: block;
}

body.dark-mode .login-logo-dark {
    display: none;
}

.login-title {
    text-align: center;
    color: var(--text-main);
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.8rem;
    letter-spacing: -0.02em;
}

.login-field {
    margin-bottom: 1.2rem;
}

.login-field label {
    display: block;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.login-field input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-dark);
    border: 1px solid var(--border-glass);
    border-radius: 10px;
    color: var(--text-main);
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s;
}

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

.login-field input:focus {
    border-color: var(--accent-primary);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 0 3px rgba(230, 83, 15, 0.15);
}

.login-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--accent-red);
    padding: 0.6rem 0.9rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
    text-align: center;
}

.btn-login {
    width: 100%;
    padding: 0.8rem;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 10px;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 0.5rem;
}

.btn-login:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(230, 83, 15, 0.3);
}

.btn-login:active {
    transform: translateY(0);
}

.btn-login:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* (Old header user/logout and admin-tab styles removed — now in sidebar section) */

.admin-section {
    display: none;
}

.admin-section.active {
    display: block;
}

/* ===== PLACEHOLDER CONTENT ===== */
.placeholder-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 40vh;
    color: var(--text-muted);
    gap: 1rem;
}

.placeholder-icon {
    opacity: 0.5;
}

.placeholder-text {
    font-size: 1rem;
    font-weight: 500;
    font-family: 'acuminprowide-light', sans-serif;
    opacity: 0.6;
}

/* ===== REPORTS ===== */
.reports-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#budgets-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.report-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    transition: box-shadow 0.2s;
}

.report-card:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.report-card-icons {
    display: grid;
    grid-template-columns: auto auto;
    gap: 0.1rem;
    flex-shrink: 0;
}

.report-card-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.report-card-clickable {
    cursor: pointer;
    border-radius: 4px;
    padding: 0.15rem 0.35rem;
    transition: background 0.15s;
}

.report-card-clickable:hover {
    background: var(--hover-bg, rgba(0, 0, 0, 0.05));
}

.report-card-info strong {
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 1.1rem;
}

.report-card-info small {
    font-size: 0.78rem;
    color: var(--text-muted);
}


.report-list-drag-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 1.1rem;
    user-select: none;
    opacity: 0.5;
    transition: opacity 0.15s;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.report-list-drag-handle:hover {
    opacity: 1;
}

.report-card-dragging {
    opacity: 0.4;
}

.report-card-dragover {
    border-top: 2px solid var(--accent);
}

.btn-fav-report {
    color: var(--text-muted);
    transition: color 0.2s;
}

.btn-fav-report.active {
    color: #f59e0b;
}

.btn-fav-budget {
    color: var(--text-muted);
    transition: color 0.2s;
}

.btn-fav-budget.active {
    color: #f59e0b;
}

/* Report editor */
.report-editor {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.report-editor-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.report-title-inline {
    flex: 1;
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 1.15rem;
    font-weight: 600;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    color: inherit;
    outline: none;
    min-width: 0;
}

.report-title-inline:hover {
    border-color: var(--border);
}

.report-title-inline:focus {
    border-color: var(--accent);
    background: var(--bg-secondary, rgba(0, 0, 0, 0.03));
}

.report-editor-actions {
    display: flex;
    gap: 0.5rem;
}

.report-settings-stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.report-settings-row {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

/* Separator column between main data and comparison columns */
.report-separator-col {
    border-left: 3px solid var(--border-color) !important;
}

/* Sub-header row for grouped columns */
.report-subheader th {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    padding-top: 0 !important;
    padding-bottom: 0.35rem !important;
    border-top: none !important;
}

/* Wide articles table */
.report-articles-wide {
    font-size: 0.82rem;
}

.report-articles-wide th,
.report-articles-wide td {
    padding: 0.35rem 0.4rem;
    white-space: nowrap;
}

#report-articles-table input[type="number"],
#report-articles-table .report-diff-cell,
#report-articles-table .report-net-cell,
#report-articles-table .report-margin-val-cell,
#report-articles-table .report-margin-pct-cell,
#report-articles-table .report-cost100-cell,
#report-articles-table .report-cost300-cell,
#report-articles-table .report-cost600-cell {
    font-family: 'acuminprowide-light', sans-serif;
}

.report-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.report-field label {
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.report-currency-input {
    display: inline-flex;
    align-items: center;
    gap: 0;
    width: 80px;
    border: 1px dashed #bbb;
    border-radius: 4px;
}

.report-currency-input .currency-sym {
    font-size: 0.9rem;
    font-weight: 400;
    font-family: 'acuminprowide-light', sans-serif;
    color: var(--text-main);
    flex-shrink: 0;
    pointer-events: none;
    line-height: 1;
}

.report-currency-input input {
    width: 100% !important;
    text-align: left !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    font-family: 'acuminprowide-light', sans-serif !important;
    font-size: 0.9rem !important;
    font-weight: 400 !important;
    color: var(--text-main) !important;
}

.report-currency-input input:focus {
    outline: none !important;
}

.report-currency-input:hover {
    border: 1px dashed var(--accent-primary);
    border-radius: 4px;
}

.report-footer-textarea {
    width: 100%;
    resize: vertical;
    font-family: inherit;
    font-size: 0.88rem;
    line-height: 1.5;
    min-height: 60px;
}

/* Collapsible articles section */
.report-articles-section {
    margin: 1rem 0 0;
}

.btn-remove-report-article,
.btn-remove-budget-article {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--accent-red);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    line-height: 1;
}

.btn-remove-report-article:hover,
.btn-remove-budget-article:hover {
    background: rgba(220, 50, 50, 0.1);
    color: var(--negative, #dc3232);
}

.report-article-picker {
    margin-top: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.report-article-picker.hidden {
    display: none;
}

.picker-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 5px;
    padding: 0.5rem 0.6rem;
    overflow-y: auto;
    max-height: 160px;
}

.picker-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: background 0.12s, border-color 0.12s;
    white-space: nowrap;
    line-height: 1.4;
    text-align: center;
}

.picker-chip:hover {
    border-color: var(--accent-color);
    background: rgba(230, 83, 15, 0.08);
}

.picker-chip.picked {
    border-color: var(--accent-color);
    background: var(--accent-color);
    color: #fff;
    pointer-events: none;
}

.report-row-selected {
    background: rgba(230, 83, 15, 0.05);
}

body.dark-mode .report-row-selected {
    background: rgba(249, 115, 22, 0.08);
}

.report-drag-cell {
    width: 52px;
    padding: 0.35rem 4px 0.35rem 10px !important;
    display: flex;
    align-items: center;
    gap: 2px;
}

.report-drag-handle {
    cursor: grab;
    font-size: 1.1rem;
    opacity: 0.4;
    user-select: none;
    line-height: 1;
}

.report-drag-handle:hover {
    opacity: 0.8;
}

.report-row-dragging {
    opacity: 0.4;
}

.report-row-dragover {
    border-top: 2px solid var(--accent) !important;
}

.report-row-unselected {
    opacity: 0.6;
}

.report-price-panel {
    padding: 1rem;
    overflow: hidden;
}

.report-price-panel h4 {
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.report-price-table {
    font-size: 0.85rem;
}

.report-price-table .text-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.badge-static {
    font-size: 0.82rem;
    font-weight: 600;
    background: var(--text-muted);
    color: #fff;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}

.report-actions-bar {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    justify-content: flex-end;
}

.btn-small {
    font-size: 0.82rem;
    padding: 0.4rem 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.text-right {
    text-align: right;
}

/* ===== CHANGES TAB ===== */
.changes-log-container {
    padding: 0 0 2rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Changelog table */
.changelog-table {
    width: 100%;
    min-width: 1020px;
    border-collapse: collapse;
    font-size: 0.8rem;
    table-layout: fixed;
}

/* Group hover — JS adds .chg-hover to all rows sharing the same data-group */
.changelog-table tbody tr.chg-hover td {
    background: var(--hover-bg, rgba(99, 102, 241, 0.07));
    cursor: default;
}

.chg-th {
    background: var(--table-header-bg, var(--card-bg));
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 7px 10px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

/* Column widths */
/* Action */
.changelog-table th:nth-child(1) {
    width: 82px;
}

/* Date/Time */
.changelog-table th:nth-child(2) {
    width: 148px;
}

/* Author */
.changelog-table th:nth-child(3) {
    width: 90px;
}

/* Type */
.changelog-table th:nth-child(4) {
    width: 130px;
}

/* Code */
.changelog-table th:nth-child(5) {
    width: 230px;
}

/* Field */
.changelog-table th:nth-child(6) {
    width: 110px;
}

/* Change */
.changelog-table th:nth-child(7) {
    width: 220px;
}

/* Change */

.chg-td {
    padding: 5px 10px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

/* First row of a group gets a stronger top border to visually separate groups */
.chg-group-first td {
    border-top: 2px solid var(--border);
}

/* But not for the very first group */
.changelog-table tbody tr:first-child td {
    border-top: none;
}

/* Continuation rows within a group are lighter */
.chg-group-cont .chg-td {
    border-bottom: 1px dashed var(--border);
    opacity: 0.9;
}

/* Left accent bar per action on the first cell of each group */
.chg-group-first.chg-action-create td:first-child {
    border-left: 5px solid #22c55e;
}

.chg-group-first.chg-action-update td:first-child {
    border-left: 5px solid #3b82f6;
}

.chg-group-first.chg-action-delete td:first-child {
    border-left: 5px solid #ef4444;
}

.chg-group-cont td:first-child {
    border-left: 5px solid transparent;
}

.chg-td-datetime {
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.chg-td-author {
    font-weight: 600;
}

.chg-td-code {
    font-weight: 700;
}

.chg-td-field {
    color: var(--text-muted);
    font-style: italic;
}

.chg-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.chg-entity-article {
    background: #dbeafe;
    color: #1d4ed8;
}

.chg-entity-yarn {
    background: #fef9c3;
    color: #92400e;
}

body.dark-mode .chg-entity-article {
    background: #1e3a5f;
    color: #93c5fd;
}

body.dark-mode .chg-entity-yarn {
    background: #3b2e00;
    color: #fde68a;
}

.chg-entity-price_list {
    background: #ede9fe;
    color: #6d28d9;
}

.chg-entity-budget {
    background: #d1fae5;
    color: #065f46;
}

body.dark-mode .chg-entity-price_list {
    background: #2e1065;
    color: #c4b5fd;
}

body.dark-mode .chg-entity-budget {
    background: #064e3b;
    color: #6ee7b7;
}

.chg-action-create .chg-badge.chg-action-create {
    background: #dcfce7;
    color: #166534;
}

.chg-action-update .chg-badge.chg-action-update {
    background: #dbeafe;
    color: #1e40af;
}

.chg-action-delete .chg-badge.chg-action-delete {
    background: #fee2e2;
    color: #991b1b;
}

body.dark-mode .chg-action-create .chg-badge.chg-action-create {
    background: #14532d;
    color: #86efac;
}

body.dark-mode .chg-action-update .chg-badge.chg-action-update {
    background: #1e3a5f;
    color: #93c5fd;
}

body.dark-mode .chg-action-delete .chg-badge.chg-action-delete {
    background: #450a0a;
    color: #fca5a5;
}

.chg-old {
    color: #dc2626;
    background: #fef2f2;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.78rem;
}

body.dark-mode .chg-old {
    background: #3b0000;
    color: #fca5a5;
}

.chg-new {
    color: #16a34a;
    background: #f0fdf4;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.78rem;
}

body.dark-mode .chg-new {
    background: #052e16;
    color: #86efac;
}

.chg-empty {
    color: var(--text-muted);
    opacity: 0.4;
}

.chg-arrow {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin: 0 3px;
}

.chg-td-change {
    white-space: nowrap;
}

/* Changelog pagination */
.chg-toolbar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
}

.chg-filter-select {
    padding: 0.35rem 1.6rem 0.35rem 0.5rem;
    border: 1px dashed var(--accent-primary);
    border-radius: 8px;
    background-color: var(--bg-dark);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23E6530F'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    color: var(--text-main);
    font-family: 'acuminprowide-light', sans-serif;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
    appearance: none;
}

.chg-refresh-btn {
    appearance: none;
    background-image: none;
    background-color: var(--bg-dark);
    padding: 0.35rem 0.7rem;
}

.chg-pagination {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
}

.chg-page-info {
    color: var(--text-muted);
}

.chg-page-buttons {
    display: flex;
    align-items: center;
    gap: 2px;
}

.chg-page-btn {
    min-width: 30px;
    height: 30px;
    padding: 0 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.chg-page-btn:hover:not(.disabled):not(.active) {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
}

.chg-page-btn.active {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-main);
    border-color: var(--border);
    font-weight: 600;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

body.dark-mode .chg-page-btn.active {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.chg-page-btn.disabled {
    opacity: 0.35;
    cursor: default;
}

.chg-page-ellipsis {
    padding: 0 4px;
    color: var(--text-muted);
}

/* Changelog page transition */
@keyframes chgSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

@keyframes chgSlideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

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

.chg-slide-up {
    animation: chgSlideUp 0.5s ease-out;
}

.chg-slide-down {
    animation: chgSlideDown 0.5s ease-out;
}

/* ===== AI VOICE ASSISTANT ===== */
.ai-fab {
    position: fixed;
    right: 1.5rem;
    bottom: calc(1.5rem + env(safe-area-inset-bottom));
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid var(--accent-primary);
    background: transparent;
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(230, 83, 15, 0.15);
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    z-index: 1100;
    -webkit-tap-highlight-color: transparent;
}

.ai-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(230, 83, 15, 0.25);
}

.ai-fab:active {
    transform: scale(0.96);
}

.ai-fab-icon {
    position: relative;
    z-index: 2;
}

.ai-panel {
    position: fixed;
    right: 1.5rem;
    bottom: calc(6.5rem + env(safe-area-inset-bottom));
    width: 380px;
    max-width: calc(100vw - 3rem);
    max-height: min(560px, calc(100dvh - 9rem));
    background: var(--bg-panel);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
    border: 1px solid var(--border-glass);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.18), 0 4px 14px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1099;
    transform-origin: bottom right;
    animation: aiPanelIn 0.22s ease-out;
}

@keyframes aiPanelIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.1rem;
    border-bottom: 1px solid var(--border-glass);
    flex-shrink: 0;
}

.ai-panel-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.ai-panel-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(230, 83, 15, 0.18);
    flex-shrink: 0;
}

.ai-panel-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    letter-spacing: -0.01em;
}

.ai-panel-close {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.ai-panel-close:hover {
    background: var(--border-glass);
    color: var(--text-main);
}

.ai-panel-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    min-height: 120px;
}

.ai-panel-empty {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 1.5rem 0.5rem;
    line-height: 1.55;
}

.ai-panel-empty em {
    color: var(--text-main);
    font-style: italic;
    opacity: 0.85;
}

.ai-msg {
    max-width: 85%;
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    font-size: 0.88rem;
    line-height: 1.45;
    word-wrap: break-word;
    white-space: pre-wrap;
    animation: aiMsgIn 0.2s ease-out;
}

@keyframes aiMsgIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-msg.user {
    align-self: flex-end;
    background: var(--accent-gradient);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ai-msg.assistant {
    align-self: flex-start;
    background: var(--border-glass);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

.ai-msg.assistant strong,
.ai-chat-card-preview strong {
    font-weight: 700;
    font-family: sans-serif;
}

.ai-msg.error {
    align-self: stretch;
    max-width: 100%;
    background: rgba(239, 68, 68, 0.12);
    color: var(--accent-red);
    border: 1px solid rgba(239, 68, 68, 0.25);
    text-align: center;
    font-size: 0.82rem;
}

.ai-msg.thinking {
    align-self: flex-start;
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.85;
}

.ai-msg.thinking::after {
    content: '';
    display: inline-block;
    animation: aiThinkingDots 1.2s steps(4, end) infinite;
}

@keyframes aiThinkingDots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
    100% { content: ''; }
}

.ai-panel-status {
    padding: 0 1.1rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    min-height: 1.1em;
    text-align: center;
    flex-shrink: 0;
}

.ai-panel-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0.9rem calc(0.9rem + env(safe-area-inset-bottom)) 0.9rem;
    border-top: 1px solid var(--border-glass);
    flex-shrink: 0;
}

.ai-panel-send {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: var(--border-glass);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, transform 0.12s;
    -webkit-tap-highlight-color: transparent;
}

.ai-panel-send:hover {
    background: var(--accent-primary);
    color: #fff;
}

.ai-panel-send:active {
    transform: scale(0.94);
}

.ai-panel-header-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.ai-panel-header-btn {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.ai-panel-header-btn:hover {
    background: var(--border-glass);
    color: var(--text-main);
}

.ai-panel-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 44px;
    border: 1px solid var(--border-glass);
    background: var(--bg-dark);
    color: var(--text-main);
    border-radius: 12px;
    padding: 0 0.9rem;
    font-size: 0.92rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}

.ai-panel-input:focus {
    border-color: var(--accent-primary);
}

/* Mobile: bottom sheet */
@media (max-width: 768px) {
    .ai-fab {
        right: 1rem;
        bottom: calc(1rem + env(safe-area-inset-bottom));
        width: 56px;
        height: 56px;
    }

    .ai-panel {
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        max-height: 80dvh;
        border-radius: 18px 18px 0 0;
        animation: aiPanelInMobile 0.25s ease-out;
    }

    @keyframes aiPanelInMobile {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .ai-panel-header {
        padding: 1rem 1.1rem;
    }

    /* Hide the FAB while panel is open on mobile to avoid overlap */
    body.ai-panel-open .ai-fab {
        display: none;
    }
}

/* Print: hide assistant entirely */
@media print {
    .ai-fab,
    .ai-panel {
        display: none !important;
    }
}

/* ===== AI CHATS LIST (tab) ===== */
.ai-chats-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.ai-chat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.2rem;
    border-bottom: 1px solid var(--border-glass);
    cursor: pointer;
    transition: background 0.15s;
}

.ai-chat-card:hover {
    background: var(--border-glass);
}

.ai-chat-card-body {
    flex: 1;
    min-width: 0;
}

.ai-chat-card-title {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0 0 0.2rem 0;
}

.ai-chat-card-preview {
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-chat-card-meta {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-chat-card-date {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.ai-chat-card-delete {
    flex-shrink: 0;
}

/* ===== PRINT STYLES ===== */
.print-report-container {
    display: none;
}

@media print {
    @page {
        size: A4 portrait;
        margin: 8mm 15mm 0 15mm;

        @top-right {
            content: counter(page) " / " counter(pages);
            font-family: 'acuminprowide-light', sans-serif;
            font-size: 7pt;
            color: #999;
        }
    }

    /* Hide everything except the print container */
    body>*:not(#print-report-container):not(#print-budget-container) {
        display: none !important;
    }

    body {
        margin: 0;
        background: #fff !important;
        color: #1a1a1a !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    #print-report-container,
    #print-budget-container {
        display: block !important;
        position: static;
        width: 100%;
        padding: 0;
    }

    /* Table — uses thead/tfoot for repeating header + footer on every page */
    .print-table {
        width: 88%;
        margin: 0 auto;
        border-collapse: collapse;
        font-family: 'acuminprowide-light', sans-serif;
        font-size: 7.5pt;
        line-height: 1.25;
    }

    .print-table thead {
        display: table-header-group;
    }

    .print-table tfoot {
        display: table-footer-group;
    }

    /* Logo row inside thead — repeats on every page */
    .print-logo-row {
        background: none !important;
    }

    .print-table th.print-logo-cell {
        background: #fff !important;
        color: #1a1a1a !important;
        text-align: center;
        padding: 5mm 0 10pt 0;
        border-bottom: 1.5pt solid #1C193A;
    }

    .print-logo {
        display: inline-block;
    }

    .print-title {
        font-family: 'acuminprowide-light', sans-serif;
        font-size: 9pt;
        font-weight: 500;
        color: #555;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        margin-top: 6pt;
    }

    /* Column header row */
    .print-table th {
        background: #1C193A !important;
        color: #fff !important;
        padding: 4pt 6pt;
        text-align: left;
        font-size: 6.5pt;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        white-space: nowrap;
    }

    .print-table th.th-code {
        width: 10%;
    }

    .print-table th.th-desc {
        width: 21%;
    }

    .print-table th.th-comp {
        width: 28%;
    }

    .print-table th.th-weight {
        width: 11%;
        text-align: center;
    }

    .print-table th.th-price {
        width: 15%;
        text-align: right;
    }

    /* Table body — compact rows, prevent splitting across pages */
    .print-table td {
        padding: 4.5pt 6pt;
        border-bottom: 0.5pt solid #ddd;
        vertical-align: middle;
    }

    .print-table tbody tr {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .print-table tr.row-alt td {
        background: #f8f8f8 !important;
    }

    .print-table .cell-code {
        font-weight: 600;
        letter-spacing: 0.02em;
    }

    .print-table .cell-center {
        text-align: center;
        font-variant-numeric: tabular-nums;
    }

    .print-table .cell-price {
        text-align: right;
        font-variant-numeric: tabular-nums;
        font-weight: 500;
    }

    /* Tfoot spacer (desktop) — same content as footer but invisible; forces Chrome
       to account for its height when calculating page breaks */
    .print-tfoot-spacer {
        padding: 8pt 0 8mm 0 !important;
        border-top: none !important;
        border-bottom: none !important;
        background: #fff !important;
    }

    .print-tfoot-spacer .print-footer-text {
        color: transparent !important;
    }

    /* Fixed footer — pinned to bottom of every page (desktop browsers) */
    .print-footer-fixed {
        position: fixed;
        bottom: 0;
        left: 6%;
        right: 6%;
        padding: 8pt 0 8mm 0;
        border-top: 0.5pt solid #ccc;
        text-align: left;
        font-family: 'acuminprowide-light', sans-serif;
        font-size: 6.5pt;
        line-height: 1.4;
        color: #999;
        background: #fff;
    }

    /* Footer inside tfoot — repeats on every printed page (iOS Safari fallback) */
    .print-tfoot-row {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .print-tfoot-cell {
        padding: 8pt 0 4pt 0 !important;
        border-top: 0.5pt solid #ccc !important;
        border-bottom: none !important;
        background: #fff !important;
        text-align: left;
        font-family: 'acuminprowide-light', sans-serif;
        font-size: 6.5pt;
        line-height: 1.4;
        color: #999;
    }

    .print-footer-text {
        display: block;
    }
}