:root {
    --ink: #171717;
    --ink-soft: #4b4b4b;
    --muted: #7b746b;
    --paper: #f4efe8;
    --card: #fffdf9;
    --line: #e3dacd;
    --line-strong: #d3c6b4;
    --green: #1f7a4c;
    --green-bg: #e6f4ec;
    --red: #b3322a;
    --red-bg: #fbe9e7;
    --amber: #8a5a0b;
    --amber-bg: #fbf1dd;
    --blue: #245c96;
    --blue-bg: #e8f1fb;
    --radius: 16px;
    --shadow: 0 18px 45px rgba(23, 23, 23, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
    font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--ink); }

code, pre {
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-size: .86em;
    background: #f0e9df;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1px 5px;
}

pre {
    padding: 12px 14px;
    overflow: auto;
    white-space: pre-wrap;
}

code.wrap { word-break: break-all; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.text-warn { color: var(--red); }

/* Top bar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(244, 239, 232, .92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px 22px;
    display: flex;
    align-items: center;
    gap: 22px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    flex: 0 0 auto;
}

.brand img { border-radius: 10px; }

.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand strong { font-size: 1.02rem; }
.brand small { color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }

.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.nav a {
    text-decoration: none;
    padding: 7px 11px;
    border-radius: 999px;
    color: var(--ink-soft);
    font-weight: 700;
    font-size: .88rem;
}

.nav a:hover { background: #ebe3d8; color: var(--ink); }
.nav a.active { background: var(--ink); color: #fff; }

.nav-sep {
    width: 1px;
    height: 22px;
    background: var(--line-strong);
    margin: 0 6px;
}

.account {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.account-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.account-text strong,
.account-text small {
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-text small { color: var(--muted); font-size: .75rem; }

.avatar {
    border-radius: 50%;
    object-fit: cover;
    flex: 0 0 auto;
    background: #e7ded1;
}

.avatar-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: .78rem;
    color: var(--ink-soft);
    border: 1px solid var(--line);
}

/* Layout */
.admin-main {
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px 22px 60px;
}

.admin-footer {
    text-align: center;
    color: var(--muted);
    font-size: .78rem;
    padding: 0 22px 28px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.page-head h1 { margin: 0; font-size: 1.75rem; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; }

/* Cards */
.cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 4px 14px rgba(23, 23, 23, .03);
}

.card-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; font-weight: 700; }
.card-value { font-size: 1.9rem; line-height: 1.05; }
.card-value.ok { color: var(--green); }
.card-value.warn { color: var(--amber); }
.card-note { color: var(--muted); font-size: .78rem; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 18px;
    box-shadow: 0 4px 14px rgba(23, 23, 23, .03);
}

.panel-flush { padding: 0; overflow: hidden; }
.panel.narrow { max-width: 560px; margin: 40px auto; }

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.panel-head h2 { margin: 0; font-size: 1.08rem; }

.link { color: var(--ink); font-weight: 700; font-size: .84rem; }

/* Status lists */
.status-list, .user-list, .detail-list { list-style: none; margin: 0; padding: 0; }

.status-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px dashed var(--line);
}

.status-list li:last-child { border-bottom: 0; }

.user-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px dashed var(--line);
}

.user-list li:last-child { border-bottom: 0; }
.user-list-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 1; }
.user-list-text small { color: var(--muted); }

.detail-list { display: grid; grid-template-columns: 180px 1fr; gap: 10px 16px; }
.detail-list dt { color: var(--muted); font-weight: 700; font-size: .84rem; }
.detail-list dd { margin: 0; word-break: break-word; }
.detail-list dd .badge { margin: 0 4px 4px 0; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 800;
    letter-spacing: .02em;
    background: #eee7dc;
    color: var(--ink-soft);
    white-space: nowrap;
}

.badge-ok { background: var(--green-bg); color: var(--green); }
.badge-warn { background: var(--amber-bg); color: var(--amber); }
.badge-admin { background: var(--ink); color: #fff; }
.badge-muted { background: #eee7dc; color: var(--muted); }

/* Buttons and fields */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--ink);
    background: var(--ink);
    color: #fff;
    font: inherit;
    font-weight: 800;
    font-size: .86rem;
    padding: 9px 16px;
    border-radius: 999px;
    text-decoration: none;
    cursor: pointer;
    transition: transform .12s ease, opacity .12s ease;
    white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }

.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn-ghost:hover { background: #eee6da; }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn-sm { padding: 6px 11px; font-size: .78rem; }
.btn-block { width: 100%; }
.btn-google {
    background: #fff;
    color: #1f1f1f;
    border-color: var(--line-strong);
    box-shadow: 0 2px 8px rgba(23, 23, 23, .08);
}
.btn-google:hover { background: #faf8f4; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; font-weight: 700; color: var(--ink-soft); }
.field.grow { flex: 1 1 220px; }

input, select {
    font: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 9px 12px;
    min-width: 0;
}

input:focus, select:focus, .btn:focus-visible {
    outline: 2px solid #8a7a62;
    outline-offset: 2px;
}

.stack { display: flex; flex-direction: column; gap: 12px; }
.inline { display: inline-flex; margin: 0; }

.invite-form, .filters {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.filters { padding: 0; }
.filters .btn { align-self: flex-end; }

/* Flash and notices */
.flash {
    border-radius: 12px;
    padding: 12px 15px;
    margin-bottom: 16px;
    font-weight: 700;
    font-size: .88rem;
    border: 1px solid transparent;
}

.flash-success { background: var(--green-bg); color: var(--green); border-color: #c9e6d6; }
.flash-error { background: var(--red-bg); color: var(--red); border-color: #f0c9c5; }
.flash-info { background: var(--blue-bg); color: var(--blue); border-color: #c9dcf2; }

.notice {
    background: #f6f1e9;
    border: 1px dashed var(--line-strong);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--ink-soft);
    font-size: .86rem;
    margin-top: 12px;
}

/* Tables */
.table-wrap { overflow-x: auto; }

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

.table th, .table td {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.table th {
    background: #f7f2ea;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--muted);
    white-space: nowrap;
}

.table tr:last-child td { border-bottom: 0; }
.table th.right { text-align: right; }

.user-cell { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.user-cell div { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-cell small { color: var(--muted); }
.user-cell .badge { margin-left: 6px; }

.row-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }

.empty {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 34px 22px;
    text-align: center;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 6px;
}

.quick-links { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }

/* Auth screen */
.auth-wrap { display: grid; place-items: center; padding: 30px 0 60px; }
.auth-card {
    width: min(460px, 100%);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 30px;
    box-shadow: var(--shadow);
}

.auth-head { text-align: center; margin-bottom: 20px; }
.auth-head h1 { margin: 12px 0 4px; font-size: 1.6rem; }
.auth-head p { margin: 0; }

.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 74px;
    height: 74px;
    border-radius: 24px;
    background: #efe7db;
    border: 1px solid var(--line);
}

.auth-logo img { border-radius: 18px; }

.or {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
    color: var(--muted);
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.or::before, .or::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}

.setup-help {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px dashed var(--line);
    font-size: .84rem;
    color: var(--ink-soft);
}

.setup-help p { margin: 6px 0; }

@media (max-width: 980px) {
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2 { grid-template-columns: 1fr; }
    .account-text { display: none; }
}

@media (max-width: 720px) {
    .topbar-inner { flex-wrap: wrap; gap: 10px; }
    .nav { order: 3; width: 100%; }
    .account { margin-left: auto; }
    .cards { grid-template-columns: 1fr; }
    .detail-list { grid-template-columns: 1fr; gap: 2px 0; }
    .detail-list dt { margin-top: 8px; }
    .admin-main { padding: 20px 14px 50px; }
    .panel { padding: 16px; }
    .table th, .table td { padding: 10px 12px; }
}

/* AI history / DataTables */
.history-table-wrap { padding: 0; }

.dt-container {
    padding: 14px 16px 16px;
    font-size: .88rem;
}

.dt-container .dt-length,
.dt-container .dt-search,
.dt-container .dt-info,
.dt-container .dt-pagination {
    color: var(--muted);
    font-size: .82rem;
}

.dt-container .dt-search input,
.dt-container .dt-length select {
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    padding: 6px 9px;
    font-size: .84rem;
    background: #fff;
    margin-left: 6px;
}

.dt-container .dt-search input { min-width: 220px; }

.dt-container .dt-pagination .dt-paging { margin: 0; }
.dt-container .dt-pagination .dt-paging .page-link,
.dt-container .dt-pagination .dt-paging .paginate_button {
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 4px 9px;
    margin: 0 2px;
    color: var(--ink);
    background: #fff;
    font-size: .8rem;
}

.dt-container .dt-pagination .dt-paging .active > .page-link,
.dt-container .dt-pagination .dt-paging .current {
    background: var(--ink);
    border-color: var(--ink);
    color: #fff;
}

.dt-container table.dataTable {
    border-collapse: collapse;
    margin: 0;
}

.dt-container table.dataTable > thead > tr > th,
.dt-container table.dataTable > tbody > tr > td {
    border-bottom: 1px solid var(--line);
}

.dt-container table.dataTable > thead > tr > th {
    background: #f7f2ea;
    color: var(--muted);
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    white-space: nowrap;
}

.dt-container table.dataTable > tbody > tr:last-child > td { border-bottom: 0; }
.dt-container .dt-processing { border-radius: 10px; box-shadow: var(--shadow); }

.history-preview {
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink-soft);
}

.history-preview-answer { color: var(--muted); }
.history-preview:hover { color: var(--ink); }

.history-dialog {
    border: 0;
    padding: 0;
    width: min(780px, calc(100vw - 32px));
    max-height: 86vh;
    background: transparent;
    color: var(--ink);
}

.history-dialog::backdrop {
    background: rgba(23, 23, 23, .48);
    backdrop-filter: blur(2px);
}

.history-dialog-inner {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 22px;
    max-height: 86vh;
    overflow: auto;
    box-shadow: var(--shadow);
}

.history-dialog-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.history-dialog-head strong { display: block; font-size: 1.05rem; }
.history-dialog-head small { display: block; margin-top: 2px; }

.history-block { margin-top: 16px; }

.history-label {
    display: block;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}

.history-text,
.history-pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    background: #f8f3eb;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: .9rem;
    line-height: 1.55;
}

.history-pre {
    max-height: 220px;
    overflow: auto;
    font-size: .78rem;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

@media (max-width: 720px) {
    .dt-container { padding: 12px; }
    .dt-container .dt-search input { min-width: 0; width: 100%; }
    .dt-container .dt-layout-row { gap: 8px; }
    .history-preview { max-width: 180px; }
}

/* Email OTP / reCAPTCHA settings */
.settings-form { margin-top: 4px; }

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 18px;
    margin-bottom: 16px;
}

.settings-grid .full { grid-column: 1 / -1; }

.check-field {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    color: var(--ink-soft);
    font-size: .88rem;
}

.check-field input[type="checkbox"] {
    width: 18px;
    height: 18px;
    min-width: 18px;
    accent-color: var(--ink);
    padding: 0;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.otp-notice {
    margin-top: 0;
    margin-bottom: 16px;
    text-align: center;
}

.otp-resend {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.recaptcha-note {
    text-align: center;
    margin: 8px 0 0;
}

@media (max-width: 720px) {
    .settings-grid { grid-template-columns: 1fr; }
    .settings-grid .full { grid-column: 1; }
}
