/* OpenWebCode v2 — Dark terminal theme */

:root {
  --bg: #0a0e14;
  --bg-secondary: #111820;
  --bg-tertiary: #1a2332;
  --text: #e6edf3;
  --text-dim: #7d8590;
  --accent: #58a6ff;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --border: #21262d;
  --radius: 6px;
}

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

body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* === HEADER === */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent);
}

.badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  background: var(--bg-tertiary);
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-family: monospace;
}

.badge.model { color: var(--green); border-color: var(--green); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  margin-left: 0.5rem;
}
.status-dot.ok { background: var(--green); }
.status-dot.loading { background: var(--yellow); animation: pulse 1s infinite; }
.status-dot.error { background: var(--red); }

@keyframes pulse { 50% { opacity: 0.5; } }

.status-text {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.save-indicator {
  font-size: 0.65rem;
  color: var(--text-dim);
  font-family: monospace;
  transition: color 0.3s;
}
.save-indicator.flash { color: var(--green); }

#header button {
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  background: var(--bg-tertiary);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}
#header button:hover { color: var(--text); border-color: var(--accent); }
#header button.active { color: var(--green); border-color: var(--green); }

/* === LEDs ACTIVITY === */

.leds {
  display: flex;
  gap: 0.35rem;
  margin-left: 0.75rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--border);
}

.led {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  font-family: monospace;
  font-size: 0.65rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.led:hover { color: var(--text); border-color: var(--accent); }

.led-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: 0.5;
  transition: all 0.15s;
}

.led.on { color: var(--text); border-color: currentColor; }
.led.on .led-dot { opacity: 1; box-shadow: 0 0 6px currentColor; animation: led-pulse 0.9s ease-in-out infinite; }

#led-ia.on { color: var(--accent); }
#led-ia.on .led-dot { background: var(--accent); }
#led-tools.on { color: #d29922; }
#led-tools.on .led-dot { background: #d29922; }
#led-save.on { color: var(--green); }
#led-save.on .led-dot { background: var(--green); }
#led-net.on { color: #bc8cff; }
#led-net.on .led-dot { background: #bc8cff; }

.led-count {
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 0.4rem;
}

@keyframes led-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.35); }
}

/* === ACTIVITY PANEL === */

.activity-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 35vh;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 90;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
}

.activity-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
}

.activity-title {
  font-weight: 700;
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
}

#activity-filter {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.7rem;
  padding: 0.15rem 0.3rem;
}

#activity-counters {
  display: flex;
  gap: 0.5rem;
  flex: 1;
  margin-left: 0.5rem;
}

.act-counter {
  font-family: monospace;
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 0.1rem 0.4rem;
  background: var(--bg);
  border-radius: 3px;
  border: 1px solid var(--border);
}
.act-counter b { color: var(--text); margin-right: 0.25rem; }
.act-counter.act-ia b { color: var(--accent); }
.act-counter.act-tools b { color: #d29922; }
.act-counter.act-save b { color: var(--green); }
.act-counter.act-net b { color: #bc8cff; }

.activity-header button {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}
.activity-header button:hover { color: var(--text); border-color: var(--accent); }

.activity-log {
  flex: 1;
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  padding: 0.4rem 0.75rem;
}

.act-line {
  display: grid;
  grid-template-columns: 90px 60px 1fr;
  gap: 0.5rem;
  padding: 0.1rem 0;
  border-bottom: 1px solid rgba(33, 38, 45, 0.5);
}

.act-time { color: var(--text-dim); }
.act-ch {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
}
.act-line-ch-ia .act-ch { color: var(--accent); }
.act-line-ch-tools .act-ch { color: #d29922; }
.act-line-ch-save .act-ch { color: var(--green); }
.act-line-ch-net .act-ch { color: #bc8cff; }

.act-msg { color: var(--text); white-space: pre-wrap; word-break: break-word; }
.act-line-error .act-msg { color: var(--red); }
.act-line-warn .act-msg { color: var(--yellow); }

#btn-activity.on, #btn-activity.active {
  color: var(--accent);
  border-color: var(--accent);
}

/* === BOOT SCREEN === */

#boot-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3rem;
  padding: 2rem;
}

.boot-robot pre {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  color: var(--accent);
  line-height: 1.2;
}

#boot-log {
  max-width: 500px;
}

.boot-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.boot-subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}

#boot-steps {
  font-size: 0.8rem;
  font-family: monospace;
  line-height: 1.8;
}

.step-ok { color: var(--green); }
.step-ok::before { content: '[ok] '; }
.step-fail { color: var(--red); }
.step-fail::before { content: '[!!] '; }
.step-loading { color: var(--yellow); }
.step-loading::before { content: '[..] '; }

#boot-progress {
  margin-top: 1rem;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

#boot-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.4s ease;
}

#boot-error {
  margin-top: 1rem;
  padding: 0.75rem;
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--red);
  white-space: pre-wrap;
  font-family: monospace;
}

#boot-config {
  margin-top: 1.5rem;
}

#boot-config label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}

#boot-config input {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: monospace;
  font-size: 0.85rem;
}

#boot-config button {
  width: 100%;
  padding: 0.6rem;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
}

.note {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
}

/* === APP LAYOUT (sidebar + main + preview) === */

#app {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 1fr;
  overflow: hidden;
  min-height: 0;
}
#app.with-preview {
  grid-template-columns: 240px 1fr 480px;
}

#app > * { min-height: 0; min-width: 0; }

/* Sidebar */
#sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-title {
  font-weight: 700;
  font-size: 0.7rem;
  flex: 1;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.sidebar-head button {
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}
.sidebar-head button.primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}
.sidebar-head button:hover { border-color: var(--accent); }

.session-list { flex: 1; overflow-y: auto; padding: 0.4rem; }
.session-item {
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 0.2rem;
  transition: all 0.15s;
}
.session-item:hover { background: var(--bg-tertiary); }
.session-item.active { background: var(--bg-tertiary); border-left: 3px solid var(--accent); padding-left: calc(0.6rem - 3px); }
.session-title { font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-time { font-size: 0.65rem; color: var(--text-dim); margin-top: 0.2rem; font-family: monospace; }
.sidebar-empty { padding: 1rem; text-align: center; font-size: 0.8rem; color: var(--text-dim); }

/* Main */
#main { display: flex; flex-direction: column; overflow: hidden; }

.thread { flex: 1; overflow-y: auto; padding: 1rem 1.5rem; }
.thread-empty { text-align: center; color: var(--text-dim); padding: 4rem 1rem; font-size: 0.9rem; line-height: 1.6; }

.msg {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  overflow: hidden;
}
.msg-user { border-color: rgba(88, 166, 255, 0.3); }
.msg-assistant { border-color: rgba(63, 185, 80, 0.3); }
.msg-tool { border-color: rgba(210, 153, 34, 0.3); }

.msg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0.75rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}
.msg-role {
  font-family: monospace;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}
.msg-user .msg-role { color: var(--accent); }
.msg-assistant .msg-role { color: var(--green); }
.msg-tool .msg-role { color: var(--yellow); }
.msg-time { font-size: 0.65rem; color: var(--text-dim); font-family: monospace; }

.msg-body { padding: 0.75rem 1rem; }
.part { margin-bottom: 0.5rem; }
.part:last-child { margin-bottom: 0; }
.part-text {
  font-size: 0.88rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.part-tool {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
  margin: 0.5rem 0;
}
.tool-head {
  display: flex;
  justify-content: space-between;
  font-family: monospace;
  font-size: 0.72rem;
  margin-bottom: 0.3rem;
}
.tool-name { color: var(--yellow); font-weight: 700; }
.tool-state { color: var(--text-dim); }
.tool-completed .tool-state { color: var(--green); }
.tool-error .tool-state { color: var(--red); }
.tool-running .tool-state { color: var(--yellow); animation: pulse 1s infinite; }
.tool-input, .tool-output {
  background: var(--bg-secondary);
  padding: 0.4rem;
  border-radius: 3px;
  font-size: 0.7rem;
  color: var(--text);
  margin-top: 0.3rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 250px;
  overflow-y: auto;
}

.part-other { font-size: 0.75rem; color: var(--text-dim); font-family: monospace; padding: 0.3rem; background: var(--bg); border-radius: 3px; }

/* Composer */
.composer {
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 0.6rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.composer textarea {
  width: 100%;
  min-height: 65px;
  max-height: 200px;
  resize: vertical;
  padding: 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  line-height: 1.5;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.composer-actions button {
  font-size: 0.78rem;
  padding: 0.4rem 0.85rem;
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}
.composer-actions button.primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}
.composer-actions button:hover { opacity: 0.9; }

.session-id {
  font-family: monospace;
  font-size: 0.65rem;
  color: var(--text-dim);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.15rem 0.35rem;
}

/* === PREVIEW PANEL === */

#preview-panel {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
}

.preview-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.preview-header button {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: var(--bg-tertiary);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}
.preview-header button:hover { color: var(--text); }

#preview-iframe {
  flex: 1;
  border: none;
  background: #fff;
}

/* === MODALS === */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: grid;
  place-items: center;
  z-index: 100;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 420px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content.modal-wide {
  max-width: 600px;
}

.modal-content h2 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--accent);
}

.modal-content h3 {
  font-size: 0.85rem;
  margin: 1rem 0 0.5rem;
  color: var(--text-dim);
}

.modal-content label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

.modal-content input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: monospace;
  font-size: 0.85rem;
}

.modal-content pre {
  font-size: 0.75rem;
  overflow-x: auto;
  color: var(--text-dim);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-actions button {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
}

.modal-actions button:first-child {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}

/* === DASHBOARD === */

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.dash-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}

.dash-number {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  font-family: monospace;
}

.dash-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.dash-files {
  max-height: 200px;
  overflow-y: auto;
}

.dash-file {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  font-family: monospace;
}

.dash-path { color: var(--text); }
.dash-size { color: var(--text-dim); }
.dash-empty { color: var(--text-dim); font-size: 0.8rem; text-align: center; padding: 1rem; }

/* === UTILITIES === */

.hidden { display: none !important; }

/* xterm overrides */
.xterm { height: 100%; }
.xterm-viewport { overflow-y: auto !important; }
