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

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    z-index: 50;
    box-shadow: var(--shadow);
}

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

/* Views */
.view { display: none; min-height: 100vh; }
.view.active { display: flex; }

/* Container */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
    width: 100%;
}

/* Home */
#view-home {
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.logo {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary);
    text-align: center;
    margin-bottom: 0.25rem;
}

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

/* Card */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

/* Inputs */
.input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 0.75rem;
    outline: none;
    transition: border-color 0.2s;
}
.input:focus { border-color: var(--primary); }

select.input { appearance: auto; cursor: pointer; }

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-text { background: none; color: var(--primary); padding: 0.5rem; }
.btn-text:hover { text-decoration: underline; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.875rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.btn-group { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.btn-group .btn { flex: 1; }

.divider {
    text-align: center;
    margin: 1.25rem 0;
    position: relative;
}
.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    border-top: 1px solid var(--border);
}
.divider span {
    background: var(--surface);
    padding: 0 1rem;
    position: relative;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.join-group { display: flex; gap: 0.5rem; align-items: flex-start; }
.join-group .input { margin-bottom: 0; }
.join-group .btn { white-space: nowrap; }

/* Auth section */
.auth-section { text-align: center; padding: 0.5rem; }
.hidden { display: none !important; }
.error { color: var(--danger); font-size: 0.875rem; margin-top: 0.5rem; }

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 400px;
    width: 90%;
}
.modal-content h2 { margin-bottom: 1rem; }
.modal-subtitle { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 1rem; }
.success { color: var(--success); font-size: 0.875rem; margin-top: 0.5rem; }

.share-link-group { display: flex; gap: 0.5rem; }
.share-link-group .input { margin-bottom: 0; flex: 1; }

.qr-container { text-align: center; margin: 1rem 0; }
.qr-container img { max-width: 200px; border-radius: 8px; }

/* QR Scanner */
.btn-scan { width: 100%; margin-top: 0.5rem; }
.scanner-modal { max-width: 400px; text-align: center; }
.scanner-modal .btn-scan-upload { display: block; width: 100%; margin-bottom: 0.5rem; cursor: pointer; text-align: center; }
.scanner-status { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin: 0.75rem 0; }

/* Room View */
#view-room { flex-direction: column; }

.room-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.room-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.room-info { text-align: center; }
.room-code { color: var(--text-muted); font-size: 0.8rem; display: block; }

.room-lang-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
.room-lang-bar label { color: var(--text-muted); white-space: nowrap; }
.input-sm { padding: 0.4rem 0.6rem; font-size: 0.85rem; margin-bottom: 0; max-width: 200px; }

.participants-bar {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    min-height: 2.5rem;
}
.participant-chip {
    background: var(--bg);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    word-wrap: break-word;
}
.message.sent {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message.received {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.message .sender {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    opacity: 0.8;
}
.message .translated { font-size: 1rem; }
.message .original {
    font-size: 0.75rem;
    opacity: 0.6;
    margin-top: 0.25rem;
    font-style: italic;
}
.message .time {
    font-size: 0.65rem;
    opacity: 0.5;
    margin-top: 0.25rem;
    text-align: right;
}
.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
    padding: 0.25rem;
    max-width: 100%;
}

/* Chat input */
.chat-input-area {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.chat-input-area .input { margin-bottom: 0; flex: 1; }

/* Admin */
.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.admin-header h1 { font-size: 1.5rem; }

.admin-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}
.tab {
    padding: 0.5rem 1rem;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.admin-panel { display: none; }
.admin-panel.active { display: block; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}
.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    text-align: center;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.admin-table th, .admin-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.admin-table th { background: var(--bg); font-weight: 600; }
.admin-table input[type="number"] {
    width: 80px;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.tier-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.tier-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.tier-card-header {
    background: var(--primary);
    color: #fff;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.95rem;
}
.tier-card-body { padding: 0.5rem 0; }
.tier-limit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    gap: 0.5rem;
}
.tier-limit-row:last-child { border-bottom: none; }
.tier-limit-row .limit-label { flex: 1; color: var(--text-muted); }
.tier-limit-row input[type="number"] {
    width: 70px;
    padding: 0.2rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-align: center;
}
.tier-limit-row .btn-sm { padding: 0.15rem 0.5rem; font-size: 0.75rem; }
.add-limit-form { margin-top: 1rem; }
.add-limit-form h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.form-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}
.form-row .input { flex: 1; min-width: 140px; }

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

.input-label { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.25rem; display: block; }
.hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

#translation-health { white-space: pre-wrap; font-family: monospace; font-size: 0.875rem; }

/* Responsive */
@media (max-width: 600px) {
    .logo { font-size: 2rem; }
    .container { padding: 1rem; }
    .message { max-width: 90%; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .admin-table { font-size: 0.75rem; }
    .admin-table th, .admin-table td { padding: 0.5rem; }
}
