/* shell.css — Production PWA Экосистема */
@import url('https://fonts.googleapis.com/css2?family=Onest:wght@300;400;500;600;700&display=swap');

:root {
  --bg:        #0a0d14;
  --bg-2:      #111520;
  --bg-3:      #181d2e;
  --bg-4:      #1e2438;
  --accent:    #3b7eff;
  --accent-2:  #6c3bff;
  --accent-glow: rgba(59,126,255,0.25);
  --green:     #22c55e;
  --red:       #ef4444;
  --amber:     #f59e0b;
  --text:      #e2e8f8;
  --text-2:    #a0aec8;
  --text-3:    #5a6480;
  --border:    rgba(255,255,255,0.06);
  --border-2:  rgba(255,255,255,0.1);
  --radius:    16px;
  --radius-sm: 10px;
  --shadow:    0 8px 40px rgba(0,0,0,0.5);
  --shadow-sm: 0 2px 12px rgba(0,0,0,0.3);
  --sidebar-w: 260px;
  --header-h:  56px;
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
  --font: 'Onest', -apple-system, 'SF Pro Text', sans-serif;
}

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

html { height: 100%; }
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ═══════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════ */
#sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
#sidebar-overlay.active { opacity: 1; pointer-events: all; }

#sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  z-index: 300;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
}
#sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 16px 12px 16px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 600; color: var(--text);
}
.logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-icon svg { width: 16px; height: 16px; color: white; }

.sidebar-nav {
  flex: 1; overflow-y: auto;
  padding: 8px 8px;
}
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 2px; }

.nav-section-label {
  font-size: 10px; font-weight: 600;
  color: var(--text-3); letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 12px 8px 4px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px;
  background: transparent; border: none;
  border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px;
  font-family: var(--font); font-weight: 400;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left; position: relative;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active {
  background: rgba(59,126,255,0.12);
  color: var(--accent);
  font-weight: 500;
}
.nav-item.active svg { stroke: var(--accent); }

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: white; font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
}
.nav-badge:empty { display: none; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: calc(12px + var(--safe-bottom));
}

.connection-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-3);
  padding: 4px 0 8px;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3);
  transition: background 0.3s;
  flex-shrink: 0;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.error { background: var(--red); }

.install-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 12px;
  background: rgba(59,126,255,0.1);
  border: 1px solid rgba(59,126,255,0.2);
  border-radius: var(--radius-sm);
  color: var(--accent); font-size: 12.5px;
  font-family: var(--font); cursor: pointer;
  transition: background 0.2s;
}
.install-btn svg { width: 15px; height: 15px; }
.install-btn:hover { background: rgba(59,126,255,0.18); }

/* ═══════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════ */
#app-shell {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  max-width: 800px; margin: 0 auto;
  background: var(--bg);
}

/* ─── Header ─────────────────────────────── */
#app-header {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 12px;
  height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 8px; }
.header-right { display: flex; align-items: center; gap: 2px; }

.app-info { display: flex; flex-direction: column; gap: 1px; }
.app-name { font-size: 15px; font-weight: 600; line-height: 1.2; }
.app-status { font-size: 11px; color: var(--text-3); }
.app-status.online { color: var(--green); }

.icon-btn {
  width: 38px; height: 38px;
  background: transparent; border: none;
  border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

/* ─── Content area ───────────────────────── */
#content-area {
  flex: 1; overflow: hidden;
  position: relative; display: flex; flex-direction: column;
}

.view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.view.active { display: flex; }

/* ─── Messages ───────────────────────────── */
#app-messages {
  flex: 1; overflow-y: auto;
  padding: 16px 14px;
  display: flex; flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
#app-messages::-webkit-scrollbar { width: 3px; }
#app-messages::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 2px; }

/* Messages */
.msg { display: flex; animation: msgIn 0.2s ease; }
.msg-user { justify-content: flex-end; }
.msg-bot  { justify-content: flex-start; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px; line-height: 1.6;
  word-break: break-word;
}
.msg-user .msg-bubble {
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 12px rgba(59,126,255,0.3);
}
.msg-bot .msg-bubble {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-bottom-left-radius: 4px;
}
.msg-bubble strong { font-weight: 600; }
.msg-bubble em { font-style: italic; opacity: 0.85; }
.msg-bubble code {
  background: var(--bg-4); border-radius: 4px;
  padding: 1px 5px; font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.msg-edited { opacity: 0.85; }

/* Typing */
.msg-typing .msg-bubble {
  display: flex; gap: 4px; align-items: center;
  padding: 13px 16px;
}
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-3);
  animation: tdot 1.3s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes tdot {
  0%,60%,100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* System message */
.msg-system {
  text-align: center; font-size: 11.5px;
  color: var(--text-3); padding: 2px 0;
  animation: msgIn 0.2s ease;
}

/* ─── Module slot ────────────────────────── */
#module-slot {
  flex-shrink: 0;
  max-height: 55vh;
  overflow-y: auto;
  padding: 0 14px;
}
#module-slot:empty { display: none; }

/* ─── Hints ──────────────────────────────── */
#hints-bar {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px 14px 8px;
  flex-shrink: 0;
}
.hint-btn {
  background: var(--bg-3);
  color: var(--accent);
  border: 1px solid rgba(59,126,255,0.2);
  border-radius: 20px;
  padding: 5px 13px; font-size: 12.5px;
  font-family: var(--font);
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.hint-btn:hover {
  background: rgba(59,126,255,0.12);
  border-color: rgba(59,126,255,0.4);
}

/* ─── Input area ─────────────────────────── */
#app-input-area {
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-toolbar {
  display: flex; gap: 4px;
  padding-bottom: 6px;
}

.tool-btn {
  width: 32px; height: 32px;
  background: transparent; border: none;
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  transition: background 0.15s, color 0.15s;
}
.tool-btn:hover { background: var(--bg-3); color: var(--text-2); }
.tool-btn svg { width: 17px; height: 17px; }

.input-wrapper {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: 20px;
  padding: 8px 8px 8px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrapper:focus-within {
  border-color: rgba(59,126,255,0.4);
  box-shadow: 0 0 0 3px rgba(59,126,255,0.08);
}

#app-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 14px; line-height: 1.5;
  resize: none; max-height: 120px;
  font-family: var(--font);
}
#app-input::placeholder { color: var(--text-3); }

.voice-btn {
  width: 34px; height: 34px;
  background: transparent; border: none;
  border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3); flex-shrink: 0;
  transition: color 0.2s, background 0.2s;
}
.voice-btn:hover { color: var(--accent); background: rgba(59,126,255,0.1); }
#toggle-voice.on { color: var(--accent); background: rgba(59,126,255,0.15); opacity: 1 !important; }
#toggle-voice { transition: all 0.2s; }
.voice-btn.recording {
  color: var(--red);
  background: rgba(239,68,68,0.15);
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
.voice-btn svg { width: 18px; height: 18px; }

.send-btn {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), #2563eb);
  border: none; border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 2px 10px rgba(59,126,255,0.4);
}
.send-btn:hover { opacity: 0.9; box-shadow: 0 4px 16px rgba(59,126,255,0.5); }
.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { background: var(--bg-4); box-shadow: none; cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; color: white; margin-left: 1px; }

/* ─── Banners ─────────────────────────────── */
#update-banner, #offline-banner {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: 12px; padding: 10px 16px;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; box-shadow: var(--shadow-sm);
  z-index: 500; white-space: nowrap;
}
#update-banner[hidden], #offline-banner[hidden] { display: none; }
#btn-update {
  background: var(--accent); color: white;
  border: none; border-radius: 7px;
  padding: 4px 12px; cursor: pointer;
  font-size: 12.5px; font-family: var(--font);
}

/* ═══════════════════════════════════════════
   DYNAMIC VIEWS
═══════════════════════════════════════════ */

/* History view */
.history-view { padding: 16px; overflow-y: auto; }
.history-day { margin-bottom: 20px; }
.history-day-label {
  font-size: 11px; font-weight: 600;
  color: var(--text-3); text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0 0 8px;
}
.history-item {
  display: flex; gap: 10px; padding: 10px 12px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 6px;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.history-item:hover { background: var(--bg-3); border-color: var(--border-2); }
.history-item-text { flex: 1; font-size: 13.5px; color: var(--text-2); line-height: 1.4; }
.history-item-time { font-size: 11px; color: var(--text-3); white-space: nowrap; }

/* News / Articles view */
.feed-view { padding: 12px; overflow-y: auto; gap: 10px; display: flex; flex-direction: column; }
.feed-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
}
.feed-card:hover { border-color: var(--border-2); transform: translateY(-1px); }
.feed-card-img { width: 100%; height: 160px; object-fit: cover; background: var(--bg-3); }
.feed-card-body { padding: 12px 14px; }
.feed-card-source { font-size: 11px; color: var(--accent); font-weight: 500; margin-bottom: 4px; }
.feed-card-title { font-size: 14px; font-weight: 600; line-height: 1.4; margin-bottom: 6px; }
.feed-card-desc { font-size: 12.5px; color: var(--text-2); line-height: 1.5; }
.feed-card-meta { display: flex; gap: 12px; margin-top: 8px; }
.feed-card-time { font-size: 11px; color: var(--text-3); }

/* Mini apps grid */
.miniapps-view { padding: 16px; overflow-y: auto; }
.miniapps-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.miniapp-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 16px 8px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: center;
}
.miniapp-item:hover { background: var(--bg-3); border-color: var(--border-2); }
.miniapp-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.miniapp-name { font-size: 12px; color: var(--text-2); font-weight: 500; }

/* Iframe mini app */
.miniapp-frame-wrap {
  position: absolute; inset: 0;
  background: var(--bg); z-index: 10;
  display: flex; flex-direction: column;
}
.miniapp-frame-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.miniapp-frame-title { flex: 1; font-size: 14px; font-weight: 600; }
.miniapp-frame-wrap iframe {
  flex: 1; border: none; background: white;
}

/* Settings / Profile view */
.settings-view { padding: 16px; overflow-y: auto; }
.settings-section { margin-bottom: 24px; }
.settings-section-title {
  font-size: 12px; font-weight: 600;
  color: var(--text-3); text-transform: uppercase;
  letter-spacing: 0.06em; margin-bottom: 8px;
}
.settings-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 6px;
}
.settings-item-label { font-size: 13.5px; }
.settings-item-value { font-size: 12.5px; color: var(--text-3); }
.toggle {
  width: 44px; height: 24px;
  background: var(--bg-4); border-radius: 12px;
  border: none; cursor: pointer; position: relative;
  transition: background 0.2s;
}
.toggle::after {
  content: ''; position: absolute;
  width: 18px; height: 18px; background: white;
  border-radius: 50%; top: 3px; left: 3px;
  transition: transform 0.2s;
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(20px); }

/* ═══════════════════════════════════════════
   ANIMATIONS & UTILS
═══════════════════════════════════════════ */
.fade-in { animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.slide-up { animation: slideUp 0.3s cubic-bezier(0.4,0,0.2,1); }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════
   DESKTOP (768px+)
═══════════════════════════════════════════ */
@media (min-width: 768px) {
  #app-shell {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

@media (min-width: 1024px) {
  /* Sidebar always open on desktop */
  #sidebar {
    transform: translateX(0);
    position: fixed;
    top: 0; bottom: 0; left: calc(50% - 400px);
  }
  #sidebar-overlay { display: none !important; }
  #app-shell {
    left: calc(50% - 400px + var(--sidebar-w));
    right: calc(50% - 400px);
    position: fixed; top: 0; bottom: 0;
    max-width: none;
    border-left: none;
    margin: 0;
  }
  #btn-sidebar-close { display: none; }
}

/* ═══════════════════════════════════════════
   TELEGRAM THEME SUPPORT
═══════════════════════════════════════════ */
body.tg-theme {
  --bg: var(--tg-theme-bg-color, #0a0d14);
  --bg-2: var(--tg-theme-secondary-bg-color, #111520);
  --text: var(--tg-theme-text-color, #e2e8f8);
  --accent: var(--tg-theme-button-color, #3b7eff);
}

/* ═══════════════════════════════════════════
   SCROLLBAR (global)
═══════════════════════════════════════════ */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 2px; }
