/**
 * Omicsboard Lab — web client styles
 * Genomac Holdings | Omicsboard Platform
 *
 * Mobile-first, built fresh for the tab layout (no drag-resize handles, no
 * fixed dual-pane split like desktop's renderer/styles.css). Color tokens
 * are the SAME dark palette the desktop app's own Appearance theme system
 * uses (--bg #0D1117, --panel-bg #161B22, --text #E6EDF3, accent #E8722C)
 * for brand consistency across surfaces.
 */

:root {
  --bg: #0D1117;
  --panel-bg: #161B22;
  --panel-bg-2: #1C2128;
  --border: #30363D;
  --text: #E6EDF3;
  --text-muted: #8B949E;
  --accent: #E8722C;
  --accent-hover: #FF8C42;
  --accent-deep: #B5530F;
  --error: #F85149;
  --success: #3FB950;
  --info: #58A6FF;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.screen {
  height: 100dvh;
  width: 100%;
}

/* The `hidden` attribute must always win over #signin-screen/#app-screen's
   own `display: flex` below — an ID selector otherwise beats the UA
   stylesheet's `[hidden] { display:none }`, so without this override the
   sign-in card stays visible underneath the app screen after sign-in. */
[hidden] {
  display: none !important;
}

/* ───────────────────────── Sign-in screen ───────────────────────── */

#signin-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.signin-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
}

.signin-logo {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}

.signin-sub {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 6px;
  margin-bottom: 22px;
}

.signin-tabs {
  display: flex;
  gap: 4px;
  background: var(--panel-bg-2);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 18px;
}

.signin-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 0;
  border-radius: 6px;
  cursor: pointer;
}

.signin-tab.active {
  background: var(--panel-bg);
  color: var(--text);
}

.signin-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.signin-form input {
  background: var(--panel-bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  outline: none;
  width: 100%;
}

.signin-form input:focus {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  font-weight: 600;
  padding: 12px 0;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 4px;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }

.link-btn {
  background: none;
  border: none;
  color: var(--info);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  align-self: center;
}

.signin-error {
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(248,81,73,0.12);
  border: 1px solid rgba(248,81,73,0.35);
  color: var(--error);
  border-radius: 8px;
  font-size: 13px;
}

/* ───────────────────────── App screen ───────────────────────── */

#app-screen {
  display: flex;
  flex-direction: column;
}

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

.app-header-title {
  font-weight: 700;
  font-size: 15px;
}

.signout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12.5px;
  cursor: pointer;
}

.signout-btn:hover { color: var(--text); border-color: var(--text-muted); }

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 12px 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--text-muted);
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
}

.tab-badge.kind-cell { background: var(--info); color: #fff; }
.tab-badge.kind-running { background: var(--accent); color: #fff; }
.tab-badge.kind-output { background: var(--success); color: #fff; }
.tab-badge.kind-error { background: var(--error); color: #fff; }

.app-main {
  flex: 1;
  min-height: 0;
  position: relative;
}

.view {
  display: none;
  height: 100%;
  flex-direction: column;
}

.view.active {
  display: flex;
}

/* ───────────────────────── Chat view ───────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 88%;
  border-radius: 12px;
  padding: 10px 13px;
  line-height: 1.5;
  font-size: 14.5px;
}

.msg-body p { margin: 0 0 8px 0; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: 4px 0 8px 0; padding-left: 20px; }
.msg-body code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px; font-size: 0.92em; }
.msg-body pre.md-code-block { background: #0A0D12; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 8px 0; }
.msg-body pre.md-code-block code { background: none; padding: 0; }
.msg-body a { color: var(--info); }

.msg-user {
  align-self: flex-end;
  background: var(--accent-deep);
  color: #fff;
}

.msg-assistant {
  align-self: flex-start;
  background: var(--panel-bg);
  border: 1px solid var(--border);
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: flex-end;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.chat-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

.chat-input:focus { border-color: var(--accent); }

.btn-send {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.5; cursor: default; }

/* ───────────────────────── Notebook view ───────────────────────── */

.notebook-cells {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.notebook-empty {
  color: var(--text-muted);
  font-size: 13.5px;
  text-align: center;
  padding: 30px 20px;
}

.cell-section {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-top: 6px;
}

.cell {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.cell-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg-2);
}

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

.cell-status {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.cell-status-idle { background: rgba(139,148,158,0.2); color: var(--text-muted); }
.cell-status-running { background: rgba(232,114,44,0.2); color: var(--accent); }
.cell-status-ok { background: rgba(63,185,80,0.2); color: var(--success); }
.cell-status-error { background: rgba(248,81,73,0.2); color: var(--error); }

.cell-code {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  background: #0A0D12;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
}

.cell-outputs:not(:empty) {
  border-top: 1px solid var(--border);
}

.cell-output {
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.cell-output-stream.cell-output-stderr { color: var(--error); }
.cell-output-image { max-width: 100%; border-radius: 6px; display: block; }
.cell-output-html { overflow-x: auto; }
.cell-output-html table { border-collapse: collapse; font-size: 12px; }
.cell-output-html th, .cell-output-html td { border: 1px solid var(--border); padding: 4px 8px; }
.cell-output-error-title { color: var(--error); font-weight: 700; margin-bottom: 4px; }
.cell-output-traceback { color: var(--text-muted); margin: 0; white-space: pre-wrap; }

/* ───────────────────────── Net status ───────────────────────── */

.net-status {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-bg-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 12.5px;
  color: var(--text-muted);
  z-index: 50;
}

.net-status.error { color: var(--error); border-color: rgba(248,81,73,0.35); }

/* ───────────────────────── Small-phone safety ───────────────────────── */

@media (max-width: 340px) {
  .msg { max-width: 94%; }
  .app-header-title { font-size: 14px; }
}
