/* ============================================================
   common.css — Design System / Crypto Arbitrage Telegram WebApp
   Etalon: index.html (pd11), card-v6.html, add_api_key.html
   ============================================================ */

/* ── 1. CSS Custom Properties (Design Tokens) ──────────────── */

:root {
  /* Semantic colors */
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --color-warning: #d97706;
  --color-accent: var(--tg-theme-button-color, #0088cc);

  /* Chart colors (Dagger-style trading palette: bull=green, bear=red).
     Используются для свечей, факт./реалтайм линий и кнопок Вход/Выход.
     Отличаются от --color-success/--color-danger более насыщенным оттенком. */
  --color-bull: #26a69a;
  --color-bear: #ef5350;
  --color-bull-faint: rgba(38, 166, 154, 0.12);
  --color-bear-faint: rgba(239, 83, 80, 0.12);

  /* Палитра 4 ролей графика спреда (s1t3q-b ext 10в, ревизия после ручной проверки).
     Live (Вход/Выход) = классические bull/bear для интуитивного восприятия.
     Факт. = ярче чем Live чтобы статичные линии визуально выделялись. */
  --color-entry-live: #26a69a;        /* зелёный bull (как свечи) */
  --color-entry-fact: #84e635;        /* салатовый — ярче чем live, чтобы факт. выделялся */
  --color-exit-live:  #ef5350;        /* красный bear */
  --color-exit-fact:  #ff7043;        /* оранжевый */
  --color-entry-live-faint: rgba(38, 166, 154, 0.18);
  --color-entry-fact-faint: rgba(132, 230, 53, 0.22);
  --color-exit-live-faint:  rgba(239, 83, 80, 0.18);
  --color-exit-fact-faint:  rgba(255, 112, 67, 0.22);

  /* Backgrounds */
  --bg-primary: var(--tg-theme-bg-color, #ffffff);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #f5f5f5);

  /* Text */
  --text-primary: var(--tg-theme-text-color, #000000);
  --text-secondary: #64748b;
  --text-hint: var(--tg-theme-hint-color, #999);

  /* Border */
  --border-light: rgba(0, 0, 0, 0.08);
  --border-divider: rgba(0, 0, 0, 0.06);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;

  /* Font stack */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* ── 2. Reset ──────────────────────────────────────────────── */

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

/* ── 3. Body ───────────────────────────────────────────────── */

body {
  font-family: var(--font-family);
  background: var(--bg-secondary);
  color: var(--text-primary);
  min-height: 100vh;
  padding-bottom: 80px;
}

/* ── 4. Container ──────────────────────────────────────────── */

.container {
  max-width: 500px;
  margin: 0 auto;
  padding: 16px 12px;
}

@media (min-width: 768px) {
  .container {
    padding: 20px;
  }
}

/* ── 5. Page Header ────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-top: 8px;
}

.page-title {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── 6. Bottom Navigation ──────────────────────────────────── */

.nav-tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-light);
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.nav-tab {
  flex: 1;
  padding: 8px 10px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  background: transparent;
  color: var(--text-hint);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.nav-tab.active {
  background: var(--color-accent);
  color: #ffffff;
}

.nav-icon { font-size: 18px; }
.nav-label { font-size: 10px; }

/* ── 7. Card ───────────────────────────────────────────────── */

.card {
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
}

/* ── 8. Buttons ────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s ease;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-accent);
  color: #ffffff;
  width: 100%;
}

.btn-danger {
  background: var(--color-danger);
  color: #ffffff;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-primary);
}

/* ── 9. Chips / Tabs (sort-bar, strategy) ──────────────────── */

.chip {
  flex: 1;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-hint);
  font-family: var(--font-family);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.chip.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.10);
}

.chip:active { opacity: 0.7; }

/* ── 10. Badges ────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  line-height: 1;
}

.badge-green {
  color: var(--color-success);
  background: rgba(22, 163, 74, 0.12);
}

.badge-red {
  color: var(--color-danger);
  background: rgba(220, 38, 38, 0.12);
}

.badge-yellow {
  color: var(--color-warning);
  background: rgba(217, 119, 6, 0.12);
}

/* ── 11. Form Elements ─────────────────────────────────────── */

.input,
.select,
.textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  font-family: var(--font-family);
  border: 1px solid var(--text-hint);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23999' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-accent);
}

.textarea {
  resize: vertical;
  min-height: 80px;
}

@media (max-width: 767px) {
  .input,
  .select,
  .textarea {
    padding: 11px;
    font-size: 15px;
  }
}

/* ── 12. State Indicators ──────────────────────────────────── */

.state-loading {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-hint);
  font-size: 14px;
}

.state-loading::before {
  content: '';
  display: block;
  width: 20px;
  height: 20px;
  margin: 0 auto 8px;
  border: 2px solid rgba(0, 136, 204, 0.2);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: common-spin 0.8s linear infinite;
}

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

.state-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-hint);
  font-size: 14px;
}

.state-error {
  background: rgba(220, 38, 38, 0.08);
  border-left: 3px solid var(--color-danger);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 14px;
  color: var(--color-danger);
  margin-bottom: 20px;
}

.state-success {
  background: rgba(22, 163, 74, 0.08);
  border-left: 3px solid var(--color-success);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 14px;
  color: var(--color-success);
  margin-bottom: 20px;
}

/* ── 13. Page Feedback (toast notifications) ─────────────── */

.page-feedback {
  display: none;
  position: fixed;
  top: 12px;
  left: 16px;
  right: 16px;
  z-index: 9999;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
}

.page-feedback.success {
  background: rgba(22, 163, 74, 0.12);
  color: var(--color-success);
}

.page-feedback.error {
  background: rgba(220, 38, 38, 0.12);
  color: var(--color-danger);
}

/* ── 14. Utility Classes ───────────────────────────────────── */

.text-hint { color: var(--text-hint); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
