/* =============================================
   AVALANCHE STORM - Professional Design System
   ============================================= */

/* --- CSS Custom Properties --- */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-200: #bfdbfe;
    --secondary: #64748b;
    --secondary-dark: #475569;
    --success: #059669;
    --success-light: #d1fae5;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;

    --sidebar-bg: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    --sidebar-width: 260px;
    --sidebar-collapsed: 0px;

    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    --bg-hover: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-white: #ffffff;

    --border-color: #e2e8f0;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    --transition: all 0.2s ease;
    --transition-slow: all 0.3s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-page);
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0;
    line-height: 1.3;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-dark);
}

/* --- Page Header --- */
.page-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.page-header h2 {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
}

.page-header .page-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-sm);
    background: var(--primary-50);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

/* --- Cards --- */
.card-panel {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    overflow: hidden;
    transition: var(--transition);
}

.card-panel:hover {
    box-shadow: var(--shadow-md);
}

.card-panel-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-panel-body {
    padding: 1.25rem;
}

/* --- Form Controls --- */
.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-bottom: 0.375rem;
}

.form-control, .form-select {
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 0.5rem 0.875rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    background-color: var(--bg-input);
    transition: var(--transition);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-200);
    outline: none;
    background-color: var(--bg-card);
}

.form-control:disabled, .form-select:disabled {
    background-color: var(--bg-page);
    color: var(--text-secondary);
    border-color: var(--border-color);
    cursor: not-allowed;
}

.form-control::placeholder {
    color: var(--text-muted);
}

textarea.form-control {
    resize: vertical;
}

/* --- Buttons --- */
.btn {
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.5rem 1.25rem;
    border-radius: var(--border-radius-sm);
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    cursor: pointer;
    width: auto;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3);
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 1px 2px rgba(5, 150, 105, 0.3);
}

.btn-success:hover {
    background: #047857;
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #b91c1c;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-page);
    color: var(--text-secondary);
    border: 1.5px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.btn-outline-primary {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.btn-outline-primary:hover {
    background: var(--primary-50);
}

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

.btn:focus {
    box-shadow: 0 0 0 3px var(--primary-200);
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius-sm);
}

/* --- List Items --- */
.item-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.item-list li {
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-list li:last-child {
    border-bottom: none;
}

.item-list li:hover {
    background: var(--bg-hover);
}

.item-list li.active {
    background: var(--primary-50);
    color: var(--primary);
    font-weight: 600;
    border-left: 3px solid var(--primary);
}

.item-list li.text-muted {
    color: var(--text-muted);
    cursor: default;
    font-style: italic;
}

/* --- Search Input --- */
.search-box {
    position: relative;
}

.search-box .form-control {
    padding-left: 2.5rem;
}

.search-box .search-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
}

/* --- Page Wrapper (master-detail + action-bar) --- */
.page-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    /* height is determined by remaining space after page-header and glt-bar */
}

/* Make main content area a flex column so page-body gets remaining space */
main {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 0px); /* full viewport, sidebar handles itself */
    overflow: hidden;
}

/* --- Action Bar --- */
.action-bar {
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    display: flex;
    justify-content: center;
    gap: 0.625rem;
    flex-wrap: wrap;
    flex-shrink: 0;
    width: 100%;
}

/* --- Master-Detail Layout --- */
.master-detail {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.master-panel {
    width: 30%;
    min-width: 240px;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background: var(--bg-card);
}

.master-panel.disabled-panel {
    pointer-events: none;
    opacity: 0.5;
}

.master-panel .panel-search {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.master-panel .panel-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
}

.detail-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-page);
    min-height: 0;
}

.detail-panel-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    padding: 1.5rem;
    min-height: 0;
    min-width: 0;
}

.detail-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 800px;
    min-width: 0;
}

.detail-card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.detail-card-header h3 {
    font-size: 1.1rem;
    margin: 0;
}

.detail-card-body {
    padding: 1.5rem;
}

/* --- Invoice Styles --- */
.invoice-paper {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    max-width: 500px;
    width: 100%;
    padding: 1.75rem;
    font-size: 0.9rem;
}

.invoice-paper .invoice-header-section {
    border-bottom: 2px solid var(--text-primary);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.invoice-paper .invoice-client-info {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1.25rem;
    line-height: 1.6;
}

.order-item {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.order-item:last-child {
    border-bottom: none;
}

.product-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-meta {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    font-size: 0.8rem;
}

.meta {
    text-align: center;
}

.meta .label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.meta .value {
    font-weight: 500;
    color: var(--text-primary);
}

.meta.total .value {
    font-weight: 700;
    color: var(--primary-dark);
}

.invoice-totals-section {
    border-top: 2px solid var(--border-color);
    padding-top: 0.875rem;
    margin-top: 0.875rem;
}

.invoice-totals-section .total-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: 0.9rem;
}

.invoice-totals-section .total-row.grand-total {
    border-top: 2px solid var(--text-primary);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    font-weight: 700;
    font-size: 1rem;
}

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

/* --- Checkbox Items --- */
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.checkbox-item:hover {
    background: var(--bg-hover);
}

.checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* --- Notification --- */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.notification {
    background: var(--text-primary);
    color: white;
    padding: 0.875rem 1.25rem;
    margin-bottom: 0.625rem;
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    font-size: 0.9rem;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* --- Validation --- */
.valid.modified:not([type=checkbox]) {
    outline: 1.5px solid var(--success);
}

.invalid {
    outline: 1.5px solid var(--danger);
}

.validation-message {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* --- Blazor Error --- */
.blazor-error-boundary {
    background: var(--danger);
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
    border-radius: var(--border-radius-sm);
    margin: 1rem;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

#blazor-error-ui {
    color-scheme: light only;
    background: #fef3c7;
    border-top: 2px solid var(--warning);
    bottom: 0;
    box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.15);
    display: none;
    left: 0;
    padding: 0.75rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    font-size: 0.9rem;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-muted);
}

.empty-state .bi {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    display: block;
}

.empty-state p {
    font-size: 0.9rem;
}

/* --- Status Badge --- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-badge.success {
    background: var(--success-light);
    color: var(--success);
}

.status-badge.danger {
    background: var(--danger-light);
    color: var(--danger);
}

/* --- Separator / Divider --- */
.separator {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    margin: 0 0.5rem;
}

/* --- Dropdown (autocomplete) --- */
.z-100 {
    z-index: 100;
}

.autocomplete-dropdown {
    position: absolute;
    width: 100%;
    z-index: 100;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    box-shadow: var(--shadow-lg);
    margin-top: 2px;
}

.autocomplete-dropdown li {
    padding: 0.5rem 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.9rem;
    list-style: none;
    border-bottom: 1px solid var(--border-color);
}

.autocomplete-dropdown li:last-child {
    border-bottom: none;
}

.autocomplete-dropdown li:hover {
    background: var(--primary-50);
    color: var(--primary);
}

/* --- Grid Helpers --- */
.form-grid {
    display: grid;
    gap: 1rem;
}

.form-grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.form-grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* --- Loading Spinner --- */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: inline-block;
}

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

/* --- Paper Card --- */
.paper-card {
    background: var(--bg-card);
    padding: 1rem;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 0.75rem;
}

/* --- Print --- */
@media print {
    body * {
        visibility: hidden;
    }
    .invoice-actions {
        display: none !important;
    }
    #invoice, #invoice * {
        visibility: visible;
    }
    #invoice {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .page-body {
        height: auto;
        min-height: calc(100vh - 65px);
    }

    .master-detail {
        flex-direction: column;
        flex: 1;
    }

    .master-panel {
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .detail-panel {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .detail-panel-scroll {
        padding: 1rem;
        overflow-x: auto;
    }

    .detail-card {
        max-width: 100%;
        width: 100%;
    }

    .detail-card-body {
        padding: 1rem;
    }

    .detail-card-header {
        padding: 0.75rem 1rem;
    }

    .form-grid-2, .form-grid-3, .form-grid-4 {
        grid-template-columns: 1fr;
    }

    .action-bar {
        justify-content: center;
        padding: 0.75rem 1rem;
        position: sticky;
        bottom: 0;
        z-index: 10;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
    }

    .action-bar .btn {
        flex: 1;
        min-width: 0;
        max-width: 180px;
    }

    .product-meta {
        grid-template-columns: repeat(2, 1fr);
    }

    .page-header {
        padding: 1rem;
    }

    .page-header h2 {
        font-size: 1.1rem;
    }

    .invoice-paper {
        padding: 1rem;
        max-width: 100%;
    }

    .invoice-actions {
        justify-content: center;
    }

    .card-panel-body {
        padding: 1rem;
    }

    .card-panel-header {
        padding: 0.75rem 1rem;
    }

    /* Autocomplete dropdown mobile */
    .autocomplete-dropdown {
        max-height: 180px;
    }

    /* Invoice totals */
    .invoice-totals-section .total-row {
        font-size: 0.85rem;
    }

    /* SupplierProducts two-column → stack */
    .supplier-products-layout {
        flex-direction: column !important;
    }

    .supplier-products-layout > .card-panel {
        min-height: 200px;
    }
}

@media (max-width: 480px) {
    .master-panel {
        max-height: 35vh;
    }

    .detail-panel {
        padding: 0.75rem;
    }

    .detail-card-body {
        padding: 0.75rem;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }

    .action-bar .btn {
        max-width: 150px;
    }

    .form-label {
        font-size: 0.75rem;
    }

    .form-control, .form-select {
        font-size: 0.85rem;
        padding: 0.4rem 0.75rem;
    }

    .page-header {
        padding: 0.75rem 1rem;
    }

    .page-header h2 {
        font-size: 1rem;
    }

    .invoice-paper {
        padding: 0.75rem;
        font-size: 0.8rem;
    }

    .product-meta {
        font-size: 0.7rem;
    }
}

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

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

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
