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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
    position: relative;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 5px;
}

.subtitle {
    opacity: 0.9;
    font-size: 1.1em;
}

.controls {
    display: flex;
    gap: 15px;
    padding: 25px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    flex-wrap: wrap;
    align-items: flex-end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-size: 0.9em;
    font-weight: 600;
    color: #555;
}

.control-group input {
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    width: 120px;
}

.control-group input:focus {
    outline: none;
    border-color: #667eea;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.loading {
    text-align: center;
    padding: 60px;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.error {
    background: #f8d7da;
    color: #721c24;
    padding: 15px 25px;
    margin: 20px;
    border-radius: 6px;
    border: 1px solid #f5c6cb;
    white-space: pre-line;
    line-height: 1.6;
}

.help-text {
    font-size: 0.9em;
    color: #666;
    margin-left: 15px;
}

.hidden {
    display: none;
}

.dashboard-empty-state {
    margin: 24px 20px 0;
    padding: 20px 22px;
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.6);
    color: #334155;
    line-height: 1.55;
    font-size: 0.95rem;
}

.dashboard-empty-state-lead {
    font-weight: 700;
    font-size: 1.05rem;
    margin: 0 0 10px;
    color: #1e293b;
}

.dashboard-empty-state p {
    margin: 0 0 12px;
}

.dashboard-empty-state p:last-child {
    margin-bottom: 0;
}

.dashboard-empty-state-hint {
    font-size: 0.88rem;
    color: #64748b;
}

.results {
    padding: 25px;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.forecast-filters {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-item label {
    font-size: 0.9em;
    font-weight: 600;
    color: #555;
}

.filter-select {
    padding: 8px 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: white;
    font-size: 0.95em;
}

.filter-select:focus {
    outline: none;
    border-color: #667eea;
}

.filter-help {
    font-size: 0.9em;
    color: #666;
}

.card {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.card.large {
    grid-column: 1 / -1;
}

.card h3 {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat {
    font-size: 2em;
    font-weight: bold;
    color: #333;
}

.tabs {
    display: flex;
    gap: 10px;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 20px;
    align-items: center;
}

.tab-btn {
    padding: 12px 24px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    color: #666;
    transition: all 0.3s;
}

#po-download-csv {
    margin-left: auto;
}

.tab-btn:hover {
    color: #667eea;
}

.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.tab-content {
    display: none;
}

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

.pnl-panel {
    background: white;
    border-radius: 8px;
    padding: 1.5rem 1.75rem;
    border: 1px solid #e8e8ef;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.pnl-panel h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1.15rem;
    color: #333;
}

.pnl-intro {
    margin: 0 0 1.25rem 0;
    color: #666;
    line-height: 1.5;
    max-width: 42rem;
}

.pnl-table {
    width: 100%;
    max-width: 40rem;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

.pnl-table th[scope="row"] {
    text-align: left;
    font-weight: 600;
    color: #333;
    padding: 0.65rem 0.75rem 0.35rem 0;
    vertical-align: top;
    width: 42%;
}

.pnl-table .pnl-value {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #1a1a2e;
    padding: 0.65rem 0 0.35rem 0.75rem;
    white-space: nowrap;
}

.pnl-value-with-link {
    font-weight: 400;
}

a.pnl-value-link {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #4c5fd5;
    text-decoration: none;
    border-bottom: 1px solid rgba(76, 95, 213, 0.35);
}

a.pnl-value-link:hover {
    color: #3a4abf;
    border-bottom-color: #3a4abf;
}

.pnl-table .pnl-desc {
    font-size: 0.85rem;
    color: #777;
    padding: 0 0 0.85rem 0;
    line-height: 1.45;
    border-bottom: 1px solid #eee;
}

.pnl-table tr:last-child .pnl-desc {
    border-bottom: none;
}

.pnl-cashflow.negative {
    color: #b91c1c;
}

.pnl-section-head {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #555;
    padding: 1rem 0 0.35rem 0;
    border-bottom: 1px solid #e5e5e5;
}

.pnl-input-cell {
    text-align: right;
    vertical-align: middle;
    padding: 0.35rem 0 0.35rem 0.75rem;
}

.pnl-opex-input {
    width: 100%;
    max-width: 11rem;
    margin-left: auto;
    display: block;
    padding: 0.45rem 0.55rem;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    border: 1px solid #cfd4dc;
    border-radius: 6px;
    text-align: right;
    color: #1a1a2e;
    background: #fafbfc;
}

.pnl-opex-input:focus {
    outline: none;
    border-color: #667eea;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.pnl-opex-pct-hint {
    font-weight: 400;
    font-size: 0.82em;
    color: #666;
}

.pnl-input-cell-suffix {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
}

.pnl-input-cell-suffix .pnl-opex-input {
    max-width: 8.5rem;
    flex: 0 0 auto;
}

.pnl-input-suffix {
    font-weight: 600;
    font-size: 0.95rem;
    color: #444;
    user-select: none;
    flex-shrink: 0;
}

.pnl-cash-at-hand-input {
    width: 100%;
    max-width: 11rem;
    margin-left: auto;
    display: block;
    padding: 0.45rem 0.55rem;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    border: 1px solid #cfd4dc;
    border-radius: 6px;
    text-align: right;
    color: #1a1a2e;
    background: #fafbfc;
}

.pnl-cash-at-hand-input:focus {
    outline: none;
    border-color: #667eea;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.pnl-remaining-cash.negative {
    color: #b91c1c;
}

.table-container {
    overflow-x: auto;
    margin-bottom: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

thead {
    background: #f8f9fa;
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 2px solid #e0e0e0;
}

td {
    padding: 12px 15px;
    border-bottom: 1px solid #f0f0f0;
}

/* Purchase Recommendations */
.po-table-hint {
    margin: 0 0 10px;
    font-size: 0.88em;
    color: #555;
    line-height: 1.4;
}

.po-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    background: #fff;
}

#po-table {
    table-layout: fixed;
    width: 100%;
    min-width: 1080px;
}

#po-table th,
#po-table td {
    padding: 8px 8px;
    font-size: 0.88em;
    vertical-align: middle;
}

#po-table thead th {
    background: #f8f9fb;
    font-weight: 600;
    color: #444;
    border-bottom: 2px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 3;
}

#po-table .po-col-sku,
#po-table .po-col-supplier {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#po-table .po-col-money,
#po-table .po-col-num,
#po-table .po-col-pct,
#po-table .po-col-soo,
#po-table .po-col-stock {
    text-align: right;
    white-space: nowrap;
}

#po-table .po-col-flag,
#po-table .po-col-action {
    text-align: center;
    white-space: nowrap;
}

#po-table th.po-col-type,
#po-table td.po-col-type { width: 7%; min-width: 72px; }
#po-table th.po-col-sku,
#po-table td.po-col-sku { width: 14%; min-width: 110px; }
#po-table th.po-col-supplier,
#po-table td.po-col-supplier { width: 12%; min-width: 100px; }
#po-table th.po-col-stock,
#po-table td.po-col-stock { width: 8%; min-width: 72px; }
#po-table th.po-col-soo,
#po-table td.po-col-soo { width: 5%; min-width: 44px; }
#po-table th.po-col-money,
#po-table td.po-col-money { width: 7%; min-width: 64px; }
#po-table th.po-col-pct,
#po-table td.po-col-pct { width: 5%; min-width: 48px; }
#po-table th.po-col-num,
#po-table td.po-col-num { width: 5%; min-width: 44px; }
#po-table th.po-col-order,
#po-table td.po-col-order { width: 6%; min-width: 56px; }
#po-table th.po-col-flag,
#po-table td.po-col-flag {
    width: 6%;
    min-width: 64px;
    position: sticky;
    right: 52px;
    z-index: 2;
    background: #fff;
    box-shadow: -6px 0 8px -4px rgba(0, 0, 0, 0.08);
}
#po-table thead th.po-col-flag {
    background: #f8f9fb;
    z-index: 4;
}
#po-table th.po-col-action,
#po-table td.po-col-action {
    width: 5%;
    min-width: 52px;
    position: sticky;
    right: 0;
    z-index: 2;
    background: #fff;
}
#po-table thead th.po-col-action {
    background: #f8f9fb;
    z-index: 4;
}

#po-table tbody tr:hover td.po-col-flag,
#po-table tbody tr:hover td.po-col-action {
    background: #f8f9fa;
}

.po-stock {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
    gap: 2px;
}

.po-stock-avail {
    font-weight: 700;
    font-size: 1.05em;
}

.po-stock-avail.stock-zero {
    color: #dc2626;
}

.po-stock-meta {
    font-size: 0.78em;
    color: #6b7280;
    font-weight: 500;
}

.flag-cell {
    font-weight: 700;
    font-size: 0.9em;
    letter-spacing: 0.02em;
}

.po-type-select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    font-size: 0.95em;
    font-weight: 600;
}

.po-order-input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    text-align: right;
    font-weight: 600;
    font-size: 0.95em;
}

.po-order-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.po-order-input:disabled {
    background: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}

tbody tr:hover {
    background: #f8f9fa;
}

.financial-summary {
    margin-bottom: 30px;
}

.financial-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 15px;
}

.financial-stats div {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.financial-stats label {
    font-size: 0.9em;
    color: #666;
}

.financial-stats span {
    font-size: 1.5em;
    font-weight: bold;
    color: #28a745;
}

.po-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.single-unit-controls {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.sku-dropdown {
    padding: 10px 15px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
    min-width: 300px;
    background: white;
    margin-bottom: 20px;
}

.sku-dropdown:focus {
    outline: none;
    border-color: #667eea;
}

.sku-details-bar {
    display: flex;
    gap: 30px;
    padding: 15px 20px;
    background: white;
    border-radius: 6px;
    border: 2px solid #e0e0e0;
    flex-wrap: wrap;
    transition: opacity 0.3s, background-color 0.3s;
}

.sku-details-bar.loading {
    background: #f5f5f5;
    opacity: 0.7;
}

.sku-detail-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 120px;
}

.sku-detail-label {
    font-size: 0.85em;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sku-detail-value {
    font-size: 1.5em;
    font-weight: bold;
    color: #333;
    min-height: 1.5em;
    display: flex;
    align-items: center;
}

.sku-detail-value.flag-reorder {
    color: #dc2626; /* red */
}

.sku-detail-value.flag-ordered {
    color: #2563eb; /* blue */
}

.sku-detail-value.flag-review {
    color: #d97706; /* yellow/orange */
}

.sku-detail-value.flag-ok {
    color: #16a34a; /* green */
}

.flag-cell.flag-reorder {
    color: #dc2626; /* red */
}

.flag-cell.flag-ordered {
    color: #2563eb; /* blue */
}

.flag-cell.flag-review {
    color: #d97706; /* yellow/orange */
}

.flag-cell.flag-ok {
    color: #16a34a; /* green */
}

.loading-spinner-small {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid #e5e7eb;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.loading-spinner-small {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top: 2px solid #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.chart-container {
    margin-top: 20px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chart-legend {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-line {
    display: inline-block;
    width: 30px;
    height: 3px;
    background-color: #667eea;
    border-radius: 2px;
}

.legend-line-dashed {
    background-image: repeating-linear-gradient(
        to right,
        currentColor 0px,
        currentColor 5px,
        transparent 5px,
        transparent 10px
    );
}

.legend-line-dotted {
    background-image: repeating-linear-gradient(
        to right,
        currentColor 0px,
        currentColor 3px,
        transparent 3px,
        transparent 6px
    );
}

.legend-line-dashed-alt {
    background-image: repeating-linear-gradient(
        to right,
        currentColor 0px,
        currentColor 4px,
        transparent 4px,
        transparent 6px,
        currentColor 6px,
        currentColor 7px,
        transparent 7px,
        transparent 9px
    );
}

.legend-label {
    font-size: 0.9em;
    color: #555;
    font-weight: 500;
}

#sales-chart {
    max-width: 100%;
    height: 400px;
}

.modal {
    display: block;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    overflow: auto;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    margin: 50px auto;
    padding: 30px;
    border-radius: 12px;
    max-width: 800px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
}

.close:hover {
    color: #000;
}

#modal-body {
    margin-top: 20px;
}

.modal-chart {
    margin: 20px 0;
}

.modal-chart h4 {
    margin-bottom: 10px;
}

.settings-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: 2px solid #667eea;
    color: #667eea;
    font-size: 1.5em;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.settings-btn:hover {
    background: #667eea;
    color: white;
    transform: rotate(90deg);
}

.settings-content {
    padding: 20px 0;
}

.settings-description {
    color: #666;
    font-size: 0.9em;
    margin-bottom: 20px;
    line-height: 1.5;
}

.settings-group {
    margin-bottom: 30px;
}

.settings-item {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 6px;
}

.settings-item label {
    min-width: 200px;
    font-weight: 600;
    color: #333;
}

.settings-item input[type="number"] {
    width: 80px;
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 1em;
    text-align: center;
}

.settings-item input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
}

.settings-help {
    color: #666;
    font-size: 0.9em;
}

.settings-actions {
    display: flex;
    gap: 15px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.modal-chart table {
    font-size: 0.9em;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85em;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: 600;
}

.badge-trend {
    background: #d4edda;
    color: #155724;
}

.badge-average {
    background: #fff3cd;
    color: #856404;
}

