/* === Variables === */
:root {
  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-header: #1a1f36;
  --color-header-text: #ffffff;
  --color-primary: #4f6ef7;
  --color-primary-hover: #3b5ae0;
  --color-primary-disabled: #a0b0e8;
  --color-text: #2d3748;
  --color-text-muted: #718096;
  --color-border: #e2e8f0;
  --color-output-bg: #1e1e2e;
  --color-output-text: #cdd6f4;
  --color-error: #e53e3e;
  --color-error-bg: #fff5f5;
  --color-success: #38a169;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Code", "Fira Code", "JetBrains Mono", Consolas, monospace;
}

/* === Reset === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
header {
  background: var(--color-header);
  color: var(--color-header-text);
  padding: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 100%;
}

.header-content {
  flex: 1;
}

/* === Agent Status === */
.agent-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
  white-space: nowrap;
}

.agent-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.agent-connected .agent-dot {
  background: #38a169;
  box-shadow: 0 0 6px rgba(56, 161, 105, 0.6);
}

.agent-connected .agent-label {
  color: #68d391;
}

.agent-disconnected .agent-dot {
  background: #e53e3e;
  box-shadow: 0 0 6px rgba(229, 62, 62, 0.6);
}

.agent-disconnected .agent-label {
  color: #fc8181;
}

.agent-unknown .agent-dot {
  background: #718096;
}

.agent-unknown .agent-label {
  color: #a0aec0;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header p {
  font-size: 0.875rem;
  opacity: 0.7;
  margin-top: 2px;
}

/* === Main === */
main {
  max-width: 960px;
  margin: 24px auto;
  padding: 0 20px;
  flex: 1;
  width: 100%;
}

/* === Controls Panel === */
.controls {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group select,
.form-group input {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.9375rem;
  font-family: var(--font-sans);
  border: 1.5px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.15);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* === Execute Button === */
#execute-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-sans);
  color: #ffffff;
  background: var(--color-primary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  margin-top: 4px;
}

#execute-btn:hover:not(:disabled) {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
}

#execute-btn:active:not(:disabled) {
  transform: translateY(0);
}

#execute-btn:disabled {
  background: var(--color-primary-disabled);
  cursor: not-allowed;
}

#execute-btn.loading .btn-text {
  display: none;
}

#execute-btn.loading .btn-spinner {
  display: inline-block !important;
}

/* Spinner */
.btn-spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Output Section === */
.output-section {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}

.output-header h3 {
  font-size: 0.9375rem;
  font-weight: 600;
}

#output-meta {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.output-area {
  background: var(--color-output-bg);
  color: var(--color-output-text);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  padding: 20px;
  max-height: 500px;
  overflow-y: auto;
  min-height: 120px;
}

.output-placeholder {
  color: #6c7086;
  font-style: italic;
  font-family: var(--font-sans);
}

/* Output parser styles */
.output-plain {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.output-empty {
  color: #6c7086;
  font-style: italic;
}

/* Table output */
.table-wrapper {
  overflow-x: auto;
}

.output-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.output-table th {
  background: #313244;
  color: #cba6f7;
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.output-table td {
  padding: 6px 12px;
  border-bottom: 1px solid #313244;
  white-space: nowrap;
}

.output-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.output-table tbody tr:hover {
  background: rgba(79, 110, 247, 0.08);
}

/* Log output */
.output-log {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-error {
  color: #f38ba8;
  font-weight: 600;
}

.log-warn {
  color: #f9e2af;
}

.log-info {
  color: #89b4fa;
}

/* Error display in output area */
.output-error {
  color: #f38ba8;
  font-family: var(--font-sans);
  padding: 8px 0;
}

.output-error strong {
  display: block;
  margin-bottom: 4px;
}

/* === Footer === */
footer {
  text-align: center;
  padding: 16px 20px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* === Responsive === */
@media (max-width: 768px) {
  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .controls {
    padding: 16px;
  }

  .output-area {
    font-size: 0.75rem;
    padding: 12px;
    max-height: 400px;
  }
}
