/**
 * RAG OS - Intelligence Console Stylesheet
 * 
 * Design System 2026:
 * - Bespoke "Command Center" / "Terminal" aesthetic
 * - Precision 1px UI components
 * - High-contrast monochromatic base + electric accents
 * - Optimized for density and professional utility
 */

:root {
  --bg-core: #05060a;
  --bg-panel: #0a0c14;
  --bg-elevated: #111420;

  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-dim: #475569;

  --accent: #22d3ee;
  --accent-dim: rgba(34, 211, 238, 0.15);
  --ready: #10b981;
  --fail: #f43f5e;
  --warn: #f59e0b;

  --border: rgba(255, 255, 255, 0.06);
  --border-active: rgba(34, 211, 238, 0.3);

  --font-sans: "Plus Jakarta Sans", -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  --ease: cubic-bezier(0.2, 0, 0, 1);
}

/* ==========================================================================
   Reset & System Background
   ========================================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-core);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.system-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  z-index: -1;
  pointer-events: none;
  opacity: 0.5;
}

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

/* ==========================================================================
   System Header
   ========================================================================== */
.system-header {
  height: 54px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--bg-panel);
  z-index: 100;
}

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

.system-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.logo-bit {
  width: 10px;
  height: 10px;
  background: var(--accent);
  transform: rotate(45deg);
  box-shadow: 0 0 10px var(--accent);
}
.logo-text {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 1px;
  color: var(--text-primary);
}
.logo-version {
  color: var(--accent);
  margin-left: 2px;
}

.system-breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-dim);
}
.crumb-active {
  color: var(--text-secondary);
}

.system-status {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.status-item {
  display: flex;
  flex-direction: column;
}
.status-label {
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--text-dim);
}
.status-value {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
}
.status-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
}
.text-accent {
  color: var(--accent);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s;
}
.icon-btn:hover {
  color: var(--accent);
}

/* ==========================================================================
   Main Content
   ========================================================================== */
.system-main {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.console-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 2rem;
  max-width: 1300px;
  margin: 0 auto;
}

/* ==========================================================================
   Common Console Box
   ========================================================================== */
.console-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  margin-bottom: 2rem;
}

.box-header {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.box-tag {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 800;
  color: var(--text-dim);
  letter-spacing: 1.5px;
}

.box-shortcut {
  font-size: 0.55rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 2px 4px;
  border-radius: 2px;
}

/* ==========================================================================
   Input Box
   ========================================================================== */
.input-box {
  border-color: var(--border-active);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  padding: 1rem;
  gap: 1rem;
}
#query-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 500;
  resize: none;
  outline: none;
  min-height: 28px;
  max-height: 200px;
  line-height: 1.5;
}
#query-input::placeholder {
  color: var(--text-dim);
}

.run-btn {
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: var(--bg-core);
  border: none;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ease);
}
.run-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 0 15px var(--accent);
}
.run-btn:disabled {
  background: var(--text-dim);
  opacity: 0.5;
}

/* ==========================================================================
   Monitor Box
   ========================================================================== */
.latency-tag {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--accent);
}

.monitor-flow {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow-x: auto;
  gap: 0.5rem;
}

.m-node {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  opacity: 0.2;
  transition: all 0.4s var(--ease);
  width: 90px;
  flex-shrink: 0;
}

.m-index {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text-dim);
}
.m-label {
  font-size: 0.6rem;
  font-weight: 800;
  color: var(--text-secondary);
}
.m-sub {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m-time {
  font-family: var(--font-mono);
  font-size: 0.5rem;
  color: var(--accent);
  height: 1em;
}

.m-connector {
  flex: 1;
  height: 1px;
  background: var(--border);
  margin-top: -24px;
  min-width: 10px;
  position: relative;
  overflow: hidden;
}
.m-line-inner {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  transform: translateX(-100%);
}

@keyframes scan {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

.m-connector.flowing .m-line-inner {
  animation: scan 1.5s linear infinite;
}
.m-connector.locked {
  background: var(--ready);
  box-shadow: 0 0 5px var(--ready);
  opacity: 0.5;
}
.m-connector.broken {
  background: var(--fail);
}

.m-node.active {
  opacity: 1;
  transform: translateY(-2px);
}
.m-node.active .m-label {
  color: var(--accent);
}
.m-node.ready {
  opacity: 1;
}
.m-node.ready .m-label {
  color: var(--ready);
}
.m-node.fail {
  opacity: 1;
}
.m-node.fail .m-label {
  color: var(--fail);
}

/* ==========================================================================
   Result Area
   ========================================================================== */
.output-area {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  animation: slideUp 0.5s var(--ease);
}
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-text {
  padding: 1.5rem;
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1px;
  background: var(--border);
}
.source-node {
  background: var(--bg-panel);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.node-idx {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text-dim);
}
.node-content {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.node-origin {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--accent);
  text-transform: uppercase;
}

/* ==========================================================================
   Library & Sidebar
   ========================================================================== */
.library-scroller {
  height: 300px;
  overflow-y: auto;
  padding: 0.5rem;
  scrollbar-width: none;
}
.lib-node {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}
.lib-node:hover {
  background: rgba(255, 255, 255, 0.02);
}

.node-type {
  width: 32px;
  height: 32px;
  background: var(--bg-elevated);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  font-weight: 800;
  color: var(--text-dim);
}
.node-type.pdf {
  color: var(--fail);
}
.node-type.csv {
  color: var(--ready);
}
.node-type.txt {
  color: var(--accent);
}

.node-name {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.node-meta {
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text-dim);
}

.library-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sys-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.6rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  cursor: pointer;
  transition: all 0.2s;
}
.sys-btn:hover {
  background: var(--border);
  color: var(--text-primary);
}
.sys-btn.secondary {
  border-color: transparent;
  background: transparent;
  color: var(--text-dim);
}
.sys-btn.secondary:hover {
  color: var(--warn);
}

.spec-list {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.spec-item {
  display: flex;
  justify-content: space-between;
}
.spec-label {
  font-size: 0.55rem;
  color: var(--text-dim);
  font-weight: 800;
}
.spec-val {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   Footer
   ========================================================================== */
.system-footer {
  height: 28px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
}

.activity-pulse {
  width: 6px;
  height: 6px;
  background: var(--ready);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--ready);
}
.footer-text {
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 1px;
}

/* ==========================================================================
   Drawer
   ========================================================================== */
.system-drawer {
  position: fixed;
  right: -320px;
  top: 54px;
  bottom: 28px;
  width: 320px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  z-index: 90;
  transition: right 0.3s var(--ease);
  padding: 1.5rem;
}
.system-drawer.active {
  right: 0;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2rem;
}
.drawer-header h3 {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.close-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
}

.config-cell {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.cell-label {
  font-size: 0.55rem;
  color: var(--text-dim);
  font-weight: 800;
  letter-spacing: 1px;
}
.cell-val {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent);
}

.drawer-actions {
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px dashed var(--border);
}
.btn-danger {
  width: 100%;
  padding: 0.75rem;
  background: transparent;
  border: 1px solid var(--fail);
  color: var(--fail);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 800;
  cursor: pointer;
}
.btn-danger:hover {
  background: var(--fail);
  color: var(--bg-core);
}

/* ==========================================================================
   Toasts
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 40px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.8rem 1.2rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.toast.success {
  border-left: 3px solid var(--ready);
}
.toast.error {
  border-left: 3px solid var(--fail);
}

/* ==========================================================================
   Minimal Components
   ========================================================================== */
.minimal-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.55rem;
  padding: 2px 6px;
  cursor: pointer;
}
.minimal-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
}

/* Responsive adjustments */
@media (max-width: 1000px) {
  .console-grid {
    grid-template-columns: 1fr;
  }
  .sidebar-panel {
    order: 2;
  }
}
