:root {
    --bg: #f3f6fa;
    --card: #ffffff;
    --ink: #172033;
    --muted: #667085;
    --line: #d7dde8;
    --primary: #1d4ed8;
    --primary-dark: #1e3a8a;
    --danger: #b42318;
    --danger-dark: #7a271a;
    --success-bg: #dcfce7;
    --success-text: #166534;
    --warn-bg: #fef3c7;
    --warn-text: #92400e;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Arial, Helvetica, sans-serif; font-size: 15px; }
.topbar { background: #111827; color: white; padding: 12px 22px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 8px rgba(0,0,0,.14); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 100px; height: 40px; object-fit: contain; background: white; border-radius: 8px; padding: 3px; flex: 0 0 auto; }
.app-title { font-size: 18px; font-weight: 700; }
.app-subtitle { font-size: 12px; color: #cbd5e1; margin-top: 2px; }
.nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.nav a { color: white; text-decoration: none; font-weight: 600; }
.nav a:hover { text-decoration: underline; }
.user-pill { background: #374151; border-radius: 999px; padding: 6px 10px; font-size: 13px; }

.page { max-width: 1200px; margin: 32px auto; padding: 0 18px; }
.grid { display: grid; gap: 22px; align-items: start; }
.two-col { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.ops-grid { grid-template-columns: minmax(0, 1fr) 340px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 4px 12px rgba(16,24,40,.08); padding: 24px; }
.card.narrow { max-width: 460px; margin: 0 auto; }
h1, h2 { margin: 0 0 8px 0; }
hr { border: none; border-top: 1px solid var(--line); margin: 24px 0; }
.muted { color: var(--muted); margin-top: 0; }
.hint { color: var(--muted); font-size: 13px; margin-top: 6px; display: inline-block; }

label { display: block; font-weight: 700; margin: 14px 0 6px; }
input, select { width: 100%; border: 1px solid #b8c1d1; border-radius: 7px; padding: 10px 11px; font-size: 15px; background: white; }
input:focus, select:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.inline-form { display: flex; gap: 10px; align-items: center; }
.inline-form input { flex: 1; }
.password-wrapper { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; }
.password-wrapper input { flex: 1; min-width: 0; }
button, .button-link { border: none; border-radius: 7px; padding: 10px 14px; font-weight: 700; cursor: pointer; white-space: nowrap; display: inline-block; text-decoration: none; }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary, .button-link { background: var(--primary); color: white; }
.primary:hover, .button-link:hover { background: var(--primary-dark); }
.secondary { background: #e5e7eb; color: #111827; }
.secondary:hover { background: #d1d5db; }
.danger { background: var(--danger); color: white; }
.danger:hover { background: var(--danger-dark); }
.full { width: 100%; margin-top: 16px; }
.small { padding: 7px 9px; font-size: 13px; }

.messages { max-width: 760px; margin: 0 auto 18px; }
.message { padding: 12px 14px; border-radius: 8px; margin-bottom: 10px; border: 1px solid transparent; }
.message.success { background: var(--success-bg); color: var(--success-text); border-color: #86efac; }
.message.warning { background: var(--warn-bg); color: var(--warn-text); border-color: #fcd34d; }
.message.error { background: var(--error-bg); color: var(--error-text); border-color: #fca5a5; }

.result-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.badge { border-radius: 999px; padding: 5px 10px; font-size: 13px; font-weight: 700; }
.badge.success { background: var(--success-bg); color: var(--success-text); }
.badge.warning { background: var(--warn-bg); color: var(--warn-text); }
.badge.neutral { background: #e5e7eb; color: #374151; }
.details { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px 14px; margin: 18px 0; }
.details dt { color: var(--muted); font-weight: 700; }
.details dd { margin: 0; }
.details.compact { grid-template-columns: 75px minmax(0, 1fr); font-size: 14px; }
.policy-box { margin: 12px 0; border: 1px solid var(--line); background: #f8fafc; border-radius: 8px; padding: 12px 14px; color: #334155; }
.policy-box ul, .small-list { margin: 8px 0 0 20px; padding: 0; }
.small-list li { margin: 7px 0; }

.qr-box { text-align: center; margin: 18px 0; }
.qr-box img { max-width: 240px; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: white; }
.manual-secret { margin: 12px 0; }
.manual-secret code { display: block; margin-top: 8px; padding: 8px; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; overflow-wrap: anywhere; }

/* Ops Panel */
.ops-header { margin-bottom: 18px; }
.user-card { border: 1px solid var(--line); border-radius: 10px; padding: 0; margin-top: 14px; background: #fafbfc; overflow: hidden; }
.user-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; padding: 14px 16px; }
.accordion-header { cursor: pointer; user-select: none; }
.accordion-header:hover { background: #f1f5f9; }
.user-card.expanded .accordion-header { background: #eef4ff; border-bottom: 1px solid var(--line); }
.user-card-body { display: none; padding: 0 16px 16px; }
.user-card.expanded .user-card-body { display: block; }
.chevron { font-weight: 800; color: var(--muted); transition: transform .15s ease-in-out; }
.user-card.expanded .chevron { transform: rotate(90deg); }
.user-email { font-weight: 800; font-size: 16px; overflow-wrap: anywhere; }
.user-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stacked-form { margin-top: 10px; padding-top: 10px; border-top: 1px solid #e5e7eb; }
.form-row { display: flex; gap: 12px; align-items: flex-end; justify-content: space-between; }
.form-row.wrap { flex-wrap: wrap; }
.field { min-width: 120px; }
.field.sm { width: 130px; }
.field.md { width: auto; min-width: 110px; }
.field.grow { flex: 1 1 260px; }
.field.button-field { align-self: flex-end; }
.field label { margin-top: 0; font-size: 13px; color: #344054; }
.password-row input { min-width: 230px; }
.logs-card { margin-top: 22px; }
.logs-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
#logFilter { margin: 8px 0 12px; }
.log-container { max-height: 430px; overflow-y: auto; background: #0f172a; color: #e5e7eb; padding: 12px; border-radius: 8px; font-family: Consolas, Monaco, monospace; font-size: 13px; line-height: 1.4; }
.log-line { padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.07); white-space: pre-wrap; overflow-wrap: anywhere; }

@media (max-width: 900px) {
    .two-col, .ops-grid { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
    .inline-form, .password-wrapper { flex-direction: column; align-items: stretch; }
    .details { grid-template-columns: 1fr; gap: 3px; }
    .form-row { flex-direction: column; align-items: stretch; }
    .field, .field.sm, .field.md { width: 100%; }
    .user-card-top { flex-direction: row; }
    .logs-title-row { flex-direction: column; }
}
