:root {
    --bg-body: #0c0e14;
    --bg-surface: #13161f;
    --bg-elevated: #1b1f2b;
    --bg-hover: #242938;
    --bg-input: #10131a;
    --border: #262b3d;
    --border-subtle: #1c2030;
    --text-primary: #dfe1ea;
    --text-secondary: #858aa0;
    --text-muted: #4e5268;
    --accent: #c9a84c;
    --accent-hover: #ddbf66;
    --accent-dim: rgba(201, 168, 76, 0.12);
    --accent-glow: rgba(201, 168, 76, 0.25);
    --success: #48b06b;
    --error: #d95454;
    --radius: 6px;
    --radius-lg: 10px;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    --transition: 180ms ease;
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.55;
    min-height: 100vh;
}

#app {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px;
}

/* ── Header ─────────────────────────────────────────────── */

header {
    padding: 28px 0 0;
    margin-bottom: 20px;
}

#app-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: var(--accent);
    margin-bottom: 16px;
}

.tab-bar {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}

.tab {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.92rem;
    font-weight: 500;
    padding: 8px 18px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color var(--transition), border-color var(--transition);
}

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

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

/* ── Panels ─────────────────────────────────────────────── */

.panel {
    display: none;
}

.panel.active {
    display: block;
}

/* ── Filter Bar ─────────────────────────────────────────── */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    padding: 7px 12px;
    width: 180px;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

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

.filter-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-dim);
}

.filter-input[type="number"] {
    width: 120px;
    -moz-appearance: textfield;
}

.filter-input[type="number"]::-webkit-inner-spin-button,
.filter-input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.filter-toggles {
    gap: 14px;
}

/* ── Toggle Switch ──────────────────────────────────────── */

.toggle-label {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch {
    position: relative;
    width: 32px;
    height: 18px;
    background: var(--bg-hover);
    border-radius: 9px;
    transition: background var(--transition);
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 12px;
    height: 12px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform var(--transition), background var(--transition);
}

.toggle-label input:checked + .toggle-switch {
    background: var(--accent-dim);
}

.toggle-label input:checked + .toggle-switch::after {
    transform: translateX(14px);
    background: var(--accent);
}

.toggle-text {
    font-size: 0.82rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ── Primary Button ─────────────────────────────────────── */

.btn-primary {
    background: var(--accent);
    color: #0c0e14;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 7px 20px;
    cursor: pointer;
    transition: background var(--transition), transform 100ms ease;
    margin-left: auto;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Results Container ──────────────────────────────────── */

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

.result-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    transition: border-color var(--transition);
}

.result-card:hover {
    border-color: var(--border);
}

.result-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
}

.result-npc-name {
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 90px;
}

.result-text {
    color: var(--text-primary);
    flex: 1;
    word-break: break-word;
    white-space: pre-wrap;
}

.result-item-id {
    font-weight: 600;
    color: var(--accent);
    white-space: nowrap;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.result-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    margin-left: auto;
}

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.75rem;
    padding: 3px 8px;
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition), background var(--transition);
    white-space: nowrap;
}

.btn-icon:hover {
    color: var(--text-secondary);
    border-color: var(--text-muted);
    background: var(--bg-hover);
}

.btn-icon.boring-active {
    color: var(--error);
    border-color: var(--error);
    background: rgba(217, 84, 84, 0.1);
}

.btn-icon.expand-active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-dim);
}

.ref-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 2px;
}

.badge-retail {
    font-size: 0.7rem;
    font-weight: 700;
    color: #b08d57;
    background: rgba(176, 141, 87, 0.15);
    border: 1px solid rgba(176, 141, 87, 0.3);
    border-radius: 3px;
    padding: 1px 5px;
    line-height: 1;
}

/* ── Ref Sub-Window ─────────────────────────────────────── */

.ref-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 300ms ease;
}

.ref-panel.open {
    max-height: 800px;
}

.ref-panel-inner {
    padding: 0 14px 12px;
    border-top: 1px solid var(--border-subtle);
}

.ref-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0 8px;
}

.ref-nav-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    padding: 4px 10px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.ref-nav-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.ref-nav-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.ref-counter {
    font-size: 0.8rem;
    color: var(--text-muted);
    flex: 1;
    text-align: center;
}

.ref-detail {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}

.ref-meta {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.ref-meta-item {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.ref-meta-item span {
    color: var(--text-secondary);
}

.ref-context {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-subtle);
}

.ref-context-line {
    font-size: 0.82rem;
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--text-secondary);
}

.ref-context-line.highlight {
    background: var(--accent-dim);
    color: var(--text-primary);
}

.ref-context-line .ctx-name {
    font-weight: 600;
    color: var(--accent);
    margin-right: 4px;
}

.ref-loading {
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 8px 0;
    text-align: center;
}

.ref-error {
    font-size: 0.82rem;
    color: var(--error);
    padding: 8px 0;
    text-align: center;
}

/* ── Pagination ─────────────────────────────────────────── */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 0 32px;
}

.pagination:empty {
    display: none;
}

.page-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    padding: 6px 16px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.page-btn:hover:not(:disabled) {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.page-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.page-info {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ── Empty State ────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ── Loading Indicator ──────────────────────────────────── */

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 640px) {
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-input {
        width: 100%;
    }

    .filter-toggles {
        flex-wrap: wrap;
    }

    .btn-primary {
        margin-left: 0;
    }

    .result-header {
        flex-wrap: wrap;
    }

    .ref-meta {
        flex-direction: column;
        gap: 4px;
    }
}
