:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --panel2: #f8fafc;
    --text: #18202a;
    --muted: #667085;
    --line: #e3e8ef;
    --primary: #4b2e83;
    --primary2: #6240a3;
    --danger: #b42318;
    --ok: #16835b;
    --warn: #b7791f;
    --shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

[data-theme="dark"] {
    --bg: #0d1117;
    --panel: #151b23;
    --panel2: #10151c;
    --text: #edf2f7;
    --muted: #9aa6b2;
    --line: #293241;
    --primary: #8b6bc9;
    --primary2: #a387df;
    --danger: #f97066;
    --ok: #3cc98a;
    --warn: #e5ad4d;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body {
    font-size: 14px;
}

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

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.hidden {
    display: none !important;
}

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

.small {
    font-size: 12px;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.center {
    text-align: center;
}

.topbar {
    height: 66px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    font-weight: 800;
    letter-spacing: 0.3px;
}

.brand small {
    font-weight: 500;
    color: var(--muted);
    margin-left: 8px;
}

.who {
    display: flex;
    align-items: center;
    gap: 9px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    background: var(--panel2);
    color: var(--text);
    border-radius: 10px;
}

.tabs {
    display: flex;
    gap: 4px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 0 24px;
    position: sticky;
    top: 66px;
    z-index: 19;
}

.tab {
    padding: 15px 16px;
    color: var(--muted);
    font-weight: 650;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    text-decoration: none;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--primary);
    border-color: var(--primary);
}

main {
    max-width: 1500px;
    margin: 0 auto;
    padding: 24px;
}

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

.page-head h1,
.page-head h2,
.page-head p {
    margin-top: 0;
}

.page-head h1 {
    margin-bottom: 5px;
    font-size: 23px;
}

.page-head p {
    margin-bottom: 0;
    color: var(--muted);
}

.compact-head {
    margin-bottom: 12px;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.section-heading h2 {
    margin: 0 0 5px;
}

.section-heading p {
    margin: 0;
    color: var(--muted);
}

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

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.card .num {
    font-size: 30px;
    font-weight: 800;
}

.card .lbl {
    margin-top: 5px;
    color: var(--muted);
    font-size: 12px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 18px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}

.panel h2,
.panel h3 {
    margin-top: 0;
}

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

.grid3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.field-span-2 {
    grid-column: span 2;
}

.narrow-grid {
    max-width: 700px;
}

.narrow-field {
    max-width: 700px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--panel2);
    color: var(--text);
    border-radius: 9px;
    padding: 10px 11px;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(75, 46, 131, 0.12);
}

textarea {
    resize: vertical;
    min-height: 90px;
}

.btn {
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 10px 14px;
    background: var(--panel2);
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn:hover {
    filter: brightness(0.98);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #ffffff;
}

.btn-ghost {
    background: transparent;
}

.button-row {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: 14px;
}

.button-row.no-margin {
    margin-top: 0;
}

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

.row-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.linkbtn {
    border: 0;
    background: none;
    color: var(--primary);
    padding: 2px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

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

.role-badge {
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    text-transform: capitalize;
    background: var(--panel2);
    border: 1px solid var(--line);
}

.role-superadmin {
    border-color: #805ad5;
    color: #805ad5;
}

.role-admin {
    border-color: #3182ce;
    color: #3182ce;
}

.role-editor {
    border-color: #16835b;
    color: #16835b;
}

.role-viewer {
    border-color: #718096;
    color: #718096;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 5px 8px;
    font-size: 11px;
    font-weight: 800;
}

.status-active {
    background: rgba(22, 131, 91, 0.12);
    color: var(--ok);
}

.status-unknown {
    background: rgba(183, 121, 31, 0.12);
    color: var(--warn);
}

.status-offline {
    background: rgba(180, 35, 24, 0.12);
    color: var(--danger);
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    background: currentColor;
}

.summary-table,
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td,
.summary-table th,
.summary-table td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.data-table th,
.summary-table th {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.4px;
}

.data-table tr:hover {
    background: var(--panel2);
}

.table-wrap {
    overflow: auto;
}

.searchbar {
    position: relative;
}

.searchbar input {
    padding-left: 40px;
}

.search-icon {
    position: absolute;
    left: 13px;
    top: 10px;
    color: var(--muted);
    z-index: 1;
}

.search-suggestions {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    z-index: 40;
    max-height: 360px;
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
    padding: 5px;
}

.search-suggestions.hidden {
    display: none;
}

.suggestion {
    display: flex;
    width: 100%;
    gap: 12px;
    align-items: center;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 11px 12px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text);
}

.suggestion:hover {
    background: var(--panel2);
}

.suggestion strong {
    font-size: 13px;
}

.suggestion span {
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.suggestion-empty {
    padding: 12px;
    color: var(--muted);
    font-size: 13px;
}

.chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chip {
    border: 1px solid var(--line);
    background: var(--panel2);
    color: var(--text);
    border-radius: 999px;
    padding: 8px 11px;
    cursor: pointer;
}

.chip:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.notice {
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(75, 46, 131, 0.08);
    border: 1px solid rgba(75, 46, 131, 0.18);
}

.errbox {
    display: none;
    padding: 10px 12px;
    border-radius: 9px;
    background: rgba(180, 35, 24, 0.1);
    border: 1px solid rgba(180, 35, 24, 0.25);
    color: var(--danger);
    margin-bottom: 12px;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    background: var(--text);
    color: var(--panel);
    padding: 12px 15px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    z-index: 100;
    display: none;
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.58);
    z-index: 50;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.overlay.show {
    display: flex;
}

.modal {
    width: min(760px, 100%);
    max-height: 90vh;
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.modal-wide {
    width: min(920px, 100%);
}

.credential-modal {
    width: min(700px, 100%);
}

.modal h2 {
    margin: 0 0 16px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    margin-top: 18px;
}

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

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.auth-wrap {
    width: min(440px, 100%);
}

.auth-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.auth-logo {
    text-align: center;
    font-size: 26px;
    font-weight: 900;
    margin-bottom: 5px;
}

.auth-sub {
    text-align: center;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 22px;
}

.auth-card .field {
    margin-bottom: 14px;
}

.auth-actions {
    margin-top: 18px;
}

.auth-actions .btn {
    width: 100%;
}

.auth-foot {
    text-align: center;
    margin-top: 14px;
}

.top-auth {
    position: fixed;
    right: 20px;
    top: 20px;
}


.password-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
    align-items: stretch;
}

.password-input-row .btn {
    white-space: nowrap;
}

.secret-actions {
    display: flex;
    gap: 7px;
    align-items: center;
    flex-wrap: wrap;
}

.secretbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.secretbox-row .secretbox {
    margin-top: 0;
    flex: 1 1 260px;
}

.config-port-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 90px;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel2);
}

.config-port-row label {
    font-size: 12px;
    font-weight: 700;
}

.password-meter {
    height: 5px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 5px;
}

.password-meter span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--primary);
}

.approval-card {
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 14px;
    margin-bottom: 10px;
    background: var(--panel2);
}

.approval-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.diff {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 10px;
}

.diff > div {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.diff pre {
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow: auto;
    font-size: 11px;
}

.secretbox {
    margin-top: 8px;
    padding: 10px;
    border: 1px dashed var(--primary);
    border-radius: 8px;
    background: var(--panel2);
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.cred-section {
    margin-top: 18px;
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.cred-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin: 8px 0;
}

.readonly-value {
    padding: 9px 0;
    word-break: break-word;
}

.section-rule {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 20px 0;
}

.note-edit {
    display: flex;
    gap: 6px;
    min-width: 260px;
}

.config-grid,
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.config-section {
    min-width: 0;
}

.config-section h3 {
    margin-bottom: 10px;
}

.config-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 50px;
}

.config-row > span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.config-row .linkbtn {
    flex: 0 0 auto;
    margin-left: auto;
}

.inline-add {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    margin-top: 9px;
}

.field-help {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 5px;
    width: 15px;
    height: 15px;
    border: 1px solid var(--line);
    border-radius: 50%;
    font-size: 10px;
    cursor: help;
}

.field input:invalid {
    border-color: var(--danger);
}

@media (max-width: 1100px) {
    .config-grid,
    .catalog-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

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

    .grid3 {
        grid-template-columns: 1fr 1fr;
    }

    .topbar {
        padding: 0 14px;
    }

    .tabs {
        padding: 0 10px;
        overflow: auto;
    }

    main {
        padding: 15px;
    }

    .brand small {
        display: none;
    }
}

@media (max-width: 620px) {
    .cards,
    .grid2,
    .grid3,
    .diff,
    .config-grid,
    .catalog-grid {
        grid-template-columns: 1fr;
    }

    .field-span-2 {
        grid-column: auto;
    }

    .whoUser {
        display: none;
    }

    .topbar {
        height: 60px;
    }

    .tabs {
        top: 60px;
    }

    .tab {
        padding: 12px 10px;
        font-size: 12px;
    }

    .page-head,
    .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .data-table {
        min-width: 950px;
    }

    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .btn {
        width: 100%;
    }

    .note-edit {
        min-width: 0;
        flex-direction: column;
    }
}


/* Login status and helper controls */
.status-ok {
    color: #176b3a;
}

.status-error {
    color: #a32121;
}

.auth-secondary-actions {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--muted);
}

.inline-add {
    flex-wrap: wrap;
}

.inline-add input {
    min-width: 180px;
}

#sqlPatchFields {
    align-items: center;
}

#sqlPatchFields input {
    flex: 1 1 180px;
}

.field-hint {
    margin-top: 5px;
    font-size: 12px;
    opacity: 0.72;
}
