:root {
    --bg: #f4f6f9;
    --card: #ffffff;
    --text: #1a1f36;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --success-bg: #ecfdf5;
    --success-text: #065f46;
    --info-bg: #eff6ff;
    --info-text: #1e40af;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem 3rem;
}

.shell-wide {
    max-width: 1320px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.topbar .muted {
    display: block;
    font-size: 0.9rem;
}

.topbar-nav {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.section-title {
    margin: 1.5rem 0 0.75rem;
    font-size: 1.1rem;
}

.badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: var(--info-bg);
    color: var(--info-text);
    margin-left: 0.35rem;
}

.badge-warn {
    background: #fef3c7;
    color: #92400e;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success-text);
}

.badge-error {
    background: var(--error-bg);
    color: var(--error-text);
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    margin: 1.25rem 0 1.5rem;
    padding: 1rem 1.25rem;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.filter-bar label {
    flex: 1;
    min-width: 260px;
}

.history-panel {
    margin-top: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.history-table thead {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

.history-table th {
    text-align: left;
    padding: 0.9rem 1.1rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #64748b;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.history-table td {
    padding: 1rem 1.1rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.history-table tbody tr {
    transition: background 0.15s ease;
}

.history-table tbody tr:hover {
    background: #f8fafc;
}

.history-table tbody tr:last-child td {
    border-bottom: 0;
}

.col-datetime {
    white-space: nowrap;
    min-width: 110px;
}

.cell-date {
    display: block;
    font-weight: 600;
    color: var(--text);
}

.cell-time {
    display: block;
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 0.1rem;
}

.col-email {
    color: #334155;
    font-size: 0.9rem;
}

.domain-chip {
    display: inline-block;
    padding: 0.35rem 0.7rem;
    background: #eff6ff;
    color: #1d4ed8;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.88rem;
    word-break: break-word;
}

.login-code {
    display: inline-block;
    padding: 0.3rem 0.55rem;
    background: #f3f4f6;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    color: #374151;
}

.ip-chip {
    display: inline-block;
    padding: 0.3rem 0.55rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.82rem;
    color: #475569;
}

.col-status {
    min-width: 120px;
}

.status-pill {
    display: inline-block;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    letter-spacing: 0.02em;
}

.status-pill.badge-success {
    background: #dcfce7;
    color: #166534;
}

.status-pill.badge-error {
    background: #fee2e2;
    color: #991b1b;
}

.status-pill.badge-warn {
    background: #fef3c7;
    color: #92400e;
}

.history-detail {
    display: block;
    margin-top: 0.4rem;
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: normal;
    line-height: 1.35;
    max-width: 220px;
}

.empty-state-box {
    margin-top: 1.5rem;
    padding: 2.5rem 1.5rem;
    text-align: center;
    background: #f9fafb;
    border: 1px dashed var(--border);
    border-radius: 12px;
}

.empty-state-title {
    margin: 0 0 0.35rem;
    font-weight: 700;
    font-size: 1.05rem;
}

.history-table .nowrap {
    white-space: nowrap;
}

.history-table .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88rem;
}

.history-foot {
    margin: 1rem 0 0;
    font-size: 0.85rem;
}

.empty-state {
    margin: 1.5rem 0 0;
}

.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.65rem 0.5rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.data-table th {
    font-size: 0.85rem;
    color: var(--muted);
}

.actions-cell {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: flex-start;
}

.inline-form {
    display: inline;
}

.inline-details summary {
    cursor: pointer;
    list-style: none;
}

.inline-details summary::-webkit-details-marker {
    display: none;
}

.stack-tight {
    margin-top: 0.5rem;
    min-width: 220px;
}

.btn-danger {
    background: #dc2626;
}

.btn-danger:hover {
    background: #b91c1c;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.75rem 2rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.card-flush {
    padding-bottom: 1.25rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.count-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    background: #f3f4f6;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.card-narrow { max-width: 420px; margin: 3rem auto; }

h1 {
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
}

.muted { color: var(--muted); }

.stack {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
}

label {
    display: grid;
    gap: 0.35rem;
    font-weight: 600;
    font-size: 0.95rem;
}

input[type="text"],
input[type="email"],
input[type="password"] {
    font: inherit;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

input:focus {
    outline: 2px solid rgba(37, 99, 235, 0.25);
    border-color: var(--primary);
}

.btn {
    display: inline-block;
    border: 0;
    border-radius: 8px;
    padding: 0.7rem 1rem;
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}

.btn:hover { background: var(--primary-hover); }
.btn-full { width: 100%; }
.btn-small { padding: 0.4rem 0.75rem; font-size: 0.85rem; }

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

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

.alert {
    border-radius: 8px;
    padding: 0.85rem 1rem;
    margin: 1rem 0;
}

.alert-error { background: var(--error-bg); color: var(--error-text); }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-info { background: var(--info-bg); color: var(--info-text); }

.credential-box {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.credential-box code {
    background: rgba(0, 0, 0, 0.06);
    padding: 0.5rem 0.65rem;
    border-radius: 6px;
    font-size: 1rem;
    word-break: break-all;
}

.center { text-align: center; }

.debug-raw {
    margin-top: 0.75rem;
    font-weight: normal;
}

.debug-raw pre {
    margin: 0.5rem 0 0;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.85rem;
}

body.is-loading {
    overflow: hidden;
}

.loader-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    animation: loader-fade-in 0.2s ease-out;
}

.loader-overlay[hidden] {
    display: none !important;
}

.loader-card {
    width: min(100%, 360px);
    background: var(--card);
    border-radius: 16px;
    padding: 2rem 1.75rem;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
    animation: loader-pop 0.25s ease-out;
}

.loader-spinner {
    width: 52px;
    height: 52px;
    margin: 0 auto 1.25rem;
    border: 4px solid #e5e7eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: loader-spin 0.85s linear infinite;
}

.loader-title {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
    font-weight: 700;
}

.loader-text {
    margin: 0;
    color: var(--text);
    font-size: 0.95rem;
}

.loader-hint {
    margin: 0.75rem 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.loader-dots {
    display: flex;
    justify-content: center;
    gap: 0.35rem;
    margin-top: 1rem;
}

.loader-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary);
    opacity: 0.35;
    animation: loader-bounce 1.2s ease-in-out infinite;
}

.loader-dots span:nth-child(2) { animation-delay: 0.15s; }
.loader-dots span:nth-child(3) { animation-delay: 0.3s; }

.btn:disabled {
    opacity: 0.75;
    cursor: wait;
}

@keyframes loader-spin {
    to { transform: rotate(360deg); }
}

@keyframes loader-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes loader-pop {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes loader-bounce {
    0%, 80%, 100% {
        opacity: 0.35;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-5px);
    }
}
