/* ============================================================
   SOFT UI + NEUMORPHISM DESIGN SYSTEM (v5) – Fully Reorganized
   - Mobile-first, responsive, with icons, analysis page,
     form grids, and all utility classes
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap');

/* ---------- DESIGN TOKENS ---------- */
:root {
    /* Light theme */
    --bg-gradient-start: #f0f2f5;
    --bg-gradient-end: #e0e5ec;
    --surface: #ffffff;
    --surface-alt: #f7f9fc;
    --text: #1a1a2e;
    --text-secondary: #5a6171;
    --text-tertiary: #8e95a2;

    --primary: #5c6bc0;
    --primary-light: #8e99f3;
    --primary-dark: #26418f;
    --primary-shadow: rgba(92, 107, 192, 0.12);

    --accent-1: #ff7043;
    --accent-2: #26a69a;
    --accent-3: #ffca28;

    --success: #43a047;
    --danger: #e53935;
    --warning: #ffa000;

    /* Neumorphism shadows – light */
    --nm-light: #ffffff;
    --nm-dark: #d1d9e6;
    --nm-shadow-inset: inset 2px 2px 5px var(--nm-dark),
    inset -2px -2px 5px var(--nm-light);
    --nm-shadow-elevated: 8px 8px 16px var(--nm-dark),
    -8px -8px 16px var(--nm-light);
    --nm-shadow-flat: 4px 4px 8px var(--nm-dark),
    -4px -4px 8px var(--nm-light);
    --nm-shadow-button: 3px 3px 6px var(--nm-dark),
    -3px -3px 6px var(--nm-light);
    --nm-shadow-pressed: inset 3px 3px 6px var(--nm-dark),
    inset -3px -3px 6px var(--nm-light);

    --radius-card: 20px;
    --radius-btn: 14px;
    --transition: 0.2s ease;
    --transition-slow: 0.3s ease;

    --footer-bg: var(--surface);
    --footer-shadow: 0 -4px 12px rgba(0, 0, 0, 0.04);
    --safe-bottom: env(safe-area-inset-bottom, 16px);
}

/* Dark theme overrides */
.dark-mode {
    --bg-gradient-start: #12131f;
    --bg-gradient-end: #1a1a2e;
    --surface: #222437;
    --surface-alt: #2a2d44;
    --text: #f0f0f5;
    --text-secondary: #b0b5c9;
    --text-tertiary: #7d8299;

    --primary: #8e99f3;
    --primary-light: #b0b9ff;
    --primary-dark: #5c6bc0;

    --accent-1: #ff8a65;
    --accent-2: #4db6ac;
    --accent-3: #ffd54f;

    --nm-light: #2f334a;
    --nm-dark: #0c0d17;
    --nm-shadow-inset: inset 2px 2px 4px var(--nm-dark),
    inset -2px -2px 4px var(--nm-light);
    --nm-shadow-elevated: 8px 8px 16px var(--nm-dark),
    -8px -8px 16px var(--nm-light);
    --nm-shadow-flat: 4px 4px 8px var(--nm-dark),
    -4px -4px 8px var(--nm-light);
    --nm-shadow-button: 3px 3px 6px var(--nm-dark),
    -3px -3px 6px var(--nm-light);
    --nm-shadow-pressed: inset 3px 3px 6px var(--nm-dark),
    inset -3px -3px 6px var(--nm-light);

    --footer-bg: var(--surface);
    --footer-shadow: 0 -4px 12px rgba(0, 0, 0, 0.4);
}

/* ---------- RESET & BASE ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Vazirmatn', sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: var(--text);
    direction: rtl;
    line-height: 1.7;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--transition-slow), color var(--transition-slow);
    padding-bottom: calc(70px + var(--safe-bottom));
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ---------- TYPOGRAPHY ---------- */
.page-title {
    font-size: 2rem;
    font-weight: 700;
    margin: 28px 0 20px;
    color: var(--primary-dark);
    text-shadow: 2px 2px 4px var(--nm-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-title .icon {
    font-size: 2rem;
    color: inherit;
}

/* ---------- CARDS (Neumorphic) ---------- */
.card {
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--nm-shadow-elevated);
    transition: box-shadow var(--transition), transform var(--transition);
}

.card:active {
    box-shadow: var(--nm-shadow-inset);
}

.card-header {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-dark);
    border-bottom: 1px solid var(--nm-dark);
    padding-bottom: 12px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header .icon {
    color: var(--primary-dark);
}

/* ---------- TABLES ---------- */
.table-responsive {
    overflow-x: auto;
    margin-top: 16px;
    border-radius: var(--radius-card);
    background: var(--surface);
    padding: 0;
    box-shadow: var(--nm-shadow-elevated);
}

.report-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9rem;
    min-width: 600px;
}

.report-table th {
    background: var(--surface);
    color: var(--text);
    padding: 14px 10px;
    text-align: center;
    border-bottom: 1px solid var(--nm-dark);
    font-weight: 600;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}

.report-table td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 1px solid var(--nm-dark);
    background: var(--surface);
    color: var(--text);
    transition: background 0.15s;
}

/* Rounded corners for first/last cells */
.report-table tr:first-child th:first-child {
    border-top-right-radius: var(--radius-card);
}

.report-table tr:first-child th:last-child {
    border-top-left-radius: var(--radius-card);
}

.report-table tr:last-child td:first-child {
    border-bottom-right-radius: var(--radius-card);
}

.report-table tr:last-child td:last-child {
    border-bottom-left-radius: var(--radius-card);
}

/* ---------- STICKY FIRST COLUMN (iOS safe) ---------- */
.report-table th:first-child,
.report-table td:first-child {
    position: sticky;
    right: 0;
    z-index: 1;
    background-color: var(--surface);
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.08);
}

.report-table th:first-child::before,
.report-table td:first-child::before {
    display: none;
}

/* Alternating row colours – sticky first cell must match */
.section-0 td:first-child {
    background-color: #fafbfe;
}

.section-1 td:first-child {
    background-color: #f4f7fb;
}

.section-2 td:first-child {
    background-color: #eef2f8;
}

.section-3 td:first-child {
    background-color: #e7ecf4;
}

.section-4 td:first-child {
    background-color: #e1e6f0;
}

.dark-mode .section-0 td:first-child {
    background-color: #1e2235;
}

.dark-mode .section-1 td:first-child {
    background-color: #21263c;
}

.dark-mode .section-2 td:first-child {
    background-color: #252a42;
}

.dark-mode .section-3 td:first-child {
    background-color: #292e48;
}

.dark-mode .section-4 td:first-child {
    background-color: #2d324e;
}

.total-row td:first-child {
    background-color: var(--surface-alt);
}

.section-0 td {
    background: #fafbfe;
}

.section-1 td {
    background: #f4f7fb;
}

.section-2 td {
    background: #eef2f8;
}

.section-3 td {
    background: #e7ecf4;
}

.section-4 td {
    background: #e1e6f0;
}

.dark-mode .section-0 td {
    background: #1e2235;
}

.dark-mode .section-1 td {
    background: #21263c;
}

.dark-mode .section-2 td {
    background: #252a42;
}

.dark-mode .section-3 td {
    background: #292e48;
}

.dark-mode .section-4 td {
    background: #2d324e;
}

.total-row td {
    font-weight: 700;
    color: var(--primary-dark);
    background: var(--surface-alt);
    border-top: 2px solid var(--primary);
}

.name-col {
    text-align: right;
    font-weight: 500;
    padding-right: 12px;
}

.total-col {
    font-weight: 700;
    color: var(--primary);
}

.img-cell img {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 10px;
    background: var(--surface-alt);
    padding: 4px;
}

/* ---------- BUTTONS (Neumorphic) ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-btn);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--nm-shadow-button);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: box-shadow var(--transition), transform var(--transition);
    position: relative;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
}

.btn:active {
    transform: translateY(1px);
    box-shadow: var(--nm-shadow-pressed);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--nm-shadow-button), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.btn-primary:active {
    box-shadow: var(--nm-shadow-pressed), inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-accent1 {
    background: var(--accent-1);
    color: #fff;
}

.btn-accent2 {
    background: var(--accent-2);
    color: #fff;
}

.btn-full {
    width: 100%;
}

/* ---------- FORM ELEMENTS ---------- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.form-group .btn {
    height: 44px;
    font-size: 1rem;
}

.input {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: var(--radius-btn);
    background: var(--surface-alt);
    box-shadow: inset 2px 2px 5px var(--nm-dark), inset -2px -2px 5px var(--nm-light);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    transition: box-shadow var(--transition);
}

.input:focus {
    outline: none;
    box-shadow: inset 2px 2px 5px var(--nm-dark), inset -2px -2px 5px var(--nm-light), 0 0 0 2px var(--primary-light);
}

select.input {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg fill='gray' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
    background-repeat: no-repeat;
    background-position: left 12px center;
    background-size: 20px;
}

/* ---------- TOP BAR ---------- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    gap: 10px;
    background: linear-gradient(135deg, var(--surface), var(--surface-alt));
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    position: sticky;
    top: 0;
    z-index: 99;
    flex-wrap: wrap;
}

.top-bar .logo {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--primary-dark);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
    text-shadow: 1px 1px 2px var(--nm-light);
}

.top-bar .logo img {
    height: 28px;
    width: auto;
}

.user-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: var(--nm-shadow-button);
}

.theme-toggle-btn {
    background: var(--surface);
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: var(--nm-shadow-button);
    transition: box-shadow var(--transition);
    color: var(--text);
}

.theme-toggle-btn:active {
    box-shadow: var(--nm-shadow-pressed);
}

.date-info {
    display: flex;
    gap: 10px;
    font-size: 0.75rem;
    background: var(--surface-alt);
    padding: 4px 12px;
    border-radius: 40px;
    white-space: nowrap;
}

/* ---------- FOOTER ---------- */
.mobile-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--footer-bg);
    box-shadow: var(--footer-shadow);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 16px));
    z-index: 100;
    backdrop-filter: blur(12px);
}

.footer-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.7rem;
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 12px;
    transition: color var(--transition), background var(--transition), box-shadow var(--transition);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.footer-item.active {
    color: var(--primary);
    background: var(--surface-alt);
    box-shadow: var(--nm-shadow-inset);
}

/* ---------- Category Popup ---------- */
.category-popup {
    position: fixed;
    bottom: 70px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.08);
    padding: 12px 16px 16px;
    display: none;
    z-index: 99;
    transform: translateY(0);
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.category-popup.open {
    display: block;
}

.category-popup a {
    display: block;
    padding: 16px 24px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.95rem;
    border-bottom: 1px solid var(--nm-dark);
    transition: background 0.15s;
}

.category-popup a:last-child {
    border-bottom: none;
}

.category-popup a:active {
    background: var(--surface-alt);
    box-shadow: var(--nm-shadow-inset);
}

.dark-mode .category-popup {
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.4), inset 0 1px 0 var(--nm-light);
}

.popup-row {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.popup-row:last-child {
    margin-bottom: 0;
}

.popup-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 40px;
    background: var(--surface);
    box-shadow: var(--nm-shadow-button);
    color: var(--text);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
    transition: box-shadow var(--transition), transform var(--transition);
    white-space: nowrap;
}

.popup-item:active {
    box-shadow: var(--nm-shadow-pressed);
    transform: translateY(1px);
}

.popup-icon {
    width: 20px;
    height: 20px;
    margin-left: 4px;
}

.popup-item .popup-icon {
    width: 20px;
    height: 20px;
    background-color: var(--text);
    border-radius: 4px;
}

/* ---------- LOGIN PAGE ---------- */
.login-container {
    max-width: 420px;
    margin: 0 auto;
    padding: 24px;
    padding-top: 12vh;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 40px 32px;
    box-shadow: var(--nm-shadow-elevated);
}

/* ---------- STATUS MESSAGE ---------- */
.status-message {
    position: relative;
    z-index: 5;
    margin-top: 16px;
}

/* ---------- BOTTLENECK / LP ANALYSIS ---------- */
.lp-container {
    margin-top: 40px;
}

.lp-title {
    font-size: 1.8rem;
    color: var(--primary-dark);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.lp-title::before {
    content: "⚡";
    font-size: 2rem;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.lp-product-card {
    background: var(--surface);
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: var(--nm-shadow-elevated);
    transition: transform 0.2s, box-shadow 0.2s;
}

.lp-product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1), var(--nm-shadow-elevated);
}

.product-card-header {
    background: linear-gradient(135deg, var(--primary), var(--accent-2));
    padding: 16px 20px;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: inset 0 -2px 8px rgba(0, 0, 0, 0.2);
}

.bottleneck-list {
    padding: 16px 20px;
}

.bottleneck-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 20px;
    position: relative;
}

.bottleneck-item:last-child {
    margin-bottom: 0;
}

.bottleneck-item::before {
    content: "";
    position: absolute;
    right: 15px;
    top: 32px;
    bottom: -20px;
    width: 2px;
    background: var(--nm-dark);
}

.bottleneck-item:last-child::before {
    display: none;
}

.step-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
    box-shadow: var(--nm-shadow-button);
    z-index: 1;
}

.step-content {
    flex: 1;
    background: var(--surface-alt);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 0.85rem;
}

.step-content .piece-name {
    font-weight: 700;
    display: block;
    color: var(--text);
    margin-bottom: 4px;
}

.step-content .limit {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.step-content .limit strong {
    font-size: 1rem;
    font-weight: 800;
    color: var(--accent-2);
    background: rgba(38, 166, 154, 0.1);
    padding: 2px 6px;
    border-radius: 20px;
    display: inline-block;
    margin-right: 4px;
}

.badge.shared {
    display: inline-block;
    background: var(--accent-3);
    color: #000;
    border-radius: 50px;
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-right: 6px;
}

.bottleneck-list .next-bottleneck-line {
    text-align: center;
    padding: 12px;
    margin-top: 8px;
    background: var(--surface-alt);
    border-radius: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.bottleneck-list .next-bottleneck-line strong {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--accent-2);
    background: rgba(38, 166, 154, 0.1);
    padding: 2px 8px;
    border-radius: 20px;
    margin: 0 4px;
}

.global-bottlenecks {
    background: var(--surface);
    border-radius: var(--radius-card);
    padding: 20px;
    box-shadow: var(--nm-shadow-elevated), inset 0 2px 12px rgba(0, 0, 0, 0.02);
    margin-top: 24px;
}

.global-bottlenecks h4 {
    color: var(--primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.global-bottlenecks h4::before {
    content: "🏆";
}

.global-bottleneck-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    padding: 10px 14px;
    background: var(--surface-alt);
    border-radius: 12px;
    margin-bottom: 8px;
}

.global-bottleneck-item .rank {
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
}

.global-bottleneck-item .name {
    font-weight: 600;
    flex: 1;
}

.global-bottleneck-item .dual {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.family-group {
    margin-bottom: 32px;
}

.family-name {
    font-size: 1.3rem;
    color: var(--accent-1);
    margin-bottom: 16px;
    padding-right: 8px;
    border-right: 4px solid var(--accent-1);
}

.family-products {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

/* Transfer Section*/
.transfer-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
    align-items: end;
}

.transfer-row .swap-btn {
    margin-bottom: 16px;
    padding: 8px;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--nm-shadow-button);
    background: var(--surface);
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    color: var(--primary-dark);
}

.transfer-row .swap-btn:active {
    box-shadow: var(--nm-shadow-pressed);
    transform: scale(0.92);
}

/* Two‑column compact rows – used for phases & quantity/weight */
.transfer-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.transfer-full {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ---------- ANALYSIS PAGE ---------- */
/* Form grid */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-items: end;
}

.grid-full {
    grid-column: 1 / -1;
}

/* Summary grid */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.summary-item {
    background: var(--surface-alt);
    border-radius: 14px;
    padding: 16px;
    box-shadow: var(--nm-shadow-inset);
    text-align: center;
}

.summary-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.summary-value {
    font-weight: 700;
    font-size: 1.1rem;
}

.highlight {
    color: var(--accent-1);
    font-size: 1.3rem;
    font-weight: 700;
}

.feasible-yes {
    color: var(--success);
}

.feasible-no {
    color: var(--danger);
}

/* Piece cards */
.piece-card {
    background: var(--surface);
    border-radius: 16px;
    margin-bottom: 16px;
    box-shadow: var(--nm-shadow-flat);
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow 0.2s;
}

.piece-card:hover {
    box-shadow: var(--nm-shadow-elevated);
}

.piece-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--nm-dark);
    user-select: none;
}

.piece-name {
    font-weight: 700;
    font-size: 1rem;
}

.piece-phase {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-right: auto;
    margin-left: 12px;
}

.piece-leadtime {
    font-weight: 600;
    color: var(--accent-1);
    white-space: nowrap;
    margin-left: 12px;
}

.piece-expand-icon {
    transition: transform 0.2s;
    font-size: 0.8rem;
}

.piece-card.expanded .piece-expand-icon {
    transform: rotate(180deg);
}

.piece-details {
    display: none;
    padding: 16px;
    background: var(--surface);
}

.piece-card.expanded .piece-details {
    display: block;
}

.piece-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.piece-stats div {
    background: var(--surface-alt);
    border-radius: 10px;
    padding: 10px;
    text-align: center;
    box-shadow: var(--nm-shadow-inset);
}

.sources-title {
    font-weight: 700;
    margin: 16px 0 8px;
    color: var(--primary-dark);
}

.sources-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 8px;
}

.sources-table th,
.sources-table td {
    padding: 10px 8px;
    text-align: center;
    border-bottom: 1px solid var(--nm-dark);
}

.sources-table th {
    background: var(--surface-alt);
    font-weight: 600;
    color: var(--text-secondary);
}

.sources-table td:first-child {
    text-align: right;
}

.phase-path {
    color: var(--text-secondary);
    font-size: 0.8rem;
    direction: ltr;
    white-space: nowrap;
}

/* Clean list */
.clean-list {
    list-style: none;
    padding: 0;
}

.clean-list li {
    padding: 12px 16px;
    border-bottom: 1px solid var(--nm-dark);
    font-weight: 500;
}

.clean-list li:last-child {
    border-bottom: none;
}

/* Error box */
.error-box {
    background: rgba(229, 57, 53, 0.08) !important;
}

.error-text {
    color: var(--danger);
    margin: 0;
}

/* Deficit colors */
.deficit-danger {
    color: var(--danger);
}

.deficit-success {
    color: var(--success);
}

/* styles for day‑by‑day simulation */
.highlight {
    color: var(--accent-1);
    font-size: 1.3rem;
    font-weight: 700;
}

.feasible-yes {
    color: var(--success);
}

.feasible-no {
    color: var(--danger);
}

.piece-card {
    cursor: pointer;
}

.piece-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: var(--surface-alt);
    border-radius: 12px;
    margin-bottom: 8px;
    user-select: none;
}

.piece-name {
    font-weight: 700;
}

.piece-phase {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.piece-leadtime {
    color: var(--accent-1);
    font-weight: 600;
}

.piece-expand-icon {
    transition: transform 0.2s;
}

.piece-details {
    padding: 12px;
    background: var(--surface);
    border-radius: 0 0 12px 12px;
}

.piece-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.piece-stats > div {
    background: var(--surface-alt);
    padding: 8px;
    border-radius: 8px;
    text-align: center;
}

.sources-title {
    font-weight: 700;
    margin: 8px 0;
    color: var(--primary-dark);
}

.day-card {
    background: var(--surface-alt);
    border-radius: 12px;
    margin-bottom: 10px;
    padding: 10px;
    box-shadow: var(--nm-shadow-inset);
}

.day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
}

.day-toggle-icon {
    transition: transform 0.2s;
}

.day-body {
    margin-top: 10px;
    padding: 10px;
    background: var(--surface);
    border-radius: 10px;
}

.day-section {
    margin-bottom: 12px;
}

.day-section strong {
    display: block;
    margin-bottom: 4px;
    color: var(--primary-dark);
}

.day-section ul {
    list-style: none;
    padding-right: 12px;
    margin: 0;
}

.day-section li {
    padding: 2px 0;
}

.sub-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-top: 4px;
}

.sub-table th, .sub-table td {
    padding: 4px 8px;
    border-bottom: 1px solid var(--nm-dark);
    text-align: center;
}

.steady-state-note {
    margin-top: 8px;
    padding: 8px;
    background: rgba(255, 202, 40, 0.15);
    border-radius: 8px;
    font-weight: 500;
    text-align: center;
}

.clean-list {
    list-style: none;
    padding: 0;
}

.clean-list li {
    padding: 8px 12px;
    border-bottom: 1px solid var(--nm-dark);
}

/* Icon helpers */
.icon-white {
    background-color: #fff;
}

.steady-state-note {
    margin-top: 8px;
    padding: 8px;
    background: rgba(255, 202, 40, 0.15);
    border-radius: 8px;
    font-weight: 500;
    text-align: center;
}

/* ---------- FINANCIAL CALCULATOR ---------- */
.product-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.product-card-calc .product-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--surface-alt);
    border-radius: 14px 14px 0 0;
    font-weight: 600;
}

.product-card-body {
    padding: 12px;
}

.quantity-input {
    width: 80px;
    text-align: center;
}

.action-card {
    text-align: center;
    margin-top: 8px;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--surface-alt);
    border-radius: 12px;
    box-shadow: var(--nm-shadow-inset);
}

.result-name {
    font-weight: 500;
}

.result-cost {
    font-weight: 700;
    color: var(--primary-dark);
}

.shortage-badge {
    background: var(--warning);
    color: #000;
    border-radius: 20px;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 600;
}

.total-net-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--primary-light);
    color: #fff;
    border-radius: 12px;
    margin-top: 8px;
    font-size: 1.1rem;
    font-weight: 600;
}

.final-summary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}


/* ---------- UTILITY CLASSES ---------- */
.flex {
    display: flex;
}

.justify-between {
    justify-content: space-between;
}

.items-center {
    align-items: center;
}

.gap-10 {
    gap: 10px;
}

.mt-2 {
    margin-top: 8px;
}

.mb-2 {
    margin-bottom: 8px;
}

.text-center {
    text-align: center;
}

/* Order form & planning */
.success-box {
    background: #e8f5e9;
    color: #2e7d32;
    padding: 12px;
    border-radius: var(--radius-card);
    box-shadow: var(--nm-shadow-flat);
}

/* ---------- MOBILE HEADER ADJUSTMENTS ---------- */
@media (max-width: 600px) {
    .top-bar {
        flex-wrap: nowrap;
        padding: 8px 10px;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .top-bar .logo {
        font-size: 0.95rem;
        white-space: nowrap;
    }

    .top-bar .logo img {
        height: 22px;
    }

    .date-info {
        font-size: 0.55rem;
        padding: 1px 6px;
        white-space: nowrap;
        background: transparent;
        box-shadow: none;
        order: 1;
    }

    .date-info span:first-child {
        display: none;
    }

    .user-area {
        gap: 6px;
        white-space: nowrap;
        order: 2;
        margin-right: auto;
    }

    .avatar {
        width: 28px;
        height: 28px;
        font-size: 0.7rem;
    }

    .theme-toggle-btn {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
}

/* ---------- MOBILE GENERAL OPTIMISATIONS (≤ 768px) ---------- */
@media (max-width: 768px) {
    .container {
        padding: 0 12px;
    }

    .page-title {
        font-size: 1.5rem;
        margin: 20px 0 16px;
    }

    .card {
        padding: 16px;
        border-radius: 16px;
        margin-bottom: 16px;
    }

    .card-header {
        font-size: 1rem;
        margin-bottom: 12px;
        padding-bottom: 8px;
    }

    .table-responsive {
        margin-top: 8px;
        border-radius: 12px;
        -webkit-overflow-scrolling: touch;
    }

    .report-table {
        font-size: 0.8rem;
        min-width: auto;
    }

    .report-table th, .report-table td {
        padding: 8px 6px;
    }

    .report-table th:first-child,
    .report-table td:first-child {
        box-shadow: 1px 0 4px rgba(0, 0, 0, 0.06);
    }

    .img-cell img {
        width: 32px;
        height: 32px;
        border-radius: 8px;
    }

    .btn {
        padding: 8px 16px;
        font-size: 0.85rem;
        border-radius: 12px;
    }

    .input {
        padding: 10px 12px;
        font-size: 1rem;
        border-radius: 12px;
    }

    .form-group label {
        font-size: 0.8rem;
    }

    .product-grid {
        grid-template-columns: 1fr;
    }

    .family-products {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .piece-stats {
        grid-template-columns: 1fr 1fr;
    }
}

/* ---------- ICON LIBRARY (mask-based) ---------- */
.icon {
    display: inline-block;
    width: 24px;
    height: 24px;
    background-color: currentColor;
    mask-size: contain;
    mask-repeat: no-repeat;
    mask-position: center;
    vertical-align: middle;
    flex-shrink: 0;
}

.icon-lock {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C9.2 2 7 4.2 7 7v3H6a2 2 0 0 0-2 2v8c0 1.1.9 2 2 2h12a2 2 0 0 0 2-2v-8a2 2 0 0 0-2-2h-1V7c0-2.8-2.2-5-5-5zm0 2c1.7 0 3 1.3 3 3v3H9V7c0-1.7 1.3-3 3-3zm-6 8h12v8H6v-8zm6 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z'/%3E%3C/svg%3E");
}

.icon-report {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 3h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2zm0 2v14h14V5H5zm2 2h4v8H7V7zm6 2h4v6h-4V9zm-6 4h4v2H7v-2zm6-2h4v4h-4v-4z'/%3E%3C/svg%3E");
}

.icon-transfer {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M15 3h6v6h-2V6.4l-4.3 4.3-1.4-1.4L17.6 5H15V3zm-6 18H3v-6h2v2.6l4.3-4.3 1.4 1.4L6.4 19H9v2z'/%3E%3C/svg%3E");
}

.icon-assemble {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 21v-2h2.6l4.6-4.6-1.4-1.4L4.2 17.6V15H2v6h6v-2H5.4l2.8-2.8 1.4 1.4L6.8 19H9v2H3zm14-18h6v6h-2V6.4l-4.3 4.3-1.4-1.4L19.6 5H17V3zm-3 9.4l1.4-1.4 2.8 2.8H16v2h6v-6h-2v2.6l-4.6-4.6z'/%3E%3C/svg%3E");
}

.icon-sell {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2zm0 18a8 8 0 1 1 8-8 8 8 0 0 1-8 8zm-1-5h2v-1h-2v-1h2a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1h-2V8h-2v1h-2v2h2v1h-2a1 1 0 0 0-1 1v2a1 1 0 0 0 1 1h2v1h2zm0-6h2v1h-2V9zm0 4h2v1h-2v-1z'/%3E%3C/svg%3E");
}

.icon-history {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm.5-13H11v6l5.2 3.2.8-1.3-4.5-2.7V7z'/%3E%3C/svg%3E");
}

.icon-debt {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2zm0 18a8 8 0 1 1 8-8 8 8 0 0 1-8 8zm1-14v2h2v2h-2v4a2 2 0 0 0 2 2h2v-2h-2v-2h2a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-2V6h-2zm-3 0v2H8v2h2v4a2 2 0 0 0 2 2h2v-2h-2v-2h2a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-2V6h-2z'/%3E%3C/svg%3E");
}

.icon-weight {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20.57 14.86L22 13.43 20.57 12 17 15.57 8.43 7 12 3.43 10.57 2 9.14 3.43 7.71 2 5.57 4.14 4.14 2.71 2.71 4.14 2 5.57 3.43 7 2 8.43l3.57 3.57L7 16.57 3.43 13 2 14.43 3.43 15.86 2 17.29 4.14 19.43l1.43-1.43L7 19.57 8.43 18.16 10.57 20.3 12 18.87 13.43 20.3 15.57 18.16 17 19.57 18.43 18.16 20.57 20.3 22 18.87 20.57 17.44 22 16 20.57 14.86zM12 15.57l3.57-3.57L18.57 15 20 13.43 18.57 12 20 10.57 18.57 9.14 16.43 11.28 15 9.86 17.14 7.71 15.57 6.14 12 9.71 8.43 6.14 6.86 7.71 9 9.86 7.57 11.28 5.43 9.14 4 10.57 5.43 12 4 13.43 5.57 14.86 7.71 12.72 9.14 14.14 7 16.28 8.43 17.71 12 14.14 15.57 17.71 17.14 16.28 15 14.14 16.43 12.72 18.57 14.86 20 13.43z'/%3E%3C/svg%3E");
}

.icon-phase {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2zm0 18a8 8 0 1 1 8-8 8 8 0 0 1-8 8zm-1-5h2v-1h-2v-1h2a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1h-2V8h-2v1h-2v2h2v1h-2a1 1 0 0 0-1 1v2a1 1 0 0 0 1 1h2z'/%3E%3C/svg%3E");
}

.icon-piece {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5'/%3E%3C/svg%3E");
}

.icon-admin {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 15.5A3.5 3.5 0 0 1 8.5 12 3.5 3.5 0 0 1 12 8.5a3.5 3.5 0 0 1 3.5 3.5 3.5 3.5 0 0 1-3.5 3.5m7.43-2.53c.04-.32.07-.64.07-.97 0-.33-.03-.66-.07-1l2.11-1.63c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.31-.61-.22l-2.49 1c-.52-.39-1.06-.73-1.69-.98l-.37-2.65A.506.506 0 0 0 14 2h-4c-.25 0-.46.18-.5.42l-.37 2.65c-.63.25-1.17.59-1.69.98l-2.49-1c-.22-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64L4.57 11c-.04.34-.07.67-.07 1 0 .33.03.65.07.97l-2.11 1.66c-.19.15-.25.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1.01c.52.4 1.06.74 1.69.99l.37 2.65c.04.24.25.42.5.42h4c.25 0 .46-.18.5-.42l.37-2.65c.63-.26 1.17-.59 1.69-.99l2.49 1.01c.22.08.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64l-2.11-1.66z'/%3E%3C/svg%3E");
}

.icon-analysis {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 3v18h18V3H3zm16 16H5V5h14v14zM9 17H7v-5h2v5zm4 0h-2V7h2v10zm4 0h-2v-7h2v7z'/%3E%3C/svg%3E");
}

.icon-analysis-plot {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 9.2h3V19H5V9.2zM10.6 5h2.8v14h-2.8V5zm5.6 8H19v6h-2.8v-6z'/%3E%3C/svg%3E");
}

.icon-analysis-time {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm.5-13H11v6l5.25 3.15.75-1.23-4.5-2.67z'/%3E%3C/svg%3E");
}

.swap-btn.icon-swap {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z'/%3E%3C/svg%3E");
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.99 11L3 15l3.99 4v-3H14v-2H6.99v-3zM21 9l-3.99-4v3H10v2h7.01v3L21 9z'/%3E%3C/svg%3E");
    background-color: currentColor;
}

.icon-calc {
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 2h10a2 2 0 012 2v16a2 2 0 01-2 2H7a2 2 0 01-2-2V4a2 2 0 012-2zm0 2v4h10V4H7zm0 6v2h2v-2H7zm4 0v2h2v-2h-2zm4 0v2h2v-2h-2zm-8 4v2h2v-2H7zm4 0v2h2v-2h-2zm4 0v2h2v-2h-2zm-8 4v2h2v-2H7zm4 0v2h2v-2h-2zm4 0v2h2v-2h-2z'/%3E%3C/svg%3E");
}