/* djust Developer Debug Panel - Professional Theme */

/* --- Variables --- */
:root {
    --djust-bg-main: #0f172a;       /* Slate 900 */
    --djust-bg-sidebar: #020617;    /* Slate 950 */
    --djust-bg-item: #1e293b;       /* Slate 800 */
    --djust-border: #334155;        /* Slate 700 */
    --djust-text-main: #e2e8f0;     /* Slate 200 */
    --djust-text-muted: #94a3b8;    /* Slate 400 */
    --djust-accent: #3b82f6;        /* Blue 500 */
    --djust-accent-hover: #2563eb;  /* Blue 600 */
    --djust-success: #10b981;       /* Emerald 500 */
    --djust-error: #ef4444;         /* Red 500 */
    --djust-warning: #f59e0b;       /* Amber 500 */
    --djust-font-mono: 'JetBrains Mono', 'Fira Code', 'Monaco', monospace;
    --djust-font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* --- Toggle Button --- */
.djust-debug-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--djust-bg-item);
    color: var(--djust-text-muted);
    border: 1px solid var(--djust-border);
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.djust-debug-button:hover {
    background: var(--djust-bg-main);
    color: var(--djust-text-main);
    border-color: var(--djust-accent);
    transform: translateY(-2px) scale(1.05);
}

.djust-debug-button.active {
    background: var(--djust-accent);
    color: white;
    border-color: var(--djust-accent);
    bottom: 370px; /* Move above panel when open */
}

/* --- Main Panel (Bottom Dock) --- */
.djust-debug-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 350px;
    max-height: 80vh;
    min-height: 200px;
    background: var(--djust-bg-main);
    color: var(--djust-text-main);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    z-index: 9999;
    display: flex;
    flex-direction: row; /* Sidebar + Content */
    font-family: var(--djust-font-sans);
    border-top: 1px solid var(--djust-border);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    transform: translateY(100%); /* Hidden by default */
}

.djust-debug-panel.visible {
    transform: translateY(0);
}

.djust-debug-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: transparent;
    cursor: ns-resize;
    z-index: 10;
}

.djust-debug-panel::before:hover {
    background: var(--djust-accent);
}

/* --- Sidebar (Left) --- */
.djust-debug-sidebar {
    width: 200px;
    background: var(--djust-bg-sidebar);
    border-right: 1px solid var(--djust-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.djust-debug-header {
    padding: 16px;
    border-bottom: 1px solid var(--djust-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.djust-debug-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--djust-text-main);
    letter-spacing: 0.5px;
}

.djust-debug-tabs {
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 4px;
}

.djust-debug-tab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--djust-text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-align: left;
}

.djust-debug-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--djust-text-main);
}

.djust-debug-tab.active {
    background: var(--djust-accent);
    color: white;
}

.tab-badge {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}

.tab-badge.error {
    background: var(--djust-error);
    color: white;
}

/* --- Content Area (Right) --- */
.djust-debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    padding-bottom: 24px; /* Space for status bar */
    background: var(--djust-bg-main);
    position: relative;
}

/* --- Toolbar (Inside Content) --- */
.djust-toolbar {
    position: sticky;
    top: 0;
    background: var(--djust-bg-main); /* Match main bg */
    border-bottom: 1px solid var(--djust-border);
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    backdrop-filter: blur(8px);
}

.toolbar-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--djust-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.btn-xs {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 4px;
    border: 1px solid var(--djust-border);
    background: var(--djust-bg-item);
    color: var(--djust-text-main);
    cursor: pointer;
}

.btn-xs:hover {
    border-color: var(--djust-text-muted);
}

/* --- Lists (Events, Handlers) --- */
.debug-list {
    padding: 16px;
}

/* Handler Item */
.handler-item {
    background: var(--djust-bg-item);
    border: 1px solid var(--djust-border);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
}

.handler-name {
    font-family: var(--djust-font-mono);
    font-size: 13px;
    color: var(--djust-accent);
    margin-bottom: 4px;
}

.handler-sig {
    font-family: var(--djust-font-mono);
    font-size: 12px;
    color: var(--djust-text-muted);
}

/* Event Filter Bar */
.events-filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--djust-bg-item);
    border: 1px solid var(--djust-border);
    border-radius: 4px;
    margin-bottom: 8px;
}

.events-filter-input {
    flex: 1;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--djust-border);
    border-radius: 4px;
    padding: 4px 8px;
    color: var(--djust-text);
    font-family: var(--djust-font-mono);
    font-size: 12px;
    outline: none;
}

.events-filter-input:focus {
    border-color: var(--djust-accent);
}

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

.events-filter-select {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--djust-border);
    border-radius: 4px;
    padding: 4px 8px;
    color: var(--djust-text);
    font-family: var(--djust-font-mono);
    font-size: 12px;
    cursor: pointer;
    outline: none;
}

.events-filter-select:focus {
    border-color: var(--djust-accent);
}

.events-filter-clear {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 4px;
    padding: 4px 10px;
    color: var(--djust-error);
    font-family: var(--djust-font-mono);
    font-size: 11px;
    cursor: pointer;
    white-space: nowrap;
}

.events-filter-clear:hover {
    background: rgba(239, 68, 68, 0.25);
}

.events-filter-count {
    color: var(--djust-text-muted);
    font-family: var(--djust-font-mono);
    font-size: 11px;
    white-space: nowrap;
}

/* Event Item */
.event-item {
    background: var(--djust-bg-item);
    border: 1px solid var(--djust-border);
    border-left: 3px solid var(--djust-success);
    border-radius: 4px;
    margin-bottom: 8px;
    overflow: hidden;
}

.event-item.error {
    border-left-color: var(--djust-error);
    background: rgba(239, 68, 68, 0.05);
}

.event-item.warning {
    border-left-color: #f59e0b;
    background: rgba(245, 158, 11, 0.08);
}

.event-item.warning .event-name {
    color: #f59e0b;
}

.event-warning-message {
    color: #f59e0b;
    font-size: 12px;
    padding: 4px 0;
}

.event-header {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-family: var(--djust-font-mono);
    font-size: 12px;
    user-select: none;
}

.event-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.event-header span:first-child {
    transition: transform 0.2s ease;
    display: inline-block;
}

.event-name {
    color: var(--djust-accent);
    font-weight: 600;
    flex: 1;
}

.event-item.error .event-name {
    color: var(--djust-error);
}

/* Event Replay Button */
.event-replay-btn {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 4px;
    padding: 2px 6px;
    color: var(--djust-accent);
    font-size: 12px;
    cursor: pointer;
    line-height: 1;
    transition: background 0.15s;
}

.event-replay-btn:hover {
    background: rgba(59, 130, 246, 0.3);
}

.event-replay-btn.replay-pending {
    opacity: 0.6;
    cursor: wait;
}

.event-replay-btn.replay-success {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4);
    color: var(--djust-success);
}

.event-replay-btn.replay-error {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--djust-error);
}

.event-meta {
    color: var(--djust-text-muted);
    font-size: 11px;
}

.event-body {
    padding: 12px;
    border-top: 1px solid var(--djust-border);
    background: rgba(0, 0, 0, 0.1);
    font-family: var(--djust-font-mono);
    font-size: 12px;
}

.event-body pre {
    margin: 0;
    white-space: pre-wrap;
    color: var(--djust-text-muted);
}

/* Patch Item */
.patch-item {
    background: var(--djust-bg-item);
    border: 1px solid var(--djust-border);
    border-radius: 4px;
    margin-bottom: 8px;
}

.patch-header {
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    font-family: var(--djust-font-mono);
    font-size: 12px;
    color: var(--djust-text-muted);
    user-select: none;
}

.patch-header span:first-child span:first-child {
    transition: transform 0.2s ease;
    display: inline-block;
}

.patch-count {
    color: var(--djust-warning);
    font-weight: 600;
}

.patch-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Handler Details */
.handler-desc {
    font-size: 12px;
    color: var(--djust-text-muted);
    margin-bottom: 8px;
    font-style: italic;
}

.handler-signature {
    margin-top: 8px;
    font-size: 12px;
}

.handler-signature strong {
    color: var(--djust-text-main);
}

.param {
    margin-left: 16px;
    margin-top: 4px;
    font-family: var(--djust-font-mono);
    font-size: 11px;
    color: var(--djust-text-muted);
}

.param code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--djust-accent);
}

.param .type {
    color: #22d3ee; /* Cyan */
}

.param .default {
    color: #a78bfa; /* Purple */
}

.param .required {
    color: var(--djust-error);
    font-weight: 600;
}

.handler-decorators {
    margin-top: 8px;
    font-size: 12px;
}

.handler-decorators code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--djust-warning);
    font-family: var(--djust-font-mono);
}

/* Variable Details */
.variable-item {
    background: var(--djust-bg-item);
    border: 1px solid var(--djust-border);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
}

.variable-name {
    font-family: var(--djust-font-mono);
    font-size: 13px;
    color: var(--djust-accent);
    margin-bottom: 4px;
    font-weight: 600;
}

.variable-type {
    font-size: 11px;
    color: #22d3ee; /* Cyan */
    margin-bottom: 4px;
}

.variable-value {
    font-size: 12px;
    color: var(--djust-text-muted);
}

.variable-value code {
    color: var(--djust-text-main);
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--djust-font-mono);
}

/* Event/Patch Body Details */
.event-params {
    margin-bottom: 8px;
}

.event-params strong {
    color: var(--djust-text-main);
    display: block;
    margin-bottom: 4px;
}

.event-error {
    margin-top: 8px;
    padding: 8px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--djust-error);
    border-radius: 4px;
    color: var(--djust-error);
}

.event-error strong {
    display: block;
    margin-bottom: 4px;
}

/* Empty States */
.empty {
    text-align: center;
    color: var(--djust-text-muted);
    padding: 32px;
    font-size: 13px;
}

/* History Count */
.history-count {
    font-size: 11px;
    color: var(--djust-text-muted);
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

/* Status Bar */
.djust-status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 24px;
    background: var(--djust-bg-sidebar);
    border-top: 1px solid var(--djust-border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 11px;
    color: var(--djust-text-muted);
    gap: 16px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--djust-text-muted);
}

.status-dot.connected { background: var(--djust-success); }
.status-dot.disconnected { background: var(--djust-error); }

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--djust-border);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--djust-text-muted);
}

/* --- State Timeline Tab --- */
.state-timeline-container {
    padding: 8px;
}

.state-timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(15, 23, 42, 0.5);
    border: 2px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
    margin-bottom: 12px;
}

.state-timeline-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--djust-text-main);
}

.timeline-icon {
    font-size: 18px;
}

.state-count {
    padding: 2px 8px;
    background: rgba(59, 130, 246, 0.2);
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--djust-accent);
}

.clear-state-btn {
    padding: 6px 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    color: #f87171;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}

.clear-state-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
}

.state-timeline-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.state-entry {
    background: var(--djust-bg-item);
    border: 1px solid var(--djust-border);
    border-radius: 6px;
    overflow: hidden;
    transition: all 0.15s;
}

.state-entry:hover {
    border-color: rgba(59, 130, 246, 0.4);
}

.state-entry.has-changes {
    border-left: 3px solid var(--djust-accent);
}

.state-entry.expanded {
    border-color: var(--djust-accent);
}

.state-entry-header {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 12px;
    user-select: none;
}

.state-entry-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.state-entry .expand-icon {
    color: var(--djust-text-muted);
    font-size: 10px;
    transition: transform 0.2s;
}

.state-entry.expanded .expand-icon {
    transform: rotate(90deg);
}

.state-trigger {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.state-trigger.trigger-mount {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
}

.state-trigger.trigger-event {
    background: rgba(251, 146, 60, 0.2);
    color: #fdba74;
}

.state-event-name {
    font-family: var(--djust-font-mono);
    color: var(--djust-accent);
    font-weight: 600;
}

.state-change-count {
    padding: 2px 8px;
    background: rgba(148, 163, 184, 0.15);
    border-radius: 10px;
    font-size: 10px;
    color: var(--djust-text-muted);
}

.state-time {
    margin-left: auto;
    color: var(--djust-text-muted);
    font-size: 11px;
}

.state-entry-details {
    padding: 12px;
    border-top: 1px solid var(--djust-border);
    background: rgba(15, 23, 42, 0.3);
}

.state-changes {
    margin-bottom: 16px;
}

.state-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--djust-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.state-change-item {
    background: rgba(30, 41, 59, 0.5);
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 6px;
}

.state-change-item:last-child {
    margin-bottom: 0;
}

.change-type-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    margin-right: 8px;
}

.change-type-badge.added {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
}

.change-type-badge.modified {
    background: rgba(251, 191, 36, 0.2);
    color: #fde047;
}

.change-type-badge.removed {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
}

.change-key {
    font-family: var(--djust-font-mono);
    font-weight: 600;
    color: var(--djust-accent);
}

.change-values {
    margin-top: 8px;
    font-size: 11px;
}

.change-before,
.change-after {
    margin-bottom: 4px;
}

.change-label {
    color: var(--djust-text-muted);
    font-weight: 500;
    margin-right: 8px;
}

.change-values pre {
    margin: 4px 0 0 0;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    font-family: var(--djust-font-mono);
    font-size: 11px;
    color: var(--djust-text-main);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.change-before pre {
    border-left: 2px solid rgba(239, 68, 68, 0.5);
}

.change-after pre {
    border-left: 2px solid rgba(16, 185, 129, 0.5);
}

.no-changes {
    padding: 12px;
    text-align: center;
    color: var(--djust-text-muted);
    font-style: italic;
    font-size: 12px;
}

.state-snapshot {
    margin-top: 12px;
}

.state-snapshot-content {
    margin: 0;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    font-family: var(--djust-font-mono);
    font-size: 11px;
    color: var(--djust-text-muted);
    overflow-x: auto;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Network Tab — directional color coding */
.network-direction.sent {
    color: #f59e0b;
    font-weight: 600;
}

.network-direction.received {
    color: #22d3ee;
    font-weight: 600;
}

.network-item.sent {
    border-left: 3px solid #f59e0b;
}

.network-item.received {
    border-left: 3px solid #22d3ee;
}

/* Network copy button */
.network-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 4px;
    padding: 3px 8px;
    color: var(--djust-accent);
    font-family: var(--djust-font-mono);
    font-size: 11px;
    cursor: pointer;
}

.network-copy-btn:hover {
    background: rgba(59, 130, 246, 0.3);
}

.network-copy-btn.copied {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4);
    color: var(--djust-success);
}

.network-payload {
    position: relative;
}
