:root {
    --portal-accent: #38cfff;
    --portal-accent-strong: #0aa8dd;
    --portal-danger: #ff4a63;
    --portal-dark-1: #060b14;
    --portal-dark-2: #0b1424;
    --portal-dark-3: #111e33;
    --portal-border: #294462;
    --portal-border-strong: #3c638f;
    --portal-text: #d9eaf8;
    --portal-muted: #86a4c0;
    --portal-ok: #2ebd7f;
    --portal-warn: #d05f6b;
}

* { box-sizing: border-box; }

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

body {
    font-family: "IBM Plex Sans", "Segoe UI", "Helvetica Neue", sans-serif;
    color: var(--portal-text);
    background:
        linear-gradient(rgba(31, 57, 89, 0.22) 1px, transparent 1px),
        linear-gradient(90deg, rgba(31, 57, 89, 0.22) 1px, transparent 1px),
        radial-gradient(circle at 10% 5%, rgba(10, 168, 221, 0.14), transparent 34%),
        radial-gradient(circle at 90% 85%, rgba(255, 74, 99, 0.12), transparent 40%),
        linear-gradient(160deg, #050a12 0%, #0a1323 42%, #0d1a2d 100%);
    background-size: 24px 24px, 24px 24px, auto, auto, auto;
    padding: 22px;
}

.page {
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
}

header {
    background: linear-gradient(180deg, rgba(22, 38, 61, 0.95), rgba(13, 24, 40, 0.95));
    color: #fff;
    border: 1px solid var(--portal-border-strong);
    border-bottom: 2px solid var(--portal-accent);
    border-radius: 8px;
    padding: 16px 18px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    box-shadow: 0 12px 24px rgba(2, 7, 16, 0.5);
}

h1 {
    margin: 0;
    font-size: 1.5rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    font-family: "JetBrains Mono", "Fira Code", "IBM Plex Mono", monospace;
}

#userBox {
    display: inline-block;
    background: #102036;
    border: 1px solid #2f587e;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.8rem;
    color: #d6ecff;
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

.storage-warning {
    margin: 8px 0 0 0;
    padding: 8px 10px;
    border: 1px solid #7d3f45;
    border-radius: 8px;
    background: rgba(96, 23, 27, 0.28);
    color: #ffd8dc;
}

.maintenance-banner {
    margin: 8px 0 0 0;
    padding: 8px 10px;
    border: 1px solid #8e6d26;
    border-radius: 8px;
    background: rgba(122, 88, 12, 0.32);
    color: #ffecbf;
}

.preview-link {
    color: #c8ecff;
    font-size: 0.8rem;
    text-decoration: none;
    border: 1px solid #2f587e;
    background: #102036;
    border-radius: 6px;
    padding: 6px 10px;
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

.preview-link:hover {
    color: #e9f8ff;
    background: #143052;
}

.card {
    background: linear-gradient(180deg, rgba(13, 24, 40, 0.97), rgba(9, 18, 31, 0.97));
    border-radius: 8px;
    border: 1px solid var(--portal-border);
    box-shadow: 0 10px 22px rgba(2, 6, 15, 0.52);
    padding: 0.95rem;
    margin-bottom: 1rem;
}

.login-shell {
    padding: 0;
    overflow: hidden;
}

.login-layout {
    display: grid;
    grid-template-columns: minmax(260px, 1.2fr) minmax(280px, 1fr);
}

.login-intro {
    padding: 1.35rem 1.3rem;
    border-right: 1px solid #2c4b6e;
    background:
        linear-gradient(145deg, rgba(17, 46, 80, 0.92), rgba(11, 27, 46, 0.96)),
        radial-gradient(circle at 20% 20%, rgba(56, 207, 255, 0.18), transparent 45%);
}

.login-kicker {
    margin: 0 0 0.35rem 0;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #8ec2ea;
    font-size: 0.73rem;
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

.login-title {
    margin: 0;
    font-size: 1.45rem;
}

.login-copy {
    margin: 0.55rem 0 0.9rem 0;
    color: #b8d4ee;
}

.login-meta {
    padding-top: 0.8rem;
    border-top: 1px dashed rgba(95, 145, 188, 0.5);
}

.login-meta .hint {
    margin: 0.3rem 0;
}

.login-panel {
    padding: 1.35rem 1.2rem;
    background: linear-gradient(180deg, rgba(10, 22, 36, 0.96), rgba(7, 15, 27, 0.96));
}

.login-panel h3 {
    margin: 0 0 0.8rem 0;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.92rem;
    color: #9ec5e6;
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

.login-panel #loginForm {
    display: grid;
    gap: 0.35rem;
}

.login-panel #loginError {
    margin-top: 0.6rem;
}

.hidden { display: none !important; }

h2, h3 { margin-top: 0; }

label {
    display: block;
    margin-bottom: 0.6rem;
    color: var(--portal-muted);
}

input,
select,
button {
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.58rem;
    border-radius: 4px;
    border: 1px solid #325477;
    background: #0e1b2d;
    color: var(--portal-text);
}

textarea {
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.58rem;
    border-radius: 4px;
    border: 1px solid #325477;
    background: #0e1b2d;
    color: var(--portal-text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

input:focus,
select:focus {
    outline: 2px solid rgba(56, 207, 255, 0.35);
    outline-offset: 1px;
    border-color: #4f89bc;
}

button {
    border: 1px solid #3f6d98;
    cursor: pointer;
    background: linear-gradient(180deg, #123054, #0e2641);
    color: #dff3ff;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.78rem;
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

button:hover {
    border-color: #5da1de;
    background: linear-gradient(180deg, #153963, #113051);
}

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

a { color: #9dc5ff; }

a:hover { color: #d4ebff; }

.toolbar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(136px, 1fr));
    gap: 0.6rem;
    align-items: center;
}

.toolbar button.is-active {
    border-color: #ffd54a;
    color: #ffeaa1;
    background: linear-gradient(180deg, #3a330d, #2a2409);
}

.search-row {
    margin-top: 8px;
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    gap: 0.6rem;
    align-items: center;
}

.search-results {
    margin-top: 8px;
    padding: 8px;
    max-height: 240px;
    overflow: auto;
}

.search-results-meta {
    margin: 0 0 8px 0;
    color: var(--portal-muted);
    font-size: 0.82rem;
}

.search-result-item {
    width: 100%;
    text-align: left;
    margin: 0 0 6px 0;
    padding: 8px 10px;
    border: 1px solid #315474;
    background: #0f2239;
    color: #cae9ff;
    border-radius: 4px;
}

.search-result-item:last-child {
    margin-bottom: 0;
}

.search-result-item strong {
    display: block;
    font-size: 0.9rem;
}

.search-result-item span {
    display: block;
    color: var(--portal-muted);
    font-size: 0.8rem;
}

.measure-point-label {
    background: rgba(5, 12, 22, 0.85);
    border: 1px solid #ffd54a;
    color: #ffe39b;
    font-size: 0.68rem;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    border-radius: 3px;
    padding: 1px 3px;
}

.map-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 12px;
    align-items: start;
}

.map-main {
    min-width: 0;
}

.detail-sidebar {
    margin-top: 0.7rem;
    max-height: calc(100vh - 170px);
    overflow: auto;
    padding: 0.8rem;
}

.map-main .detail-sidebar {
    margin-top: 0.7rem;
    max-height: none;
    width: 100%;
}

.detail-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #2f4f71;
    padding-bottom: 8px;
    margin-bottom: 8px;
}

.detail-head h3 {
    margin: 0;
}

.detail-close-btn {
    width: auto;
    min-width: 44px;
    margin: 0;
    padding: 0.25rem 0.6rem;
    font-size: 1.1rem;
    line-height: 1;
}

.detail-body {
    display: grid;
    gap: 12px;
}

.detail-section {
    border: 1px solid #2f4f71;
    border-radius: 6px;
    background: #0e1c2f;
    padding: 10px;
}

.detail-section h4 {
    margin: 0 0 8px 0;
}

.detail-meta-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    font-size: 0.9rem;
}

.detail-summary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.detail-actions-row {
    margin-top: 10px;
}

.detail-actions-row button {
    width: auto;
    min-width: 260px;
}

.detail-table th,
.detail-table td {
    font-size: 0.82rem;
}

.mobile-menu-toggle {
    display: none;
    margin-bottom: 8px;
}

.layer-sidebar h3 {
    margin: 0 0 10px 0;
}

.layer-info-box {
    margin-top: 0.7rem;
    border: 1px solid #2f4f71;
    border-radius: 6px;
    background: #0f1d30;
    padding: 0.55rem 0.6rem;
    font-size: 0.8rem;
    line-height: 1.35;
}

.context-info-section {
    margin-top: 8px;
}

.context-info-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
    font-size: 0.78rem;
}

.context-info-table th,
.context-info-table td {
    border: 1px solid #2f4f71;
    padding: 4px 6px;
    text-align: left;
    vertical-align: top;
}

.context-info-table th {
    background: #122743;
    color: #d8eaff;
}

#layerGeometryDebugBox {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 0.72rem;
    max-height: 220px;
    overflow: auto;
}

.layer-toggles {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
    min-width: 0;
}

.layer-group {
    border: 1px solid #2c4664;
    border-radius: 6px;
    background: #0d1a2b;
    overflow: hidden;
}

.layer-group-toggle {
    width: auto;
    margin: 0;
    text-align: center;
    padding: 0.35rem 0.5rem;
    font-size: 0.76rem;
    background: linear-gradient(180deg, #122b49, #0f223b);
}

.layer-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    border-bottom: 1px solid #2f4f71;
    padding: 0.5rem 0.55rem;
    background: linear-gradient(180deg, #122b49, #0f223b);
}

.layer-group-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0;
    color: #dff3ff;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 0.76rem;
}

.layer-group-switch input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.layer-group.is-collapsed .layer-group-head {
    border-bottom: 0;
}

.layer-group-items {
    display: grid;
    gap: 0.45rem;
    padding: 0.45rem;
}

.layer-subgroup-title {
    margin: 0;
    padding: 0.2rem 0.35rem;
    border-left: 3px solid #3a6288;
    color: #9ec0df;
    font-size: 0.76rem;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    background: rgba(18, 43, 73, 0.35);
    border-radius: 3px;
}

.layer-subgroup {
    display: grid;
    gap: 0.4rem;
}

.layer-subgroup-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    margin-top: 0.1rem;
}

.layer-subgroup-toggle {
    width: auto;
    margin: 0;
    padding: 0.25rem 0.45rem;
    font-size: 0.7rem;
    line-height: 1.1;
}

.layer-subgroup-items {
    display: grid;
    gap: 0.45rem;
}

.layer-subgroup.is-collapsed .layer-subgroup-items {
    display: none;
}

.m2000-circle-list {
    display: grid;
    gap: 0.25rem;
    margin-top: 0.15rem;
    padding: 0.35rem;
    border: 1px solid #2b4867;
    border-radius: 4px;
    background: rgba(11, 27, 45, 0.7);
    max-height: 180px;
    overflow: auto;
}

.m2000-circle-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
    font-size: 0.74rem;
    color: #d8e8f6;
}

.m2000-circle-item input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.m2000-circle-status {
    color: #8eb6d7;
}

.m2000-circle-empty {
    font-size: 0.72rem;
    color: #88a8c4;
}

.layer-group.is-collapsed .layer-group-items {
    display: none;
}

.layer-group-count {
    color: var(--portal-muted);
    font-weight: 400;
}

.layer-sidebar {
    overflow: hidden;
}

.layer-toggle-row {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 0.45rem;
    margin: 0;
    color: var(--portal-text);
    background: #101d30;
    border: 1px solid #315474;
    border-radius: 4px;
    padding: 0.5rem 0.55rem;
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

.layer-toggle-main {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    align-items: start;
    gap: 0.45rem;
    margin: 0;
    min-width: 0;
}

.layer-toggles input[type="checkbox"] {
    width: auto;
    margin: 0;
    margin-top: 0.15rem;
}

.layer-label-text {
    display: block;
    min-width: 0;
    max-width: 100%;
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.layer-label-sub {
    display: block;
    margin-top: 0.12rem;
    font-size: 0.68rem;
    color: var(--portal-muted);
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

.layer-label-wrap {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
}

.layer-label-main {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr);
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
}

.layer-color-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: 1px solid #3f5e7f;
    box-shadow: 0 0 0 1px rgba(8, 17, 28, 0.55);
}

.layer-load-status {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border: 1px solid #315474;
    border-radius: 999px;
    padding: 0.1rem 0.4rem;
    white-space: nowrap;
    color: #c8def5;
}

.layer-load-status.is-loading {
    color: #ffe6a6;
    border-color: #92743b;
    background: rgba(146, 116, 59, 0.2);
}

.layer-load-status.is-ready {
    color: #b9f0d3;
    border-color: #2f6b52;
    background: rgba(47, 107, 82, 0.2);
}

.layer-load-status.is-error {
    color: #ffd0d0;
    border-color: #8a4040;
    background: rgba(138, 64, 64, 0.22);
}

.layer-load-status.is-off {
    color: #94acc4;
    border-color: #3a4f66;
    background: rgba(58, 79, 102, 0.22);
}

.layer-opacity-row {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.3rem;
}

.layer-opacity-label {
    font-size: 0.66rem;
    color: var(--portal-muted);
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

.layer-opacity-slider {
    width: 100%;
    margin: 0;
}

.layer-opacity-value {
    font-size: 0.7rem;
    color: #d8ecff;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    min-width: 38px;
    text-align: right;
}

.toolbar label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0;
    color: var(--portal-text);
    background: #152237;
    border: 1px solid #344860;
    border-radius: 8px;
    padding: 0.52rem 0.58rem;
}

.toolbar input[type="checkbox"] {
    width: auto;
    margin: 0;
}

#map {
    height: 70vh;
    border: 1px solid var(--portal-border);
    border-radius: 6px;
    overflow: hidden;
    background: #0f1828;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.map-main #contextInfoBox {
    margin-top: 0.6rem;
    width: 100%;
}

.context-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.context-close-btn {
    width: auto;
    min-width: 96px;
    margin: 0;
    padding: 0.25rem 0.55rem;
}

.context-table-wrap {
    margin-top: 6px;
    max-height: 240px;
    overflow: auto;
    border: 1px solid #2f4f71;
    border-radius: 6px;
    background: #0f1d30;
}

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

.context-table th,
.context-table td {
    border: 1px solid #2f4f71;
    padding: 4px 6px;
    text-align: left;
    vertical-align: top;
}

.context-table th {
    background: #122743;
    color: #d8eaff;
    position: sticky;
    top: 0;
    z-index: 1;
}

.whitespot-overview-card {
    margin-top: 0.6rem;
}

.whitespot-overview-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

.whitespot-overview-head h3 {
    margin: 0;
    font-size: 1.02rem;
}

.whitespot-overview-actions {
    display: flex;
    gap: 0.5rem;
}

#whitespotOverviewStatus {
    margin: 0.45rem 0 0.6rem;
}

menu {
    display: flex;
    gap: 0.5rem;
    padding: 0;
    margin: 1rem 0 0;
}

menu button { flex: 1; }

.error {
    color: #ffc7d0;
    min-height: 1.2rem;
}

.field-error {
    display: block;
    margin-top: 0.3rem;
    color: #ffc7d0;
    font-size: 0.8rem;
    line-height: 1.25;
}

.input-invalid {
    border-color: #d86a7a !important;
    outline: 2px solid rgba(216, 106, 122, 0.22);
    outline-offset: 1px;
}

.status-badge {
    display: inline-block;
    margin-left: 0;
    padding: 0.08rem 0.42rem;
    border-radius: 999px;
    border: 1px solid #2d6f59;
    color: #9fe8c8;
    background: rgba(29, 74, 57, 0.3);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.ok {
    border-color: rgba(54, 171, 118, 0.9);
    color: #d3ffe8;
    background: rgba(25, 91, 60, 0.36);
}

.status-badge.warn {
    border-color: rgba(246, 197, 63, 0.9);
    color: #fff4cc;
    background: rgba(106, 81, 22, 0.32);
}

.status-badge.fail {
    border-color: rgba(241, 96, 96, 0.9);
    color: #ffe3e3;
    background: rgba(129, 35, 44, 0.34);
}

.status-badge.override {
    border-color: #2758a8;
    color: #d8e8ff;
    background: rgba(39, 88, 168, 0.32);
}

.status-badge-running {
    border-color: #7b8ad8;
    color: #d6ddff;
    background: rgba(56, 87, 180, 0.3);
}

.btn {
    border: 0;
    border-radius: 8px;
    background: #0f3155;
    color: #eef6ff;
    font-weight: 700;
    padding: 8px 12px;
    min-height: 36px;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.btn.ghost {
    background: transparent;
    color: #dfe9f8;
    border: 1px solid #435875;
}

.btn.ghost:hover {
    background: rgba(67, 88, 117, 0.22);
}

.btn.ghost.ok {
    border-color: rgba(54, 171, 118, 0.9);
    color: #e7fff2;
    box-shadow: 0 0 0 1px rgba(54, 171, 118, 0.15);
}

.btn.ghost.warn {
    border-color: rgba(246, 197, 63, 0.9);
    color: #fff3cc;
    box-shadow: 0 0 0 1px rgba(246, 197, 63, 0.15);
}

.btn.ghost.fail {
    border-color: rgba(241, 96, 96, 0.9);
    color: #ffe3e3;
    box-shadow: 0 0 0 1px rgba(241, 96, 96, 0.15);
}

.btn.ghost.override {
    border-color: #2758a8;
    color: #d8e8ff;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.2);
}

#settingsMessage {
    margin-top: 0.6rem;
    padding: 0.45rem 0.6rem;
    border-radius: 6px;
    border: 1px solid transparent;
    min-height: 1.2rem;
}

#settingsMessage.settings-msg-success {
    color: #b9f0d3;
    border-color: #2f6b52;
    background: rgba(47, 107, 82, 0.2);
}

#settingsMessage.settings-msg-error {
    color: #ffd0d0;
    border-color: #8a4040;
    background: rgba(138, 64, 64, 0.22);
}

#settingsMessage.settings-msg-info {
    color: #c9def8;
    border-color: #355277;
    background: rgba(53, 82, 119, 0.22);
}

.hint {
    color: var(--portal-muted);
    font-size: 0.9rem;
}

dialog {
    width: min(1240px, 97vw);
    max-height: 94vh;
    overflow: auto;
    border: 1px solid var(--portal-border);
    border-radius: 8px;
    background: linear-gradient(180deg, rgba(12, 23, 38, 0.98), rgba(8, 17, 30, 0.98));
    color: var(--portal-text);
}

dialog::backdrop {
    background: rgba(2, 7, 15, 0.62);
}

dialog form {
    margin-bottom: 0.8rem;
}

dialog .card {
    margin-top: 0.6rem;
    box-shadow: none;
    background: #121d2f;
}

code {
    display: block;
    background: #111b2b;
    color: #d8e6fb;
    padding: 0.45rem 0.6rem;
    border-radius: 4px;
    border: 1px solid #334864;
    overflow-x: auto;
    white-space: nowrap;
}

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

.data-table th,
.data-table td {
    border: 1px solid #30435c;
    padding: 0.45rem;
    vertical-align: top;
}

.data-table th {
    background: #10263e;
    color: #e8efff;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

.table-scroll .data-table {
    min-width: 780px;
}

.role-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-right: 0.4rem;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    line-height: 1.2;
}

.role-inline input[type="checkbox"] {
    width: auto;
    min-width: 0;
    margin: 0;
    margin-top: 0;
    padding: 0;
    flex: 0 0 auto;
}

#rolesList .data-table td:nth-child(3),
#usersList .data-table td:nth-child(4) {
    min-width: 260px;
}

#rolesList .data-table td:nth-child(3) .role-inline,
#usersList .data-table td:nth-child(4) .role-inline {
    margin-right: 0.55rem;
    margin-bottom: 0.35rem;
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 6px;
}

.permission-item {
    border: 1px solid #335473;
    border-radius: 6px;
    background: #102139;
    padding: 6px 8px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 8px;
    align-items: start;
    margin: 0;
}

.permission-item-rti {
    margin: 0;
    display: block;
    width: 100%;
    text-align: left;
    white-space: normal;
    word-break: break-word;
}

.permission-item-rti input[type="checkbox"] {
    display: none;
}

.permission-item input[type="checkbox"] {
    width: auto;
    margin: 2px 0 0 0;
}

.permission-main {
    font-weight: 600;
    color: #d9ecff;
}

.permission-meta {
    grid-column: 2;
    font-size: 0.75rem;
    color: #9ec0df;
    line-height: 1.3;
}

.role-perm-toggle {
    margin: 0 6px 6px 0;
    user-select: none;
    display: inline-block;
    max-width: 100%;
    white-space: normal;
    text-align: left;
    word-break: break-word;
    line-height: 1.25;
}

.role-perm-toggle input[type="checkbox"] {
    display: none;
}

.rti-style-table td {
    vertical-align: top;
}

.rti-inline-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.rti-badge-stack {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.layer-lock-toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    gap: 8px;
    align-items: end;
    margin-bottom: 8px;
}

.layer-lock-toolbar label {
    margin: 0;
}

.layer-lock-select {
    min-width: 260px;
    width: 100%;
}

.layer-lock-inline-actions {
    margin-top: 6px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.layer-lock-inline-actions .btn {
    margin: 0;
    min-width: 84px;
    padding: 6px 10px;
    min-height: 32px;
    font-size: 0.7rem;
}

.layer-lock-summary {
    margin: 0;
}

.layer-lock-toolbar + .table-scroll .permission-grid {
    max-height: 190px;
    overflow: auto;
    padding-right: 4px;
}

.settings-shell {
    display: grid;
    gap: 12px;
}

.settings-dialog-head {
    border: 1px solid #325476;
    background: linear-gradient(180deg, rgba(17, 34, 57, 0.96), rgba(12, 24, 41, 0.96));
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.settings-dialog-head h3 {
    margin: 0;
}

.settings-dialog-head .hint {
    margin: 4px 0 0 0;
}

.settings-shell-grid {
    grid-template-columns: minmax(190px, 240px) minmax(0, 1fr);
    align-items: start;
    gap: 12px;
}

.settings-nav {
    display: grid;
    gap: 12px;
    align-content: start;
}

.settings-nav-group {
    border: 1px solid #2e4e70;
    background: linear-gradient(180deg, rgba(17, 35, 58, 0.95), rgba(12, 24, 40, 0.95));
    border-radius: 10px;
    padding: 10px;
    display: grid;
    gap: 8px;
    box-shadow: inset 0 0 0 1px rgba(110, 164, 216, 0.06);
}

.settings-nav-title {
    margin: 0;
    color: #8fb8da;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.72rem;
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

.settings-nav .subnav-tabs button,
.settings-nav button {
    width: 100%;
    min-width: 0;
    text-align: left;
    padding: 0.56rem 0.62rem;
    margin: 0;
    border-radius: 8px;
    font-size: 0.76rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    background: #11263f;
    border: 1px solid #355b81;
    color: #d8ecff;
}

.settings-page {
    min-width: 0;
    border: 1px solid #2e4e70;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(14, 28, 46, 0.94), rgba(10, 20, 34, 0.96));
    padding: 12px;
    box-shadow: inset 0 0 0 1px rgba(110, 164, 216, 0.06);
}

.settings-close-row {
    justify-content: flex-end;
    border-top: 1px solid #325476;
    margin-top: 12px;
    padding-top: 10px;
}

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

.subnav-tabs button {
    width: auto;
    min-width: 120px;
    background: #11263f;
    border: 1px solid #355b81;
    color: #cae9ff;
    border-radius: 8px;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.75rem;
    margin: 0;
}

.subnav-tabs button.active {
    background: linear-gradient(180deg, #15507f, #103c62);
    border-color: #71baf0;
    color: #eef9ff;
    box-shadow: inset 0 0 0 1px rgba(196, 230, 255, 0.15);
}

.panel {
    background: #0f1c2f;
    border: 1px solid #325476;
    border-radius: 6px;
    padding: 12px;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

.settings-panel {
    display: none;
}

.settings-panel.active {
    display: block;
}

.settings-panel h4 {
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #2f4f71;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.82rem;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    color: #d7ebff;
}

.settings-subpanel {
    margin-bottom: 10px;
}

.settings-subpanel:last-of-type {
    margin-bottom: 0;
}

.settings-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px 12px;
}

.settings-inline-checks {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 6px 12px;
    margin-top: 4px;
}

.settings-inline-checks label {
    margin-bottom: 0;
}

dialog .panel h4 {
    margin-top: 0;
}

#settingsDialog form,
#uploadDialog form {
    display: grid;
    gap: 8px;
}

#settingsDialog menu,
#uploadDialog menu {
    margin-top: 6px;
    justify-content: flex-start;
    flex-wrap: wrap;
}

#settingsDialog menu button,
#uploadDialog menu button {
    flex: 0 0 auto;
    min-width: 170px;
}

#settingsDialog .panel,
#uploadDialog .panel {
    border-radius: 8px;
    border-color: #315474;
    background: linear-gradient(180deg, rgba(14, 29, 47, 0.94), rgba(11, 23, 38, 0.95));
}

#settingsDialog .table-scroll,
#uploadDialog .table-scroll {
    border: 1px solid #2f4f71;
    border-radius: 8px;
    background: rgba(10, 20, 33, 0.55);
    padding: 4px;
}

#settingsDialog pre,
#uploadDialog pre {
    border: 1px solid #325476;
    border-radius: 8px;
    background: #0d1d31;
    padding: 10px;
    max-height: 260px;
    overflow: auto;
}

#settingsDialog #settingsMessage,
#uploadDialog #uploadMessage {
    border-radius: 8px;
    border: 1px solid #325476;
    background: rgba(15, 31, 51, 0.65);
    padding: 8px 10px;
}

.map-popup .leaflet-popup-content {
    margin: 10px 12px;
    line-height: 1.35;
    word-break: break-word;
}

@media (max-width: 760px) {
    body { padding: 12px; }
    #map { height: 60vh; }
    .map-layout {
        grid-template-columns: 1fr;
    }
    .detail-sidebar {
        max-height: none;
    }
    .mobile-menu-toggle {
        display: block;
    }
    .toolbar {
        grid-template-columns: 1fr 1fr;
        display: none;
    }
    .search-row {
        grid-template-columns: 1fr;
        display: none;
    }
    .toolbar.is-open {
        display: grid;
    }
    .search-row.is-open {
        display: grid;
    }
    .layer-toggles { grid-template-columns: 1fr; }
    menu {
        flex-direction: column;
    }
    menu button {
        width: 100%;
    }

    .login-layout {
        grid-template-columns: 1fr;
    }

    .login-intro {
        border-right: 0;
        border-bottom: 1px solid #2c4b6e;
    }

    .settings-shell-grid {
        grid-template-columns: 1fr;
    }

    .settings-nav {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }
}

@media (max-width: 480px) {
    .toolbar {
        grid-template-columns: 1fr;
    }
    .subnav-tabs button {
        flex: 1 1 calc(50% - 8px);
        min-width: 0;
    }
}
