/* ============================================================
   Sistema di Votazione Panathlon  CSS unico (votante + admin)
   ============================================================ */

:root {
    --pn-orange:      #f5a623;
    --pn-orange-dark: #d99518;
    --pn-black:       #1a1a1a;
    --pn-grey:        #2a2a2a;
    --pn-grey-light:  #6b6b6b;
    --pn-bg:          #f4f5f7;
    --pn-text:        #1a1a1a;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
                 Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    color: var(--pn-text);
    background: var(--pn-bg);
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

.container {
    max-width: 980px;
    margin: 0 auto;
    padding: 16px;
}

a { color: var(--pn-orange-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--pn-grey-light); }
.small { font-size: 0.85rem; }
.inline { display: inline; }

/* ---------------------------------------------------------------- brand header */
.brand-header {
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 14px 0;
}
.brand-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.brand-logo {
    height: 64px;
    width: auto;
    flex-shrink: 0;
}
.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.05;
    flex: 1 1 auto;
}
.brand-text strong {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--pn-black);
}
.brand-text small {
    font-size: 0.78rem;
    color: var(--pn-grey-light);
    letter-spacing: 2px;
    margin-top: 4px;
    text-transform: uppercase;
}
.brand-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- nav bar (dark, sotto il brand) */
.topbar, .admin-topbar {
    background: var(--pn-black);
    color: #fff;
    border-radius: 0 0 28px 28px;
}
.topbar .container,
.admin-topbar .container {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px;
    min-height: 56px;
}
.topbar-title {
    background: var(--pn-orange);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 18px 18px;
    display: inline-flex;
    align-items: center;
}

.admin-nav { display: flex; gap: 0; align-items: stretch; flex-wrap: wrap; }
.admin-nav a,
.admin-nav .nav-link-btn {
    color: #fff;
    padding: 18px 18px;
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    display: inline-flex;
    align-items: center;
    transition: background 0.15s;
}
.admin-nav a:hover,
.admin-nav .nav-link-btn:hover { background: rgba(255,255,255,0.08); text-decoration: none; }
.admin-nav a.active { background: var(--pn-orange); color: #fff; }
.admin-nav form { display: inline-flex; align-items: stretch; }
.nav-link-btn {
    background: transparent;
    border: 0;
    cursor: pointer;
    font: inherit;
    color: #fff;
}

.btn-link {
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.5);
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
}
.btn-link:hover { background: rgba(255,255,255,0.12); }

.footer { padding: 24px 0; color: var(--pn-grey-light); text-align: center; font-size: 0.85rem; }

/* ---------------------------------------------------------------- alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 16px 0;
    font-weight: 500;
}
.alert-success { background: #e2f5e8; color: #155724; border: 1px solid #b8e0c2; }
.alert-error   { background: #fdecea; color: #842029; border: 1px solid #f5c2c7; }
.field-error   { color: #b00020; font-size: 0.9rem; margin-top: 4px; }

/* ---------------------------------------------------------------- card */
.card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.04);
    padding: 20px;
    margin: 16px 0;
}
.card.narrow { max-width: 420px; margin: 24px auto; }
.card h2, .card h3 { margin-top: 0; }
.big { font-size: 1.25rem; font-weight: 600; }

/* ---------------------------------------------------------------- forms */
.form label {
    display: block;
    margin-top: 12px;
    font-weight: 600;
    font-size: 0.95rem;
}
.form input[type="text"],
.form input[type="email"],
.form input[type="password"],
.form input[type="number"],
.form textarea,
.form select {
    width: 100%;
    padding: 12px;
    margin-top: 6px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
}
.form textarea { min-height: 120px; resize: vertical; }
.form input:focus, .form textarea:focus { outline: 2px solid var(--pn-orange); border-color: var(--pn-orange); }

.form-actions { margin-top: 20px; display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- buttons */
.btn {
    display: inline-block;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-align: center;
    transition: filter 0.15s;
    text-decoration: none;
    line-height: 1;
}
.btn:hover { filter: brightness(0.95); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 0.9rem; }

.btn-primary        { background: var(--pn-orange); color: #fff; }
.btn-primary:hover  { background: var(--pn-orange-dark); filter: none; }
.btn-secondary      { background: #e5e7eb; color: var(--pn-text); }
.btn-success        { background: #2e7d32; color: #fff; }
.btn-danger         { background: #c62828; color: #fff; }
.btn-danger-outline { background: #fff;    color: #c62828; border: 1px solid #c62828; }
.btn-warning        { background: var(--pn-orange); color: #fff; }

/* ---------------------------------------------------------------- voter pages */
.voter-body { background: linear-gradient(180deg, #f4f5f7 0%, #e9ecef 100%); min-height: 100vh; }
.voter-body .topbar { margin-bottom: 8px; }
.voter-card { text-align: center; padding-top: 28px; padding-bottom: 28px; }
.voter-greeting { font-size: 1rem; color: #555; margin: 0 0 16px; }
.question-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 12px 0 8px;
    line-height: 1.25;
}
.question-description {
    color: #555;
    font-size: 1rem;
    margin-bottom: 24px;
}

.ballot-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
}
.ballot-form .btn {
    padding: 22px;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 1px;
}
.btn-yes     { background: #2e7d32; color: #fff; }
.btn-no      { background: #c62828; color: #fff; }
.btn-abstain { background: #757575; color: #fff; }

/* messaggi di stato sessione (lato votante) */
.session-msg {
    padding: 40px 16px;
    text-align: center;
}
.session-msg h2 { margin: 8px 0 4px; }
.session-msg-icon {
    font-size: 3rem;
    line-height: 1;
    margin-bottom: 8px;
}
.session-msg-not-started .session-msg-icon { color: var(--pn-orange); }
.session-msg-closed .session-msg-icon {
    display: inline-block;
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--pn-grey-light);
    color: #fff;
    font-size: 0;
    position: relative;
    margin: 0 auto 12px;
}
.session-msg-closed .session-msg-icon::after {
    content: "";
    position: absolute;
    left: 22px; top: 14px;
    width: 12px; height: 26px;
    border: solid #fff;
    border-width: 0 4px 4px 0;
    transform: rotate(45deg);
}

/* stato "in attesa" */
.waiting { padding: 40px 16px; text-align: center; }
.spinner {
    width: 48px; height: 48px;
    border: 4px solid #d0d4dc;
    border-top-color: var(--pn-orange);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* "voto registrato" */
.thanks { padding: 24px 16px; }
.check-icon {
    width: 64px; height: 64px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: #2e7d32;
    position: relative;
}
.check-icon::after {
    content: "";
    position: absolute;
    left: 22px; top: 14px;
    width: 12px; height: 26px;
    border: solid #fff;
    border-width: 0 4px 4px 0;
    transform: rotate(45deg);
}

/* ---------------------------------------------------------------- ballot multi voter */
.ballot-multi .voter-rows {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 20px;
    text-align: left;
}
.voter-row {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.voter-row.is-voted {
    background: #f4faf5;
    border-color: #c5e3c9;
}
.voter-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.voter-row-name {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--pn-black);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.voter-row-code code {
    background: #f3f4f6;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #555;
}
.badge-self     { background: var(--pn-black);  color: #fff; font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; }
.badge-delegate { background: var(--pn-orange); color: #fff; font-size: 0.7rem; padding: 2px 8px; border-radius: 999px; }
.voter-row .ballot-form {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}
.voter-row .ballot-form .btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 14px 6px;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}
.voter-row-status {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #2e7d32;
    font-weight: 600;
}
.voter-row-status .check-icon {
    width: 28px; height: 28px;
    margin: 0;
    flex: 0 0 auto;
}
.voter-row-status .check-icon::after {
    left: 9px; top: 5px;
    width: 6px; height: 13px;
    border-width: 0 3px 3px 0;
}
.voter-row-status .answer-si       { color: #2e7d32; }
.voter-row-status .answer-no       { color: #c62828; }
.voter-row-status .answer-astenuto { color: #555; }

/* ---------------------------------------------------------------- delegates panel */
.delegates-panel {
    margin-top: 24px;
    padding: 14px 16px;
    background: #fafbfc;
    border: 1px dashed #d0d4dc;
    border-radius: 12px;
    text-align: left;
}
.delegates-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}
.delegates-header h3 { margin: 0; font-size: 1rem; color: var(--pn-black); }
.delegates-list {
    list-style: none;
    padding: 0;
    margin: 8px 0 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.delegate-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 10px;
    flex-wrap: wrap;
}
.delegate-name { font-weight: 600; flex: 1 1 auto; }
.delegate-code {
    background: #f3f4f6;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #555;
}
.delegate-add-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.delegate-add-form input {
    flex: 1 1 160px;
    padding: 10px 12px;
    border: 1px solid #d0d4dc;
    border-radius: 8px;
    font-size: 1rem;
    text-transform: uppercase;
}
.delegate-details {
    margin: 14px 0;
    background: #fafbfc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 12px;
}
.delegate-details summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--pn-orange-dark);
    list-style: revert;
}
.delegate-details textarea {
    width: 100%;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid #d0d4dc;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    text-transform: uppercase;
    box-sizing: border-box;
}
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* ---------------------------------------------------------------- admin */
.admin-body { background: #f4f5f7; }
.admin-main { padding-top: 8px; padding-bottom: 40px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.page-header h2 { margin: 0; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin: 16px 0;
}
.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.stat-card .stat-value { display: block; font-size: 1.8rem; font-weight: 700; color: var(--pn-black); }
.stat-card .stat-label { display: block; color: #777; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}
@media (min-width: 760px) {
    .grid-2 { grid-template-columns: 1fr 1fr; }
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin: 16px 0;
}
.table th, .table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    vertical-align: top;
    text-align: left;
}
.table th { background: #f1f3f5; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.5px; }
.table td.actions { white-space: nowrap; }
.table .inline { margin-right: 4px; }

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.badge-draft  { background: #e5e7eb; color: #555; }
.badge-open   { background: #d3f3df; color: #155724; }
.badge-closed { background: #fde2e2; color: #842029; }

/* dashboard risultati */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin: 16px 0;
}
.result-card {
    background: #fff;
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.result-card header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.result-card .question-title { font-size: 1.1rem; margin: 0 0 12px; }
.bars { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.bar-row { display: grid; grid-template-columns: 80px 1fr 110px; gap: 8px; align-items: center; font-size: 0.9rem; }
.bar-label { font-weight: 600; }
.bar-track { height: 14px; background: #eee; border-radius: 7px; overflow: hidden; }
.bar-fill  { height: 100%; transition: width 0.4s; }
.bar-si        { background: #2e7d32; }
.bar-no        { background: #c62828; }
.bar-astenuto  { background: #757575; }
.result-card .question-title a { color: inherit; }
.result-card .question-title a:hover { color: var(--pn-orange-dark); text-decoration: none; }
.result-card-actions { margin-top: 10px; }

/* ---------------------------------------------------------------- dashboard: stato sessione globale */
.session-state {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 14px 18px;
    border-radius: 12px;
    margin: 12px 0 16px;
    background: #fff;
    border-left: 6px solid #d0d4dc;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.session-state-info {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}
.session-state-label { color: var(--pn-grey-light); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; }
.session-state-value { font-size: 1.4rem; font-weight: 800; margin-top: 2px; letter-spacing: 0.5px; }
.session-state-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.session-state-not-started { border-left-color: #9ca3af; }
.session-state-not-started .session-state-value { color: #4b5563; }
.session-state-in-progress { border-left-color: #2e7d32; background: #f4faf5; }
.session-state-in-progress .session-state-value { color: #2e7d32; }
.session-state-closed { border-left-color: #c62828; background: #fdf2f2; }
.session-state-closed .session-state-value { color: #c62828; }

/* ---------------------------------------------------------------- dashboard: domanda in evidenza */
.current-question-card {
    border-left: 6px solid var(--pn-orange);
    padding: 20px 24px;
}
.current-question-empty { border-left-color: #d0d4dc; }
.current-question-head .badge { display: inline-block; }
.current-question-title {
    font-size: 1.6rem;
    font-weight: 800;
    margin: 8px 0 4px;
    color: var(--pn-black);
    line-height: 1.2;
}
.current-question-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 18px 0 14px;
}
.current-question-stats .stat-card { padding: 18px; }
.current-question-stats .stat-value { font-size: 2.4rem; line-height: 1; }
.current-question-stats .stat-label { margin-top: 6px; }
.stat-voted   .stat-value { color: #2e7d32; }
.stat-missing .stat-value { color: var(--pn-orange-dark); }
.stat-total   .stat-value { color: var(--pn-black); }
.current-question-bars { margin-top: 8px; }
.current-question-bars .bar-track { height: 18px; }
.current-question-bars .bar-row { font-size: 0.95rem; }
.current-question-actions {
    display: flex;
    gap: 8px;
    margin-top: 18px;
    flex-wrap: wrap;
}
.dashboard-section-title {
    margin: 28px 0 8px;
    color: var(--pn-grey-light);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
}

@media (max-width: 600px) {
    .current-question-stats { grid-template-columns: 1fr 1fr; }
    .current-question-stats .stat-total { grid-column: span 2; }
    .current-question-stats .stat-value { font-size: 1.9rem; }
    .current-question-title { font-size: 1.3rem; }
}

/* ---------------------------------------------------------------- mobile tuning */
@media (max-width: 600px) {
    .brand-logo { height: 48px; }
    .brand-text strong { font-size: 1.05rem; letter-spacing: 0.3px; }
    .brand-text small  { font-size: 0.7rem;  letter-spacing: 1.2px; }
    .admin-nav a { padding: 14px 12px; font-size: 0.8rem; }
}
@media (max-width: 480px) {
    .container { padding: 12px; }
    .ballot-form .btn { padding: 20px; font-size: 1.35rem; }
    .voter-row .ballot-form .btn { padding: 12px 4px; font-size: 0.9rem; letter-spacing: 0.2px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .table { font-size: 0.9rem; }
    .table td.actions { white-space: normal; }
    .topbar .container, .admin-topbar .container { padding: 8px 12px; }
    .admin-topbar .admin-nav { width: 100%; justify-content: flex-start; }
    .admin-nav a { padding: 10px; }
    .topbar, .admin-topbar { border-radius: 0 0 18px 18px; }
    /* voter topbar: titolo + Esci sempre sulla stessa riga */
    .topbar .container { flex-wrap: nowrap; }
    .topbar .topbar-title { padding: 14px 14px; font-size: 0.8rem; }
    .topbar .admin-nav .nav-link-btn { padding: 14px 14px; font-size: 0.8rem; }
}
