:root {
    --hero: #1b6aa3;
    --hero-deep: #155887;
    --navy: #1a2740;
    --cyan: #5ec8e8;
    --cyan-hover: #3db6de;
    --white: #ffffff;
    --bg: #f3f6f9;
    --ink: #1a2332;
    --muted: #6b7785;
    --line: #e4e8ee;
    --ghost: #eef1f4;
    --danger: #b42318;
    --ok: #157a4b;
    --shadow: 0 18px 40px rgba(16, 42, 67, 0.12);
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.5 Inter, "Segoe UI", sans-serif;
}

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

.topbar {
    display: flex;
    align-items: center;
    gap: 28px;
    background: var(--white);
    padding: 14px 32px;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 0 rgba(16, 42, 67, 0.06);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #126C9F;
}

.brand:hover { text-decoration: none; }

.brand-logo {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    object-fit: contain;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.05;
}

.brand-text strong {
    font-size: 1.25rem;
    font-weight: 700;
    color: #126C9F;
}

.brand-text small {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 500;
}

.topbar nav {
    display: flex;
    justify-content: center;
    gap: 28px;
    flex: 1;
}

.topbar nav a {
    color: var(--ink);
    font-weight: 500;
    padding: 6px 0;
}

.topbar nav a:hover,
.topbar nav a.is-active {
    color: var(--hero);
    text-decoration: none;
}

.topbar nav a.is-active {
    box-shadow: inset 0 -2px 0 var(--cyan);
}

.account {
    display: flex;
    align-items: center;
    gap: 12px;
}

.account-name { color: var(--muted); font-size: 0.92rem; }

.page {
    max-width: none;
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 28px 32px 72px;
}

.page-head, .split {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
    margin-bottom: 18px;
}

.page-head > div:first-child {
    min-width: 0;
}

.page-head h1 {
    margin-bottom: 4px;
}

.page-head .lede {
    margin: 0;
}

.page-head-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    flex: 0 0 auto;
}

.page-head-actions .search input {
    min-width: 260px;
}

h1 { margin: 0 0 8px; font-size: 1.85rem; font-weight: 700; letter-spacing: -0.02em; }
.lede { margin: 0 0 16px; color: var(--muted); }
.back { margin: 0 0 12px; }
.mono { font-family: "IBM Plex Mono", monospace; }

.panel {
    background: var(--white);
    border: 0;
    border-radius: var(--radius);
    padding: 12px 8px 14px;
    box-shadow: var(--shadow);
}

.stack { display: grid; gap: 14px; }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
label { display: grid; gap: 6px; font-weight: 600; font-size: 0.92rem; }

input, select, textarea, button {
    font: inherit;
}

input, select, textarea {
    border: 1px solid #d9dee6;
    border-radius: 10px;
    padding: 12px 14px;
    background: var(--white);
    color: var(--ink);
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(94, 200, 232, 0.45);
    border-color: var(--cyan);
}

button,
.search button,
.btn-primary {
    background: var(--hero);
    color: var(--white);
    border: 0;
    border-radius: 10px;
    padding: 12px 18px;
    font-weight: 600;
    cursor: pointer;
}

button:hover,
.btn-primary:hover {
    background: var(--hero-deep);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

button.secondary,
.btn-cyan {
    background: var(--cyan);
    color: var(--white);
}

button.secondary:hover,
.btn-cyan:hover {
    background: var(--cyan-hover);
}

.btn-ghost,
button.btn-ghost {
    background: var(--ghost);
    color: var(--ink);
    padding: 8px 14px;
    font-weight: 600;
}

.btn-ghost:hover { background: #e4e8ee; }

button.linkish, .linkish {
    background: none;
    border: 0;
    color: var(--hero);
    padding: 0;
    cursor: pointer;
    font: inherit;
}

.search { display: flex; gap: 8px; }
.search input { min-width: 220px; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; table-layout: auto; }
th, td {
    text-align: left;
    padding: 18px 16px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
th { color: var(--muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: 0; }

.flash {
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
}
.flash-success { background: #e8f6ee; color: var(--ok); }
.flash-error { background: #fde8e6; color: var(--danger); }

.pager { display: flex; gap: 16px; align-items: center; margin-top: 16px; color: var(--muted); }

.zone-table input, .zone-table select { width: 100%; }

.auth-body {
    position: relative;
    min-height: 100vh;
    background: var(--hero);
}

.auth-body .topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}

.hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 96px 20px 40px;
    box-sizing: border-box;
}

.auth-card {
    width: min(440px, 100%);
    background: var(--white);
    border-radius: 20px;
    padding: 32px;
    box-shadow: var(--shadow);
}

.auth-card h1 {
    margin-bottom: 8px;
}

.auth-card .lede {
    margin-bottom: 20px;
}

.auth-card input,
.auth-card select,
.auth-card button {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.mfa-qr {
    display: flex;
    justify-content: center;
    margin: 0 0 16px;
}

.mfa-qr svg {
    width: 180px;
    height: 180px;
}

.mfa-secret {
    display: grid;
    gap: 6px;
    margin: 0 0 18px;
    font-size: 0.85rem;
    color: var(--muted);
}

.mfa-secret code {
    display: block;
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.92rem;
    color: var(--ink);
    background: var(--ghost);
    border-radius: 8px;
    padding: 10px 12px;
    word-break: break-all;
}

.otp-input {
    letter-spacing: 0.4em;
    padding-right: 0.2em;
    font-size: 1.25rem;
    font-weight: 600;
    text-align: center;
    font-family: "IBM Plex Mono", monospace;
}

.filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
    gap: 12px;
    align-items: end;
    background: var(--white);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.filter-actions { display: flex; gap: 8px; align-items: center; }
.button-link {
    display: inline-flex;
    align-items: center;
    color: var(--muted);
    padding: 10px 8px;
}
.muted { color: var(--muted); }
.pill {
    display: inline-block;
    background: rgba(94, 200, 232, 0.18);
    color: var(--hero-deep);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.75rem;
    font-weight: 700;
    vertical-align: middle;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: none;
}
.modal.is-open,
.modal:not([hidden]) {
    display: grid;
    place-items: center;
    padding: 24px;
    box-sizing: border-box;
}
.modal[hidden] { display: none !important; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(26, 39, 64, 0.45);
}
.modal-dialog {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: min(480px, 100%);
    max-height: 100%;
    min-width: 0;
    overflow: hidden;
    background: var(--white);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
}
.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    flex: 0 0 auto;
}
.modal-head h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.modal-dialog form {
    display: grid;
    gap: 14px;
    min-width: 0;
    overflow: auto;
}
.modal-dialog label,
.modal-dialog input,
.modal-dialog select {
    min-width: 0;
    max-width: 100%;
}
.modal-dialog input,
.modal-dialog select {
    width: 100%;
    box-sizing: border-box;
}
.modal-dialog select {
    overflow: hidden;
    text-overflow: ellipsis;
}
.modal-dialog .btn-primary {
    width: 100%;
}

.pill-danger {
    background: #fde8e6;
    color: var(--danger);
}

.pill-muted {
    background: var(--ghost);
    color: var(--muted);
}

.row-disabled td { color: var(--muted); }

.row-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 10px;
    align-items: center;
}

.row-actions form {
    margin: 0;
    display: inline-flex;
    flex: 0 0 auto;
}

.row-actions button {
    padding: 8px 12px;
    font-size: 0.85rem;
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
}

.col-actions {
    width: 1%;
    white-space: nowrap;
    vertical-align: middle;
}

.users-table {
    width: max-content;
    min-width: 100%;
    table-layout: auto;
}

.users-table-wrap {
    width: max-content;
    min-width: 100%;
    box-sizing: border-box;
    overflow: visible;
    padding: 12px 24px 16px;
}

.users-table th,
.users-table td {
    padding: 18px 16px;
}

.users-table th.col-actions,
.users-table td.col-actions {
    padding-right: 20px;
}

.users-table .col-org {
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.users-table .cell-email {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.users-table .col-status,
.users-table .col-handle,
.users-table .col-contact {
    white-space: nowrap;
}

.users-table .col-actions {
    width: 1%;
}

button.btn-danger,
.btn-danger {
    background: var(--danger);
    color: var(--white);
}

button.btn-danger:hover,
.btn-danger:hover {
    background: #912018;
}

.meta-panel {
    padding: 18px 20px;
    margin-bottom: 18px;
}

.meta-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px 24px;
    margin: 0;
}

.meta-list dt {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.meta-list dd {
    margin: 4px 0 0;
}

#open-create-user {
    background: var(--cyan);
}

#open-create-user:hover {
    background: var(--cyan-hover);
}

@media (max-width: 1100px) {
    .filters { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
    .page-head, .split, .account, .topbar { flex-direction: column; align-items: stretch; }
    .filters, .form-row { grid-template-columns: 1fr; }
    .topbar nav { justify-content: flex-start; }
    .auth-body .topbar,
    .auth-body .account {
        flex-direction: row;
        align-items: center;
    }
}
