/* ==========================================================================
   Live Vote – Mobile-first CSS
   ========================================================================== */

/* ── Reset & variables ──────────────────────────────────────────────────── */

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

:root {
    --color-bg:        #f4f5f7;
    --color-surface:   #ffffff;
    --color-primary:   #4f46e5;
    --color-primary-h: #4338ca;
    --color-success:   #16a34a;
    --color-danger:    #dc2626;
    --color-warning:   #f59e0b;
    --color-text:      #1e293b;
    --color-text-sec:  #64748b;
    --color-border:    #e2e8f0;
    --radius:          0.75rem;
    --shadow:          0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --transition:      0.3s ease;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100dvh;
}

/* ── Layout containers ──────────────────────────────────────────────────── */

.container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 1.25rem 1rem;
}

.container--wide {
    max-width: 900px;
}

/* ── Typography ─────────────────────────────────────────────────────────── */

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    line-height: 1.3;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */

.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 48px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
    line-height: 1.3;
}

.btn:active {
    transform: scale(0.97);
}

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

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

.btn--success {
    background: var(--color-success);
    color: #fff;
}

.btn--danger {
    background: var(--color-danger);
    color: #fff;
}

.btn--warning {
    background: var(--color-warning);
    color: #fff;
}

.btn--outline {
    background: transparent;
    border: 2px solid var(--color-border);
    color: var(--color-text);
}

.btn--outline:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.btn--small {
    min-height: 36px;
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
}

.btn--block {
    display: flex;
    width: 100%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Vote option buttons ────────────────────────────────────────────────── */

.vote-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.vote-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    padding: 1rem 1.25rem;
    font-size: 1.15rem;
    font-weight: 600;
    background: var(--color-surface);
    color: var(--color-text);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    -webkit-tap-highlight-color: transparent;
    text-align: center;
    word-break: break-word;
}

.vote-btn:hover {
    border-color: var(--color-primary);
    background: #eef2ff;
}

.vote-btn:active {
    transform: scale(0.97);
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

/* ── Form elements ──────────────────────────────────────────────────────── */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
    color: var(--color-text-sec);
}

.input {
    width: 100%;
    min-height: 48px;
    padding: 0.65rem 0.85rem;
    font-size: 1rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition);
}

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

/* ── Result bars ────────────────────────────────────────────────────────── */

.results-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.result-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.result-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-weight: 600;
    font-size: 1rem;
}

.result-count {
    font-size: 0.85rem;
    color: var(--color-text-sec);
    font-weight: 400;
}

.result-bar-track {
    width: 100%;
    height: 32px;
    background: #e2e8f0;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.result-bar-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 6px;
    transition: width 0.6s cubic-bezier(.4,0,.2,1);
    min-width: 0;
}

.result-bar-pct {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--color-text);
}

.results-total {
    margin-top: 0.75rem;
    text-align: center;
    font-size: 0.95rem;
    color: var(--color-text-sec);
    font-weight: 600;
}

/* ── State screens (vote page) ──────────────────────────────────────────── */

.screen {
    display: none;
    animation: fadeIn 0.35s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Waiting state */
.waiting-screen {
    text-align: center;
    padding: 3rem 1rem;
}

.waiting-screen p {
    font-size: 1.15rem;
    color: var(--color-text-sec);
    margin-bottom: 1.5rem;
}

.pulse-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    background: var(--color-primary);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: .3; transform: scale(.8); }
    50%      { opacity: 1;  transform: scale(1.2); }
}

/* Confirmation state */
.confirmation-screen {
    text-align: center;
    padding: 3rem 1rem;
}

.check-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    background: var(--color-success);
    color: #fff;
    border-radius: 50%;
    font-size: 2rem;
    margin-bottom: 1rem;
    animation: popIn 0.4s cubic-bezier(.175,.885,.32,1.275);
}

@keyframes popIn {
    0%   { transform: scale(0); }
    100% { transform: scale(1); }
}

.confirmation-screen p {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-success);
}

/* ── Poll list (admin) ──────────────────────────────────────────────────── */

.poll-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.poll-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
}

.poll-item--open {
    border-color: var(--color-success);
}

.poll-question {
    font-weight: 600;
    font-size: 1rem;
    word-break: break-word;
}

.poll-status {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    width: fit-content;
}

.poll-status--open   { background: #dcfce7; color: #166534; }
.poll-status--closed { background: #fee2e2; color: #991b1b; }

.poll-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ── Option fields (admin create) ───────────────────────────────────────── */

.option-fields {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.option-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.option-row .input {
    flex: 1;
}

.option-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: #fee2e2;
    color: var(--color-danger);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    flex-shrink: 0;
    transition: background var(--transition);
}

.option-remove:hover {
    background: #fecaca;
}

/* ── Admin toolbar ──────────────────────────────────────────────────────── */

.admin-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.admin-toolbar h1 {
    margin-bottom: 0;
}

/* ── Login form ─────────────────────────────────────────────────────────── */

.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 1rem;
}

.login-card {
    width: 100%;
    max-width: 380px;
}

.login-card h1 {
    text-align: center;
}

.login-error {
    color: var(--color-danger);
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 0.75rem;
    display: none;
}

/* ── Utility ────────────────────────────────────────────────────────────── */

.text-center { text-align: center; }
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }
.hidden { display: none !important; }

.link {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
}

.link:hover {
    text-decoration: underline;
}

.separator {
    height: 1px;
    background: var(--color-border);
    margin: 1.25rem 0;
}

/* ── Notification toast ─────────────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-text);
    color: #fff;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   PROJECTION MODE
   ========================================================================== */

body.projection-mode {
    background: #0f172a;
    color: #f1f5f9;
}

body.projection-mode .admin-panel {
    display: none !important;
}

body.projection-mode .results-panel {
    display: block !important;
}

body.projection-mode .results-panel {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2.5rem 2rem;
}

body.projection-mode .results-panel h1 {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 2rem;
    color: #f1f5f9;
}

body.projection-mode .result-label {
    font-size: 1.3rem;
    color: #f1f5f9;
}

body.projection-mode .result-count {
    color: #94a3b8;
}

body.projection-mode .result-bar-track {
    height: 48px;
    background: #1e293b;
    border-radius: 8px;
}

body.projection-mode .result-bar-fill {
    background: linear-gradient(90deg, #6366f1, #818cf8);
    border-radius: 8px;
}

body.projection-mode .result-bar-pct {
    font-size: 1rem;
    color: #f1f5f9;
}

body.projection-mode .results-total {
    font-size: 1.25rem;
    color: #94a3b8;
    margin-top: 2rem;
}

body.projection-mode .results-list {
    gap: 1.25rem;
}

/* Exit projection button */
.btn-exit-projection {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 999;
    background: rgba(255,255,255,.1);
    color: rgba(255,255,255,.5);
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 6px;
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition);
    display: none;
}

body.projection-mode .btn-exit-projection {
    display: block;
}

.btn-exit-projection:hover {
    background: rgba(255,255,255,.2);
    color: rgba(255,255,255,.8);
}

/* ── Responsive (desktop) ───────────────────────────────────────────────── */

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

    .container { padding: 2rem 1.5rem; }

    .vote-btn {
        font-size: 1.25rem;
        min-height: 64px;
    }

    .poll-item {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }

    .poll-actions {
        flex-shrink: 0;
    }
}
