/* Tot Bot Cabinet (my.tot-bot.ru) — Telegram-like layout */

@font-face { font-family: Manrope; font-weight: 400; font-style: normal; font-display: swap;
  src: url('fonts/manrope-cyrillic-400-normal.woff2') format('woff2'),
       url('fonts/manrope-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: Manrope; font-weight: 500; font-style: normal; font-display: swap;
  src: url('fonts/manrope-cyrillic-500-normal.woff2') format('woff2'),
       url('fonts/manrope-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: Manrope; font-weight: 600; font-style: normal; font-display: swap;
  src: url('fonts/manrope-cyrillic-600-normal.woff2') format('woff2'),
       url('fonts/manrope-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: Manrope; font-weight: 700; font-style: normal; font-display: swap;
  src: url('fonts/manrope-cyrillic-700-normal.woff2') format('woff2'),
       url('fonts/manrope-latin-700-normal.woff2') format('woff2'); }

/* 17.04: переведено с light на DARK (основная тема Tot Bot) */
:root {
  --bg-page: #0A0F2C;
  --bg-card: #151D42;
  --bg-card-alt: #0E1538;
  --bg-accent-soft: rgba(245,130,32,0.08);
  --text: #F1F5F9;
  --text-secondary: #94A3B8;
  /* BROW-04: lightened for 4.7:1 contrast */
  --text-muted: #94A3B8;
  --brand-orange: #F58220;
  --brand-orange-hover: #E0710A;
  /* BROW-03: darker orange for 4.5:1 contrast with white */
  --brand-orange-dark: #C75F1C;
  --brand-blue: #5B85E8;
  --border: #1C2650;
  --border-subtle: #151D42;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;
}
/* Dark-тема: white background -> dark */
.btn--ghost { background: #1C2650 !important; color: var(--text) !important; }
.auth-screen { background: linear-gradient(135deg, #0E1538 0%, #0A0F2C 100%) !important; }
.auth-card { background: var(--bg-card) !important; border-color: var(--border) !important; box-shadow: 0 12px 40px rgba(0,0,0,0.5) !important; }
.auth-card h1, .auth-card__logo { color: var(--text) !important; }
.auth-card__sub { color: var(--text-secondary) !important; }
.auth-tabs, .sidebar__search input, .auth-field input { background: var(--bg-card-alt) !important; color: var(--text) !important; border-color: var(--border) !important; }
.auth-tab.active { background: var(--bg-card) !important; color: var(--text) !important; box-shadow: 0 1px 3px rgba(0,0,0,0.3) !important; }
/* input на focus НЕ становится белым (был bug: при клике текст белый на белом фоне) */
.auth-field input:focus, .sidebar__search input:focus { background: var(--bg-card-alt) !important; color: var(--text) !important; border-color: var(--brand-orange) !important; }
/* Chat-input в main.js (внутри заказа) тоже может иметь этот bug */
.chat-input-wrap input, .chat-input-wrap textarea, .form-input, input[type="text"], input[type="email"], textarea, select {
  background: var(--bg-card-alt) !important; color: var(--text) !important; border-color: var(--border) !important;
}
.chat-input-wrap input:focus, .chat-input-wrap textarea:focus, input:focus, textarea:focus, select:focus {
  background: var(--bg-card-alt) !important; color: var(--text) !important; border-color: var(--brand-orange) !important;
}
.cabinet-top, .sidebar, .chat-input-wrap, .order-view__head { background: var(--bg-card) !important; }
.order-view__stage { background: var(--bg-card-alt) !important; }
.chat-msg--assistant, .chat-msg--bot { background: var(--bg-card-alt) !important; color: var(--text) !important; border-color: var(--border) !important; }
.order-view__gen-bar { background: var(--border) !important; }
.main { background: var(--bg-page) !important; }
input, select, textarea { color: var(--text) !important; }
.cabinet-top__logout:hover, .order-item:hover { background: var(--bg-card-alt) !important; color: var(--text) !important; }
.order-item.active { background: var(--bg-accent-soft) !important; }
.form-payment-info { background: rgba(245,130,32,0.08) !important; border-color: rgba(245,130,32,0.25) !important; }

*, *::before, *::after { box-sizing: border-box; }
html {
  /* BROW-01 */
  -webkit-text-size-adjust: 100%;
  /* BROW-05 */
  color-scheme: dark;
}
html, body { height: 100%; }

/* BROW-01: all form inputs ≥16px (iOS Safari no-zoom) */
input, textarea, select { font-size: 16px; }

/* BROW-02: prefer dynamic viewport for full-screen cabinet layouts */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}
body {
  margin: 0;
  font-family: Manrope, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg-page);
  line-height: 1.5;
}
a { color: var(--brand-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--r-md); border: none;
  font-size: 1rem; font-weight: 600; line-height: 1;
  transition: background 0.18s, transform 0.12s;
}
.btn:active { transform: scale(0.98); }
.btn--primary { background: var(--brand-orange); color: #fff; }
.btn--primary:hover { background: var(--brand-orange-hover); }
.btn--primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--dark { background: #111418; color: #fff; }
.btn--dark:hover { background: #1F242B; }
.btn--ghost { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn--ghost:hover { border-color: var(--text); }
.btn--full { width: 100%; }
.btn--sm { padding: 8px 16px; font-size: 0.88rem; }

/* ═══ AUTH SCREEN ═══ */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #FFF3EA 0%, #EFF1F4 100%);
}
.auth-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 40px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 12px 40px rgba(15,20,25,0.08);
}
.auth-card__logo {
  font-size: 1.5rem; font-weight: 800; margin-bottom: 20px; letter-spacing: -0.02em;
}
.auth-card__logo span { color: var(--brand-orange); }
.auth-card h1 { margin: 0 0 6px; font-size: 1.4rem; letter-spacing: -0.01em; }
.auth-card__sub { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 22px; }
.auth-tabs {
  display: flex; gap: 4px; padding: 4px;
  background: var(--bg-card-alt); border-radius: var(--r-md);
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1; padding: 10px; background: transparent; border: none;
  border-radius: var(--r-sm); font-size: 0.88rem; font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.auth-tab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.auth-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.auth-field span { font-size: 0.85rem; color: var(--text-secondary); font-weight: 500; }
.auth-field input {
  padding: 11px 14px;
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 1rem; font-family: inherit;
  outline: none;
}
.auth-field input:focus { border-color: var(--brand-orange); background: #fff; }
.auth-consent {
  display: flex; gap: 10px;
  font-size: 0.78rem; color: var(--text-secondary);
  margin-bottom: 16px; line-height: 1.5;
  cursor: pointer;
}
.auth-consent input { margin-top: 2px; accent-color: var(--brand-orange); flex-shrink: 0; }
.auth-info {
  font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 16px;
  background: var(--bg-accent-soft); padding: 14px;
  border-radius: var(--r-md); border: 1px solid rgba(245,130,32,0.2);
}
.auth-status {
  margin: 10px 0 0; font-size: 0.85rem; text-align: center; display: none;
}
.auth-card__hint {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

/* ═══ CABINET LAYOUT ═══ */
.cabinet {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.cabinet-top {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.cabinet-top__logo { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; }
.cabinet-top__logo span { color: var(--brand-orange); }
.cabinet-top__user { display: flex; align-items: center; gap: 12px; }
.cabinet-top__email {
  font-size: 0.88rem; color: var(--text-secondary);
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cabinet-top__logout {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 0.82rem;
  color: var(--text-secondary);
}
.cabinet-top__logout:hover { background: var(--bg-card-alt); color: var(--text); }

.cabinet-body {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar__head {
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}
.sidebar__title { font-weight: 700; font-size: 1.05rem; }
.sidebar__new {
  font-size: 0.85rem; color: var(--brand-orange); font-weight: 600;
}
.sidebar__search { padding: 8px 12px; border-bottom: 1px solid var(--border-subtle); }
.sidebar__search input {
  width: 100%; padding: 8px 12px;
  background: var(--bg-card-alt); border: 1px solid var(--border);
  border-radius: var(--r-md); font-family: inherit; font-size: 0.88rem;
  outline: none;
}
.sidebar__search input:focus { border-color: var(--brand-orange); background: #fff; }
.sidebar__list { flex: 1; overflow-y: auto; }
.sidebar__empty {
  padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 0.88rem;
}

.order-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background 0.12s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.order-item:hover { background: var(--bg-card-alt); }
.order-item.active { background: var(--bg-accent-soft); border-left: 3px solid var(--brand-orange); padding-left: 13px; }
.order-item__top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.order-item__id { font-weight: 700; font-size: 0.88rem; }
.order-item__badge {
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}
.order-item__badge--active { background: rgba(245,130,32,0.15); color: var(--brand-orange); }
.order-item__badge--done { background: rgba(16,129,72,0.15); color: #0A8148; }
.order-item__badge--other { background: var(--bg-card-alt); color: var(--text-muted); }
.order-item__topic {
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.order-item__meta {
  font-size: 0.72rem; color: var(--text-muted);
  display: flex; gap: 8px; align-items: center;
}

/* Main panel */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-page);
}
.main__empty {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-muted);
}
.main__empty-icon { font-size: 4rem; opacity: 0.4; margin-bottom: 10px; }

.order-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.order-view__head {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  flex-shrink: 0;
}
.order-view__top-row {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  margin-bottom: 10px;
}
.order-view__title-wrap { flex: 1; min-width: 0; }
.order-view__id { font-size: 0.82rem; color: var(--text-muted); font-weight: 600; letter-spacing: 0.04em; }
.order-view__title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 4px 0 0;
}
.order-view__status-badge {
  padding: 6px 12px; border-radius: var(--r-full);
  font-size: 0.78rem; font-weight: 700; flex-shrink: 0;
}
.order-view__progress {
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  margin-top: 10px;
  display: grid;
  gap: 8px;
}
.order-view__stages {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
}
.order-view__stage {
  flex: 1;
  padding: 6px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  text-align: center;
  font-weight: 500;
  color: var(--text-muted);
}
.order-view__stage--done {
  background: #D4F0E0; border-color: #A8E5C2; color: #0A6843;
}
.order-view__stage--current {
  background: var(--brand-orange); border-color: var(--brand-orange); color: #fff; font-weight: 700;
}
.order-view__gen-bar {
  height: 6px; background: var(--border); border-radius: 3px; overflow: hidden;
}
.order-view__gen-bar-fill {
  height: 100%; background: var(--brand-orange); transition: width 0.4s;
}
.order-view__gen-status {
  font-size: 0.85rem; color: var(--text-secondary);
  display: flex; justify-content: space-between; align-items: center;
}
.order-view__pay-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.order-view__download {
  margin-top: 12px;
}

/* Chat area */
.chat-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--bg-page);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--r-lg);
  font-size: 0.92rem;
  line-height: 1.55;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.chat-msg--user {
  align-self: flex-end;
  background: var(--brand-orange);
  color: #fff;
  border-bottom-right-radius: var(--r-sm);
}
.chat-msg--assistant, .chat-msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--r-sm);
}
.chat-msg--system {
  align-self: center;
  background: var(--bg-accent-soft);
  border: 1px solid rgba(245,130,32,0.2);
  font-size: 0.82rem;
  color: var(--text-secondary);
  max-width: 90%;
}

.chat-input-wrap {
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}
.chat-input-wrap input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
}
.chat-input-wrap input:focus { border-color: var(--brand-orange); background: #fff; }
.chat-send-btn {
  width: 40px; height: 40px;
  background: var(--brand-orange);
  color: #fff;
  border: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.2rem;
}
.chat-send-btn:disabled { opacity: 0.5; }

/* Mobile */
@media (max-width: 820px) {
  .cabinet-body { grid-template-columns: 1fr; }
  .sidebar { display: block; }
  .sidebar.hidden-mobile { display: none; }
  .main.hidden-mobile { display: none; }
  .order-view__head { padding: 12px 16px; }
  .chat-wrap { padding: 14px 16px; }
}

/* Toast */
#global-toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #111418; color: #fff;
  padding: 12px 20px; border-radius: var(--r-md);
  font-size: 0.88rem; z-index: 9999;
  opacity: 0; transition: opacity 0.2s;
  pointer-events: none; max-width: 90vw;
}

/* Auth-screen + form core */
.auth-form { display: flex; flex-direction: column; }

.sidebar__referral {
  display: block;
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  background: linear-gradient(135deg, rgba(245,130,32,0.12), rgba(245,130,32,0.04));
  text-decoration: none !important;
  transition: background 0.15s;
  flex-shrink: 0;
}
.sidebar__referral:hover { background: rgba(245,130,32,0.18); }
.sidebar__referral-title {
  color: var(--brand-orange);
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 4px;
}
.sidebar__referral-sub {
  color: var(--text-secondary);
  font-size: 0.76rem;
  line-height: 1.4;
}

/* BROW-M04: prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* BROW-M07: ≥44×44 tap targets on touch */
@media (hover: none) and (pointer: coarse) {
  .auth-tab, .auth-btn, .btn, button, .sidebar__item, .sidebar__referral {
    min-height: 44px;
  }
}

/* BROW-M09: iPhone safe-area */
@supports (padding: env(safe-area-inset-top)) {
  .sidebar, header, .auth-screen {
    padding-top: env(safe-area-inset-top);
  }
  .auth-screen {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* BROW-M10: backdrop-filter fallback */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .modal, .glass, .sidebar {
    background-color: rgba(10, 15, 44, 0.95) !important;
  }
}

@media print {
  .sidebar, .auth-screen, .modal, button {
    display: none !important;
  }
  body { background: #fff !important; color: #000 !important; }
}
