/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface-2:   #22263a;
  --surface-3:   #2a2f45;
  --border:      #2e3349;
  --primary:     #6366f1;
  --primary-dk:  #4f52d4;
  --primary-bg:  rgba(99,102,241,.14);
  --primary-txt: #a5b4fc;
  --text-1:      #f0f2ff;
  --text-2:      #9aa0c0;
  --text-3:      #5c6385;
  --danger:      #ef4444;
  --success:     #22c55e;
  --warn:        #f59e0b;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --sidebar-w:   240px;
  --sidebar-collapsed: 0px;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  line-height: 1.55;
  display: flex;
}
a { color: var(--primary-txt); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
img { max-width: 100%; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 1rem; color: var(--text-1);
  text-decoration: none;
}
.sidebar-brand-icon { font-size: 1.4rem; flex-shrink: 0; }
.sidebar-nav {
  flex: 1;
  padding: 10px 10px;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 500; color: var(--text-2);
  transition: background .15s, color .15s;
  text-decoration: none;
}
.nav-link:hover { background: var(--surface-2); color: var(--text-1); text-decoration: none; }
.nav-link.active { background: var(--primary-bg); color: var(--primary-txt); }
.nav-link .nav-icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-link .nav-label { flex: 1; }
.sidebar-footer {
  padding: 14px 14px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-user {
  display: flex; align-items: center; gap: 9px; overflow: hidden;
}
.sidebar-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
}
.sidebar-user-info { flex: 1; overflow: hidden; }
.sidebar-username { font-size: 0.85rem; font-weight: 600; color: var(--text-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-companion { font-size: 0.75rem; color: var(--text-3); }
.btn-logout {
  width: 100%; padding: 7px 12px;
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-3);
  font-size: 0.82rem; text-align: center;
  transition: color .15s, border-color .15s;
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }

/* ── Mobile sidebar overlay ─────────────────────────────────────────────────── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 99;
  background: rgba(0,0,0,.5);
}
.sidebar-overlay.open { display: block; }

/* Mobile hamburger */
.sidebar-toggle {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 101;
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-1); font-size: 1.1rem;
  align-items: center; justify-content: center;
}

/* ── Main content ────────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Page wrapper ────────────────────────────────────────────────────────────── */
.page { padding: 28px 0 48px; flex: 1; }
.container    { max-width: 900px;  margin: 0 auto; padding: 0 24px; }
.container-sm { max-width: 520px;  margin: 0 auto; padding: 0 24px; }
.container-md { max-width: 680px;  margin: 0 auto; padding: 0 24px; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-label { font-size: 0.78rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-1);
  font-size: 0.9rem; transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary); background: var(--bg);
}
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 600; border: none;
  transition: background .15s, transform .1s, opacity .15s;
  cursor: pointer;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); }
.btn-secondary { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.btn-secondary:hover { color: var(--text-1); border-color: var(--text-3); }
.btn-danger    { background: rgba(239,68,68,.15); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-sm  { padding: 5px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }
.badge-success { background: rgba(34,197,94,.15);  color: var(--success); }
.badge-warn    { background: rgba(245,158,11,.15); color: var(--warn); }
.badge-danger  { background: rgba(239,68,68,.15);  color: var(--danger); }
.badge-info    { background: var(--primary-bg);    color: var(--primary-txt); }

/* ── Auth pages ─────────────────────────────────────────────────────────────── */
body.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 36px 32px; box-shadow: var(--shadow);
}
.auth-logo  { text-align: center; font-size: 2.2rem; margin-bottom: 8px; }
.auth-title { text-align: center; font-size: 1.4rem; font-weight: 700; margin-bottom: 4px; }
.auth-sub   { text-align: center; font-size: 0.85rem; color: var(--text-2); margin-bottom: 28px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 0.85rem; color: var(--text-2); }
.auth-tabs { display: flex; gap: 0; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.auth-tab {
  flex: 1; padding: 10px; text-align: center;
  font-size: 0.88rem; font-weight: 600; color: var(--text-3);
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  background: none; border-top: none; border-left: none; border-right: none;
  margin-bottom: -1px;
}
.auth-tab.active { color: var(--primary-txt); border-bottom-color: var(--primary); }

/* ── Alert ─────────────────────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 0.85rem; margin-bottom: 14px; }
.alert-error   { background: rgba(239,68,68,.12); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }
.alert-success { background: rgba(34,197,94,.12);  color: #86efac; border: 1px solid rgba(34,197,94,.3); }

/* ── Telegram Widget ─────────────────────────────────────────────────────────── */
.tg-login-wrap { display: flex; justify-content: center; margin: 4px 0; }

/* ═══════════════════════════════════════════════════════════════════════════
   CHAT — ChatGPT-inspired full-height layout
   ═══════════════════════════════════════════════════════════════════════════ */

/* The chat shell takes the full main-content area */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

/* Slim header row above the messages */
.chat-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.chat-header-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.95rem; font-weight: 600; color: var(--text-1);
}
.chat-header-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2); display: flex; align-items: center;
  justify-content: center; font-size: 1rem; flex-shrink: 0;
}
.chat-status {
  font-size: 0.72rem; color: var(--success);
  display: flex; align-items: center; gap: 5px;
}
.chat-status::before {
  content: ''; display: inline-block;
  width: 6px; height: 6px; border-radius: 50%; background: var(--success);
}

/* Messages scroll area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

/* Individual message row */
.chat-msg {
  padding: 6px 24px;
  display: flex;
  flex-direction: column;
  max-width: 100%;
}
.chat-msg.user  { align-items: flex-end; }
.chat-msg.assistant { align-items: flex-start; }

/* Message content wrapper (holds bubble + meta) */
.chat-msg-inner {
  max-width: min(680px, 78%);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-msg.user .chat-msg-inner  { align-items: flex-end; }
.chat-msg.assistant .chat-msg-inner { align-items: flex-start; }

/* Sender label */
.chat-sender {
  font-size: 0.72rem; font-weight: 600;
  color: var(--text-3); margin-bottom: 2px;
  padding: 0 4px;
}

/* Bubble */
.chat-bubble-text {
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 0.92rem;
  line-height: 1.6;
  word-break: break-word;
  position: relative;
}
.chat-msg.user .chat-bubble-text {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.chat-msg.assistant .chat-bubble-text {
  background: var(--surface-2);
  color: var(--text-1);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--border);
}

/* Markdown-rendered content */
.chat-bubble-text p { margin-bottom: 8px; }
.chat-bubble-text p:last-child { margin-bottom: 0; }
.chat-bubble-text strong { font-weight: 700; }
.chat-bubble-text em { font-style: italic; }
.chat-bubble-text code {
  background: rgba(0,0,0,.25); padding: 1px 5px;
  border-radius: 4px; font-size: 0.85em; font-family: "JetBrains Mono", "Fira Code", monospace;
}
.chat-bubble-text pre {
  background: rgba(0,0,0,.35); padding: 10px 14px;
  border-radius: 8px; overflow-x: auto; margin: 8px 0;
  border: 1px solid rgba(255,255,255,.08);
}
.chat-bubble-text pre code { background: none; padding: 0; font-size: 0.82em; }
.chat-bubble-text ul, .chat-bubble-text ol { padding-left: 20px; margin: 6px 0; }
.chat-bubble-text li { margin-bottom: 2px; }

/* Timestamp + copy row under each bubble */
.chat-meta {
  display: flex; align-items: center; gap: 8px;
  padding: 0 4px;
}
.chat-time {
  font-size: 0.68rem; color: var(--text-3);
}
.btn-copy {
  opacity: 0; font-size: 0.68rem; color: var(--text-3);
  background: none; border: none; padding: 2px 5px;
  border-radius: 4px; transition: opacity .15s, color .15s, background .15s;
  cursor: pointer;
}
.chat-msg:hover .btn-copy { opacity: 1; }
.btn-copy:hover { color: var(--text-1); background: var(--surface-3); }

/* Typing indicator */
.chat-typing {
  padding: 8px 24px;
  display: none;
}
.typing-bubble {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 10px 16px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 18px; border-bottom-left-radius: 5px;
}
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3);
  animation: blink 1.3s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: .18s; }
.typing-dot:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,80%,100%{opacity:.15} 40%{opacity:1} }

/* Daily limit notice */
.chat-limit-bar {
  text-align: center; font-size: 0.75rem; color: var(--text-3);
  padding: 4px 24px 2px; flex-shrink: 0;
}

/* Input area */
.chat-input-area {
  flex-shrink: 0;
  padding: 12px 24px 20px;
  background: var(--bg);
}
.chat-input-box {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 12px;
  transition: border-color .15s;
}
.chat-input-box:focus-within { border-color: var(--primary); }
.chat-input {
  flex: 1; background: none; border: none;
  color: var(--text-1); font-size: 0.93rem;
  resize: none; max-height: 180px; line-height: 1.5;
  padding: 2px 0;
}
.chat-input:focus { outline: none; }
.chat-input::placeholder { color: var(--text-3); }
.btn-send {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
  transition: background .15s, transform .1s, opacity .15s;
}
.btn-send:hover:not(:disabled) { background: var(--primary-dk); }
.btn-send:active:not(:disabled) { transform: scale(.92); }
.btn-send:disabled { background: var(--surface-3); color: var(--text-3); cursor: not-allowed; }
.chat-hint {
  font-size: 0.72rem; color: var(--text-3); text-align: center; margin-top: 6px;
}

/* ── Dashboard ─────────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-label { font-size: 0.72rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .07em; margin-bottom: 6px; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text-1); }
.stat-sub   { font-size: 0.75rem; color: var(--text-3); margin-top: 2px; }
.section-title { font-size: 0.82rem; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .07em; margin: 20px 0 10px; }
.disc-bars { display: flex; flex-direction: column; gap: 8px; }
.disc-bar-row { display: flex; align-items: center; gap: 10px; }
.disc-bar-label { width: 20px; font-weight: 700; font-size: 0.85rem; color: var(--text-2); }
.disc-bar-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.disc-bar-fill  { height: 100%; border-radius: 4px; background: var(--primary); transition: width .6s ease; }
.disc-bar-pct   { width: 36px; font-size: 0.78rem; color: var(--text-3); text-align: right; }
.affection-ring { width: 120px; height: 120px; position: relative; margin: 0 auto; }
.affection-ring svg { transform: rotate(-90deg); }
.affection-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.affection-score { font-size: 1.5rem; font-weight: 700; }
.affection-level { font-size: 0.7rem; color: var(--text-2); margin-top: 2px; }

/* ── Tasks / Reminders ─────────────────────────────────────────────────────── */
.item-list { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color .15s;
}
.item-row:hover { border-color: var(--primary); }
.item-body { flex: 1; min-width: 0; }
.item-title { font-size: 0.92rem; font-weight: 500; color: var(--text-1); line-height: 1.35; }
.item-meta  { font-size: 0.78rem; color: var(--text-3); margin-top: 3px; }
.item-actions { display: flex; gap: 5px; flex-shrink: 0; align-items: center; }
.btn-icon {
  width: 30px; height: 30px; border-radius: 6px; border: none;
  background: none; color: var(--text-3); font-size: 0.95rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text-1); }
.btn-icon.danger:hover { background: rgba(239,68,68,.12); color: var(--danger); }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-3); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.65); align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 28px 24px;
  width: 100%; max-width: 440px; box-shadow: var(--shadow);
}
.modal-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ── Settings ──────────────────────────────────────────────────────────────── */
.settings-section { margin-bottom: 20px; }
.settings-section h3 {
  font-size: 0.95rem; font-weight: 700; color: var(--text-1);
  margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.text-sm     { font-size: 0.82rem; }
.text-muted  { color: var(--text-3); }
.text-danger { color: var(--danger); }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.25); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle {
    display: flex;
  }
  .main-content {
    margin-left: 0;
  }
  .chat-header { padding-left: 60px; }
  .chat-messages { padding: 16px 0; }
  .chat-msg { padding: 4px 12px; }
  .chat-input-area { padding: 10px 12px 16px; }
  .page .container,
  .page .container-sm,
  .page .container-md { padding-top: 56px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
