/* iONexus Main Stylesheet — iViRTH AI */
/* DM Sans, Black & White, Dark/Light adaptive */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&display=swap');

/* ── TOKENS ── */
:root {
  --bg:        #ffffff;
  --fg:        #000000;
  --surface:   #f5f5f5;
  --surface2:  #ebebeb;
  --border:    #e0e0e0;
  --muted:     #6b6b6b;
  --accent:    #000000;
  --accent-bg: #f0f0f0;
  --radius:    10px;
  --shadow:    0 2px 20px rgba(0,0,0,0.08);
  --font:      'DM Sans', system-ui, sans-serif;

  /* iON Colors */
  --trinetra: #b8960c;
  --netra:    #00b4c8;
  --one:      #c98a00;
  --ion360:   #1a3aff;
  --ion360ne: #888888;
  --trails:   #00a040;
}

[data-theme="dark"] {
  --bg:        #0a0a0a;
  --fg:        #f0f0f0;
  --surface:   #111111;
  --surface2:  #1a1a1a;
  --border:    #2a2a2a;
  --muted:     #888888;
  --accent:    #ffffff;
  --accent-bg: #1c1c1c;
  --shadow:    0 2px 20px rgba(0,0,0,0.4);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: var(--font); cursor: pointer; }

/* ── LAYOUT ── */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
.page-wrap { display: flex; min-height: 100vh; }

/* ── NAV ── */
.sidebar {
  width: 240px;
  min-height: 100vh;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.3s;
}
.sidebar-logo {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar-logo-mark {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 2px solid var(--fg);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  flex-shrink: 0;
}
.sidebar-logo-text { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.03em; }
.sidebar-logo-sub  { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }

.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; }
.nav-section-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding: 0.75rem 1.25rem 0.25rem;
}
.nav-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 0;
  color: var(--muted);
  transition: all 0.15s;
  border-left: 2px solid transparent;
}
.nav-item:hover, .nav-item.active {
  color: var(--fg);
  background: var(--surface2);
  border-left-color: var(--fg);
}
.nav-item svg { flex-shrink: 0; opacity: 0.6; }
.nav-item.active svg, .nav-item:hover svg { opacity: 1; }

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}
.user-chip {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem;
  border-radius: 8px;
  background: var(--surface2);
}
.user-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name  { font-weight: 600; font-size: 0.8rem; truncate: ellipsis; white-space: nowrap; overflow: hidden; }
.user-plan  { font-size: 0.65rem; color: var(--muted); text-transform: uppercase; }

/* ── MAIN CONTENT ── */
.main-content {
  margin-left: 240px;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky; top: 0;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex; align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  z-index: 50;
}
.topbar-title { font-weight: 600; font-size: 0.95rem; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--fg);
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--surface2); }

.page-body { flex: 1; padding: 2rem 1.5rem; }

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.card:hover { box-shadow: var(--shadow); }
.card-title { font-weight: 700; font-size: 1rem; margin-bottom: 0.25rem; }
.card-sub   { font-size: 0.8rem; color: var(--muted); }

/* ── GRID ── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary { background: var(--fg); color: var(--bg); }
.btn-primary:hover { opacity: 0.85; }
.btn-secondary { background: var(--surface2); color: var(--fg); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface); }
.btn-ghost { background: transparent; color: var(--fg); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface); }
.btn-sm { padding: 0.4rem 0.875rem; font-size: 0.8rem; }
.btn-lg { padding: 0.875rem 1.75rem; font-size: 1rem; }

/* ── FORMS ── */
.form-group { margin-bottom: 1.25rem; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: border-color 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--fg);
}
.form-textarea { resize: vertical; min-height: 100px; }
.form-select { cursor: pointer; }
.form-hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.3rem; }

/* ── BADGE ── */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.badge-active   { background: #d4f0d4; color: #1a7a1a; }
.badge-draft    { background: var(--surface2); color: var(--muted); }
.badge-inactive { background: #f0d4d4; color: #7a1a1a; }

[data-theme="dark"] .badge-active   { background: #0d2e0d; color: #4caf50; }
[data-theme="dark"] .badge-draft    { background: #222; color: #888; }
[data-theme="dark"] .badge-inactive { background: #2e0d0d; color: #ef5350; }

/* ── iON NODE VISUAL ── */
.ion-node {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  position: relative;
  flex-shrink: 0;
  transition: all 0.2s;
}
.ion-node.active { animation: ion-pulse 2s ease-in-out infinite; }
@keyframes ion-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(0,0,0,0.1); }
  50%      { box-shadow: 0 0 0 10px rgba(0,0,0,0); }
}
[data-theme="dark"] .ion-node.active {
  animation: ion-pulse-dark 2s ease-in-out infinite;
}
@keyframes ion-pulse-dark {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.1); }
  50%      { box-shadow: 0 0 0 10px rgba(255,255,255,0); }
}

/* ── ION CARD ── */
.ion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: all 0.2s;
}
.ion-card:hover {
  border-color: var(--fg);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.ion-card-header { display: flex; align-items: center; gap: 0.75rem; }
.ion-card-name { font-weight: 700; font-size: 0.95rem; }
.ion-card-license {
  font-size: 0.65rem;
  font-family: 'Courier New', monospace;
  color: var(--muted);
  padding: 0.15rem 0.4rem;
  background: var(--surface2);
  border-radius: 4px;
  word-break: break-all;
}
.ion-card-fn  { font-size: 0.82rem; color: var(--muted); line-height: 1.5; }
.ion-card-footer { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* ── FREQUENCY DOT ── */
.freq-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── CHAT ── */
.chat-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.chat-bubble {
  max-width: 70%;
  padding: 0.875rem 1.1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.55;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--fg);
  color: var(--bg);
  border-bottom-right-radius: 4px;
}
.chat-bubble.ion {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-meta { font-size: 0.7rem; color: var(--muted); margin-bottom: 0.25rem; }
.chat-input-bar {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  background: var(--bg);
}
.chat-input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--fg);
  font-family: var(--font);
  font-size: 0.9rem;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
}
.chat-input:focus { outline: none; border-color: var(--fg); }

/* ── LOADING / SPINNER ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.3; }
.empty-state h3   { font-size: 1rem; font-weight: 600; color: var(--fg); margin-bottom: 0.5rem; }
.empty-state p    { font-size: 0.875rem; }

/* ── TABS ── */
.tabs { display: flex; border-bottom: 1px solid var(--border); gap: 0; }
.tab-btn {
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
  cursor: pointer;
}
.tab-btn.active, .tab-btn:hover { color: var(--fg); border-bottom-color: var(--fg); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: none; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.modal-overlay.open { display: flex; }
.modal {
  width: 100%; max-width: 600px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700;
}
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex; gap: 0.75rem; justify-content: flex-end;
}

/* ── BUILD PIPELINE ── */
.pipeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.pipeline-step {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 0;
  position: relative;
}
.pipeline-step:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 18px;
  top: 52px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.step-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  background: var(--surface);
  position: relative;
  z-index: 1;
}
.step-icon.done    { border-color: #22c55e; background: #d4f0d4; }
.step-icon.running { border-color: var(--fg); animation: ion-pulse 1.5s infinite; }
.step-icon.error   { border-color: #ef4444; background: #f0d4d4; }
[data-theme="dark"] .step-icon.done  { background: #0d2e0d; }
[data-theme="dark"] .step-icon.error { background: #2e0d0d; }
.step-body { flex: 1; }
.step-name   { font-weight: 600; font-size: 0.9rem; }
.step-agent  { font-size: 0.75rem; color: var(--muted); }
.step-output { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; font-style: italic; }

/* ── STATS BAR ── */
.stat-block { text-align: center; padding: 1rem; }
.stat-num  { font-size: 2rem; font-weight: 700; letter-spacing: -0.04em; }
.stat-lbl  { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* ── RESPONSIVE ── */
.mobile-menu-btn { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .mobile-menu-btn { display: flex; }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-body { padding: 1rem; }
  .chat-bubble { max-width: 90%; }
}

/* ── UTILITIES ── */
.flex   { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }
.mb-3  { margin-bottom: 1.5rem; }
.mt-2  { margin-top: 1rem; }
.mt-3  { margin-top: 1.5rem; }
.text-muted { color: var(--muted); }
.text-sm    { font-size: 0.8rem; }
.text-xs    { font-size: 0.7rem; }
.font-mono  { font-family: 'Courier New', monospace; }
.truncate   { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-full     { width: 100%; }

/* ── ALERT ── */
.alert {
  padding: 0.875rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  border: 1px solid;
  margin-bottom: 1rem;
}
.alert-success { border-color: #22c55e; background: #d4f0d4; color: #166534; }
.alert-error   { border-color: #ef4444; background: #f0d4d4; color: #7f1d1d; }
[data-theme="dark"] .alert-success { background: #0d2e0d; color: #4ade80; }
[data-theme="dark"] .alert-error   { background: #2e0d0d; color: #f87171; }

/* ── PWA INSTALL BANNER ── */
#pwa-install {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--fg); color: var(--bg);
  padding: 0.875rem 1.25rem;
  border-radius: 12px;
  display: none;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 300;
}
#pwa-install.show { display: flex; }
