:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --text: #1c1e21;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --warn-bg: #fffbeb;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 760px;
    margin: 0 auto;
    padding: 20px 16px 60px;
}

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

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar .brand {
    font-weight: 700;
    font-size: 17px;
    color: var(--text);
}

.topbar .user-info {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 10px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { line-height: 1.5; }
.muted { color: var(--text-muted); font-size: 14px; }

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin: 14px 0 6px;
    color: var(--text);
}
label:first-child { margin-top: 0; }

input[type=text], input[type=password], input[type=date], input[type=time], input[type=url], select, textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 11px 18px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s ease;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:active { background: var(--primary-dark); }
.btn.block { width: 100%; margin-top: 16px; }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #f3f4f6; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

.list { list-style: none; margin: 0; padding: 0; }
.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}
.list-item:last-child { border-bottom: none; }

.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 3px 9px;
    border-radius: 999px;
}
.badge.owner { background: #ede9fe; color: #6d28d9; }
.badge.organizer { background: #dbeafe; color: #1d4ed8; }
.badge.user { background: #f3f4f6; color: #4b5563; }
.badge.scanned { background: var(--success-bg); color: var(--success); }
.badge.pending { background: var(--warn-bg); color: #b45309; }

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
}
.alert.error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert.success { background: var(--success-bg); color: var(--success); border: 1px solid #bbf7d0; }
.alert.info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }

.party-link {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}
.party-link:hover { text-decoration: none; border-color: var(--primary); }
.party-link .name { font-weight: 700; font-size: 16px; color: var(--text); }
.party-link .meta { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.qr-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0 4px;
}
#qrcode {
    padding: 16px;
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.qr-timer {
    margin-top: 14px;
    font-size: 13px;
    color: var(--text-muted);
}
.qr-timer .bar {
    width: 160px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 6px auto 0;
    overflow: hidden;
}
.qr-timer .bar-fill {
    height: 100%;
    background: var(--primary);
    width: 100%;
    transition: width 1s linear;
}

.credentials-box {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 14px;
    margin-top: 10px;
    font-size: 14px;
}
.credentials-box .cred-line { font-family: ui-monospace, monospace; font-size: 15px; margin: 4px 0; }

.scan-result {
    text-align: center;
    padding: 24px 16px;
}
.scan-result .name { font-size: 26px; font-weight: 700; margin: 10px 0 4px; }
.scan-result .status { font-size: 15px; margin-bottom: 6px; }
.scan-result.ok { background: var(--success-bg); border-radius: var(--radius); }
.scan-result.fail { background: var(--danger-bg); border-radius: var(--radius); }
.scan-result.already { background: var(--warn-bg); border-radius: var(--radius); }

#reader { width: 100%; max-width: 420px; margin: 0 auto; border-radius: var(--radius); overflow: hidden; }
#reader video { width: 100%; display: block; }

footer.page-footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 24px 0 8px;
}

form.inline { display: inline; }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 4px;
}
.stat-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 8px;
    text-align: center;
}
.stat-num { font-size: 22px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.02em; }

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 14px;
}
.progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.hbar-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}
.hbar {
    height: 10px;
    background: var(--primary);
    border-radius: 4px;
    min-width: 3px;
}
.hbar-wrap span { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    h1 { font-size: 19px; }
    .card { padding: 16px; }
    .list-item { flex-direction: column; align-items: flex-start; }
    .list-item .actions { width: 100%; display: flex; gap: 8px; }
    .list-item .actions .btn { flex: 1; }
}
