/* CSS Variables */
:root {
    --desktop-overlay: rgba(0,0,0,0.1);
    --win-bg: #ffffff;
    --win-border: #dcdcdc;
    --chrome-bg: #f4f4f4;
    --text: #111;
    --muted: #888;
    --grid: #e9e9e9;
    --focus: #3b82f6;
    --excel-green: #217346;
    --excel-green-light: #70ad47;
    --excel-header-bg: #f2f2f2;
    --excel-ribbon-bg: #f8f9fa;
    --excel-selected: #cfe2f3;
    --excel-border: #d0d7de;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

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

/* Desktop Environment */
.desktop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-image: url('./assets/new-background.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
}

.desktop::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, transparent 0%, var(--desktop-overlay) 100%);
    pointer-events: none;
}

/* App Window */
.app-window {
    position: relative;
    width: 85%;
    height: 90%;
    max-width: 1200px;
    max-height: 900px;
    min-width: 800px;
    min-height: 600px;
    background: var(--win-bg);
    border: 1px solid var(--win-border);
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
    animation: windowPopIn 200ms ease-out;
    transform-origin: center;
}

@keyframes windowPopIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-window {
        animation: none;
    }
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    background: transparent;
    z-index: 15;
}

.resize-handle.nw {
    top: -5px;
    left: -5px;
    width: 15px;
    height: 15px;
    cursor: nw-resize;
}

.resize-handle.ne {
    top: -5px;
    right: -5px;
    width: 15px;
    height: 15px;
    cursor: ne-resize;
}

.resize-handle.sw {
    bottom: -5px;
    left: -5px;
    width: 15px;
    height: 15px;
    cursor: sw-resize;
}

.resize-handle.se {
    bottom: -5px;
    right: -5px;
    width: 15px;
    height: 15px;
    cursor: se-resize;
}

/* Window Chrome */
.window-chrome {
    background: var(--chrome-bg);
    border-bottom: 1px solid var(--win-border);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: grab;
    user-select: none;
    min-height: 40px;
}

.window-chrome:active {
    cursor: grabbing;
}

.window-controls {
    display: flex;
    gap: 8px;
}

.control-btn {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.control-btn.close {
    background: #ff5f57;
}

.control-btn.minimize {
    background: #ffbd2e;
}

.control-btn.maximize {
    background: #28ca42;
}

.control-btn:hover {
    opacity: 0.8;
}

.window-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

/* Tab Bar */
.tab-bar {
    background: var(--chrome-bg);
    border-bottom: 1px solid var(--win-border);
    padding: 0 16px;
    display: flex;
}

.tab {
    background: var(--win-bg);
    border: 1px solid var(--win-border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    position: relative;
    top: 1px;
}

.tab.active {
    background: var(--win-bg);
    z-index: 1;
}

.tab-icon {
    font-size: 14px;
}

.tab-text {
    font-weight: 500;
}

.tab:not(.active) {
    opacity: 0.7;
}

.tab:not(.active):hover {
    opacity: 0.9;
}

/* Content Container */
.content-container {
    flex: 1;
    background: var(--win-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Tab Content */
.tab-content {
    display: none !important;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.tab-content.active {
    display: flex !important;
}

/* Excel Container */
.excel-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--win-bg);
    overflow: hidden;
}

/* Excel Ribbon */
.excel-ribbon {
    background: var(--excel-ribbon-bg);
    border-bottom: 1px solid var(--excel-border);
}

.ribbon-tabs {
    display: flex;
    background: var(--excel-ribbon-bg);
    border-bottom: 1px solid var(--excel-border);
    padding: 0 8px;
}

.ribbon-tab {
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.ribbon-tab:hover {
    background: rgba(0,0,0,0.05);
}

.ribbon-tab.active {
    border-bottom-color: var(--excel-green);
    color: var(--excel-green);
    background: var(--win-bg);
}

.ribbon-content {
    display: flex;
    padding: 8px 16px;
    gap: 24px;
    background: var(--win-bg);
    border-bottom: 1px solid var(--excel-border);
}

.ribbon-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.ribbon-tools {
    display: flex;
    gap: 4px;
}

.ribbon-btn {
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
}

.ribbon-btn:hover {
    background: rgba(0,0,0,0.05);
    border-color: var(--excel-border);
}

.ribbon-label {
    font-size: 10px;
    color: var(--muted);
    text-align: center;
}

/* Formula Bar */
.formula-bar {
    display: flex;
    align-items: center;
    background: var(--win-bg);
    border-bottom: 1px solid var(--excel-border);
    padding: 4px 8px;
    gap: 8px;
}

.name-box {
    width: 80px;
}

.name-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--excel-border);
    border-radius: 2px;
    font-size: 12px;
    text-align: center;
    background: var(--win-bg);
}

.formula-input-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
}

.formula-buttons {
    display: flex;
    gap: 2px;
}

.formula-btn {
    width: 24px;
    height: 24px;
    border: 1px solid var(--excel-border);
    background: var(--excel-header-bg);
    border-radius: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s ease;
}

.formula-btn:hover {
    background: #e8e8e8;
}

.formula-input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid var(--excel-border);
    border-radius: 2px;
    font-size: 12px;
    background: var(--win-bg);
}

/* Spreadsheet Area */
.spreadsheet-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--win-bg);
}

/* Excel Headers */
.excel-headers {
    display: grid;
    grid-template-columns: 50px repeat(15, 80px);
    background: var(--excel-header-bg);
    border-bottom: 2px solid var(--excel-border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.select-all-btn {
    background: var(--excel-header-bg);
    border-right: 1px solid var(--excel-border);
    border-bottom: 1px solid var(--excel-border);
    cursor: pointer;
    position: relative;
}

.select-all-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    border: 1px solid var(--muted);
    background: transparent;
}

.excel-col-header {
    padding: 8px 4px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    border-right: 1px solid var(--excel-border);
    border-bottom: 1px solid var(--excel-border);
    background: var(--excel-header-bg);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.excel-col-header:hover {
    background: #e8e8e8;
}

/* Excel Grid */
.excel-grid {
    display: grid;
    grid-template-columns: 50px repeat(15, 80px);
    flex: 1;
    overflow: auto;
    background: var(--win-bg);
}

.excel-row-header {
    padding: 0 8px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    border-right: 1px solid var(--excel-border);
    border-bottom: 1px solid var(--excel-border);
    background: var(--excel-header-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.excel-row-header:hover {
    background: #e8e8e8;
}

.excel-cell {
    border-right: 1px solid var(--excel-border);
    border-bottom: 1px solid var(--excel-border);
    padding: 4px 8px;
    min-height: 32px;
    display: flex;
    align-items: center;
    background: var(--win-bg);
    position: relative;
    cursor: cell;
    font-size: 12px;
    transition: all 0.2s ease;
}

.excel-cell:hover {
    background: #f8f9fa;
}

.excel-cell:focus {
    outline: 2px solid var(--excel-green);
    outline-offset: -2px;
    background: var(--win-bg);
    z-index: 2;
}

.excel-cell.selected {
    background: var(--excel-selected);
    border: 2px solid var(--excel-green);
    z-index: 3;
}

/* SFW Title Cell */
.sfw-title-cell {
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: var(--excel-green);
    background: #f0f8f0;
    border: 2px solid var(--excel-green-light);
}

.sfw-title {
    letter-spacing: 2px;
}

/* Metric Headers */
.metric-header {
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
    justify-content: center;
    background: #fff2cc;
    border: 1px solid #d6b656;
}

/* Metric Values */
.metric-value {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: #e8f5e8;
    border: 1px solid var(--excel-green-light);
}

.metric-value:hover {
    background: #d4f1d4;
}

.metric-value:focus {
    outline: 2px solid var(--excel-green);
    outline-offset: -2px;
    background: #d4f1d4;
}

.metric-value .value {
    font-size: 14px;
    font-weight: 600;
    color: var(--excel-green);
    margin-bottom: 2px;
}

.metric-value .sublabel {
    font-size: 10px;
    color: var(--excel-green);
    font-style: italic;
    opacity: 0.8;
}

/* Coming Soon Message */
.coming-soon-message {
    font-size: 12px;
    color: var(--muted);
    font-style: italic;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: #fff9e6;
    border: 1px solid #f0c674;
}

/* Buy Button Cell */
.buy-button-cell {
    justify-content: center;
    align-items: center;
    padding: 4px;
}

.buy-button {
    background: var(--excel-green);
    color: white;
    border: 1px solid var(--excel-green);
    border-radius: 4px;
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 60px;
    font-family: inherit;
}

.buy-button:hover {
    background: #1a5f38;
    border-color: #1a5f38;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.buy-button:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.buy-button:focus {
    outline: 2px solid var(--excel-green);
    outline-offset: 2px;
}

/* Excel Bottom Area */
.excel-bottom {
    display: flex;
    background: var(--excel-header-bg);
    border-top: 1px solid var(--excel-border);
    min-height: 32px;
}

/* Sheet Tabs */
.sheet-tabs {
    display: flex;
    align-items: center;
    flex: 1;
    padding: 0 8px;
    gap: 8px;
}

.sheet-nav {
    display: flex;
    gap: 2px;
}

.sheet-nav-btn {
    width: 20px;
    height: 20px;
    border: 1px solid var(--excel-border);
    background: var(--excel-header-bg);
    border-radius: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    transition: all 0.2s ease;
}

.sheet-nav-btn:hover {
    background: #e8e8e8;
}

.sheet-tab {
    padding: 4px 12px;
    font-size: 11px;
    color: var(--text);
    cursor: pointer;
    border-radius: 4px 4px 0 0;
    border: 1px solid var(--excel-border);
    border-bottom: none;
    background: #e8e8e8;
    transition: all 0.2s ease;
}

.sheet-tab.active {
    background: var(--win-bg);
    font-weight: 600;
    border-bottom: 2px solid var(--win-bg);
    margin-bottom: -1px;
}

.sheet-tab:not(.active):hover {
    background: #d8d8d8;
}

.add-sheet-btn {
    width: 20px;
    height: 20px;
    border: 1px solid var(--excel-border);
    background: var(--excel-header-bg);
    border-radius: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: var(--excel-green);
    transition: all 0.2s ease;
}

.add-sheet-btn:hover {
    background: #e8e8e8;
}

/* Status Bar */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--excel-header-bg);
    border-left: 1px solid var(--excel-border);
    min-width: 300px;
    font-size: 11px;
    color: var(--text);
}

.status-info {
    font-weight: 500;
}

.status-stats {
    display: flex;
    gap: 16px;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.zoom-btn {
    width: 20px;
    height: 20px;
    border: 1px solid var(--excel-border);
    background: var(--excel-header-bg);
    border-radius: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    transition: all 0.2s ease;
}

.zoom-btn:hover {
    background: #e8e8e8;
}

.zoom-level {
    font-size: 11px;
    font-weight: 500;
    min-width: 35px;
    text-align: center;
}

/* Chart Container */
.chart-container {
    flex: 1;
    background: var(--win-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 16px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--grid);
}

.chart-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.chart-controls {
    display: flex;
    gap: 8px;
}

.timeframe-btn {
    background: var(--chrome-bg);
    border: 1px solid var(--win-border);
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.timeframe-btn:hover {
    background: #e8e8e8;
}

.timeframe-btn.active {
    background: var(--focus);
    color: white;
    border-color: var(--focus);
}

.chart-wrapper {
    flex: 1;
    position: relative;
    min-height: 300px;
    background: var(--win-bg);
    border: 1px solid var(--grid);
    border-radius: 4px;
    padding: 16px;
}

.chart-info {
    margin-top: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--grid);
}

.price-info {
    display: flex;
    gap: 16px;
    align-items: center;
}

.current-price {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.price-change {
    font-size: 14px;
    font-weight: 500;
    color: #22c55e;
}

.price-change.negative {
    color: #ef4444;
}

.chart-footnote {
    font-size: 11px;
    color: var(--muted);
    font-style: italic;
}

/* Floating Excel Button */
.floating-excel-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background: rgba(33, 115, 70, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 30;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
}

.floating-excel-btn:hover {
    background: rgba(33, 115, 70, 1);
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.floating-excel-btn:active {
    transform: scale(0.95);
}

.floating-icon {
    font-size: 24px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Responsive Design */
@media (max-width: 1023px) {
    .app-window {
        width: 90%;
        height: 85%;
        min-width: 700px;
        min-height: 500px;
    }
    
    .excel-headers {
        grid-template-columns: 40px repeat(12, 70px);
    }
    
    .excel-grid {
        grid-template-columns: 40px repeat(12, 70px);
    }
    
    .ribbon-content {
        gap: 16px;
    }
}

@media (max-width: 767px) {
    .app-window {
        width: 95%;
        height: 90%;
        min-height: 400px;
        max-height: 90vh;
        min-width: 600px;
    }
    
    .excel-headers {
        grid-template-columns: 35px repeat(8, 60px);
    }
    
    .excel-grid {
        grid-template-columns: 35px repeat(8, 60px);
    }
    
    .window-title {
        display: none;
    }
    
    .tab-text {
        font-size: 12px;
    }
    
    .ribbon-content {
        padding: 4px 8px;
        gap: 12px;
    }
    
    .ribbon-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    /* Hide resize handles on mobile */
    .resize-handle {
        display: none;
    }
    
    /* Adjust floating button for mobile */
    .floating-excel-btn {
        width: 48px;
        height: 48px;
        bottom: 16px;
        right: 16px;
    }
    
    .floating-icon {
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .app-window {
        border-radius: 4px;
        min-width: 500px;
        width: 98%;
        height: 85%;
    }
    
    .excel-headers {
        grid-template-columns: 30px repeat(6, 50px);
    }
    
    .excel-grid {
        grid-template-columns: 30px repeat(6, 50px);
    }
    
    .metric-value .value {
        font-size: 12px;
    }
    
    .metric-value .sublabel {
        font-size: 9px;
    }
    
    .status-bar {
        min-width: 200px;
        padding: 0 8px;
    }
    
    .status-stats {
        gap: 8px;
    }
}
