/* ==========================================
   HOURGLASS ORDER DASHBOARD - STYLES
   Production-ready CSS with accessibility
   ========================================== */

:root {
    --primary: #0f172a;
    --accent: #f59e0b;
    --bg: #f8fafc;
    --white: #ffffff;
    --border: #e2e8f0;
    --text: #334155;
    --danger: #ef4444;
    --success: #10b981;
    --info: #3b82f6;
    --warning: #f59e0b;
    --muted: #94a3b8;

    /* Dark mode variables */
    --dark-bg: #1e293b;
    --dark-surface: #0f172a;
    --dark-text: #e2e8f0;
    --dark-border: #334155;
}

/* ==========================================
   GLOBAL STYLES
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

body.dark-mode {
    --bg: var(--dark-bg);
    --white: var(--dark-surface);
    --text: var(--dark-text);
    --border: var(--dark-border);
}

/* ==========================================
   HEADER
   ========================================== */
header {
    background-color: var(--primary);
    color: white;
    padding: 12px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    z-index: 30;
    flex-shrink: 0;
}

.brand {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand i {
    font-size: 1.4rem;
}

.header-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

.data-loader {
    display: flex;
    gap: 10px;
    align-items: center;
    background: rgba(255,255,255,0.1);
    padding: 8px 14px;
    border-radius: 6px;
    transition: background 0.2s;
}

.data-loader:hover {
    background: rgba(255,255,255,0.15);
}

.data-loader label {
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

input[type="file"] {
    display: none;
}

.file-status {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 600;
}

.btn-icon {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 38px;
    height: 38px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

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

.btn-icon i {
    font-size: 1.1rem;
}

.btn-icon[title]:hover::after {
    content: attr(title);
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--primary);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 100;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

/* ==========================================
   FILTER BAR
   ========================================== */
.filter-bar {
    background: var(--white);
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    z-index: 20;
    flex-shrink: 0;
}

.filter-row {
    display: grid;
    grid-template-columns: 2fr repeat(4, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
}

.filter-group label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-group input,
.filter-group select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s;
}

.filter-group input:focus,
.filter-group select:focus {
    border-color: var(--accent);
    outline: none;
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

.filter-actions {
    display: flex;
    gap: 8px;
}

.btn-reset,
.btn-save-preset {
    background: var(--primary);
    color: white;
    border: none;
    padding: 9px 16px;
    border-radius: 6px;
    cursor: pointer;
    height: 38px;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-reset:hover,
.btn-save-preset:hover {
    background: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn-save-preset {
    background: var(--success);
}

.btn-save-preset:hover {
    background: #059669;
}

.preset-selector {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.preset-tag {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.preset-tag:hover {
    border-color: var(--accent);
    background: white;
}

.preset-tag.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.preset-tag .delete {
    opacity: 0.6;
    cursor: pointer;
}

.preset-tag .delete:hover {
    opacity: 1;
}

/* ==========================================
   MAIN LAYOUT
   ========================================== */
.main-container {
    display: grid;
    grid-template-columns: 340px 1fr;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ==========================================
   SIDEBAR / ACTION PANEL
   ========================================== */
.action-panel {
    background: var(--white);
    border-right: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
}

.section-header {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--muted);
    margin: 28px 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-header:first-child {
    margin-top: 0;
}

.section-header i {
    font-size: 0.9rem;
}

.report-card {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.report-card:hover {
    transform: translateX(4px);
    border-color: var(--accent);
    box-shadow: 0 4px 8px rgba(0,0,0,0.08);
}

.report-card.active {
    border-left: 4px solid var(--accent);
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.report-card h4 {
    margin: 0 0 6px 0;
    font-size: 0.95rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
    padding-right: 50px;
}

.report-card h4 i {
    color: var(--accent);
    font-size: 1.1rem;
}

.report-card p {
    margin: 0;
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.4;
}

.badge {
    position: absolute;
    top: 14px;
    right: 14px;
    background: #cbd5e1;
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 800;
    min-width: 28px;
    text-align: center;
}

.badge.danger {
    background: #fecaca;
    color: #991b1b;
}

.badge.warning {
    background: #fde68a;
    color: #92400e;
}

.badge.success {
    background: #bbf7d0;
    color: #166534;
}

.badge.info {
    background: #bfdbfe;
    color: #1e40af;
}

/* ==========================================
   OUTPUT PANEL
   ========================================== */
.output-panel {
    padding: 32px;
    overflow-y: auto;
    background-color: #f1f5f9;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    margin-top: 120px;
}

.empty-state i {
    font-size: 5rem;
    opacity: 0.15;
    margin-bottom: 24px;
    display: block;
}

.empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 8px;
    color: var(--text);
}

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

.report-container {
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 20px -5px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--border);
}

.report-header {
    padding: 18px 28px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg);
    border-radius: 10px 10px 0 0;
}

.report-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.report-actions {
    display: flex;
    gap: 10px;
}

.report-actions button {
    padding: 10px 18px;
    border: 1px solid var(--border);
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.report-actions button:hover {
    background: var(--bg);
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--primary) !important;
    color: white !important;
    border: none !important;
}

.btn-primary:hover {
    background: #334155 !important;
}

.btn-success {
    background: var(--success) !important;
    color: white !important;
    border: none !important;
}

.btn-success:hover {
    background: #059669 !important;
}

.report-body {
    flex: 1;
    padding: 28px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    white-space: pre;
    overflow: auto;
    color: #1e293b;
    background-color: white;
}

/* ==========================================
   CHART SECTION
   ========================================== */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.chart-card {
    background: var(--bg);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.chart-card h4 {
    font-size: 0.85rem;
    color: var(--muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chart-content {
    min-height: 150px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chart-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-label {
    font-size: 0.75rem;
    min-width: 100px;
    color: var(--text);
}

.chart-bar-fill {
    flex: 1;
    height: 24px;
    background: var(--bg);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.chart-bar-value {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #fbbf24);
    transition: width 0.6s ease;
    display: flex;
    align-items: center;
    padding-left: 8px;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
}

/* ==========================================
   MODAL
   ========================================== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(3px);
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--white);
    width: 96%;
    max-width: 1600px;
    height: 92vh;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.35);
    animation: slideUp 0.3s;
}

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

.modal-header {
    padding: 18px 28px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--primary);
    color: white;
    border-radius: 12px 12px 0 0;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.close-modal {
    cursor: pointer;
    font-size: 2rem;
    opacity: 0.8;
    transition: all 0.2s;
    line-height: 1;
    padding: 0 8px;
}

.close-modal:hover {
    opacity: 1;
    transform: scale(1.1);
}

.modal-search {
    padding: 16px 24px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: center;
}

.modal-search input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
}

.modal-search input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

.column-toggle {
    padding: 10px 16px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.column-toggle:hover {
    border-color: var(--accent);
}

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

/* ==========================================
   DATA TABLE
   ========================================== */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    min-width: 1200px;
}

th {
    background: #f1f5f9;
    padding: 14px 16px;
    text-align: left;
    font-weight: 700;
    color: var(--primary);
    position: sticky;
    top: 0;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    z-index: 10;
    cursor: pointer;
    user-select: none;
}

th:hover {
    background: #e2e8f0;
}

th.sortable::after {
    content: '\f0dc';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    margin-left: 8px;
    opacity: 0.3;
    font-size: 0.7rem;
}

th.sort-asc::after {
    content: '\f0de';
    opacity: 1;
    color: var(--accent);
}

th.sort-desc::after {
    content: '\f0dd';
    opacity: 1;
    color: var(--accent);
}

td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    color: #475569;
    white-space: nowrap;
}

tr:hover {
    background: #f8fafc;
}

tr.hidden {
    display: none;
}

td.highlight-red {
    color: var(--danger);
    font-weight: 700;
    background: #fef2f2;
}

td.highlight-green {
    color: var(--success);
    font-weight: 700;
}

td.highlight-yellow {
    color: #d97706;
    font-weight: 700;
    background: #fffbeb;
}

/* ==========================================
   LOADING SPINNER
   ========================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    border: 4px solid var(--border);
    border-top: 4px solid var(--accent);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-text {
    color: var(--text);
    font-weight: 600;
}

/* ==========================================
   TOAST NOTIFICATIONS
   ========================================== */
.toast-container {
    position: fixed;
    top: 80px;
    right: 24px;
    z-index: 9998;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: white;
    padding: 14px 20px;
    border-radius: 8px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    border-left: 4px solid var(--info);
    animation: slideInRight 0.3s;
}

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

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
}

.toast i {
    font-size: 1.2rem;
}

.toast.success i {
    color: var(--success);
}

.toast.error i {
    color: var(--danger);
}

.toast.warning i {
    color: var(--warning);
}

.toast.info i {
    color: var(--info);
}

.toast-message {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 500;
}

.toast-close {
    cursor: pointer;
    opacity: 0.6;
    font-size: 1.2rem;
}

.toast-close:hover {
    opacity: 1;
}

/* ==========================================
   PRINT STYLES
   ========================================== */
@media print {
    body {
        background: white;
    }

    header,
    .filter-bar,
    .action-panel,
    .report-actions {
        display: none !important;
    }

    .main-container {
        display: block;
    }

    .output-panel {
        padding: 0;
        overflow: visible;
    }

    .report-container {
        box-shadow: none;
        border: none;
    }

    .report-body {
        font-size: 10pt;
        line-height: 1.4;
    }
}

/* ==========================================
   RESPONSIVE DESIGN
   ========================================== */
@media (max-width: 1200px) {
    .main-container {
        grid-template-columns: 280px 1fr;
    }

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

@media (max-width: 768px) {
    .main-container {
        grid-template-columns: 1fr;
    }

    .action-panel {
        display: none;
    }

    .filter-row {
        grid-template-columns: 1fr;
    }

    header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .header-actions {
        justify-content: space-between;
    }
}

/* ==========================================
   KEYBOARD FOCUS STYLES
   ========================================== */
*:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus,
select:focus,
input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ==========================================
   ACCESSIBILITY
   ========================================== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border: #000000;
    }

    .report-card {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
