:root {
    --bg-base: #070a12;
    --bg-surface: rgba(15, 23, 42, 0.75);
    --bg-surface-elevated: rgba(30, 41, 59, 0.85);
    --bg-card: rgba(15, 23, 42, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(0, 255, 204, 0.3);
    
    --accent-primary: #00ffcc;
    --accent-secondary: #00a2ff;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --accent-purple: #a855f7;
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'Fira Code', monospace;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-glow: 0 0 20px rgba(0, 255, 204, 0.15);
}

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

body {
    background-color: var(--bg-base);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(0, 162, 255, 0.06) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(0, 255, 204, 0.05) 0%, transparent 40%);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* App Header */
.app-header {
    background: rgba(7, 10, 18, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-icon {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.3);
}

.brand-text h1 {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.brand-text p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.header-status-pill {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-primary);
    box-shadow: 0 0 8px var(--accent-primary);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

/* Main Container Grid */
.main-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 340px 1fr 420px;
    gap: 1.5rem;
    padding: 1.5rem 2rem;
    max-width: 1920px;
    margin: 0 auto;
    width: 100%;
    height: calc(100vh - 75px);
    overflow: hidden;
}

/* Glass Panels */
.panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.panel-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
}

.panel-title {
    font-size: 0.95rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Tier Selector & Badges */
.tier-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    font-family: var(--font-mono);
    text-transform: uppercase;
}

.tier-anonymous {
    background: rgba(148, 163, 184, 0.15);
    color: #cbd5e1;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.tier-counter {
    background: rgba(0, 255, 204, 0.12);
    color: var(--accent-primary);
    border: 1px solid rgba(0, 255, 204, 0.35);
}

.tier-contract {
    background: rgba(0, 162, 255, 0.12);
    color: var(--accent-secondary);
    border: 1px solid rgba(0, 162, 255, 0.35);
}

.tier-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tier-card:hover {
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.tier-card.selected {
    border-color: var(--accent-primary);
    background: rgba(0, 255, 204, 0.04);
    box-shadow: inset 0 0 0 1px var(--accent-primary);
}

.tier-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tier-card-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
}

.tier-card-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Rate Limit Bar */
.rate-limit-card {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.rate-limit-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-family: var(--font-mono);
}

.rate-limit-progress {
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
}

.rate-limit-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    transition: width 0.3s ease;
}

/* Forms & Inputs */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.form-control {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.8rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    transition: border-color 0.2s;
    width: 100%;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(0, 255, 204, 0.1);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    color: #000;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 255, 204, 0.25);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(244, 63, 94, 0.3);
    color: var(--accent-rose);
}

.btn-danger:hover {
    background: rgba(244, 63, 94, 0.25);
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.72rem;
}

/* Chat Area */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    gap: 0.35rem;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
    align-self: flex-end;
}

.chat-message.agent {
    align-self: flex-start;
}

.chat-message.system {
    align-self: center;
    max-width: 95%;
}

.message-sender {
    font-size: 0.7rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.message-bubble {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    line-height: 1.5;
}

.chat-message.user .message-bubble {
    background: linear-gradient(135deg, rgba(0, 162, 255, 0.25), rgba(0, 255, 204, 0.15));
    border: 1px solid rgba(0, 162, 255, 0.3);
    color: #fff;
    border-bottom-right-radius: 2px;
}

.chat-message.agent .message-bubble {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-bottom-left-radius: 2px;
}

.chat-message.system .message-bubble {
    background: rgba(0, 255, 204, 0.05);
    border: 1px dashed rgba(0, 255, 204, 0.25);
    font-size: 0.8rem;
    color: var(--accent-primary);
    font-family: var(--font-mono);
}

/* Quick Action Chips */
.quick-prompts {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    overflow-x: auto;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
}

.chip {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.chip:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: rgba(0, 255, 204, 0.05);
}

/* Chat Input Bar */
.chat-input-bar {
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
}

.chat-input-bar input {
    flex: 1;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input-bar input:focus {
    border-color: var(--accent-primary);
}

/* Right Tabs: Protocol Monitor, Memory, Agent Spec & Test Suite */
.tab-nav {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.25);
    overflow-x: auto;
    scrollbar-width: thin;
}

.tab-nav::-webkit-scrollbar {
    height: 3px;
}

.tab-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
}

.tab-btn {
    flex: 1;
    min-width: fit-content;
    padding: 0.65rem 0.65rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 0.73rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

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

.tab-btn.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: rgba(0, 255, 204, 0.03);
}

.tab-pane {
    display: none;
    flex-direction: column;
    gap: 1rem;
    height: 100%;
    overflow-y: auto;
}

.tab-pane.active {
    display: flex;
}

/* Protocol Telemetry Stream */
.telemetry-stream {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.telemetry-item {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.telemetry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.telemetry-method {
    font-weight: 700;
    color: var(--accent-secondary);
}

.telemetry-status {
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.68rem;
}

.status-200 { background: rgba(0, 255, 204, 0.15); color: var(--accent-primary); }
.status-403 { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); }
.status-429 { background: rgba(168, 85, 247, 0.15); color: var(--accent-purple); }
.status-401 { background: rgba(244, 63, 94, 0.15); color: var(--accent-rose); }

.telemetry-code {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    padding: 0.5rem;
    white-space: pre-wrap;
    max-height: 160px;
    overflow-y: auto;
    font-size: 0.7rem;
    color: #a5b4fc;
}

/* Test Suite Results */
.test-item {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.test-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.test-desc {
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.test-status {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.test-pending { background: rgba(255, 255, 255, 0.05); color: var(--text-muted); }
.test-running { background: rgba(0, 162, 255, 0.15); color: var(--accent-secondary); animation: pulse 1s infinite; }
.test-pass { background: rgba(0, 255, 204, 0.15); color: var(--accent-primary); border: 1px solid rgba(0, 255, 204, 0.3); }
.test-fail { background: rgba(244, 63, 94, 0.15); color: var(--accent-rose); border: 1px solid rgba(244, 63, 94, 0.3); }

/* Modal Styles */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.modal-backdrop.open {
    display: flex;
}

.modal-box {
    background: #0d121f;
    border: 1px solid var(--border-highlight);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 540px;
    padding: 2rem;
    box-shadow: var(--shadow-glow);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header h3 {
    font-size: 1.15rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-alert {
    background: rgba(0, 255, 204, 0.05);
    border: 1px solid rgba(0, 255, 204, 0.2);
    border-radius: var(--radius-sm);
    padding: 0.9rem;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--accent-primary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.modal-box.modal-wide {
    max-width: 860px;
    max-height: 85vh;
    overflow-y: auto;
}

/* Operational Context Card (memory.md §1) */
.operational-context-box {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.op-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.72rem;
    padding: 0.2rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

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

.op-meta-key {
    color: var(--text-secondary);
    font-weight: 500;
}

.op-meta-val {
    color: var(--accent-primary);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    text-align: right;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Decision Flow Banner (agent.md §3) */
.decision-flow-banner {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.85rem;
    background: rgba(0, 255, 204, 0.04);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.72rem;
    color: var(--text-secondary);
    overflow-x: auto;
    white-space: nowrap;
}

.decision-step {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    cursor: pointer;
    transition: all 0.25s ease;
    user-select: none;
}

.decision-step:hover {
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

.decision-step.active {
    background: rgba(0, 255, 204, 0.12);
    border-color: rgba(0, 255, 204, 0.4);
    color: var(--accent-primary);
    font-weight: 700;
    box-shadow: 0 0 10px rgba(0, 255, 204, 0.25);
}

.decision-step.completed {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: #34d399;
}

.decision-arrow {
    color: var(--text-muted);
    font-size: 0.7rem;
}

/* Memory Tab (memory.md) */
.memory-item-card {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: all 0.2s ease;
    border-left: 3px solid var(--accent-amber);
}

.memory-item-card.resolved {
    border-left-color: #34d399;
}

.memory-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.memory-code-badge {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--accent-primary);
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.memory-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-weight: 600;
}

.memory-badge.pending {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.memory-badge.resolved {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.memory-actions {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
    margin-top: 0.25rem;
}

/* Agent Spec Tab (agent.md) */
.spec-section {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.spec-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.code-snippet-wrapper {
    position: relative;
    background: #050811;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    padding: 0.65rem;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: #a5b4fc;
    overflow-x: auto;
    max-height: 180px;
    white-space: pre-wrap;
}

.copy-snippet-btn {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: #f8fafc;
    font-size: 0.65rem;
    padding: 0.2rem 0.45rem;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-snippet-btn:hover {
    background: var(--accent-primary);
    color: #000;
}

/* Chain of Thought (agent.md §1) */
.cot-box {
    margin-bottom: 0.6rem;
    background: rgba(168, 85, 247, 0.08);
    border: 1px dashed rgba(168, 85, 247, 0.35);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    font-size: 0.74rem;
    color: #d8b4fe;
}

.cot-header {
    font-weight: 700;
    color: #c084fc;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.25rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Tabela Oficial SRO (rastreamento_real_tabela de agent.md §4.3) */
.sro-table-wrapper {
    margin-top: 0.75rem;
    overflow-x: auto;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(0, 162, 255, 0.25);
}

.sro-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    background: rgba(10, 16, 30, 0.9);
}

.sro-table th {
    background: rgba(0, 162, 255, 0.18);
    color: #38bdf8;
    padding: 0.5rem 0.65rem;
    text-align: left;
    font-family: var(--font-mono);
    border-bottom: 1px solid rgba(0, 162, 255, 0.3);
}

.sro-table td {
    padding: 0.45rem 0.65rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.sro-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Responsive adjustments */
@media (max-width: 1300px) {
    .main-layout {
        grid-template-columns: 300px 1fr 340px;
    }
}

@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }
}
