/* ===========================
   RESET & BASE
   =========================== */
*, *::before, *::after {
    box-sizing: border-box;
}

/* ===========================
   VARIABILI
   =========================== */
:root {
    --gold: #FFD700;
    --gold-light: #f0c040;
    --gold-hover: #FFC700;
    --gold-border: rgba(255, 215, 0, 0.3);
    --gold-border-strong: rgba(255, 215, 0, 0.5);
    --gold-bg: rgba(255, 215, 0, 0.15);
    --bg-dark: rgba(5, 8, 20, 0.88);
    --bg-darker: rgba(5, 8, 20, 0.97);
    --bg-navbar: rgba(5, 8, 20, 0.95);
    --text-main: #fff;
    --text-muted: #ccc;
    --text-body: #e0e0e0;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --font: system-ui, sans-serif;
    --page-margin: 30px;
    --page-padding: 20px;
}

/* ===========================
   BODY BASE (comune)
   =========================== */
body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    color: var(--text-main);
}

/* Overlay cosmo (solo login) */
body.login-page {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: url('../img/sfondo.png') no-repeat fixed center center;
    background-size: cover;
}

body.login-page::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-color: rgba(0, 0, 0, 0.85);
    background-image: radial-gradient(circle at 10% 20%, rgba(255, 255, 255, 0.12) 0, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.07) 0, transparent 45%);
}

body.login-page > * {
    position: relative;
    z-index: 1;
}

/* Sfondo pagine interne */
body.pagina {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    background: radial-gradient(circle at 20% 20%, #2b2b52 0, #050814 60%, #000 100%);
    background-attachment: fixed;
    padding-top: 120px;
}

/* ===========================
   TIPOGRAFIA
   =========================== */
h1, h2 {
    text-align: center;
    margin: 0 0 8px 0;
    background: linear-gradient(90deg, #00c3ff, #ffff1c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

h1 {
    font-size: 42px;
    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.5);
}

h2 {
    font-size: 28px;
    margin-bottom: 24px;
}

/* ===========================
   NAVBAR
   =========================== */
.navbar {
    background: var(--bg-navbar);
    border-bottom: 1px solid var(--gold-border);
    padding: 15px 0;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.nav-container {
    width: 100%;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-container h1 {
    font-size: 24px;
    text-align: left;
    margin: 0;
    background: linear-gradient(90deg, #00c3ff, #ffff1c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-logo {
    color: var(--gold);
    font-size: 24px;
    font-weight: bold;
    text-decoration: none;
    letter-spacing: 1px;
}

.nav-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 30px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.nav-item {
    margin: 0;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 16px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    transition: all 0.3s;
}

.nav-link:hover,
.nav-link.active {
    background: var(--gold-bg);
    color: var(--gold);
}

/* ===========================
   HEADER INTERNO
   =========================== */
header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* ===========================
   LOGIN WRAPPER
   =========================== */
.login-wrapper {
    background: var(--bg-dark);
    border-radius: var(--radius-xl);
    padding: 40px 50px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    border: 1px solid var(--gold-border);
    width: 100%;
    min-width: 400px;
    max-width: 480px;
}

/* ===========================
   FORM LOGIN
   =========================== */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: stretch;
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 20px;
    background: rgba(255, 255, 255, 0.03);
}

.form-group {
    display: flex;
    align-items: center;
    gap: 15px;
}

.form-group label,
.form-row label {
    min-width: 90px;
    text-align: right;
    font-weight: 500;
    color: var(--text-muted);
}

.form-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.form-row label {
    min-width: 110px;
}

/* Input generico condiviso */
.form-group input,
.form-row input,
.modal-content input,
.range-form input[type="date"] {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid rgba(255, 215, 0, 0.4);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.95);
    font-size: 14px;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.range-form input[type="date"] {
    background: #1e1e1e;
    color: var(--text-main);
}

.form-group input:focus,
.form-row input:focus,
.modal-content input:focus,
.range-form input[type="date"]:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.25);
}

/* ===========================
   BOTTONI (tutti unificati)
   =========================== */
.login-button,
.btn-add,
.btn-save,
.btn-edit,
.btn-delete,
.range-form button,
.range-form .btn-reset {
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
    display: inline-block;
}

/* Bottone primario (oro) */
.login-button,
.btn-add,
.btn-save,
.range-form button {
    background: var(--gold);
    color: #000;
    padding: 10px 24px;
    font-size: 14px;
}

.login-button:hover,
.btn-add:hover,
.btn-save:hover,
.range-form button:hover {
    background: var(--gold-hover);
    transform: translateY(-1px);
}

.login-button {
    margin-left: 105px;
}

.btn-add {
    margin-bottom: 15px;
}

.btn-save {
    margin-top: 15px;
    width: 100%;
}

/* Bottone secondario (grigio) */
.range-form .btn-reset {
    background: #555;
    color: var(--text-main);
    padding: 6px 16px;
    font-size: 0.9rem;
    margin-left: auto; /* allineato a destra */
}

.range-form .btn-reset:hover {
    background: #777;
    transform: translateY(-1px);
}

/* Bottone edit */
.btn-edit {
    padding: 6px 12px;
    background: rgba(255, 215, 0, 0.7);
    color: #000;
    font-size: 12px;
    margin-right: 5px;
}

.btn-edit:hover {
    background: rgba(255, 215, 0, 0.95);
    transform: translateY(-1px);
}

/* Bottone delete */
.btn-delete {
    padding: 6px 12px;
    background: rgba(255, 50, 50, 0.75);
    color: var(--text-main);
    font-size: 12px;
}

.btn-delete:hover {
    background: rgba(255, 50, 50, 0.95);
    transform: translateY(-1px);
}

/* ===========================
   RANGE FORM
   =========================== */
.range-form {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0 var(--page-margin) 16px var(--page-margin);
    padding: 0 var(--page-padding);
}

.range-form label {
    font-weight: bold;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ===========================
   MESSAGGIO ERRORE
   =========================== */
.errore {
    background: rgba(255, 0, 0, 0.15);
    border: 1px solid rgba(255, 0, 0, 0.6);
    color: #ff6b6b;
    padding: 10px;
    border-radius: var(--radius-sm);
    margin-bottom: 15px;
    text-align: center;
    font-size: 14px;
}

/* ===========================
   CONTAINER
   =========================== */
.table-container,
.div-container {
    margin: 0 var(--page-margin);
    padding: 0 var(--page-padding);
    overflow-x: auto;
}

/* ===========================
   TABELLA DATI
   =========================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-dark);
    border: 1px solid var(--gold-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.data-table thead {
    background: var(--gold-bg);
}

.data-table thead tr {
    border-bottom: 2px solid var(--gold-border-strong);
}

.data-table th {
    padding: 14px 16px;
    text-align: left;
    color: var(--gold);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tbody tr {
    border-bottom: 1px solid rgba(255, 215, 0, 0.08);
    transition: background 0.2s ease;
}

.data-table tbody tr:hover {
    background: var(--gold-bg);
}

.data-table tbody tr:last-child {
    border-bottom: none;
}

.data-table td {
    padding: 12px 16px;
    color: var(--text-body);
    font-size: 14px;
}

.data-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

/* ===========================
   SOTTO-TABELLA UTM
   =========================== */
.utm-subtable {
    width: 90%;
    margin: 4px 0 4px 2%;
    background-color: rgba(255, 255, 255, 0.05);
    border-left: 3px solid var(--gold-light);
}

.utm-subtable td,
.utm-subtable th {
    font-size: 0.95rem;
    padding: 6px 10px;
}

.row-utm-detail td {
    padding: 0 !important;
    background-color: rgba(0, 0, 0, 0.3);
}

/* ===========================
   ORDINAMENTO TABELLA
   =========================== */
th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable::after {
    content: ' ↕';
    font-size: 0.75rem;
    opacity: 0.5;
}

th.sortable.asc::after {
    content: ' ▲';
    opacity: 1;
}

th.sortable.desc::after {
    content: ' ▼';
    opacity: 1;
}

/* ===========================
   MODALE
   =========================== */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}

.modal.open {
    display: flex;
}

.modal-content {
    background: var(--bg-darker);
    border: 1px solid var(--gold-border);
    padding: 30px;
    width: 90%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    color: var(--text-main);
}

.modal-content h2 {
    margin: 0 0 20px 0;
    color: var(--gold);
    background: none;
    -webkit-text-fill-color: var(--gold);
}

.modal-content label {
    display: block;
    margin: 15px 0 5px;
    color: var(--text-muted);
    font-size: 14px;
}

.modal-content input {
    width: 100%;
}

.close {
    color: var(--gold);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
    transition: color 0.2s;
}

.close:hover {
    color: #ff6b6b;
}

/* ===========================
   SCROLLBAR
   =========================== */
.table-container::-webkit-scrollbar,
.div-container::-webkit-scrollbar {
    height: 8px;
}

.table-container::-webkit-scrollbar-track,
.div-container::-webkit-scrollbar-track {
    background: rgba(5, 8, 20, 0.5);
    border-radius: var(--radius-sm);
}

.table-container::-webkit-scrollbar-thumb,
.div-container::-webkit-scrollbar-thumb {
    background: rgba(255, 215, 0, 0.4);
    border-radius: var(--radius-sm);
}

.table-container::-webkit-scrollbar-thumb:hover,
.div-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 215, 0, 0.7);
}

/* ===========================
   RESPONSIVE
   =========================== */
@media (max-width: 768px) {
    .login-wrapper {
        min-width: unset;
        padding: 30px 20px;
    }

    .form-group {
        flex-direction: column;
        align-items: flex-start;
    }

    .form-group label {
        min-width: unset;
        text-align: left;
    }

    .login-button {
        margin-left: 0;
        width: 100%;
    }

    .data-table {
        font-size: 12px;
    }

    .data-table th,
    .data-table td {
        padding: 10px 12px;
    }

    .nav-menu {
        gap: 10px;
        position: static;
        transform: none;
    }

    .nav-link {
        padding: 6px 10px;
        font-size: 14px;
    }
}
