:root {
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --bg-card-hover: rgba(51, 65, 85, 0.8);
    --primary: #8b5cf6;
    --primary-glow: rgba(139, 92, 246, 0.5);
    --accent: #06b6d4;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --font-stack: 'Outfit', sans-serif;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --h1-gradient: linear-gradient(to right, #fff, #cbd5e1);
    --bg-input: rgba(15, 23, 42, 0.6);
    --text-input: #ffffff;
    --bg-nav: rgba(0, 0, 0, 0.2);
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-dropdown: #1e293b;
    --bg-danger-light: rgba(239, 68, 68, 0.15);
    --text-danger-light: #fecaca;
    --bg-primary-light: rgba(139, 92, 246, 0.05);
    --bg-modal: rgba(15, 23, 50, 0.85);
    /* Deep Indigo Backdrop */
}

/* Themes */
/* Themes */
body.theme-clean-white {
    --bg-dark: #f8f9fa;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f3f5;
    --primary: #3b82f6;
    --primary-glow: rgba(59, 130, 246, 0.1);
    --accent: #2563eb;
    --text-main: #111827;
    --text-muted: #4b5563;
    --border: #e5e7eb;
    --h1-gradient: linear-gradient(to right, #111827, #374151);

    --bg-input: #ffffff;
    --text-input: #111827;
    --bg-nav: #e5e7eb;
    --bg-hover: #f3f4f6;
    --bg-dropdown: #f9fafb;
    --bg-danger-light: #fef2f2;
    --text-danger-light: #991b1b;
    --bg-primary-light: #eff6ff;
    --bg-modal: rgba(17, 24, 39, 0.5);

    /* Graph Overrides for Clean White */
    --chart-grid-color: rgba(0, 0, 0, 0.1);
    --chart-text-color: #4b5563;
    --chart-line-color: #3b82f6;
    --chart-fill-color: rgba(59, 130, 246, 0.2);
    --chart-point-bg: #fff;
    --chart-point-border: #3b82f6;
}


body.theme-mint-pale {
    --bg-dark: #f0fdf4;
    --bg-card: #fafffb;
    --bg-card-hover: #e6fcf0;
    --primary: #10b981;
    --primary-glow: rgba(16, 185, 129, 0.1);
    --accent: #059669;
    --text-main: #064e3b;
    --text-muted: #2d5a45;
    --border: #bbf7d0;
    --h1-gradient: linear-gradient(to right, #064e3b, #065f46);
    --bg-input: #ffffff;
    --text-input: #064e3b;
    --bg-nav: #d3f9e1;
    --bg-hover: #bbf7d0;
    --bg-dropdown: #e6fcf0;
    --bg-danger-light: #fef2f2;
    --text-danger-light: #991b1b;
    --bg-primary-light: #f0fdf4;
    --bg-modal: rgba(6, 78, 59, 0.5);
    /* Rich Dark Green Tint */
}

body.theme-rose-pale {
    --bg-dark: #fff1f2;
    --bg-card: #fffafb;
    --bg-card-hover: #fff0f3;
    --primary: #f43f5e;
    --primary-glow: rgba(244, 63, 94, 0.1);
    --accent: #e11d48;
    --text-main: #4c0519;
    --text-muted: #6a2d3c;
    --border: #fecdd3;
    --h1-gradient: linear-gradient(to right, #4c0519, #881337);
    --bg-input: #ffffff;
    --text-input: #4c0519;
    --bg-nav: #f9d3dd;
    --bg-hover: #fecdd3;
    --bg-dropdown: #fff0f3;
    --bg-danger-light: #fff1f2;
    --text-danger-light: #9f1239;
    --bg-primary-light: #fff5f5;
    --bg-modal: rgba(76, 5, 25, 0.5);
    /* Rich Dark Rose Tint */
}

body.theme-sky-pale {
    --bg-dark: #f0f9ff;
    --bg-card: #fafdff;
    --bg-card-hover: #f0f9ff;
    --primary: #0ea5e9;
    --primary-glow: rgba(14, 165, 233, 0.1);
    --accent: #0284c7;
    --text-main: #0c4a6e;
    --text-muted: #2d4c6a;
    --border: #bae6fd;
    --h1-gradient: linear-gradient(to right, #0c4a6e, #075985);
    --bg-input: #ffffff;
    --text-input: #0c4a6e;
    --bg-nav: #d3e9f9;
    --bg-hover: #bae6fd;
    --bg-dropdown: #e0f2fe;
    --bg-danger-light: #fef2f2;
    --text-danger-light: #b91c1c;
    --bg-primary-light: #f0f9ff;
    --bg-modal: rgba(12, 74, 110, 0.5);
    /* Rich Dark Sky Tint */
}

body.theme-lavender-pale {
    --bg-dark: #f5f3ff;
    --bg-card: #fafbff;
    --bg-card-hover: #f5f3ff;
    --primary: #8b5cf6;
    --primary-glow: rgba(139, 92, 246, 0.1);
    --accent: #7c3aed;
    --text-main: #2e1065;
    --text-muted: #4c2d6a;
    --border: #ddd6fe;
    --h1-gradient: linear-gradient(to right, #2e1065, #4c1d95);
    --bg-input: #ffffff;
    --text-input: #2e1065;
    --bg-nav: #e6d3f9;
    --bg-hover: #ddd6fe;
    --bg-dropdown: #ede9fe;
    --bg-danger-light: #fff1f2;
    --text-danger-light: #7f1d1d;
    --bg-primary-light: #f5f3ff;
    --bg-modal: rgba(46, 16, 101, 0.5);
    /* Rich Dark Lavender Tint */
}

body.theme-lemon-pale {
    --bg-dark: #fefce8;
    --bg-card: #fffefb;
    --bg-card-hover: #fffbeb;
    --primary: #eab308;
    --primary-glow: rgba(234, 179, 8, 0.1);
    --accent: #ca8a04;
    --text-main: #422006;
    --text-muted: #5a4c2d;
    --border: #fef08a;
    --h1-gradient: linear-gradient(to right, #422006, #713f12);
    --bg-input: #ffffff;
    --text-input: #422006;
    --bg-nav: #f9f0d3;
    --bg-hover: #fef08a;
    --bg-dropdown: #fef9c3;
    --bg-danger-light: #fffbeb;
    --text-danger-light: #713f12;
    --bg-primary-light: #fefce8;
    --bg-modal: rgba(66, 32, 6, 0.5);
    /* Rich Dark Amber Tint */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-stack);
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    /* Lock height */
    display: flex;
    justify-content: center;
    padding: 1rem;
    /* Reduced padding */
    overflow: hidden;
    /* No full-page scroll */
}

/* Background */
.background-glow {
    position: fixed;
    top: -20%;
    left: -20%;
    width: 60%;
    height: 60%;
    background: radial-gradient(circle, var(--primary-glow) 0%, transparent 70%);
    filter: blur(100px);
    z-index: -1;
    opacity: 0.4;
    animation: pulse 10s infinite alternate;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    100% {
        transform: scale(1.1);
    }
}

.app-container {
    width: 98%;
    max-width: 1800px;
    height: 100%;
    /* Fill viewport height */
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
}

/* Header */
header {
    text-align: center;
    padding: 1rem 1rem 0.5rem;
}

.status-container {
    display: flex;
    flex-direction: row;
    gap: 1rem;
    align-items: center;
    justify-content: center;
    margin-top: 0.75rem;
}

#btnSaveCloud:hover {
    background: #059669 !important;
    /* Smooder green */
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

#btnSaveCloud:active {
    transform: translateY(0);
}


.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.logo-icon {
    font-size: 2rem;
}

h1 {
    font-size: 2.2rem;
    background: var(--h1-gradient);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.accent {
    color: var(--primary);
    -webkit-text-fill-color: var(--primary);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Navigation Tabs Container */
.nav-tabs {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 0.5rem;
    background: var(--bg-nav);
    border-radius: 40px;
    margin-bottom: 0.5rem;
    transition: background 0.3s ease;
}

.nav-tab {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    padding: 0.6rem 1.5rem;
    border-radius: 30px;
    cursor: pointer;
    font-family: var(--font-stack);
    font-size: 1.05rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.nav-tab:hover {
    color: var(--text-main);
    background: var(--bg-hover);
}

.nav-tab.active {
    background: var(--primary-glow);
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
}

/* Main content area */
main {
    flex: 1;
    overflow: hidden;
}

/* Views */
.view-section {
    display: none;
    height: 100%;
    animation: fadeIn 0.3s ease-out;
}

.view-section.active-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    /* Children manage their own scroll */
}

/* Ensure sub-views in stats also flex */
.stats-section {
    flex: 1;
    display: none;
    flex-direction: column;
    min-height: 0;
}

.stats-section.active-view {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Cards & Generic */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 1rem;
    /* Consolidated smaller padding for all views */
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    /* Critical for inner table scroll */
    margin-bottom: 0.5rem;
}

#view-settings {
    padding-right: 0.1rem;
    /* Tighter padding */
}

/* Specific padding for reports card removed, now global */

h2 {
    font-size: 1.25rem;
    margin-bottom: 1.2rem;
    font-weight: 600;
}

/* Forms */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
    width: 100%;
}

label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

input,
select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    color: var(--text-input);
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
    font-family: inherit;
}

.form-group input,
.form-group select {
    width: 100%;
}

option {
    background-color: var(--bg-dropdown);
    color: var(--text-main);
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.row {
    display: flex;
    gap: 1rem;
}

@media (max-width: 600px) {
    .row {
        flex-direction: column;
        gap: 0;
    }
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 0.9rem;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-family: var(--font-stack);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -5px var(--primary-glow);
}

.btn-disabled-style {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 0.9rem;
    border-radius: 12px;
    cursor: pointer;
    width: 30%;
    transition: 0.2s;
}

.btn-secondary:hover {
    background: var(--bg-nav);
    color: white;
}

.hidden {
    display: none !important;
}

/* Reports & Table */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.version-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    background: rgba(6, 182, 212, 0.1);
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    border: 1px solid rgba(6, 182, 212, 0.2);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
}

.report-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex: 1;
    /* Allow filters to take available space */
}

.filters select,
.filters input {
    padding: 0.5rem;
    font-size: 0.9rem;
    min-width: 120px;
    width: auto;
}

.actions-bar {
    display: flex;
    gap: 0.5rem;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.btn-small {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: 0.2s;
}

.btn-small:hover {
    background: var(--bg-nav);
    color: white;
    border-color: var(--accent);
}

.table-container {
    flex: 1;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
}

.report-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: var(--bg-card);
    /* Ensure solid background so rows don't show through */
}

/* Compact style for management tables */
.compact-rows td {
    padding: 0.4rem 0.6rem !important;
    font-size: 0.9rem;
}

/* Drag and Drop styles */
.draggable-row {
    cursor: grab;
    user-select: none;
}

.draggable-row:active {
    cursor: grabbing;
}

.dragging {
    opacity: 0.4;
    background: var(--bg-nav) !important;
}

.drag-over {
    border-top: 2px solid var(--accent) !important;
}

.report-table th,
.report-table td {
    padding: 0.6rem 0.8rem;
    line-height: 1.4;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.compact-table th,
.compact-table td {
    padding: 0.35rem 0.6rem;
    line-height: 1.2;
    font-size: 0.85rem;
}

.table-filter-input {
    width: 100%;
    height: 1.6rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 6px;
    color: var(--text-main);
    font-size: 0.8rem;
    margin-top: 2px;
    font-family: var(--font-stack);
    line-height: 1.6rem;
}

.table-filter-input:focus {
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.4);
    outline: none;
}

.report-table th {
    white-space: nowrap;
}

/* Ensure the first and last columns feel 'justified' to the container edges */
.report-table th:first-child,
.report-table td:first-child {
    padding-left: 1rem;
}

.report-table th:last-child,
.report-table td:last-child {
    padding-right: 1rem;
    text-align: right;
}

.report-table th {
    background: var(--bg-dropdown);
    /* solid color */
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    position: sticky;
    top: 0;
    z-index: 50;
    transition: background 0.2s;
    white-space: nowrap;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
    /* visual separation */
}

.report-table th.sortable {
    cursor: pointer;
    padding-right: 1.5rem;
    /* Space for sort arrow */
}

.report-table th.sortable:hover {
    background: var(--bg-hover);
    color: var(--text-main);
}

.report-table th.sortable::after {
    content: '';
    display: inline-block;
    margin-left: 5px;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 4px solid var(--text-muted);
    opacity: 0.3;
    transition: opacity 0.2s;
    vertical-align: middle;
}

.report-table th.sortable.asc::after {
    border-bottom: 4px solid var(--primary);
    border-top: none;
    opacity: 1;
}

.report-table th.sortable.desc::after {
    border-top: 4px solid var(--primary);
    border-bottom: none;
    opacity: 1;
}

.report-table td {
    font-size: 0.9rem;
}

.report-table tr:hover {
    background: var(--bg-card-hover);
}

/* Table Actions */
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.2rem;
    transition: 0.2s;
}

.btn-icon[disabled] {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(1);
}

.btn-icon.edit {
    color: var(--warning);
    margin-right: 0.5rem;
}

.btn-icon.delete {
    color: var(--border);
}

.btn-icon.edit:not([disabled]):hover {
    color: #fbbf24;
    transform: scale(1.1);
}

.btn-icon.delete:not([disabled]):hover {
    color: var(--danger);
    transform: scale(1.1);
}

.empty-state {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Detail Row */
.detail-row td {
    padding: 10px 20px;
    background: var(--bg-primary-light);
    border-top: none;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.expand-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-hover);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--primary);
    border: 1px solid transparent;
}

/* Sub-Navigation */
.sub-nav {
    display: flex;
    gap: 0.75rem;
    padding: 0.4rem;
    background: var(--bg-nav);
    border-radius: 12px;
    margin-bottom: 0;
    flex-wrap: wrap;
    transition: background 0.3s ease;
}

.sub-tab {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: 0.2s;
    font-weight: 500;
}

.sub-tab:hover {
    color: var(--text-main);
    background: var(--bg-hover);
}

.sub-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.setting-section {
    display: none;
    flex-direction: column;
    min-height: 0;
}

.setting-section:not(.hidden) {
    display: flex;
}

/* Sections that fill height and have internal scrolling (Tables) */
.setting-section.setting-fill {
    flex: 1;
    overflow: hidden;
}

.setting-section.setting-fill .card {
    flex: 1;
    min-height: 0;
}

/* Sections that scroll as a whole (Forms/Data) */
.setting-section.setting-scroll {
    flex: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.setting-section.setting-scroll .card {
    flex: none;
    margin-bottom: 1.5rem;
}

/* Age Indicator */
.age-indicator {
    border: 1px solid var(--danger);
    background-color: var(--danger);
    border-radius: 4px;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 0.8rem;
    margin: -5px;
    /* Adjust spacing in cell */
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

/* IAAF Table Editing Styles */
.iaaf-mark.editing,
.iaaf-points.editing {
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid var(--primary);
    padding: 4px;
    border-radius: 4px;
    outline: none;
}

.iaaf-mark.editing:focus,
.iaaf-points.editing:focus {
    background: rgba(139, 92, 246, 0.25);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-modal);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn 0.2s ease-out;
}

/* Modal Content */
.modal-content {
    width: 90%;
    max-width: 600px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 25px 80px -12px var(--primary-glow);
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}


.modal-overlay.hidden {
    display: none !important;
}

/* Progress Bar */
.progress-container {
    width: 100%;
    height: 12px;
    background: var(--bg-nav);
    border-radius: 6px;
    margin: 1.5rem 0;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent), var(--primary));
    background-size: 200% 100%;
    border-radius: 6px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    animation: progressPulse 2s linear infinite;
}

@keyframes progressPulse {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: 0% 0;
    }
}

.progress-text {
    text-align: center;
    font-size: 1rem;
    color: var(--text-muted);
}

/* --- Admin Visibility Rules --- */
/* By default (non-admin), hide management tabs */
.nav-tab[data-tab="log"],
.nav-tab[data-tab="history"],
.nav-tab[data-tab="settings"] {
    display: none !important;
}

/* Actions explicitly managed by JS */

/* When Admin is logged in */
body.is-admin .nav-tab[data-tab="log"],
body.is-admin .nav-tab[data-tab="history"],
body.is-admin .nav-tab[data-tab="settings"] {
    display: block !important;
}

/* --- Approval Workflow Styles --- */
.badge-pending {
    background: var(--bg-hover);
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: bold;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
    transition: 0.2s;
}

.badge-pending:hover {
    color: var(--text-main);
    border-color: var(--accent);
}

td .badge-pending {
    /* If covering IDR content in existing layout, maybe center it? */
    margin: 0 auto;
}

/* Ensure parent cell has relative positioning for badge context */
/* Use specificity to target the name div */
td>div[style*="position:relative"],
td>div {
    position: relative !important;
}

.approve-btn {
    transition: transform 0.2s;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1em;
}

.approve-btn:hover {
    transform: scale(1.2);
}

/* =============================================================
   RESPONSIVE DESIGN — Tablet (≤1024px) & Mobile (≤640px)
   ============================================================= */

/* ── Tablet ─────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    body {
        padding: 0.5rem;
        overflow: auto;
        /* allow page-level scroll on smaller screens */
        height: auto;
        min-height: 100vh;
    }

    .app-container {
        width: 100%;
        height: auto;
        overflow: visible;
    }

    main {
        overflow: visible;
    }

    .view-section.active-view {
        overflow: visible;
        height: auto;
    }

    .card {
        overflow: visible;
        min-height: 0;
    }

    h1 {
        font-size: 1.5rem;
    }

    .nav-tabs {
        flex-wrap: wrap;
        gap: 0.4rem;
        border-radius: 16px;
        padding: 0.4rem;
    }

    .nav-tab {
        font-size: 0.85rem;
        padding: 0.45rem 0.9rem;
    }

    .report-toolbar {
        flex-direction: column;
        gap: 0.6rem;
        margin-bottom: 0.8rem;
    }

    .filters {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .filters select,
    .filters input {
        min-width: 0;
        flex: 1 1 140px;
        font-size: 0.82rem;
    }

    .actions-bar {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .report-table th,
    .report-table td {
        padding: 0.45rem 0.55rem;
        font-size: 0.82rem;
    }
}

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 640px) {
    body {
        padding: 0.3rem;
    }

    header {
        padding: 0.5rem 0.3rem 0.3rem;
    }

    /* Collapse the top-bar grid to a simpler column layout */
    .top-bar {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 0.4rem;
    }

    h1 {
        font-size: 1.1rem;
        text-align: center;
    }

    .subtitle {
        display: none;
        /* hide "Powered by..." line on tiny screens */
    }

    .logo-icon svg {
        width: 28px;
        height: 28px;
    }

    /* Shrink nav tabs to icon-like pills */
    .nav-tabs {
        gap: 0.25rem;
        border-radius: 12px;
        padding: 0.3rem;
    }

    .nav-tab {
        font-size: 0.75rem;
        padding: 0.35rem 0.65rem;
        border-radius: 20px;
    }

    .card {
        padding: 0.6rem;
        border-radius: 12px;
    }

    /* Section header: title left, version badge right in one line */
    .section-header {
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .section-header h2 {
        font-size: 1rem;
        margin-bottom: 0.3rem;
    }

    /* Filters: full-width stacked dropdowns */
    .filters {
        flex-direction: column;
        gap: 0.35rem;
    }

    .filters select,
    .filters input[type="text"],
    .filters input[type="search"] {
        width: 100%;
        min-width: 0;
        flex: none;
        font-size: 0.9rem;
    }

    /* Export buttons: shrink text, allow wrap */
    .actions-bar {
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    .btn-small {
        font-size: 0.75rem;
        padding: 0.35rem 0.6rem;
    }

    /* Report table: horizontal scroll with touch */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }

    .report-table {
        min-width: 620px;
        /* prevent table from collapsing too narrow */
    }

    .report-table th,
    .report-table td {
        padding: 0.4rem 0.4rem;
        font-size: 0.78rem;
        white-space: nowrap;
    }

    /* Hide less critical table columns on tiny screens */
    .report-table .col-wind,
    .report-table td:nth-child(7) {
        /* wind column */
        display: none;
    }

    /* Form rows stack on mobile */
    .form-row {
        flex-direction: column !important;
        gap: 0 !important;
    }

    .form-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .btn-secondary {
        width: 100%;
    }

    /* Stats filter row: wrap */
    .filters[style*="display:flex"] {
        flex-wrap: wrap;
    }

    /* Cloud & save controls */
    #cloudStatus,
    #btnSaveCloud {
        font-size: 0.78rem;
        padding: 0.3rem 0.6rem;
    }
}