/* ── Nyx Web UI — shared styles ──────────────────────────────────────────── */

:root {
  --bg:           #0a0a0c;
  --surface:      #111117;
  --surface-2:    #18181f;
  --surface-hover:#1e1e28;
  --border:       #22222e;
  --border-light: #2a2a3a;
  --accent:       #6d5acd;
  --accent-dim:   #2d2460;
  --accent-hover: #7e6bdc;
  --text:         #e2e2ec;
  --text-muted:   #6a6a88;
  --text-dim:     #44445a;
  --user-bubble:  #1f1840;
  --nyx-bubble:   #141420;
  --success:      #22c55e;
  --error:        #ef4444;
  --warning:      #f59e0b;
  --sidebar-w:    224px;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    14px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Layout ─────────────────────────────────────────────────────────────── */

.nyx-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.nyx-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 4px;
}

.nyx-sidebar__logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.nyx-logo-icon {
  font-size: 22px;
  color: var(--accent);
  line-height: 1;
}

.nyx-logo-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.nyx-sidebar__nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nyx-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}

.nyx-nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nyx-nav-item.active {
  background: var(--accent-dim);
  color: var(--text);
}

.nyx-nav-icon { font-size: 16px; width: 20px; text-align: center; }

.nyx-sidebar__divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.nyx-new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
}

.nyx-new-chat-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--text);
}

.nyx-sidebar__user {
  padding: 10px;
  border-radius: var(--radius-sm);
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 4px;
}

.nyx-user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: block;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nyx-logout-btn {
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: color 0.12s;
}

.nyx-logout-btn:hover { color: var(--error); }

/* ── Main content area ───────────────────────────────────────────────────── */

.nyx-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Chat page ───────────────────────────────────────────────────────────── */

.nyx-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.nyx-chat-header__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.nyx-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-muted);
}

.nyx-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s;
}

.nyx-status-dot.connected  { background: var(--success); }
.nyx-status-dot.connecting { background: var(--warning); animation: pulse 1.2s infinite; }
.nyx-status-dot.error      { background: var(--error); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.nyx-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nyx-messages::-webkit-scrollbar { width: 5px; }
.nyx-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.nyx-msg {
  display: flex;
  padding: 4px 20px;
  max-width: 100%;
}

.nyx-msg--user { justify-content: flex-end; }
.nyx-msg--nyx  { justify-content: flex-start; }

.nyx-msg__bubble {
  max-width: 72%;
  padding: 11px 15px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  line-height: 1.65;
  word-break: break-word;
}

.nyx-msg--user .nyx-msg__bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  color: #d8d0ff;
}

.nyx-msg--nyx .nyx-msg__bubble {
  background: var(--nyx-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.nyx-msg__bubble p { margin: 0 0 8px; }
.nyx-msg__bubble p:last-child { margin-bottom: 0; }
.nyx-msg__bubble pre {
  background: #0d0d12;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 13px;
  margin: 8px 0;
}
.nyx-msg__bubble code { font-family: "SF Mono", "Fira Code", monospace; font-size: 13px; }
.nyx-msg__bubble :not(pre) > code {
  background: rgba(109,90,205,0.15);
  padding: 1px 5px;
  border-radius: 4px;
}
.nyx-msg__bubble ul, .nyx-msg__bubble ol { padding-left: 20px; margin: 6px 0; }
.nyx-msg__bubble li { margin: 3px 0; }
.nyx-msg__bubble strong { font-weight: 600; color: #c8c0f0; }
.nyx-msg--nyx .nyx-msg__bubble strong { color: #b0b0e0; }
.nyx-msg__bubble h1, .nyx-msg__bubble h2, .nyx-msg__bubble h3 {
  font-weight: 600;
  margin: 12px 0 6px;
  color: var(--text);
}

.nyx-tool-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

.nyx-tool-status::before {
  content: '';
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.nyx-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.nyx-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite;
}

.nyx-typing span:nth-child(2) { animation-delay: 0.2s; }
.nyx-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ── Input area ──────────────────────────────────────────────────────────── */

.nyx-input-area {
  flex-shrink: 0;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.nyx-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 8px 10px 8px 14px;
  transition: border-color 0.15s;
}

.nyx-input-row:focus-within { border-color: var(--accent); }

.nyx-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  resize: none;
  max-height: 180px;
  font-family: inherit;
  padding: 4px 0;
}

.nyx-textarea::placeholder { color: var(--text-dim); }

.nyx-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s, background 0.12s;
  flex-shrink: 0;
}

.nyx-icon-btn:hover { color: var(--text); background: var(--surface-hover); }
.nyx-icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.nyx-icon-btn.recording { color: var(--error); animation: pulse 1s infinite; }

.nyx-send-btn {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

.nyx-send-btn:hover { background: var(--accent-hover); color: #fff; }
.nyx-send-btn:disabled { background: var(--surface-2); color: var(--text-dim); }

.nyx-input-hint {
  font-size: 11.5px;
  color: var(--text-dim);
  text-align: center;
  margin-top: 8px;
}

/* ── Login page ──────────────────────────────────────────────────────────── */

.nyx-login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}

.nyx-login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
}

.nyx-login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.nyx-login-logo .nyx-logo-icon { font-size: 40px; display: block; margin-bottom: 10px; }
.nyx-login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.nyx-login-logo p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.nyx-form-group {
  margin-bottom: 16px;
}

.nyx-form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.nyx-form-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  color: var(--text);
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.nyx-form-input:focus { border-color: var(--accent); }
.nyx-form-input::placeholder { color: var(--text-dim); }

.nyx-login-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 13px;
  padding: 10px 13px;
  margin-bottom: 16px;
  display: none;
}

.nyx-login-error.visible { display: block; }

.nyx-btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  font-family: inherit;
}

.nyx-btn-primary:hover { background: var(--accent-hover); }
.nyx-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── History page ────────────────────────────────────────────────────────── */

.nyx-history-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.nyx-history-sidebar {
  width: 300px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.nyx-history-search {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.nyx-history-search input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  font-family: inherit;
}

.nyx-history-search input:focus { border-color: var(--accent); }
.nyx-history-search input::placeholder { color: var(--text-dim); }

.nyx-session-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nyx-session-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.nyx-session-item:hover { background: var(--surface-hover); }
.nyx-session-item.active { background: var(--accent-dim); }

.nyx-session-item__preview {
  font-size: 13.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.nyx-session-item__meta {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
}

.nyx-history-main {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nyx-history-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
}

.nyx-conv-msg {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
}

.nyx-conv-msg--user { align-items: flex-end; }
.nyx-conv-msg--assistant { align-items: flex-start; }

.nyx-conv-msg__label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.nyx-conv-msg__text {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
}

.nyx-conv-msg--user .nyx-conv-msg__text { background: var(--user-bubble); color: #d8d0ff; }
.nyx-conv-msg--assistant .nyx-conv-msg__text { background: var(--nyx-bubble); border: 1px solid var(--border); color: var(--text); }

/* ── Dashboard page ──────────────────────────────────────────────────────── */

.nyx-dashboard-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nyx-dash-header {
  margin-bottom: 24px;
}

.nyx-dash-header h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.nyx-dash-header p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Tab bar ───────────────────────────────────────────────────────────── */

.nyx-tab-bar {
  display: flex;
  gap: 6px;
  margin-top: 16px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: fit-content;
}

.nyx-tab {
  background: transparent;
  border: none;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}
.nyx-tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}
.nyx-tab.active {
  color: var(--text);
  background: var(--accent-dim);
  box-shadow: 0 1px 3px rgba(109,90,205,0.2);
}

.nyx-tab-content { margin-top: 22px; }

/* ── Health cards ──────────────────────────────────────────────────────── */

.nyx-health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.nyx-health-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.nyx-health-card.pass  { border-left: 3px solid var(--success); }
.nyx-health-card.warn  { border-left: 3px solid var(--warning); }
.nyx-health-card.fail  { border-left: 3px solid var(--error); }

.nyx-health-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.nyx-health-card__title { font-size: 14px; font-weight: 600; }
.nyx-health-card__badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 10px;
}
.nyx-health-card__badge.pass  { color: var(--success); background: rgba(34,197,94,0.12); }
.nyx-health-card__badge.warn  { color: var(--warning); background: rgba(245,158,11,0.12); }
.nyx-health-card__badge.fail  { color: var(--error);   background: rgba(239,68,68,0.12); }

.nyx-health-card__items {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.7;
}

/* ── Sortable tables ───────────────────────────────────────────────────── */

.nyx-usage-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}
.nyx-usage-table th[data-sort]:hover { color: var(--text); }
.nyx-usage-table th[data-sort]::after {
  content: ' \2195';
  font-size: 10px;
  opacity: 0.4;
}

/* ── Action cards (optimization proposals) ─────────────────────────────── */

.nyx-action-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.nyx-action-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
}
.nyx-action-card__head {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
}
.nyx-action-card__type {
  font-weight: 600;
  color: var(--text);
}
.nyx-action-card__risk {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: 8px;
}
.nyx-action-card__risk.low      { color: var(--success); background: rgba(34,197,94,0.12); }
.nyx-action-card__risk.medium   { color: var(--warning); background: rgba(245,158,11,0.12); }
.nyx-action-card__risk.high     { color: var(--error);   background: rgba(239,68,68,0.12); }
.nyx-action-card__risk.critical { color: #f43f5e;        background: rgba(244,63,94,0.15); }
.nyx-action-card__target { color: var(--accent); font-size: 12px; }
.nyx-action-card__reason { color: var(--text-muted); margin-top: 4px; line-height: 1.5; }

.nyx-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.nyx-kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.nyx-kpi-card__label {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
  margin-bottom: 6px;
}

.nyx-kpi-card__value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
}

.nyx-chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.nyx-chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.nyx-chart-card__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}

.nyx-usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-top: 4px;
}

.nyx-usage-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}

.nyx-usage-table td {
  padding: 6px 6px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.nyx-usage-table tr:last-child td { border-bottom: none; }

/* ── Loading / error states ─────────────────────────────────────────────── */

.nyx-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

.nyx-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Diagnostics overlay ─────────────────────────────────────────────────── */

.nyx-diag-btn {
  background: none;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.12s;
  font-family: inherit;
}

.nyx-diag-btn:hover { border-color: var(--accent); color: var(--text); }
