*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    /* Base palette: #10B981 (emerald), #FFFFFF (white), #1A1F3A (navy) */
    --color-bg: #f0f2f6;
    --color-surface: #FFFFFF;
    --color-text: #1A1F3A;
    --color-text-secondary: #4a5072;
    --color-text-muted: #7c82a1;
    --color-border: #d8dce8;
    --color-border-light: #eceef4;
    --color-primary: #1A1F3A;
    --color-primary-hover: #12162b;
    --color-primary-bg: #e8eaf4;
    --color-green: #10B981;
    --color-green-bg: #ecfdf5;
    --color-green-border: #10B981;
    --color-red: #dc2626;
    --color-red-bg: #fef2f2;
    --color-orange: #d97706;
    --color-orange-bg: #fffbeb;
    --color-navbar: #1A1F3A;
    --shadow-sm: 0 1px 2px rgba(26, 31, 58, 0.05), 0 1px 3px rgba(26, 31, 58, 0.07);
    --shadow-md: 0 2px 4px rgba(26, 31, 58, 0.05), 0 4px 12px rgba(26, 31, 58, 0.08);
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.15s ease;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Navbar ===== */
.navbar {
    background: var(--color-navbar);
    color: #fff;
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(26, 31, 58, 0.15), 0 4px 12px rgba(26, 31, 58, 0.1);
}

.navbar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 0;
    padding-bottom: 0;
    min-height: 52px;
}

.navbar-brand {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.05rem;
    white-space: nowrap;
    letter-spacing: -0.01em;
    transition: opacity var(--transition);
}

.navbar-brand:hover {
    opacity: 0.85;
    color: #fff;
}

.navbar-logo {
    height: 70px;
    width: auto;
    display: block;
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--color-text-muted);
    overflow: hidden;
    max-width: 1440px;
    margin: 0 auto;
    padding: 10px 20px 0;
}

.breadcrumbs a {
    color: var(--color-text-muted);
    text-decoration: none;
    white-space: nowrap;
    transition: color var(--transition);
}

.breadcrumbs a:hover {
    color: var(--color-text);
}

.breadcrumbs .sep {
    color: var(--color-border);
    user-select: none;
}

.breadcrumbs .current {
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

/* ===== Layout ===== */
.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 28px 20px;
    overflow: hidden;
}

h1 {
    margin: 0 0 24px;
    font-size: 1.65rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--color-text);
}

h2 {
    margin: 0 0 12px;
    font-size: 1.05rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    color: var(--color-text);
}

/* ===== Card ===== */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--color-border-light);
    min-width: 0;
}

.card h2 {
    margin-bottom: 16px;
}

/* ===== Table ===== */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th,
.table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table thead th {
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 2px solid var(--color-border);
    background: #f5f6fa;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr {
    transition: background var(--transition);
}

.table tbody tr:hover {
    background: #f3f4fa;
}

/* ===== Column widths ===== */
.col-checkbox {
    width: 2.5rem;
}

/* ===== Utility classes ===== */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-nowrap {
    white-space: nowrap;
}

/* ===== Links ===== */
a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
}

/* ===== Badge / Pill ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.5;
}

.badge-home {
    background: var(--color-primary-bg);
    color: var(--color-primary);
}

.badge-away {
    background: var(--color-red-bg);
    color: var(--color-red);
}

.badge-w {
    background: var(--color-green-bg);
    color: var(--color-green);
}

.badge-d {
    background: var(--color-orange-bg);
    color: var(--color-orange);
}

.badge-l {
    background: var(--color-red-bg);
    color: var(--color-red);
}

.badge-upcoming {
    background: #eceef4;
    color: var(--color-text-secondary);
}

.badge-season {
    background: #e8eaf4;
    color: #1A1F3A;
}

/* ===== Score display ===== */
.score {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.score-win {
    color: var(--color-green);
}

.score-loss {
    color: var(--color-red);
}

.score-draw {
    color: var(--color-orange);
}

.score-pending {
    color: var(--color-text-muted);
}

/* ===== Match history row coloring ===== */
.result-w {
    background: #f7fdf7;
}

.result-l {
    background: #fef8f8;
}

.result-d {
    background: #fefcf5;
}

/* ===== Win% color coding ===== */
.winpct-high {
    color: var(--color-green);
    font-weight: 600;
}

.winpct-mid {
    color: var(--color-orange);
    font-weight: 600;
}

.winpct-low {
    color: var(--color-red);
    font-weight: 600;
}

/* ===== Muted text ===== */
.muted {
    color: var(--color-text-muted);
}

small.muted {
    font-weight: 400;
}

/* ===== Season/League listing ===== */
.league-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.league-list li {
    border-bottom: 1px solid var(--color-border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.league-list li:last-child {
    border-bottom: none;
}

.league-list > li > a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 8px;
    text-decoration: none;
    color: inherit;
    flex: 1;
    min-width: 0;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.league-list > li > a:hover {
    background: #f3f4fa;
    text-decoration: none;
}

.league-name {
    font-weight: 500;
}

.league-code {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-family: "SF Mono", SFMono-Regular, ui-monospace, monospace;
}

/* ===== Round/Matchday headers ===== */
.round-header {
    background: #f3f4fa;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
}

.round-header td {
    padding: 8px 14px;
    border-bottom: 2px solid var(--color-border);
}

.matchday-header {
    background: #f3f4fa;
}

.matchday-header td {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--color-text-secondary);
    padding: 10px 14px;
    border-bottom: 2px solid var(--color-border);
    letter-spacing: 0.02em;
}

/* ===== Rank highlight ===== */
.rank-1 {
    font-weight: 700;
}

/* ===== Own team highlighting ===== */
.team-ours {
    background: var(--color-green-bg);
}

.team-ours td:first-child {
    border-left: 3px solid var(--color-green);
}

.team-ours-name {
    color: var(--color-green);
    font-weight: 600;
}

.team-ours-badge {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-green);
    margin-right: 4px;
    vertical-align: middle;
}

/* ===== Favorite star button ===== */
.btn-favorite {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.15rem;
    color: #c0c4d6;
    padding: 2px;
    line-height: 1;
    transition: color var(--transition), transform var(--transition);
}

.btn-favorite:hover {
    color: #facc15;
    transform: scale(1.15);
}

.btn-favorite.active {
    color: #facc15;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.4;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    border: none;
    vertical-align: middle;
    transition: background var(--transition), box-shadow var(--transition), transform 0.1s ease;
    gap: 6px;
}

.btn:hover {
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    box-shadow: 0 1px 2px rgba(26, 31, 58, 0.25);
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    box-shadow: 0 2px 4px rgba(26, 31, 58, 0.3);
    color: #fff;
}

.btn-sm {
    padding: 4px 12px;
    font-size: 0.78rem;
}

.btn-secondary {
    background: #eceef4;
    color: #4a5072;
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: #d8dce8;
    color: #1A1F3A;
}

.btn-danger {
    background: var(--color-red);
    color: #fff;
}

.btn-danger:hover {
    background: #b91c1c;
}

/* ===== Page header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    margin-bottom: 0;
}

/* ===== Card header/footer ===== */
.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-header-row h2 {
    margin-bottom: 0;
}

.card-footer {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--color-border-light);
}

/* ===== Inline actions ===== */
.actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inline-form {
    display: inline;
}

.league-list li .actions {
    visibility: hidden;
    flex-shrink: 0;
}

.league-list li:hover .actions {
    visibility: visible;
}

/* ===== Forms ===== */
form > div {
    margin-bottom: 16px;
}

form > div:last-of-type:not(.form-actions) {
    margin-bottom: 0;
}

form label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #2d3358;
    margin-bottom: 6px;
}

form input[type="text"],
form input[type="password"],
form input[type="number"],
form input[type="email"],
form input[type="url"],
form select,
form textarea {
    display: block;
    width: 100%;
    padding: 9px 13px;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-surface);
    border: 1px solid #c0c4d6;
    border-radius: var(--radius-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
}

form input[type="text"]:focus,
form input[type="password"]:focus,
form input[type="number"]:focus,
form input[type="email"]:focus,
form input[type="url"]:focus,
form select:focus,
form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(26, 31, 58, 0.12);
}

form select {
    appearance: auto;
}

form ul li {
    color: var(--color-red);
    font-size: 0.82rem;
    margin-top: 4px;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border-light);
}

/* ===== Preview page grid ===== */
.preview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.preview-grid .card {
    margin-bottom: 0;
    min-width: 0;
}

/* ===== Matchup table ===== */
.matchup-table .slot-row {
    border-bottom: 2px solid var(--color-border);
}

.matchup-vs {
    text-align: center;
    font-weight: 700;
    color: var(--color-text-muted);
    font-size: 0.82rem;
}

.suggestion-highlight {
    background: var(--color-green-bg);
    border-left: 3px solid var(--color-green);
}

@media (max-width: 768px) {
    .preview-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Sparkline ===== */
.sparkline {
    display: inline-block;
    vertical-align: middle;
}

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--color-text-muted);
}

/* ===== Match header ===== */
.match-header {
    text-align: center;
}

.match-header-meta {
    margin: 0 0 8px;
}

.match-header-title {
    margin-bottom: 8px;
}

.match-header-score {
    font-size: 1.5rem;
}

.match-header-badges {
    margin: 0;
}

.match-header-subtitle {
    margin-top: -4px;
    margin-bottom: 16px;
    font-size: 0.88rem;
}

/* ===== Lineup card layout (mobile) ===== */
.lineup-cards {
    display: none;
}

.lineup-card {
    background: var(--color-green-bg);
    border-left: 3px solid var(--color-green);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 10px;
}

.lineup-card:last-child {
    margin-bottom: 0;
}

.lineup-card-header {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.lineup-card-matchup {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.lineup-card-side {
    flex: 1;
    min-width: 0;
}

.lineup-card-vs {
    flex-shrink: 0;
    color: var(--color-text-muted);
    font-weight: 700;
    font-size: 0.8rem;
    padding-top: 2px;
}

.lineup-card-detail {
    font-size: 0.85rem;
}

.lineup-card-subdetail {
    font-size: 0.8rem;
}

/* ===== Excluded player row ===== */
.player-excluded td {
    opacity: 0.4;
    text-decoration: line-through;
}

.player-excluded td:first-child {
    opacity: 1;
    text-decoration: none;
}

/* ===== Login page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 52px);
    padding: 24px 16px;
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border-light);
}

.login-card h1 {
    font-size: 1.35rem;
    margin-bottom: 28px;
    text-align: center;
}

.btn-login {
    width: 100%;
    padding: 10px;
    font-size: 0.95rem;
    margin-top: 8px;
}

/* ===== Alert ===== */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 16px;
}

.alert-danger {
    background: var(--color-red-bg);
    color: var(--color-red);
    border: 1px solid #fecaca;
}

/* ===== Navbar user section ===== */
.navbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.navbar-username {
    font-size: 0.82rem;
    color: #8b90ab;
}

.btn-logout {
    background: rgba(255, 255, 255, 0.08);
    color: #8b90ab;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-logout:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

/* ===== Substitute dialog ===== */
.substitute-dialog {
    border: none;
    border-radius: var(--radius);
    padding: 0;
    max-width: 520px;
    width: 90vw;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(26, 31, 58, 0.2), 0 0 0 1px rgba(26, 31, 58, 0.06);
}

.substitute-dialog[open] {
    display: flex;
    flex-direction: column;
}

.substitute-dialog::backdrop {
    background: rgba(26, 31, 58, 0.5);
    backdrop-filter: blur(4px);
}

.substitute-dialog-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.substitute-dialog-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
}

.substitute-dialog-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.substitute-dialog-body h4 {
    margin: 16px 0 8px;
    font-size: 0.88rem;
    color: var(--color-text-secondary);
}

.substitute-dialog-body h4:first-child {
    margin-top: 0;
}

.substitute-dialog-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
    background: #f5f6fa;
}

.substitute-player-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
}

.substitute-player-row label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    flex: 1;
}

.substitute-player-stats {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.btn-close-dialog {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0;
    line-height: 1;
    transition: color var(--transition);
}

.btn-close-dialog:hover {
    color: var(--color-text);
}

/* ===== Substitute section in roster ===== */
.substitute-heading {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    padding: 10px 0 4px;
    border-top: 2px dashed var(--color-border);
    margin-top: 4px;
}

.substitute-team-name {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-weight: normal;
}

/* ===== Scrollable table wrapper ===== */
.table-scroll {
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-width: 0;
}

.table-scroll::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.85));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.table-scroll.is-scrollable::after {
    opacity: 1;
}

.table-scroll.is-scrolled-end::after {
    opacity: 0;
}

/* ===== Upcoming matches mobile cards ===== */
.upcoming-cards {
    display: none;
}

.upcoming-card {
    display: block;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-light);
    margin-bottom: 8px;
    text-decoration: none;
    color: inherit;
    transition: background var(--transition);
}

.upcoming-card:last-child {
    margin-bottom: 0;
}

.upcoming-card:hover {
    background: #f3f4fa;
    text-decoration: none;
}

.upcoming-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.upcoming-card-md {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.upcoming-card-middle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.upcoming-card-opponent {
    font-weight: 600;
    font-size: 0.95rem;
}

.upcoming-card-date {
    font-size: 0.8rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .navbar-logo {
        height: 52px;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 14px 10px;
    }

    .card {
        padding: 16px;
        border-radius: 8px;
    }

    .table {
        font-size: 0.8rem;
    }

    .table th,
    .table td {
        padding: 7px 6px;
    }

    .hide-mobile {
        display: none;
    }

    .lineup-table {
        display: none;
    }

    .lineup-cards {
        display: block;
    }

    .upcoming-table {
        display: none;
    }

    .upcoming-cards {
        display: block;
    }

    h1 {
        font-size: 1.35rem;
    }

    .navbar-logo {
        height: 40px;
    }
}
