/* === Reset & Base === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #242836;
    --border: #2a2e3a;
    --text: #e4e6ed;
    --text-muted: #8b8fa3;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --success: #22c55e;
    --accent: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

/* === Header === */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

.instruction {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* === Photo Grid === */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.photo-card {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition:
        border-color 0.2s,
        transform 0.15s,
        box-shadow 0.2s;
}

.photo-card:hover {
    border-color: var(--text-muted);
    transform: translateY(-2px);
}

.photo-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
    transform: translateY(-2px);
}

.photo-img-wrapper {
    aspect-ratio: 1/1;
    overflow: hidden;
    background: var(--border);
}

.photo-img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.photo-title {
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
}

/* === Vote Form === */
.vote-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.vote-form h2 {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.contact-section {
    margin: 1.5rem 0;
}

.contact-saved {
    color: var(--accent);
    font-weight: 600;
}

.contact-section h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.contact-info {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.optional {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.85rem;
}

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

.form-group input {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition:
        background 0.2s,
        transform 0.1s;
}

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

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

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

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

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
}

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

.btn-danger:hover {
    background: var(--danger-hover);
}

/* === Voted / Success Message === */
.voted-message {
    text-align: center;
    padding: 3rem 1.5rem;
}

.check-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--success);
    color: white;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}

.voted-message h2 {
    margin-bottom: 0.5rem;
}

.voted-message p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* === Results === */
.results-container {
    margin-bottom: 2rem;
}

.total-votes {
    text-align: center;
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.total-votes span {
    color: var(--text);
    font-weight: 700;
    font-size: 1.3rem;
}

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

.result-row {
    display: flex;
    gap: 1rem;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
}

.result-photo {
    flex-shrink: 0;
    width: 72px;
    height: 72px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--border);
}

.result-photo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.result-info {
    flex: 1;
    min-width: 0;
}

.result-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 0.35rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-bar-container {
    background: var(--bg);
    border-radius: 4px;
    height: 24px;
    overflow: hidden;
    margin-bottom: 0.25rem;
}

.result-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-hover));
    border-radius: 4px;
    transition: width 0.5s ease-out;
    min-width: 0;
}

.result-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.result-count .count-value {
    color: var(--text);
    font-weight: 600;
}

/* === WebSocket Status === */
.ws-status {
    text-align: center;
    font-size: 0.8rem;
    padding: 0.5rem;
    margin-top: 1rem;
    color: var(--text-muted);
}

.ws-status.connected {
    color: var(--success);
}

.ws-status.disconnected {
    color: var(--accent);
}

/* === Error === */
.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-top: 1rem;
    text-align: center;
}

/* === Admin === */
.admin-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.admin-section h2 {
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
}

.admin-section h3 {
    font-size: 1rem;
    margin: 1.5rem 0 0.75rem;
}

.admin-danger {
    border-color: rgba(239, 68, 68, 0.3);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.75rem;
    font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.admin-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.admin-table tbody tr:hover {
    background: var(--surface-hover);
}

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

/* === Responsive === */
@media (min-width: 600px) {
    .container {
        padding: 2rem;
    }

    header h1 {
        font-size: 2.25rem;
    }

    .photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* === Language Selector === */
.lang-selector {
    display: flex;
    justify-content: flex-end;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.lang-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    background: transparent;
    border: 1px solid transparent;
    transition:
        color 0.15s,
        background 0.15s,
        border-color 0.15s;
}

.lang-btn:hover {
    color: var(--text);
    background: var(--surface-hover);
    border-color: var(--border);
}

.lang-btn.active {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border);
    font-weight: 600;
}

@media (max-width: 400px) {
    .lang-name {
        display: none;
    }

    .lang-btn {
        font-size: 1.1rem;
        padding: 0.3rem 0.5rem;
    }
}
