/* ═══════════════════════════════════════════════════════════════
   RIT CGPA CALCULATOR - MOBILE-FIRST RESPONSIVE STYLES
   ═══════════════════════════════════════════════════════════════ */

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(135deg, #eef2ff 0%, #fae8ff 100%);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Safe Area (iOS) */
.app-header {
    padding-top: env(safe-area-inset-top);
}

.app-content {
    padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
}

/* Container */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
}

/* Header (Sticky on Mobile) */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    align-items: center;
    padding: 12px 16px;
}

.back-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: var(--background);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
}

.header-title {
    margin-left: 12px;
}

.header-title h1 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
}

.header-title p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

.header-spacer {
    flex: 1;
}

/* Navigation Tabs (Fixed Bottom on Mobile) */
.calculator-tabs {
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 99;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    padding-bottom: env(safe-area-inset-bottom);
}

.calc-tab-btn {
    flex: 1;
    padding: 12px 8px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-height: 60px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.calc-tab-btn.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-color);
    border-top: 3px solid var(--primary-color);
}

.tab-icon {
    font-size: 20px;
}

.tab-label {
    font-size: 11px;
    font-weight: 600;
}

/* Content Sections */
.calc-section {
    display: none;
    animation: fadeIn 0.3s ease-out;
    padding-bottom: 80px;
    /* Space for bottom tabs */
}

.calc-section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Cards */
.card,
.form-card,
.result-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

/* Inputs (Large Touch Targets) */
input,
select,
button {
    font-family: inherit;
    font-size: 16px;
    /* Prevents zoom on iOS */
}

.input-group {
    margin-bottom: 16px;
}

.input-label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

input[type="number"],
input[type="text"],
select {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--surface);
    min-height: 48px;
    /* Touch-friendly */
    color: var(--text-primary);
    transition: border-color 0.2s;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Buttons (Large & Touch-Friendly) */
.btn,
.primary-btn,
.secondary-btn {
    width: 100%;
    padding: 14px 20px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.1s, box-shadow 0.2s;
}

.primary-btn {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.primary-btn:active {
    transform: scale(0.98);
}

.secondary-btn {
    background: white;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-group {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

/* Scenario Tabs (Inner Tabs) */
.scenario-tabs {
    display: flex;
    gap: 8px;
    background: var(--background);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
}

.tab-btn.active {
    background: var(--surface);
    color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Scenario Panels */
.scenario-panel {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.scenario-panel.active {
    display: block;
}

/* Responsive Tables (Stack on Mobile) */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px;
    /* Allow horizontal scroll */
}

th {
    background: var(--background);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
}

th,
td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

tr:last-child td {
    border-bottom: none;
}

/* Subject Cards (Mobile Alternative to Table) */
.subject-card-mobile {
    background: var(--background);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    border-left: 4px solid var(--primary-color);
}

.subject-card-mobile .subject-name {
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.subject-card-mobile .subject-details {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-size: 11px;
    text-transform: uppercase;
    opacity: 0.7;
}

.detail-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Status Badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.status-achievable {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-not-achievable {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* Comparison Grid */
.comparison-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 20px;
}

.comparison-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 16px;
    border: 2px solid var(--border-color);
}

.comparison-card.conservative {
    border-color: rgba(239, 68, 68, 0.3);
}

.comparison-card.optimistic {
    border-color: rgba(16, 185, 129, 0.3);
}

.comp-header {
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Dynamic Subject Inputs */
.subject-input-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
    align-items: start;
}

.remove-subject-btn {
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    border: 3px solid var(--primary-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-top: -12px;
    margin-left: -12px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ═══════════════════════════════════════════════════════════════
   TABLET BREAKPOINT (481px - 768px)
   ═══════════════════════════════════════════════════════════════ */

@media (min-width: 481px) {
    .container {
        padding: 24px;
        max-width: 700px;
    }

    .comparison-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .calculator-tabs {
        position: sticky;
        top: 70px;
        /* Below header */
        bottom: auto;
        border-radius: 12px;
        margin-bottom: 20px;
        padding-bottom: 0;
        border: 1px solid var(--border-color);
        z-index: 90;
    }

    .calc-tab-btn {
        flex-direction: row;
        padding: 16px 24px;
        gap: 8px;
        justify-content: center;
        border-top: none;
        border-bottom: 3px solid transparent;
    }

    .calc-tab-btn.active {
        border-top: none;
        border-bottom: 3px solid var(--primary-color);
    }

    .tab-label {
        font-size: 14px;
    }

    .calc-section {
        padding-bottom: 20px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   DESKTOP BREAKPOINT (769px+)
   ═══════════════════════════════════════════════════════════════ */

@media (min-width: 769px) {
    .container {
        max-width: 900px;
        padding: 32px;
    }

    .app-header {
        position: static;
        border-radius: 16px;
        margin-bottom: 24px;
        border: 1px solid var(--border-color);
    }

    body {
        padding: 20px;
    }

    .card,
    .form-card,
    .result-card {
        padding: 32px;
    }

    .header-title h1 {
        font-size: 24px;
    }

    /* Larger input grid on desktop */
    .input-grid-2 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }

    .input-grid-3 {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }

    .subject-input-row {
        grid-template-columns: 3fr 1fr 1fr auto;
        gap: 16px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   DARK MODE SUPPORT
   ═══════════════════════════════════════════════════════════════ */

@media (prefers-color-scheme: dark) {
    :root {
        --background: #0f172a;
        --surface: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border-color: #334155;
    }

    body {
        background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    }

    .back-btn {
        background: var(--surface);
    }

    .subject-card-mobile {
        background: #0f172a;
    }

    th {
        background: #0f172a;
    }
}