:root {
  --bg-base: #0a0e17;
  --bg-surface: #111827;
  --bg-card: #151e31;
  --bg-card-hover: #1c273e;
  --bg-input: #0f1624;
  --border-subtle: #1e293b;
  --border-focus: #38bdf8;
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --accent-primary: #0284c7;
  --accent-primary-hover: #0369a1;
  --accent-cyan: #38bdf8;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

body {
  background-color: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* App Layout */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top Navigation */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  height: 56px;
  flex-shrink: 0;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-badge {
  font-size: 11px;
  background-color: rgba(56, 189, 248, 0.12);
  color: var(--accent-cyan);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  font-weight: 600;
  border: 1px solid rgba(56, 189, 248, 0.25);
}

.nav-meta {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 12px;
  color: var(--text-muted);
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.status-indicator-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-dim);
  transition: background-color 0.3s ease;
}

.status-dot.online {
  background-color: var(--accent-emerald);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

.status-dot.busy {
  background-color: var(--accent-amber);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Workspace Grid */
.workspace-grid {
  display: grid;
  grid-template-columns: 460px 1fr;
  flex: 1;
  min-height: 0;
  height: calc(100vh - 56px);
  max-height: calc(100vh - 56px);
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  height: 100%;
}

.panel-left {
  border-right: 1px solid var(--border-subtle);
  background-color: var(--bg-base);
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.panel-right {
  background-color: #0c111c;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.goal-card {
  flex-shrink: 0;
}

.telemetry-card {
  flex-shrink: 0;
}

/* Cards */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

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

.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

/* Forms */
.agent-form {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

textarea, input[type="text"], input[type="url"], input[type="number"] {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

#goal-input {
  min-height: 72px;
  max-height: 240px;
  resize: vertical;
  overflow-y: auto;
  line-height: 1.5;
}

textarea:focus, input:focus {
  border-color: var(--border-focus);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

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

.btn-primary {
  background-color: var(--accent-primary);
  color: white;
  flex: 2;
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--accent-primary-hover);
}

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

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}
.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-card-hover);
  color: var(--text-main);
}

/* Telemetry Card */
.telemetry-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.decision-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.decision-metric {
  background-color: var(--bg-input);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 600;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.op-highlight {
  color: var(--accent-cyan);
}

.mono-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}
.badge.running {
  background-color: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
}
.badge.done {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.badge.error {
  background-color: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

/* Probabilities Distribution */
.prob-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

.prob-bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.prob-empty {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

.prob-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.prob-name {
  width: 90px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.prob-bar-track {
  flex: 1;
  height: 6px;
  background-color: var(--bg-input);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.prob-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #0284c7, #38bdf8);
  border-radius: 999px;
}

.prob-val {
  width: 45px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* History List */
.history-card {
  display: flex;
  flex-direction: column;
  min-height: 220px;
  flex-shrink: 0;
}

.history-count {
  font-size: 11px;
  color: var(--text-dim);
}

.history-list {
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 250px;
}

.history-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  background-color: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  font-size: 12px;
}

.history-step-num {
  font-family: var(--font-mono);
  font-size: 10px;
  background-color: var(--border-subtle);
  color: var(--text-muted);
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
}

.history-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-desc {
  color: var(--text-main);
  word-break: break-word;
}

.history-time {
  font-size: 10px;
  color: var(--text-dim);
}

/* Browser Frame */
.browser-frame {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.browser-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background-color: #141b2b;
  border-bottom: 1px solid var(--border-subtle);
}

.browser-controls {
  display: flex;
  gap: 6px;
}

.browser-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.browser-dot.red { background-color: #ef4444; }
.browser-dot.yellow { background-color: #f59e0b; }
.browser-dot.green { background-color: #10b981; }

.browser-address {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.icon-btn:hover {
  color: var(--text-main);
  background-color: rgba(255, 255, 255, 0.05);
}

.viewport-canvas-container {
  position: relative;
  background-color: #030712;
  height: 380px;
  min-height: 260px;
  max-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.viewport-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 40px;
}

.browser-screenshot {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
}

.target-box-overlay {
  position: absolute;
  border: 2px solid #f43f5e;
  background-color: rgba(244, 63, 94, 0.2);
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 10;
}

/* DOM Elements Card */
.elements-card {
  display: flex;
  flex-direction: column;
  min-height: 220px;
  flex-shrink: 0;
}

.table-search-input {
  width: 180px;
  padding: 4px 8px;
  font-size: 12px;
}

.elements-table-wrap {
  flex: 1;
  overflow-y: auto;
  max-height: 260px;
}

.elements-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.elements-table th {
  position: sticky;
  top: 0;
  background-color: #141d30;
  text-align: left;
  padding: 8px 12px;
  font-weight: 600;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 11px;
  text-transform: uppercase;
}

.elements-table td {
  padding: 7px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

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

.element-index-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  background-color: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.role-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.op-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background-color: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
  margin-right: 4px;
}

.text-center { text-align: center; }
.text-muted { color: var(--text-dim); }
.hidden { display: none !important; }

/* Custom Scrollbars */
.panel::-webkit-scrollbar,
.elements-table-wrap::-webkit-scrollbar,
.history-list::-webkit-scrollbar,
#goal-input::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

.panel::-webkit-scrollbar-track,
.elements-table-wrap::-webkit-scrollbar-track,
.history-list::-webkit-scrollbar-track,
#goal-input::-webkit-scrollbar-track {
  background: rgba(10, 14, 23, 0.5);
}

.panel::-webkit-scrollbar-thumb,
.elements-table-wrap::-webkit-scrollbar-thumb,
.history-list::-webkit-scrollbar-thumb,
#goal-input::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 4px;
}

.panel::-webkit-scrollbar-thumb:hover,
.elements-table-wrap::-webkit-scrollbar-thumb:hover,
.history-list::-webkit-scrollbar-thumb:hover,
#goal-input::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* Responsive */
@media (max-width: 1024px) {
  .app-layout {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }
  .workspace-grid {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
    overflow: visible;
  }
  .panel {
    height: auto;
    overflow: visible;
  }
}

