:root {
    --bg-color: #121212;
    --surface-color: #1e1e1e;
    --primary-red: #b3002d;
    --primary-red-hover: #e50039;
    --text-color: #e0e0e0;
    --text-muted: #888;
    --border-color: #333;
    --vote-for: #008f39;
    --vote-against: var(--primary-red);
    --vote-abstain: #6c757d;
    --font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
    --border-radius: 8px;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    line-height: 1.6;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

.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;
}

.hidden {
    display: none !important;
}

/* Header */
.site-header {
    background-color: var(--surface-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 2px solid var(--primary-red);
    box-shadow: var(--shadow);
}

.site-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.site-header h1 {
    font-size: 1.5rem;
    margin: 0;
    color: var(--text-color);
}

.back-link {
    color: var(--primary-red);
    text-decoration: none;
    font-weight: bold;
    transition: color 0.2s ease;
}

.back-link:hover, .back-link:focus {
    color: var(--primary-red-hover);
    outline: 2px solid var(--primary-red-hover);
    outline-offset: 4px;
}

/* Main Layout */
main.container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}

@media (min-width: 1024px) {
    main.container {
        grid-template-columns: repeat(3, 1fr);
        grid-template-areas:
            "control delegations results"
            "control delegations results";
    }
    .control-panel { grid-area: control; }
    .delegations-panel { grid-area: delegations; }
    .results-panel { grid-area: results; }
}

section {
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
}

section h2, section h3 {
    margin-bottom: 1rem;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

/* Control Panel */
.majority-selector, .session-controls {
    margin-bottom: 2rem;
}

.segmented-control {
    display: flex;
    border-radius: var(--border-radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.segmented-control input[type="radio"] {
    display: none;
}

.segmented-control label {
    flex: 1;
    padding: 0.75rem 0.5rem;
    text-align: center;
    cursor: pointer;
    background-color: var(--surface-color);
    transition: background-color 0.2s ease, color 0.2s ease;
    font-weight: 500;
}

.segmented-control input[type="radio"]:checked + label {
    background-color: var(--primary-red);
    color: white;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.segmented-control label:hover:not(.active) {
    background-color: #333;
}

.option-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1rem;
    padding: 0.5rem 0;
}

.toggle-switch {
    position: relative;
    width: 40px;
    height: 20px;
    appearance: none;
    background: #444;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.toggle-switch::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}
.toggle-switch:checked {
    background: var(--primary-red);
}
.toggle-switch:checked::before {
    transform: translateX(20px);
}

/* Contextual Panel */
.contextual-panel {
    background-color: #2a2a2a;
    padding: 1rem;
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary-red);
    transition: opacity 0.3s ease;
}
.contextual-panel h4 {
    color: var(--primary-red);
    margin-bottom: 0.5rem;
}
.contextual-panel p {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}
.contextual-panel strong {
    color: var(--text-color);
}

.button, .button-secondary {
    display: block;
    width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: var(--border-radius);
    background-color: var(--primary-red);
    color: white;
    font-weight: bold;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s ease, transform 0.1s ease;
    margin-bottom: 0.5rem;
}

.button:hover, .button:focus {
    background-color: var(--primary-red-hover);
    transform: translateY(-2px);
    outline: 2px solid var(--primary-red-hover);
    outline-offset: 2px;
}
.button-secondary {
    background-color: #555;
}
.button-secondary:hover, .button-secondary:focus {
    background-color: #777;
}

/* Delegations Panel */
.delegations-toolbar {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
@media (min-width: 768px) {
    .delegations-toolbar {
        flex-direction: row;
        justify-content: space-between;
    }
}
#search-input {
    width: 100%;
    padding: 0.75rem;
    background-color: #333;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-color);
}
#search-input:focus {
    outline: none;
    border-color: var(--primary-red);
    box-shadow: 0 0 0 2px var(--primary-red);
}
.filter-wrapper {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}
.filter-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: all 0.2s ease;
}
.filter-btn.active {
    background-color: var(--primary-red);
    color: white;
    border-color: var(--primary-red);
}
.filter-btn:hover:not(.active) {
    background-color: #333;
    color: var(--text-color);
}

.delegations-list {
    list-style: none;
    max-height: 60vh;
    overflow-y: auto;
}

.delegation-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    overflow: hidden;
    transition: background-color 0.2s ease;
}
.delegation-item:hover {
    background-color: #2a2a2a;
}
.delegation-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background-color: transparent;
    transition: background-color 0.3s ease;
}
.delegation-item[data-vote="FOR"]::before { background-color: var(--vote-for); }
.delegation-item[data-vote="AGAINST"]::before { background-color: var(--vote-against); }
.delegation-item[data-vote="ABSTAIN"]::before { background-color: var(--vote-abstain); }

.delegation-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.vote-indicator {
    font-size: 0.75rem;
    font-weight: bold;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    color: white;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.delegation-item[data-vote="FOR"] .vote-indicator { background-color: var(--vote-for); opacity: 1; transform: scale(1); }
.delegation-item[data-vote="AGAINST"] .vote-indicator { background-color: var(--vote-against); opacity: 1; transform: scale(1); }
.delegation-item[data-vote="ABSTAIN"] .vote-indicator { background-color: var(--vote-abstain); opacity: 1; transform: scale(1); }


.vote-controls {
    display: flex;
    gap: 0.25rem;
}
.vote-controls input { display: none; }
.vote-controls label {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}
.vote-controls input[value="FOR"]:checked + label { background-color: var(--vote-for); border-color: var(--vote-for); color: white; }
.vote-controls input[value="AGAINST"]:checked + label { background-color: var(--vote-against); border-color: var(--vote-against); color: white; }
.vote-controls input[value="ABSTAIN"]:checked + label { background-color: var(--vote-abstain); border-color: var(--vote-abstain); color: white; }
.vote-controls label:hover {
    background-color: #444;
}

/* Results Panel */
.results-summary {
    margin-bottom: 2rem;
}
.status-indicator {
    text-align: center;
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    transition: background-color 0.3s ease, color 0.3s ease;
}
.status-indicator.approved { background-color: var(--vote-for); color: white; }
.status-indicator.rejected { background-color: var(--vote-against); color: white; }
.status-indicator.pending { background-color: #333; }
#status-text {
    font-size: 1.5rem;
    font-weight: bold;
    display: block;
}
#status-reason {
    font-size: 0.9rem;
    opacity: 0.9;
}

.progress-bar-container {
    width: 100%;
    background-color: #333;
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    height: 30px;
}
.progress-bar {
    height: 100%;
    width: 0;
    background-color: var(--primary-red);
    transition: width 0.3s ease-in-out;
}
#progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

body.informal-mode .results-grid {
    grid-template-columns: repeat(3, 1fr); /* Adjust grid for 3 items */
}
body.informal-mode #metric-abstain {
    display: none; /* Hide abstain card */
}

.metric-card {
    background-color: #2a2a2a;
    padding: 1rem;
    text-align: center;
    border-radius: var(--border-radius);
}
.metric-value {
    display: block;
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-red);
}
.metric-label {
    color: var(--text-muted);
}

.chart-container {
    margin-bottom: 1rem;
}

/* History Log */
.history-log {
    font-size: 0.85rem;
}
#history-list {
    list-style: none;
    height: 100px;
    overflow-y: auto;
    background-color: #121212;
    padding: 0.5rem;
    border-radius: var(--border-radius);
}
#history-list li {
    padding: 0.25rem 0;
    border-bottom: 1px solid #222;
    color: var(--text-muted);
}
#history-list li:first-child {
    color: var(--text-color);
}

/* Modal */
.modal-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
.modal-content {
    background-color: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 90%;
    max-width: 500px;
    text-align: center;
}
.modal-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
}