/* ─── Google Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Inter+Tight:wght@600;700&display=swap');

/* ─── CSS Variables (Light Theme) ────────────────────────────────────────── */
:root {
    --primary: #C8102E;
    --primary-hover: #A50024;
    --alternate: #A50024;
    --secondary: #ffffff;
    --tertiary: #E2E2E2;

    --bg: #F9F9F9;
    --bg-card: #ffffff;
    --bg-nav: #C8102E;
    --bg-input: #ffffff;

    --text: #C8102E;
    --text-body: #333333;
    --text-secondary: #888888;
    --text-nav: #ffffff;

    --accent1: #FF6F61;
    --accent2: #FFB6B0;
    --accent3: #FF3B30;
    --accent4: #D9D9D9;

    --success: #28A745;
    --warning: #FFC107;
    --danger: #DC3545;
    --info: #17A2B8;

    --border: #E2E2E2;
    --border-red: #C8102E;
    --shadow: 0 2px 8px rgba(0,0,0,0.10);
    --shadow-lg: 0 5px 20px rgba(0,0,0,0.15);
    --radius: 8px;
    --radius-md: 12px;
    --radius-lg: 24px;
    --radius-sm: 4px;

    --font-heading: 'Inter Tight', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ─── Dark Theme ──────────────────────────────────────────────────────────── */
body.dark {
    --primary: #A50024;
    --primary-hover: #8a001e;
    --alternate: #A9002B;
    --secondary: #F4F4F4;
    --tertiary: #B0B0B0;

    --bg: #333333;
    --bg-card: #3C3C3C;
    --bg-nav: #A50024;
    --bg-input: #4a4a4a;

    --text: #FFE0E6;
    --text-body: #E0E0E0;
    --text-secondary: #B0B0B0;
    --text-nav: #FFE0E6;

    --border: #555555;
    --border-red: #A50024;
    --shadow: 0 2px 5px rgba(0,0,0,0.3);
    --shadow-lg: 0 5px 15px rgba(0,0,0,0.4);
}

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

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text-body);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text);
}

.hidden { display: none !important; }

/* ─── App wrapper: centered mobile column ─────────────────────────────────── */
#app-wrapper {
    width: 100%;
    max-width: 480px;
    min-height: 100vh;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

/* ─── Navbar / App Bar ────────────────────────────────────────────────────── */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-nav);
    color: var(--text-nav);
    padding: 0 8px 0 12px;
    height: 56px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Leaderboard title centered */
.navbar.title-centered .navbar-left {
    position: absolute;
    left: 0;
    right: 0;
    justify-content: center;
    pointer-events: none;
    z-index: 0;
}
.navbar.title-centered .navbar-left .navbar-back {
    position: absolute;
    left: 8px;
    pointer-events: auto;
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.navbar-title {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
    /* Stay pinned to the right edge even when `.navbar.title-centered` pulls
       `.navbar-left` out of flow, leaving this as the lone space-between child
       (which would otherwise collapse to the left and drag all icons there). */
    margin-left: auto;
}

.navbar-back {
    color: #ffffff;
    font-size: 22px;
}

.navbar-team-info {
    font-size: 12px;
    color: #ffffff;
    white-space: nowrap;
    margin-right: 4px;
    opacity: 0.9;
}

/* ─── Icon buttons ────────────────────────────────────────────────────────── */
.btn-icon {
    background: none;
    border: none;
    color: #ffffff;
    cursor: pointer;
    font-size: 20px;
    padding: 0;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    flex-shrink: 0;
}
.btn-icon:hover {
    background: rgba(255,255,255,0.18);
}

/* Inline Material icon glyphs (match FlutterFlow's 24px Icon size). */
.icon {
    width: 24px;
    height: 24px;
    display: block;
    fill: currentColor;
}
.btn-eye .icon {
    width: 20px;
    height: 20px;
}

/* Modal close btn – dark on white bg */
.modal-close-btn {
    color: var(--text-body);
    font-size: 16px;
}
.modal-close-btn:hover {
    background: var(--tertiary);
}

/* ─── Connection Status ───────────────────────────────────────────────────── */
.connection-status {
    position: fixed;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 16px;
    font-size: 12px;
    background: #FFC107;
    color: #333;
    border-radius: 0 0 6px 6px;
    max-width: 480px;
    width: 100%;
}
.connection-status.connected { background: #28A745; color: #fff; }
.connection-status.error { background: #DC3545; color: #fff; }
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #fff;
}

/* ─── Main app content ────────────────────────────────────────────────────── */
#app {
    flex: 1;
    overflow-y: auto;
}

.page {
    padding: 16px;
}

/* ─── Pill Buttons (primary CTA) ──────────────────────────────────────────── */
.btn-pill {
    display: block;
    width: 100%;
    padding: 15px 20px;
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 28px;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s, box-shadow 0.15s;
}
.btn-pill-primary {
    background: var(--primary);
    color: #ffffff;
}
.btn-pill-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow);
}

/* ─── Generic small btn (admin etc.) ─────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-body);
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    gap: 6px;
}
.btn:hover { box-shadow: var(--shadow); }
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 4px 12px; font-size: 13px; }

/* ─── Forms ───────────────────────────────────────────────────────────────── */
.form-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow);
}
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--primary);
}
.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--font-body);
    font-size: 14px;
    border: 1.5px solid var(--border-red);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-body);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(200, 16, 46, 0.15);
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 12px; }

/* ─── Login page ──────────────────────────────────────────────────────────── */
.page-login {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-height: calc(100vh - 56px);
    padding: 24px 20px 60px;
}
.login-container {
    width: 100%;
}
.login-heading {
    font-family: var(--font-heading);
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 32px;
}
.login-form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Password with eye toggle */
.password-wrapper {
    position: relative;
}
.password-wrapper input {
    width: 100%;
    padding-right: 44px;
}
.btn-eye {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-secondary);
    padding: 4px;
    line-height: 1;
}

/* ─── Situácie list page ──────────────────────────────────────────────────── */
.situacie-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 0;
}

/* Scenario card */
.sit-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 16px 18px 14px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: box-shadow 0.15s;
}
.sit-card:hover { box-shadow: var(--shadow-lg); }

.sit-card-title-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.sit-card-number {
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
}
.sit-card-name {
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}
.sit-card-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-left: 2px;
}

.sit-card-limit {
    font-size: 14px;
    color: var(--text-body);
    display: flex;
    align-items: baseline;
    gap: 4px;
}
.sit-card-limit-num {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
}
.sit-card-limit-unit {
    color: var(--primary);
    font-size: 14px;
}

/* ─── Team grid modal ─────────────────────────────────────────────────────── */
.team-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 8px 0;
}
.team-tile {
    aspect-ratio: 0.85;
    border-radius: 12px;
    border: 2px solid var(--primary);
    background: var(--bg-card);
    color: var(--primary);
    font-family: var(--font-heading);
    font-size: 36px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.team-tile:hover,
.team-tile.selected {
    background: var(--primary);
    color: #ffffff;
}

/* Modal team title style */
.modal-team-title {
    text-align: center;
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    padding: 8px 0 12px;
}
.modal-team-divider {
    border: none;
    border-top: 1.5px solid var(--primary);
    margin: 0 0 16px;
}

/* ─── Scoring page ────────────────────────────────────────────────────────── */

/* Hidden team select (keep for harness compat) */
.team-selector {
    display: none;
}

/* Info block at top of scoring page */
.scoring-info-block {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-body);
    box-shadow: var(--shadow);
}
.scoring-info-row {
    display: grid;
    grid-template-columns: auto 1fr auto 1fr;
    gap: 2px 8px;
    align-items: baseline;
    margin-bottom: 4px;
}
.scoring-info-label {
    color: var(--text-secondary);
    font-size: 12px;
    white-space: nowrap;
}
.scoring-info-value {
    font-weight: 500;
    font-size: 13px;
    color: var(--text-body);
}
.scoring-obmedzenie {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin: 6px 0 4px;
}
.scoring-rozhodcovia {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 4px 0;
}
.rozhodca-chip {
    background: var(--primary);
    color: #ffffff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 10px;
}

/* Category header bar */
.scoring-kategoria {
    margin-bottom: 10px;
}
.kat-header {
    background: var(--primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: var(--radius) var(--radius) 0 0;
}
.kat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.kat-poradie {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 700;
}
.kat-nazov {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 600;
}
.kat-max {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 700;
}

.kat-body {
    background: var(--bg-card);
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 10px 14px 14px;
    box-shadow: var(--shadow);
}
.kat-spravny-postup {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-style: italic;
}

/* Uloha cards */
.uloha-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.uloha-card {
    background: var(--bg-card);
    border: 1.5px solid var(--primary);
    border-radius: var(--radius);
    padding: 8px 10px;
    min-width: 80px;
    max-width: 120px;
    flex: 1;
    cursor: pointer;
    position: relative;
    transition: box-shadow 0.15s;
}
.uloha-card:hover { box-shadow: var(--shadow); }

.uloha-max-badge {
    background: var(--primary);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    padding: 1px 6px;
    position: absolute;
    top: -1px;
    left: -1px;
    border-radius: 6px 0 6px 0;
}
.uloha-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-body);
    margin-top: 16px;
    margin-bottom: 6px;
    line-height: 1.3;
}
.uloha-options-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.uloha-opt {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    min-width: 24px;
    text-align: center;
    padding: 2px 4px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.12s, color 0.12s;
}
.uloha-opt:hover { background: rgba(200,16,46,0.1); }
.uloha-opt.selected,
.uloha-opt.saved {
    background: var(--primary);
    color: #ffffff;
    border-radius: 4px;
}

/* Value picker modal */
.value-picker {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 8px 0;
}
.value-chip {
    display: block;
    width: 100%;
    padding: 18px 16px;
    font-family: var(--font-heading);
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    border: 2px solid var(--primary);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--primary);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.value-chip:hover,
.value-chip.selected {
    background: var(--primary);
    color: #ffffff;
}

/* ─── Leaderboard / Vyhodnotenie ──────────────────────────────────────────── */
.leaderboard-table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    margin-bottom: 0;
}
.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
}
.leaderboard-table thead tr {
    background: var(--primary);
}
.leaderboard-table th {
    padding: 14px 12px;
    text-align: center;
    color: #ffffff;
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
    border: none;
}
.leaderboard-table td {
    padding: 12px 12px;
    text-align: center;
    color: var(--primary);
    font-size: 15px;
    font-weight: 500;
    border: none;
    border-bottom: 1px solid var(--border);
}
.leaderboard-table tbody tr:nth-child(even) td {
    background: #F5F5F5;
}
body.dark .leaderboard-table tbody tr:nth-child(even) td {
    background: rgba(255,255,255,0.05);
}
.leaderboard-table td:first-child {
    font-weight: 700;
    color: var(--primary);
}
.leaderboard-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 2px solid var(--primary);
    padding: 12px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.leaderboard-pdf-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 0 16px;
}

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}
.modal {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 460px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 12px 16px 0;
}
.modal-header h3 {
    display: none; /* Title shown inside body for team-pick style */
}
.modal-body {
    padding: 0 20px 20px;
    overflow-y: auto;
}

/* ─── Admin tabs (functional, minimal restyle) ────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}
.page-header h1 {
    font-family: var(--font-heading);
    font-size: 24px;
    flex: 1;
}
.header-actions { display: flex; gap: 8px; }

.admin-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}
.tab-btn {
    padding: 10px 20px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
}
.tab-btn:hover { color: var(--text-body); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content.hidden { display: none; }
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.section-header h2 { font-family: var(--font-heading); font-size: 20px; }

/* ─── Tables (admin) ──────────────────────────────────────────────────────── */
.table-container { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
th, td {
    padding: 10px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
th {
    background: var(--primary);
    color: #ffffff;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
tr:hover td { background: rgba(200,16,46,0.04); }
td.actions { white-space: nowrap; }
td.center, th.center { text-align: center; }

/* ─── Toast ───────────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 14px;
    color: #fff;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 340px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ─── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}
.empty-state p { font-size: 16px; }

/* ─── Responsive: tablet & desktop ────────────────────────────────────────────
   The base styles above are mobile-first (a centered 480px column). From the
   tablet breakpoint up, the app shell — navbar included — stretches across the
   whole screen to match the tablet/desktop reference frames, while genuinely
   width-limited content (the login form) stays a centered, constrained column. */
@media (min-width: 768px) {
    /* The shell fills the screen instead of floating as a phone-width column. */
    #app-wrapper {
        max-width: none;
        box-shadow: none;
    }

    /* Connection status pill spans the full-width shell. */
    .connection-status {
        max-width: none;
    }

    /* Roomier app bar + content gutters on larger screens. */
    .navbar { padding: 0 16px 0 24px; }
    .page { padding: 24px 32px; }

    /* Login is centered both axes with a constrained form width. */
    .page-login {
        justify-content: center;
        padding: 24px 32px;
    }
    .login-container {
        max-width: 460px;
        margin: 0 auto;
    }

    /* Team picker and value picker get room to breathe: tiles flow in a row
       across the wide modal (matching the team-pickup reference frame). */
    .modal { max-width: 720px; }
    .team-grid {
        grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    }
    .team-tile { aspect-ratio: 1; font-size: 28px; }
}

/* Desktop: keep line lengths readable by centering page content within a wide
   max-width while the navbar stays full-bleed across the top. The scenario
   list and ranking table stay full-width single-column rows, as in the
   tablet/desktop reference frames. */
@media (min-width: 1200px) {
    .page { max-width: 1200px; margin: 0 auto; }
    .modal { max-width: 920px; }
}
