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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-color);
    min-height: 100vh;
    line-height: 1.6;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Layout */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.main-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    margin-top: 20px;
}

@media (min-width: 1024px) {
    .main-layout {
        grid-template-columns: 350px 1fr;
    }
}

/* Glassmorphism Utilities */
.glass-header,
.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    box-shadow: var(--card-shadow);
}

/* Header */
.glass-header {
    padding: 16px 24px;
    margin-bottom: 24px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--card-border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
}

/* Forms */
.input-section {
    padding: 24px;
    height: fit-content;
}

h2,
h3 {
    margin-bottom: 16px;
    font-size: 1.25rem;
}

.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 6px;
    font-weight: 500;
}

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

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2);
}

details {
    margin-bottom: 16px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

summary {
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    user-select: none;
}

.simulation-options {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.95rem;
}

.radio-label input {
    width: auto;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    padding: 8px 16px;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* Scenarios */
.scenarios-section {
    margin-top: 32px;
    border-top: 1px solid var(--card-border);
    padding-top: 20px;
}

.save-scenario-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.scenario-list {
    list-style: none;
    max-height: 200px;
    overflow-y: auto;
}

.scenario-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    margin-bottom: 6px;
    border-radius: 6px;
    font-size: 0.9rem;
}

.scenario-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 6px;
    opacity: 0.7;
}

.scenario-actions button:hover {
    opacity: 1;
}

/* Privacy Controls */
.privacy-controls {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed var(--card-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-danger {
    padding: 8px 16px;
    background: var(--danger-color, #e53e3e);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

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

.privacy-notice {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* Results Section */
.results-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
    gap: 16px;
}

.summary-card {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--card-border);
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.summary-card .label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.summary-card .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.summary-card .sub-value {
    font-size: 0.8rem;
    margin-top: 4px;
}

.positive {
    color: var(--success-color);
}

.negative {
    color: var(--danger-color);
}

/* Charts */
.charts-container {
    padding: 20px;
}

.charts-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    max-width: 100%;
}

.chart-tab {
    padding: 6px 16px;
    background: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.chart-tab.active,
.chart-tab:hover {
    background: var(--primary-color);
    color: white;
}

.canvas-wrapper {
    position: relative;
    height: 350px;
    width: 100%;
}

/* Table */
.table-container {
    padding: 20px;
}

.table-header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.table-actions {
    display: flex;
    gap: 12px;
}

.table-scroll {
    max-height: 400px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid var(--card-border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th,
td {
    padding: 10px 12px;
    text-align: right;
    border-bottom: 1px solid var(--card-border);
}

th {
    background: rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    backdrop-filter: blur(5px);
    font-weight: 600;
    color: var(--text-muted);
}

tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Footer */
.help-section {
    padding: 24px;
    margin-top: 24px;
}

.help-content {
    font-size: 0.95rem;
    color: var(--text-muted);
}

.help-content p {
    margin-bottom: 10px;
}

/* Notification Animations */
@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Table Performance Optimization */
.table-scroll {
    contain: content;
    overflow-x: auto;
    /* Enable horizontal scrolling for tables */
}

/* ========================================
   MOBILE RESPONSIVE STYLES
   ======================================== */

/* Prevent horizontal overflow on entire page */
html,
body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Force all containers to respect viewport */
.app-container,
.glass-card,
.results-section,
.charts-container,
.table-container,
.summary-grid {
    max-width: 100%;
    overflow-x: hidden;
}

/* Mobile-first adjustments */
@media (max-width: 768px) {

    /* Container adjustments */
    .app-container {
        padding: 12px;
    }

    /* Header */
    .glass-header {
        padding: 12px 16px;
        margin-bottom: 16px;
    }

    .header-content {
        gap: 12px;
    }

    h1 {
        font-size: 1.2rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    /* Input Section */
    .input-section {
        padding: 16px;
    }

    .form-row {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    /* Summary Cards - Stack vertically */
    .summary-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .summary-card {
        padding: 14px;
    }

    .summary-card .value {
        font-size: 1.3rem;
    }

    /* Charts */
    .charts-container {
        padding: 12px;
    }

    .charts-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 8px;
    }

    .chart-tab {
        padding: 6px 12px;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    .canvas-wrapper {
        height: 280px;
    }

    /* Table */
    .table-container {
        padding: 12px;
    }

    .table-header-controls {
        flex-direction: column;
        align-items: stretch;
    }

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

    table {
        font-size: 0.75rem;
        min-width: 600px;
        /* Force horizontal scroll */
    }

    th,
    td {
        padding: 8px 6px;
    }

    /* Scenarios */
    .save-scenario-row {
        flex-direction: column;
    }

    .save-scenario-row input {
        width: 100%;
    }

    /* Help section */
    .help-section {
        padding: 16px;
        margin-top: 16px;
    }
}

/* Extra small devices */
@media (max-width: 375px) {
    .app-container {
        padding: 8px;
    }

    h1 {
        font-size: 1.1rem;
    }

    .summary-card .value {
        font-size: 1.1rem;
    }

    .canvas-wrapper {
        height: 220px;
    }
}