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

:root {
  --bg: #000000;
  --glass: rgba(8, 8, 10, 0.72);
  --glass-strong: rgba(5, 5, 7, 0.88);
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --accent: #ffffff;
  --text: #f4f4f5;
  --muted: #71717a;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --cyan: #38bdf8;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Pure Black Connecting Screen (tiny white circular progress ring) ── */
.connecting-screen {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.connecting-screen[hidden] { display: none; }

.mini-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-top-color: #ffffff;
  animation: spin 0.75s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.pattern-waves-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.app-shell[hidden] { display: none; }

/* ── Minimal Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-name { font-weight: 700; letter-spacing: 3.5px; font-size: 13px; }
.topbar-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 6px; }

.btn-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.18s ease;
}
.btn-pill:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.btn-pill.active { background: #fff; color: #000; border-color: #fff; }
.btn-pill.muted { border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; background: rgba(239, 68, 68, 0.12); }
.btn-pill.btn-warn:hover { border-color: rgba(245, 158, 11, 0.5); color: #fde68a; }
.btn-pill.btn-danger { border-color: var(--red); background: rgba(239, 68, 68, 0.2); color: #fecaca; }

.btn-primary {
  background: #ffffff;
  color: #000000;
  border: none;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.18s ease;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary.btn-sm { padding: 6px 12px; font-size: 11px; }

.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon:hover { border-color: var(--border-strong); background: var(--surface-hover); }

/* ── Slide-Over Conversations Drawer ── */
.chat-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  z-index: 70;
  background: rgba(6, 6, 8, 0.94);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
}
.chat-drawer[hidden] { display: none; }

.rail-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  font-size: 11px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.chat-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.chat-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 9px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; color: var(--text); transition: 0.15s;
}
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--surface-hover); border-color: var(--border-strong); }
.chat-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.chat-item-del {
  opacity: 0; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px;
}
.chat-item:hover .chat-item-del { opacity: 1; }
.chat-item-del:hover { color: var(--red); }

/* ── Persistent Split Stage: Fixed Left (Orb+Dock) | Divider | Right Views ── */
.stage {
  flex: 1;
  min-height: 0;
  position: relative;
}

.app-split {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  min-height: 0;
}

.split-left {
  flex: 0 0 42%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 0;
  padding: 20px;
}

.orb-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

.crystalized-ball {
  position: relative;
  width: min(330px, 78%);
  height: min(330px, 56vh);
  aspect-ratio: 1 / 1;
  overflow: hidden;
}

.split-divider {
  width: 1px;
  flex: none;
  margin: 28px 0;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(255, 255, 255, 0.08) 18%,
    rgba(255, 255, 255, 0.24) 50%,
    rgba(255, 255, 255, 0.08) 82%,
    transparent 100%
  );
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.08);
}

.split-right {
  flex: 1 1 58%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 14px 24px 14px;
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  height: 100%;
  width: 100%;
  min-height: 0;
}
.view.active { display: flex; }

.chat-feed {
  flex: 1;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  overflow-y: auto;
  padding: 8px 0 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 82%;
  padding: 10px 15px;
  border-radius: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  backdrop-filter: blur(10px);
}
.msg-u { align-self: flex-end; background: rgba(255, 255, 255, 0.1); border: 1px solid var(--border-strong); }
.msg-j { align-self: flex-start; background: rgba(12, 12, 16, 0.85); border: 1px solid var(--border); }
.msg-sys { align-self: center; font-size: 11px; color: var(--muted); padding: 2px 8px; }
.msg-lbl { font-size: 9px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }

.composer {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 8px 0 4px;
  flex-shrink: 0;
}

.file-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px; margin-bottom: 8px; border-radius: 999px;
  background: var(--surface-hover); border: 1px solid var(--border-strong); font-size: 11px;
}
.file-pill button { background: none; border: none; color: var(--text); cursor: pointer; font-size: 14px; }

.composer-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--glass-strong);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 5px 6px 5px 12px;
}

.btn-attach {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer; padding: 6px; border-radius: 50%; transition: 0.15s;
}
.btn-attach:hover { color: var(--text); background: var(--surface); }

#cmd-input {
  flex: 1; background: transparent; border: none; color: var(--text);
  padding: 8px 6px; outline: none; font-size: 13px;
}

/* ── Standalone Pages (Tasks / Logs / Plugins) ── */
.page-container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100%;
  min-height: 0;
}

.page-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.page-head h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.2px; }

#view-settings .page-container {
  overflow-y: auto;
  padding-bottom: 36px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#view-settings .page-container::-webkit-scrollbar {
  display: none;
}

.settings-card {
  background: var(--glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.save-status {
  font-size: 11px;
  color: var(--green);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.plugin-grid {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 4px;
}

.plugin-row-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.plugin-row-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.plugin-row-desc {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-card, .plugin-card {
  background: var(--glass);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s;
}
.task-card:hover, .plugin-card:hover { border-color: var(--border-strong); }
.task-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.task-title { font-weight: 600; font-size: 13px; }
.badge {
  font-size: 10px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); text-transform: uppercase; letter-spacing: 0.6px;
}
.badge.running { color: var(--cyan); border-color: rgba(56, 189, 248, 0.35); }
.badge.completed, .badge.done { color: var(--green); border-color: rgba(34, 197, 94, 0.35); }
.badge.failed, .badge.cancelled { color: var(--red); border-color: rgba(239, 68, 68, 0.35); }
.task-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Logs Page */
.log-controls { display: flex; gap: 8px; align-items: center; }
.log-controls input {
  background: var(--glass); border: 1px solid var(--border); color: var(--text);
  padding: 7px 12px; border-radius: 999px; outline: none; font-size: 12px; width: 200px;
}
.log-terminal {
  flex: 1;
  overflow-y: auto;
  background: rgba(3, 3, 5, 0.85);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  font-family: Consolas, "Cascadia Code", ui-monospace, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: #d4d4d8;
}

.empty-state { color: var(--muted); text-align: center; padding: 40px 16px; font-size: 12px; grid-column: 1 / -1; }

/* ── Modals ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: 420px; max-width: 92vw;
  background: #08080a;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 22px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-wide { width: 680px; max-height: 82vh; }
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-badge { font-size: 10px; font-weight: 700; letter-spacing: 1.6px; color: var(--amber); }

.viewer-media img, .viewer-media video {
  width: 100%; max-height: 280px; object-fit: contain;
  border-radius: 10px; border: 1px solid var(--border); background: #000;
}
.viewer-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; max-height: 50vh; }
.content-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.content-card h4 { font-size: 12px; color: #fff; margin-bottom: 6px; }
.content-card pre { white-space: pre-wrap; font-family: inherit; line-height: 1.5; font-size: 12px; color: #d4d4d8; }

.form-grid { display: flex; flex-direction: column; gap: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 11px; color: var(--muted); }
.form-grid input, .form-grid select {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 9px 12px; border-radius: 10px; outline: none;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Scrollbars */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 999px; }

@media (max-width: 768px) {
  .topbar-actions { display: none; }
  .app-split { flex-direction: column; }
  .split-left { flex: 0 0 auto; padding: 10px; gap: 6px; }
  .split-divider { width: 80%; height: 1px; margin: 4px auto; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent); }
  .crystalized-ball { width: 160px; height: 160px; }
}
