:root {
    --ink: #102a35;
    --muted: #69808a;
    --line: #dce6e8;
    --surface: #ffffff;
    --canvas: #eef3f3;
    --navy: #0d2732;
    --navy-2: #143b47;
    --accent: #00a59a;
    --accent-soft: #dff5f1;
    --danger: #d94c52;
    --danger-soft: #fff0f0;
    --warning: #b88220;
    --shadow: 0 12px 40px rgba(24, 54, 63, .08);
}

* { box-sizing: border-box; }

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

body {
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 0, rgba(0,165,154,.06), transparent 26rem),
        var(--canvas);
    font-size: 14px;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }

.topbar {
    height: 76px;
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #fff;
    background: var(--navy);
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-block, .topbar-actions, .session-identity, .query-controls,
.field-label-row, .result-header, .trace-heading { display: flex; align-items: center; }

.brand-block { gap: 13px; }
.brand-mark { width: 39px; height: 39px; }
.brand-mark svg { width: 100%; height: 100%; fill: none; stroke: #34d1c3; stroke-width: 2; }
.brand-block h1 { margin: 2px 0 0; font-size: 20px; letter-spacing: .02em; }
.eyebrow, .section-kicker { font-size: 10px; font-weight: 700; letter-spacing: .18em; }
.eyebrow { color: #79a6ad; }
.section-kicker { color: var(--accent); margin-bottom: 6px; }
.topbar-actions { gap: 22px; }
.connection-state { color: #b8cbd0; font-size: 12px; display: flex; align-items: center; gap: 8px; }
.connection-state span { width: 7px; height: 7px; border-radius: 50%; background: #39d9a0; box-shadow: 0 0 0 5px rgba(57,217,160,.1); }

.user-switcher { display: flex; align-items: center; gap: 10px; color: #9eb5bb; font-size: 12px; }
.user-switcher select {
    min-width: 210px; border: 1px solid rgba(255,255,255,.17); border-radius: 7px;
    background: #173945; color: #fff; padding: 9px 34px 9px 12px; outline: none;
}
.avatar, .session-avatar { display: grid; place-items: center; border-radius: 50%; font-weight: 700; }
.avatar { width: 35px; height: 35px; color: var(--navy); background: #56d7ca; }

.session-strip {
    min-height: 112px;
    padding: 20px 28px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: minmax(250px, 1fr) 1px minmax(160px, .65fr) minmax(360px, 1.55fr) 120px;
    gap: 26px;
    align-items: center;
    animation: slideDown .45s ease-out both;
}
.session-identity { gap: 15px; }
.session-avatar { width: 53px; height: 53px; flex: 0 0 auto; color: #fff; background: linear-gradient(145deg, #0d756f, #13b7aa); box-shadow: 0 8px 20px rgba(0,165,154,.2); }
.session-name { font-size: 19px; font-weight: 750; }
.session-meta { margin-top: 4px; color: var(--muted); font-size: 12px; }
.session-divider { width: 1px; height: 56px; background: var(--line); }
.session-field > span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 7px; }
.session-field strong { display: block; font-size: 15px; }
.session-field small { display: block; color: #8da0a7; margin-top: 4px; }
.membership-list { display: flex; gap: 7px; flex-wrap: wrap; }
.membership-chip { padding: 6px 9px; border-radius: 5px; color: #17625d; background: var(--accent-soft); font-size: 12px; font-weight: 650; }
.session-stat { text-align: right; padding-right: 8px; }
.session-stat span { display: block; font-size: 30px; line-height: 1; font-weight: 750; color: var(--accent); }
.session-stat small { display: block; margin-top: 7px; color: var(--muted); }

.workspace {
    height: calc(100vh - 188px);
    min-height: 610px;
    display: grid;
    grid-template-columns: 285px minmax(520px, 1fr) 320px;
    gap: 1px;
    padding: 18px 18px 22px;
}
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); animation: riseIn .45s ease-out both; }
.org-panel { border-radius: 12px 0 0 12px; overflow: hidden; }
.query-panel { animation-delay: .06s; display: flex; flex-direction: column; }
.inspector-panel { border-radius: 0 12px 12px 0; animation-delay: .12s; overflow-y: auto; }
.panel-heading { min-height: 75px; padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.panel-heading h2 { margin: 0; font-size: 17px; }
.icon-button { width: 34px; height: 34px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--muted); }
.icon-button:hover { color: var(--accent); border-color: #8bd8d0; transform: rotate(22deg); }
.icon-button svg, .primary-button svg, .search-input svg, .security-note svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.tree-summary { height: 44px; display: flex; align-items: center; gap: 13px; padding: 0 20px; color: var(--muted); font-size: 10px; border-bottom: 1px solid var(--line); }
.legend-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; }
.legend-dot.assigned { background: #0d6c67; box-shadow: 0 0 0 3px #d8f1ee; }
.legend-dot.allowed { background: #2ab6aa; }
.legend-dot.denied { background: #b8c3c6; }
.tree-scroll { height: calc(100% - 119px); padding: 12px 9px 24px; overflow: auto; }
.tree-list { list-style: none; margin: 0; padding: 0; }
.tree-children { overflow: hidden; transform-origin: top; transition: max-height .25s ease, opacity .2s ease; }
.tree-children.collapsed { max-height: 0 !important; opacity: 0; }
.tree-row { position: relative; display: grid; grid-template-columns: 24px 1fr 18px; align-items: center; min-height: 39px; padding: 4px 7px 4px calc(7px + var(--level) * 17px); border-radius: 7px; transition: .18s ease; }
.tree-row:hover { background: #f2f7f7; }
.tree-row.selected { background: #e1f6f3; box-shadow: inset 3px 0 var(--accent); }
.tree-toggle { width: 22px; height: 22px; border: 0; background: transparent; color: #8ca0a6; padding: 5px; transition: transform .2s ease; }
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; }
.tree-toggle.placeholder { visibility: hidden; }
.tree-label { min-width: 0; cursor: pointer; }
.tree-label strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 650; color: #29444e; }
.tree-label small { display: block; margin-top: 2px; color: #91a1a6; font-size: 9px; }
.node-state { width: 8px; height: 8px; border-radius: 50%; background: #bcc6c8; }
.tree-row.authorized .node-state { background: #37b7ac; }
.tree-row.assigned .node-state { background: #075d59; box-shadow: 0 0 0 4px #d7f2ef; }
.tree-row.restricted .tree-label strong { color: #8d9a9e; }

.query-heading { padding-right: 24px; }
.query-status { display: flex; align-items: center; gap: 7px; padding: 6px 9px; border-radius: 99px; color: var(--muted); background: #f2f5f5; font-size: 11px; font-weight: 650; }
.query-status span { width: 6px; height: 6px; border-radius: 50%; background: #9aacb0; }
.query-status.allowed { color: #087269; background: var(--accent-soft); }
.query-status.allowed span { background: var(--accent); animation: pulse 1.5s infinite; }
.query-status.denied { color: #b62f36; background: var(--danger-soft); }
.query-status.denied span { background: var(--danger); }
.query-status.loading span { background: #d29424; animation: pulse .8s infinite; }

.query-builder { padding: 18px 22px 20px; border-bottom: 1px solid var(--line); background: #fbfcfc; }
.field-label-row { justify-content: space-between; margin-bottom: 10px; }
.field-label-row label { font-size: 12px; font-weight: 700; }
.text-button { border: 0; background: transparent; color: var(--accent); font-size: 11px; }
.selected-scopes { min-height: 38px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-bottom: 14px; }
.selected-scopes.empty { color: #94a5aa; font-size: 12px; }
.scope-chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 9px; border: 1px solid #b4e2dd; border-radius: 6px; background: #effaf8; color: #155f5a; font-size: 11px; font-weight: 650; animation: chipIn .18s ease-out both; }
.scope-chip.restricted { border-color: #f2b9bc; color: #ae3037; background: var(--danger-soft); }
.scope-chip button { width: 15px; height: 15px; padding: 0; border: 0; border-radius: 50%; background: rgba(0,0,0,.07); color: inherit; }
.query-controls { gap: 10px; }
.search-input { height: 42px; flex: 1; display: flex; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid var(--line); border-radius: 7px; background: #fff; transition: .2s; }
.search-input:focus-within { border-color: #56c7bd; box-shadow: 0 0 0 3px rgba(0,165,154,.08); }
.search-input svg { width: 17px; color: #91a1a6; }
.search-input input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; }
.primary-button { height: 42px; display: flex; align-items: center; gap: 12px; padding: 0 17px; border: 0; border-radius: 7px; color: #fff; background: var(--accent); font-size: 12px; font-weight: 700; box-shadow: 0 7px 18px rgba(0,165,154,.22); transition: .18s; }
.primary-button:hover { background: #008d84; transform: translateY(-1px); }
.primary-button:disabled { cursor: wait; opacity: .7; transform: none; }
.primary-button svg { width: 16px; }

.result-header { justify-content: space-between; padding: 16px 22px 12px; }
.result-header h3 { margin: 0; font-size: 14px; }
.result-header p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.result-count { min-width: 32px; padding: 6px 9px; border-radius: 7px; text-align: center; color: #17615c; background: var(--accent-soft); font-weight: 750; }
.result-table-wrap { flex: 1; min-height: 0; overflow: auto; padding: 0 22px 20px; }
.result-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.result-table th { position: sticky; top: 0; z-index: 1; padding: 10px 9px; text-align: left; color: #7b8f96; background: #fff; border-bottom: 1px solid var(--line); font-size: 9px; letter-spacing: .04em; }
.result-table td { padding: 12px 9px; border-bottom: 1px solid #edf1f2; vertical-align: middle; }
.result-table tbody tr { animation: rowIn .28s ease-out both; }
.result-table tbody tr:hover { background: #f7fbfa; }
.person-name { font-weight: 700; color: #203d47; }
.person-sub { display: block; color: #8ca0a6; margin-top: 3px; font-size: 9px; }
.org-tag { display: inline-block; padding: 4px 6px; border-radius: 4px; color: #17615c; background: #ebf7f5; }
.empty-row td { height: 150px; text-align: center; color: #9babad; }

.http-code { padding: 5px 8px; border-radius: 5px; color: #7f9095; background: #f0f3f4; font-size: 10px; font-weight: 800; }
.decision-hero { margin: 17px; padding: 16px; display: flex; gap: 13px; border-radius: 9px; background: #f3f6f6; transition: .25s; }
.decision-icon { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; color: #83969b; background: #fff; }
.shield-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.decision-hero span { color: var(--muted); font-size: 9px; letter-spacing: .08em; }
.decision-hero strong { display: block; margin-top: 2px; font-size: 16px; }
.decision-hero p { margin: 6px 0 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.decision-hero.allowed { color: #087269; background: var(--accent-soft); transform: scale(1.01); }
.decision-hero.allowed .decision-icon { color: var(--accent); }
.decision-hero.denied { color: #b62f36; background: var(--danger-soft); animation: denyShake .35s ease-out; }
.decision-hero.denied .decision-icon { color: var(--danger); }

.quick-tests { padding: 0 17px 17px; border-bottom: 1px solid var(--line); }
.quick-tests > span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 9px; letter-spacing: .08em; font-weight: 700; }
.quick-tests > div { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.quick-tests button { padding: 8px; border: 1px solid var(--line); border-radius: 6px; color: #4c636b; background: #fff; font-size: 10px; }
.quick-tests button:hover { border-color: #9bcfc9; background: #f7fbfa; }
.quick-tests i { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--accent); }
.quick-tests button.danger i { background: var(--danger); }
.trace-block { padding: 15px 17px; border-bottom: 1px solid var(--line); }
.trace-heading { justify-content: space-between; margin-bottom: 9px; }
.trace-heading span { font-size: 11px; font-weight: 700; }
.trace-heading small { color: #93a3a7; font-size: 9px; }
.trace-block pre { margin: 0; padding: 12px; max-height: 170px; overflow: auto; border-radius: 7px; color: #c7e2e3; background: #132f39; font: 10px/1.65 "Cascadia Code", Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.response-block pre { color: #c9dfd5; background: #17332f; }
.security-note { margin: 15px 17px 18px; display: flex; gap: 10px; color: #71868d; }
.security-note svg { width: 20px; height: 20px; flex: 0 0 auto; color: #8da3a8; }
.security-note p { margin: 0; font-size: 9px; line-height: 1.55; }

.skeleton { position: relative; overflow: hidden; border-radius: 7px; background: #edf2f2; }
.skeleton::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255,255,255,.75), transparent); transform: translateX(-100%); animation: shimmer 1.2s infinite; }
.tree-skeleton { height: 280px; }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 20; padding: 10px 14px; border-radius: 7px; color: #fff; background: #183741; box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: .22s; font-size: 12px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } }
@keyframes riseIn { from { opacity: 0; transform: translateY(12px); } }
@keyframes chipIn { from { opacity: 0; transform: scale(.94); } }
@keyframes rowIn { from { opacity: 0; transform: translateY(5px); } }
@keyframes pulse { 50% { opacity: .4; transform: scale(.8); } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes denyShake { 33% { transform: translateX(-4px); } 66% { transform: translateX(3px); } }

@media (max-width: 1180px) {
    .workspace { grid-template-columns: 280px minmax(540px, 1fr); height: auto; }
    .inspector-panel { grid-column: 1 / -1; border-radius: 0 0 12px 12px; display: grid; grid-template-columns: 1fr 1fr; }
    .inspector-panel .panel-heading, .inspector-panel .quick-tests, .inspector-panel .security-note { grid-column: 1 / -1; }
    .session-strip { grid-template-columns: 1fr 1px .7fr 1.4fr; }
    .session-stat { display: none; }
}

@media (max-width: 760px) {
    .topbar { height: auto; padding: 15px 18px; align-items: flex-start; }
    .connection-state, .user-switcher > span, .avatar { display: none; }
    .user-switcher select { min-width: 150px; max-width: 175px; }
    .session-strip { grid-template-columns: 1fr; gap: 16px; padding: 18px; }
    .session-divider { display: none; }
    .workspace { display: block; height: auto; padding: 12px; }
    .panel { border-radius: 10px; margin-bottom: 10px; }
    .org-panel { height: 480px; }
    .query-panel { min-height: 620px; }
    .inspector-panel { display: block; }
    .query-controls { align-items: stretch; flex-direction: column; }
    .session-name { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
