/* ── JARVIS Mini App — CSS ─────────────────────────────────────────────────
   Uses Telegram's native theme variables for seamless Telegram integration.
   If opened outside Telegram, falls back to a dark theme.
─────────────────────────────────────────────────────────────────────────── */

:root {
  --tg-bg:           var(--tg-theme-bg-color, #1a1a2e);
  --tg-text:         var(--tg-theme-text-color, #eaeaea);
  --tg-hint:         var(--tg-theme-hint-color, #6b7280);
  --tg-link:         var(--tg-theme-link-color, #60a5fa);
  --tg-button:       var(--tg-theme-button-color, #3b82f6);
  --tg-button-text:  var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #16213e);
  --tg-accent:       var(--tg-theme-accent-text-color, #60a5fa);

  --radius:   12px;
  --gap:      12px;
  --font:     -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono:     'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
}

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

html, body {
  width: 100%; height: 100%;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  overflow-x: hidden;
}

/* ── Layout ── */
#app {
  min-height: 100vh;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ── Loader ── */
.loader-wrap {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 50vh; gap: 16px;
  color: var(--tg-hint);
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--tg-secondary-bg);
  border-top-color: var(--tg-button);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Widgets ── */
.widget {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 16px;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } }

/* Text widget */
.text-widget .text-content {
  font-size: 16px;
  color: var(--tg-text);
  white-space: pre-wrap;
}

/* Markdown widget */
.markdown-widget .md-content {
  font-size: 15px;
  color: var(--tg-text);
}
.markdown-widget h1, .markdown-widget h2, .markdown-widget h3 {
  color: var(--tg-accent);
  margin-bottom: 8px;
}
.markdown-widget code {
  font-family: var(--mono);
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.markdown-widget pre {
  background: rgba(0,0,0,0.3);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  margin: 8px 0;
}
.markdown-widget ul, .markdown-widget ol { padding-left: 20px; }
.markdown-widget li { margin: 4px 0; }
.markdown-widget a { color: var(--tg-link); }

/* Image widget */
.image-widget { text-align: center; }
.image-widget .img-content {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin: 0 auto;
}
.image-widget .img-caption {
  margin-top: 8px;
  font-size: 13px;
  color: var(--tg-hint);
}

/* Chart widget */
.chart-widget .chart-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--tg-accent);
  margin-bottom: 12px;
}
.chart-widget .chart-canvas {
  max-height: 280px;
}

/* Buttons widget */
.buttons-widget .buttons-label {
  font-size: 14px;
  color: var(--tg-hint);
  margin-bottom: 10px;
}
.buttons-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tma-btn {
  padding: 10px 20px;
  background: var(--tg-button);
  color: var(--tg-button-text);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 100px;
  transition: opacity 0.2s, transform 0.1s;
}
.tma-btn:active { opacity: 0.7; transform: scale(0.97); }
.tma-btn.secondary {
  background: transparent;
  border: 1.5px solid var(--tg-button);
  color: var(--tg-button);
}

/* Table widget */
.table-widget .table-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--tg-accent);
  margin-bottom: 10px;
}
.table-scroll { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--tg-hint);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-weight: 600;
  white-space: nowrap;
}
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,0.03); }

/* Status bar */
#status-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--tg-secondary-bg);
  border-top: 1px solid rgba(255,255,255,0.06);
  padding: 6px 16px;
  font-size: 11px;
  color: var(--tg-hint);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
}
#status-bar .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  margin-right: 5px;
}
#status-bar .dot.off { background: #ef4444; }
