/* --- Tree / disclosure toggles ------------------------------------------------ */

.state-row-toggle,
.state-toggle,
.component-toggle,
.routes-toggle {
    display: none;
}

.state-row-toggle + label.state-item .item-arrow .arrow-icon,
.state-toggle + .section-header .section-arrow .arrow-icon,
.component-toggle + .component-item .tree-arrow .arrow-icon,
.component-toggle + .component-root .tree-arrow .arrow-icon,
.routes-section-arrow .arrow-icon {
    display: block;
    transition: transform 0.12s ease;
    transform: rotate(0deg);
}

.state-row-toggle:checked + label.state-item .item-arrow .arrow-icon,
.state-toggle:checked + .section-header .section-arrow .arrow-icon,
.component-toggle:checked + .component-item .tree-arrow .arrow-icon,
.component-toggle:checked + .component-root .tree-arrow .arrow-icon,
.routes-toggle:checked + .routes-section-row .routes-section-arrow .arrow-icon {
    transform: rotate(90deg);
}

.state-row-toggle:not(:checked) ~ .state-item-children,
.state-toggle:not(:checked) + .section-header + .section-items,
.component-toggle:not(:checked) + .component-item + .component-children,
.component-toggle:not(:checked) + .component-root + .component-children,
.routes-toggle:not(:checked) + .routes-section-row + .routes-section-desc {
    display: none;
}

.state-item-group,
.component-group {
    display: flex;
    flex-direction: column;
}

.state-item-group {
    gap: 1px;
}

.state-item-group-hidden,
.component-group-hidden {
    display: none;
}

.route-item.route-item-hidden {
    display: none;
}

.state-item-children,
.component-children {
    display: flex;
    flex-direction: column;
}

/* --- Theme tokens ------------------------------------------------------------- */

:root {
    color-scheme: dark;
    --bg-base: #0d0d0d;
    --bg-elevated: #141414;
    --bg-hover: rgba(255, 255, 255, 0.04);
    --bg-selected: color-mix(in srgb, var(--zx-primary) 16%, transparent);
    --bg-selected-tree: color-mix(in srgb, var(--zx-primary) 7%, transparent);
    --text-base: #e8eaed;
    --text-muted: #9aa0a6;
    --border-color: #2a2a2a;
    --interactive-hover: rgba(255, 255, 255, 0.06);

    --zx-primary: #4ade80;
    --zx-primary-dark: #16a34a;
    --zx-primary-light: #86efac;
    --zx-secondary: #ff6b35;
    --zx-accent: #ffd23f;
    --zx-bg: #0d0d0d;
    --zx-bg-light: #1a1a1a;
    --zx-card-bg: #141414;
    --zx-border: #2a2a2a;
    --zx-code-bg: #0d0d0d;
    --zx-text-muted: #9aa0a6;

    --primary: var(--zx-primary);
    --tree-name: #7dd3fc;
    --tree-name-selected: #e8eaed;
    --prop-key: #f87171;
    --value-string: #fb923c;
    --value-boolean: #60a5fa;
    --value-function: #a78bfa;
    --value-default: #9ca3af;
    --badge-bg: #374151;
    --badge-fg: #e5e7eb;
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    --tabbar-height: 28px;
    --toolbar-height: 32px;
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg-base: #ffffff;
    --bg-elevated: #f8fafc;
    --bg-hover: rgba(0, 0, 0, 0.04);
    --bg-selected: color-mix(in srgb, var(--zx-primary) 14%, #e8f5ff);
    --bg-selected-tree: color-mix(in srgb, var(--zx-primary) 6%, transparent);
    --text-base: #1f2937;
    --text-muted: #5f6368;
    --border-color: #d7dce2;
    --interactive-hover: rgba(0, 0, 0, 0.04);

    --zx-primary: #16a34a;
    --zx-primary-dark: #15803d;
    --zx-primary-light: #4ade80;
    --zx-bg: #ffffff;
    --zx-bg-light: #f1f5f9;
    --zx-card-bg: #ffffff;
    --zx-border: #d7dce2;
    --zx-code-bg: #f8fafc;
    --zx-text-muted: #5f6368;

    --tree-name: #0369a1;
    --tree-name-selected: #0f172a;
    --prop-key: #b91c1c;
    --value-string: #c2410c;
    --value-boolean: #1d4ed8;
    --value-function: #7c3aed;
    --value-default: #64748b;
    --badge-bg: #e2e8f0;
    --badge-fg: #475569;
}

/* --- Base --------------------------------------------------------------------- */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-ui);
    font-size: 12px;
    line-height: 1.4;
    background-color: var(--bg-base);
    color: var(--text-base);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

a {
    text-decoration: none;
    color: inherit;
}

/* --- App chrome --------------------------------------------------------------- */

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.app-tabs {
    display: flex;
    align-items: stretch;
    height: var(--tabbar-height);
    min-height: var(--tabbar-height);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-elevated);
    flex-shrink: 0;
    padding: 0 4px;
    gap: 0;
}

.app-tab {
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.app-tab:hover {
    color: var(--text-base);
    background: var(--bg-hover);
}

.app-tab.active {
    color: var(--text-base);
    border-bottom-color: var(--zx-primary);
}

.main-content {
    background-color: var(--bg-base);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    position: relative;
    z-index: 1;
}

/* --- Shared page chrome ------------------------------------------------------- */

.page-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.page-title {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.15rem 0;
    color: var(--text-base);
}

.page-subtitle {
    color: var(--text-muted);
    margin: 0;
    font-size: 11px;
}

/* --- Components: split panes -------------------------------------------------- */

.devtools-container {
    display: flex;
    height: 100%;
    background-color: var(--bg-base);
    color: var(--text-base);
    font-family: var(--font-mono);
    font-size: 12px;
    overflow: hidden;
}

.devtools-container > .tree-pane {
    width: calc(var(--zx-tree-pane-pct, 70) * 1%);
    flex: 0 0 calc(var(--zx-tree-pane-pct, 70) * 1%);
    min-width: 180px;
    max-width: 85%;
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
    overflow: hidden;
    flex-shrink: 0;
}

.devtools-resize-handle {
    width: 1px;
    cursor: col-resize;
    background: var(--border-color);
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.devtools-resize-handle::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -3px;
    width: 7px;
}

.devtools-resize-handle:hover,
.devtools-resize-handle.active {
    background: var(--zx-primary);
}

.devtools-dragging {
    cursor: col-resize !important;
    user-select: none !important;
}

.devtools-dragging-v {
    cursor: row-resize !important;
    user-select: none !important;
}

@media (max-width: 768px) {
    .devtools-container {
        flex-direction: column;
    }

    .devtools-container > .tree-pane {
        width: 100% !important;
        max-width: none;
        height: calc(var(--zx-tree-pane-pct, 70) * 1%);
        flex: 0 0 calc(var(--zx-tree-pane-pct, 70) * 1%);
        min-width: 0 !important;
        min-height: 15% !important;
        border-bottom: 1px solid var(--border-color);
    }

    .devtools-resize-handle {
        width: 100% !important;
        height: 1px !important;
        cursor: row-resize !important;
    }

    .devtools-resize-handle::after {
        left: 0;
        right: 0;
        top: -3px;
        bottom: auto;
        width: 100%;
        height: 7px;
    }
}

/* --- Components: toolbar ------------------------------------------------------ */

.search-box {
    height: var(--toolbar-height);
    min-height: var(--toolbar-height);
    padding: 0 8px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
}

.search-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
}

.search-input {
    width: 100%;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 6px 8px 6px 26px;
    color: var(--text-base);
    outline: none;
    font-family: var(--font-ui);
    font-size: 12px;
}

.route-path-select {
    max-width: 140px;
    min-width: 72px;
    flex-shrink: 0;
    height: 24px;
    padding: 0 6px;
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    outline: none;
    cursor: pointer;
}

.route-path-select:hover,
.route-path-select:focus {
    border-color: var(--zx-primary);
    color: var(--text-base);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    background: var(--bg-hover);
}

.search-icon {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 13px;
    height: 13px;
    color: var(--text-muted);
    pointer-events: none;
}

.native-toggle-btn {
    background: transparent;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    padding: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    color: var(--text-muted);
    transition: background-color 0.12s ease, color 0.12s ease;
    user-select: none;
    flex-shrink: 0;
}

.native-toggle-btn > * {
    pointer-events: none;
}

.native-toggle-btn:hover {
    background: var(--bg-hover);
    color: var(--text-base);
}

.native-toggle-btn-on {
    color: var(--zx-primary);
}

.native-toggle-btn-off {
    color: var(--text-muted);
}

.picker-btn-active {
    color: var(--zx-primary);
    background: var(--bg-selected);
}

/* --- Components: tree --------------------------------------------------------- */

.component-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.component-list {
    display: flex;
    flex-direction: column;
    padding: 2px 0;
}

.component-item,
.component-root {
    display: flex;
    align-items: stretch;
    padding: 0;
    color: var(--text-base);
    cursor: default;
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 20px;
    min-height: 20px;
}

.component-item:hover {
    background: var(--bg-hover);
}

.component-root {
    background: var(--bg-selected);
}

.component-root:hover {
    background: var(--bg-selected);
}

/* Selecting a parent softly marks its whole subtree (React DevTools-style). */
.component-group:has(> .component-root) > .component-children {
    background: var(--bg-selected-tree);
    box-shadow: inset 2px 0 0 color-mix(in srgb, var(--zx-primary) 35%, transparent);
}

.component-group:has(> .component-root) > .component-children .component-item:hover {
    background: color-mix(in srgb, var(--bg-selected) 55%, transparent);
}

.tree-arrow,
.tree-arrow-spacer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    margin-right: 2px;
    flex-shrink: 0;
    color: var(--text-muted);
    opacity: 0.85;
}

.tree-arrow .arrow-icon {
    width: 8px;
    height: 8px;
}

.component-toggle-label {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    align-self: stretch;
    padding: 0;
}

.component-select-btn,
.component-select-btn-leaf {
    all: unset;
    color: inherit;
    cursor: pointer;
    font: inherit;
    display: inline-flex;
    align-items: center;
    align-self: stretch;
    flex: 1;
    min-width: 0;
    padding: 0 8px 0 0;
}

.component-select-btn-leaf {
    display: flex;
    width: 100%;
    text-align: left;
}

.component-select-btn > *,
.component-select-btn-leaf > * {
    pointer-events: none;
}

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

.component-name {
    color: var(--tree-name);
}

.component-name-root {
    color: var(--tree-name-selected);
    font-weight: 600;
}

.component-badge {
    margin-left: 6px;
    background: var(--badge-bg);
    color: var(--badge-fg);
    padding: 0 5px;
    border-radius: 3px;
    font-size: 9px;
    font-family: var(--font-ui);
    font-weight: 500;
    line-height: 14px;
    text-transform: none;
    vertical-align: middle;
}

.component-badges {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 4px;
    margin-right: auto;
}

.state-inspector-header .component-badge {
    margin-left: 0;
    margin-right: 0;
}

.state-inspector-header .component-badges {
    margin-right: auto;
}

/* --- Components: inspector ---------------------------------------------------- */

.state-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
    flex: 1;
    min-width: 160px;
    overflow: hidden;
}

.component-state-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.state-header {
    height: var(--toolbar-height);
    min-height: var(--toolbar-height);
    padding: 0 8px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.state-inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 12px;
    min-height: 32px;
    box-sizing: border-box;
    border-bottom: 1px solid var(--border-color);
}

.state-inspector-header .prefs-chip {
    flex-shrink: 0;
    padding: 1px 6px;
    line-height: 16px;
    font-size: 10px;
}

.state-title {
    color: var(--tree-name);
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filter-wrapper {
    flex: 1;
    position: relative;
}

.filter-input {
    width: 100%;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 6px 4px;
    color: var(--text-base);
    outline: none;
    font-family: var(--font-ui);
    font-size: 12px;
}

.filter-input::placeholder {
    color: var(--text-muted);
}

.filter-input:focus {
    background: var(--bg-hover);
}

.state-content {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0 12px;
}

.state-section {
    margin-bottom: 2px;
}

.section-header {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 10px;
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 600;
    text-transform: lowercase;
    letter-spacing: 0.02em;
    user-select: none;
}

.section-header:hover {
    background: var(--bg-hover);
    color: var(--text-base);
}

.section-arrow {
    margin-right: 4px;
    color: var(--text-muted);
    display: inline-flex;
}

.section-arrow .arrow-icon {
    width: 10px;
    height: 10px;
}

.section-title {
    font-size: inherit;
}

.section-items {
    padding: 0 8px 4px 18px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.state-item {
    display: flex;
    align-items: baseline;
    min-height: 18px;
    line-height: 18px;
    font-size: 12px;
    padding: 1px 0;
}

label.state-item {
    cursor: pointer;
}

.state-item:hover {
    background: var(--bg-hover);
}

.item-arrow {
    width: 12px;
    text-align: center;
    margin-right: 2px;
    color: var(--text-muted);
    display: inline-flex;
    flex-shrink: 0;
}

.item-arrow .arrow-icon {
    width: 10px;
    height: 10px;
}

.item-spacer {
    width: 12px;
    display: inline-block;
    flex-shrink: 0;
}

.item-colon {
    margin: 0 4px 0 0;
    color: var(--text-muted);
}

.item-meta {
    color: var(--text-muted);
    font-style: italic;
    margin-left: 4px;
    font-size: 11px;
}

.key-default,
.key-function,
.key-boolean {
    color: var(--prop-key);
}

.value-function {
    color: var(--value-function);
    font-style: italic;
}

.value-boolean {
    color: var(--value-boolean);
}

.value-string {
    color: var(--value-string);
}

.value-default {
    color: var(--value-default);
}

.state-item-multiline {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 4px 0;
}

.value-multiline {
    display: block;
    width: calc(100% - 16px);
    margin: 2px 0 4px 16px;
    padding: 6px 8px;
    resize: vertical;
    min-height: 6em;
    max-height: 360px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    background: var(--zx-bg-light);
    color: var(--value-string);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.45;
    white-space: pre-wrap;
    outline: none;
}

.state-empty {
    padding: 16px;
    color: var(--text-muted);
    font-family: var(--font-ui);
}

.state-empty h2 {
    margin: 0 0 6px;
    font-size: 13px;
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--tree-name);
}

.state-empty p {
    margin: 0 0 8px;
    font-size: 12px;
}

.state-empty-row {
    display: flex;
    align-items: stretch;
    gap: 6px;
    margin: 8px 0;
}

.state-empty-row .prefs-input,
.state-empty-row .prefs-chip {
    height: 28px;
    box-sizing: border-box;
    font-size: 12px;
    line-height: 1;
    padding: 0 8px;
}

.state-empty-row .prefs-input {
    width: 88px;
    flex: none;
}

.state-empty-row .prefs-chip {
    display: inline-flex;
    align-items: center;
}

/* --- Routes ------------------------------------------------------------------- */

.routes-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 2px 0;
}

.route-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 3px 8px;
    font-size: 12px;
    cursor: pointer;
    min-height: 22px;
    width: 100%;
    background: none;
    border: none;
    border-left: 2px solid transparent;
    color: inherit;
    text-align: left;
    font-family: inherit;
}

.route-item > * {
    pointer-events: none;
}

.route-item:hover {
    background: var(--bg-hover);
}

.route-item-selected {
    background: var(--bg-selected);
    border-left-color: var(--zx-primary);
}

.route-path {
    color: var(--text-base);
    font-family: var(--font-mono);
    font-size: 12px;
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.route-item-selected .route-path {
    color: var(--tree-name-selected);
}

.route-methods {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 10px;
}

.route-kind-quiet {
    color: var(--text-muted);
    font-size: 10px;
    flex-shrink: 0;
}

.route-method-token {
    font-weight: 600;
}

.route-method-sep {
    color: var(--text-muted);
}

.route-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-width: 0;
}

.route-panel-title {
    color: var(--tree-name);
    font-weight: 600;
    font-size: 12px;
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.route-open-link {
    color: var(--zx-primary);
    font-size: 11px;
    font-family: var(--font-ui);
    text-decoration: none;
    flex-shrink: 0;
}

.route-open-link:hover {
    text-decoration: underline;
}

.route-method-token.method-get { color: #61affe; }
.route-method-token.method-post { color: #49cc90; }
.route-method-token.method-put { color: #fca130; }
.route-method-token.method-delete { color: #f93e3e; }
.route-method-token.method-patch { color: #f7c948; }
.route-method-token.method-head { color: #58d68d; }
.route-method-token.method-options { color: #5dade2; }
.route-method-token.method-any { color: #c792ea; }

:root[data-theme="light"] .route-method-token.method-get { color: #2563eb; }
:root[data-theme="light"] .route-method-token.method-post { color: #059669; }
:root[data-theme="light"] .route-method-token.method-put { color: #d97706; }
:root[data-theme="light"] .route-method-token.method-delete { color: #dc2626; }
:root[data-theme="light"] .route-method-token.method-patch { color: #ca8a04; }
:root[data-theme="light"] .route-method-token.method-head { color: #16a34a; }
:root[data-theme="light"] .route-method-token.method-options { color: #0284c7; }
:root[data-theme="light"] .route-method-token.method-any { color: #7c3aed; }


.app-page {
    height: 100%;
    overflow-y: auto;
}

.prefs-page {
    color: var(--text-base);
    font-family: var(--font-ui);
    height: 100%;
    overflow-y: auto;
    padding: 14px 16px 24px;
    max-width: 480px;
}

.prefs-group {
    margin-bottom: 18px;
}

.prefs-group-title {
    margin: 0 0 6px;
    padding: 0 2px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.prefs-list {
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-elevated);
    overflow: hidden;
}

.prefs-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 34px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
}

.prefs-row:last-child {
    border-bottom: none;
}

.prefs-row-stack {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px 10px;
}

.prefs-label {
    font-size: 12px;
    color: var(--text-base);
    flex-shrink: 0;
}

.prefs-mono {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.prefs-hint {
    margin: 0;
    font-size: 11px;
    color: var(--text-muted);
}

.prefs-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    color: var(--text-base);
    cursor: pointer;
    font-size: 11px;
    line-height: 1.2;
}

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

.prefs-input {
    width: 100%;
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    color: var(--text-base);
    font-size: 12px;
    padding: 5px 8px;
    outline: none;
    font-family: var(--font-mono);
}

.prefs-input:focus {
    border-color: var(--zx-primary);
}

.prefs-link {
    color: var(--text-base);
    text-decoration: none;
    cursor: pointer;
}

.prefs-link:hover {
    color: var(--zx-primary);
    background: var(--bg-hover);
}
