:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #38bdf8;
    --accent-hover: #0ea5e9;
    --border-color: #334155;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --font-main: 'Outfit', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.3s ease;
}

ul {
    list-style: none;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* App Header & Sidebar */
.app-header {
    background-color: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    height: 60px;
    display: flex;
    align-items: center;
}

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

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    display: block;
}

.logo .accent {
    color: var(--accent-color);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--accent-color);
}

/* Sidebar Drawer */
.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 900;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(2px);
}

.drawer-overlay.active {
    opacity: 1;
    visibility: visible;
}

.app-sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background-color: var(--card-bg);
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.5);
}

.app-sidebar.active {
    transform: translateX(280px);
}

.sidebar-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    display: block;
    padding: 0.75rem 1.5rem;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 1.1rem;
    border-left: 3px solid transparent;
    transition: all 0.2s;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-item.active {
    color: var(--accent-color);
    background-color: rgba(56, 189, 248, 0.1);
    border-left-color: var(--accent-color);
}

.divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 1.5rem;
}

.sidebar-footer {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-color);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.3s ease;
}

.btn-primary {
    background-color: var(--accent-color);
    color: var(--bg-color);
}

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

/* Cards */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    border-color: var(--accent-color);
}

/* Typography */
h1,
h2,
h3 {
    margin-bottom: 1rem;
    font-weight: 700;
}

h1 {
    font-size: 2.5rem;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

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

th {
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.875rem;
}

tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

input,
select {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: inherit;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

/* Footer */
.footer {
    margin-top: 4rem;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    text-align: center;
}

/* --- New Styles for UX Refactor --- */

/* Utilities */
.text-center {
    text-align: center;
}

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

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

.font-bold {
    font-weight: 700;
}

.font-semibold {
    font-weight: 600;
}

.text-secondary {
    color: var(--text-secondary);
}

.text-accent {
    color: var(--accent-color);
}

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

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

.w-12 {
    width: 3rem;
}

/* Grid Helpers */
.two-col-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

@media (min-width: 768px) {
    .two-col-grid {
        grid-template-columns: 1fr 1fr;
    }
}

/* Tabs */
.giornata-tab {
    padding: 0.75rem 1.5rem;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
    font-size: 0.9rem;
}

.giornata-tab:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.giornata-tab.active {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
    font-weight: 600;
}

/* Matches Grid */
.matches-grid {
    display: grid;
    gap: 1rem;
}

.match-card {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    align-items: center;
    padding: 1rem;
    background-color: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    gap: 1rem;
}

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

.team-away {
    text-align: left;
}

.score-display {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--accent-color);
    padding: 0 1rem;
    white-space: nowrap;
}

.winner {
    font-weight: 700;
    color: var(--text-primary);
}

/* Modal */
#tabellino-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    overflow-y: auto;
    padding: 1rem;
    backdrop-filter: blur(5px);
}

#tabellino-modal.active {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

#tabellino-modal>div {
    background-color: #1e293b;
    width: 100%;
    max-width: 900px;
    border-radius: 12px;
    margin-top: 2rem;
    border: 1px solid var(--border-color);
}

.match-header {
    text-align: center;
    margin-bottom: 2rem;
}

.match-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Events and Lineups */
.event-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.25rem 0;
    font-size: 0.9rem;
}

.event-min {
    color: var(--text-secondary);
    min-width: 30px;
    text-align: right;
}

.player-row {
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.player-num {
    display: inline-block;
    width: 25px;
    color: var(--text-secondary);
    text-align: right;
    margin-right: 0.5rem;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    .match-card {
        grid-template-columns: 1fr auto 1fr;
        font-size: 0.9rem;
    }

    .match-card button {
        grid-column: 1 / -1;
        width: 100%;
    }

    .mobile-hide {
        display: none;
    }
}

/* Teams Page Utilities */
.teams-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.toggle-icon {
    transition: transform 0.3s ease;
    color: var(--text-secondary);
}

.card.active .toggle-icon {
    transform: rotate(180deg);
}

.stats-grid-mini {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    text-align: center;
    margin-bottom: 1.5rem;
}

.stat-item-mini label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    display: block;
}

.stat-item-mini .value {
    font-size: 1.1rem;
    font-weight: 700;
}

.player-table-wrapper {
    overflow-x: auto;
}

.player-table {
    width: 100%;
    font-size: 0.9rem;
}

.player-table th {
    padding: 0.75rem 0.5rem;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.player-table td {
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

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

/* Modals */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: var(--card-bg);
    margin: auto;
    padding: 2rem;
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    position: relative;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

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

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Small buttons for bench ordering */
.btn-xs {
    padding: 2px 6px;
    font-size: 0.7rem;
    border-radius: 4px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-xs:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

/* --- General Mobile Responsiveness --- */
@media (max-width: 768px) {
    .container {
        padding: 0 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    th,
    td {
        padding: 0.5rem;
        font-size: 0.85rem;
    }

    .app-sidebar {
        width: 260px;
        /* Slightly narrower sidebar on mobile */
    }

    /* Scrollable tabs instead of wrapping */
    .giornata-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        padding-bottom: 0.5rem;
        -webkit-overflow-scrolling: touch;
    }

    .modal-content {
        max-width: 95%;
        margin: 1rem;
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.75rem;
    }

    .header-content {
        padding: 0 0.5rem;
    }

    .table-container {
        margin: 0 -1rem;
        /* Pull table to edges on very small screens */
        width: calc(100% + 2rem);
    }

    .table-container table {
        padding: 0 1rem;
    }

    .table-container th:first-child,
    .table-container td:first-child {
        padding-left: 1rem;
    }

    .table-container th:last-child,
    .table-container td:last-child {
        padding-right: 1rem;
    }

    .hero {
        padding: 2rem 0 !important;
    }

    .hero p {
        font-size: 1rem !important;
    }
}