:root {
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --bg-color: #F3F4F6;
    --card-bg: #FFFFFF;
    --text-main: #1F2937;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
    --success-color: #10B981;
    --error-color: #EF4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

header {
    background: var(--card-bg);
    padding: 20px 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

header h1 {
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 4px;
}

.instructions {
    font-size: 14px;
    color: var(--text-muted);
}

main {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 100px;
    /* Space for action bar */
}

.candidates-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

/* Candidate Card */
.candidate-card {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.candidate-card.selected {
    border-color: var(--primary-color);
    background: #EEF2FF;
}

.candidate-info {
    flex: 1;
}

.candidate-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.candidate-nickname {
    font-size: 14px;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 4px;
}

.candidate-badge {
    display: inline-block;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.candidate-badge[data-frequenza="frequenta"] {
    background: #D1FAE5;
    color: #065F46;
}

.candidate-badge[data-frequenza="non frequenta"] {
    background: #FFEDD5;
    color: #9A3412;
}

/* Filters and Sorting */
.filters-section {
    background: var(--card-bg);
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.filter-group:last-child {
    margin-bottom: 0;
}

.filter-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.filter-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-col label,
.filter-group label {
    font-size: 13px;
    font-weight: 600;
    width: 100%;
    color: var(--text-main);
}

.filter-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
}

.filter-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.clear-filters-btn {
    width: 100%;
    background: transparent;
    border: 1px dashed var(--text-muted);
    color: var(--text-muted);
    padding: 8px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 4px;
    transition: all 0.2s;
}

.clear-filters-btn:hover {
    background: var(--border-color);
    color: var(--text-main);
}

.sort-select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--card-bg);
    color: var(--text-main);
}

.search-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--card-bg);
    color: var(--text-main);
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.check-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.candidate-card.selected .check-circle {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.candidate-card.selected .check-circle::after {
    content: '';
    width: 6px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

/* Action Bar */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--card-bg);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 20;
}

.selection-status {
    font-size: 16px;
    font-weight: 600;
}

.btn {
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn.primary:active {
    background: var(--primary-hover);
    transform: scale(0.98);
}

.btn.disabled {
    background: var(--border-color);
    color: var(--text-muted);
    cursor: not-allowed;
    transform: none !important;
}

/* Toast System */
#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 90%;
    max-width: 400px;
    pointer-events: none;
}

.toast {
    background: var(--text-main);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    margin-bottom: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    width: 100%;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    background: var(--error-color);
}

.toast.success {
    background: var(--success-color);
}

/* Utility */
.hidden {
    display: none !important;
}

.fullscreen-message {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: 20px;
    text-align: center;
    background: var(--card-bg);
}

.fullscreen-message h2 {
    font-size: 24px;
    margin-bottom: 8px;
}

.fullscreen-message p {
    color: var(--text-muted);
}

/* Password Gate */
.password-gate-box {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: center;
}

.password-gate-box h2 {
    font-size: 22px;
    font-weight: 800;
}

.password-gate-box p {
    color: var(--text-muted);
    font-size: 14px;
}

.password-input-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.password-error {
    color: var(--error-color);
    font-size: 13px;
    font-weight: 600;
}

.icon-success {
    width: 64px;
    height: 64px;
    background: var(--success-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin-bottom: 24px;
}