/* ==========================================================================
   Softtun AI — design tokens
   Palette: warm near-black base with an apricot accent -- apricot is
   Armenia's national fruit and a recognizable color of Armenian identity,
   used here instead of the default SaaS blue/teal to give the product a
   distinct, locally-grounded visual signature.
   Type: Noto Sans (+ Armenian subset) throughout -- one family, multiple
   weights, chosen because it natively covers Armenian, Cyrillic, and Latin,
   which this trilingual product needs everywhere, not just body copy.
   ========================================================================== */
:root {
  --bg: #16130f;
  --bg-elevated: #1e1a14;
  --bg-sidebar: #120f0b;
  --bg-inset: #100d0a;
  --border: #2f2921;
  --border-soft: #241f19;
  --text: #f3ede2;
  --text-dim: #a89a87;
  --text-faint: #786a5a;

  --accent: #e8823c;
  --accent-hover: #d66f2b;
  --accent-soft: rgba(232, 130, 60, 0.14);
  --accent-soft-strong: rgba(232, 130, 60, 0.24);

  --user-bubble: #2a2018;
  --assistant-bubble: #1c1912;
  --danger: #e2574a;
  --danger-soft: rgba(226, 87, 74, 0.14);
  --success: #7fae6a;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --sidebar-width: 288px;

  --font-ui: "Noto Sans", "Noto Sans Armenian", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Arial, sans-serif;

  /* Safe-area insets so the layout respects notches / home indicators when
     installed as a standalone app on iOS/Android. */
  --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);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

::selection { background: var(--accent-soft-strong); color: var(--text); }

/* Visible keyboard focus everywhere, styled to match the palette instead of
   the browser default blue outline. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Auth screen ---------- */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, var(--safe-top)) max(20px, var(--safe-right)) max(24px, var(--safe-bottom)) max(20px, var(--safe-left));
  background:
    radial-gradient(60% 50% at 50% 0%, rgba(232, 130, 60, 0.08), transparent),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 30px 30px;
  text-align: center;
}
.auth-mark {
  width: 44px; height: 44px; margin: 0 auto 16px;
  border-radius: 13px;
  background: var(--accent);
  position: relative;
}
.auth-mark::after {
  content: "";
  position: absolute; left: 10px; top: 10px; width: 24px; height: 24px;
  border-radius: 50%; background: var(--bg-elevated);
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.auth-subtitle { color: var(--text-dim); margin: 0 0 26px; font-size: 14px; }

.auth-tabs {
  display: flex; gap: 4px; margin-bottom: 22px;
  background: var(--bg-inset); border-radius: var(--radius-sm); padding: 4px;
}
.auth-tab {
  flex: 1; padding: 9px; background: none; border: none;
  color: var(--text-dim); border-radius: 6px; cursor: pointer; font-size: 14px;
  font-family: inherit; font-weight: 500; transition: background 0.15s, color 0.15s;
}
.auth-tab.active { background: var(--accent); color: #1a0f06; font-weight: 700; }

.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  padding: 13px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-inset); color: var(--text); font-size: 15px; font-family: inherit;
  transition: border-color 0.15s;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-form input::placeholder { color: var(--text-faint); }
.auth-form button[type="submit"] {
  padding: 13px; border-radius: var(--radius-sm); border: none; background: var(--accent);
  color: #1a0f06; font-size: 15px; cursor: pointer; font-weight: 700; font-family: inherit;
  margin-top: 6px; transition: background 0.15s;
}
.auth-form button[type="submit"]:hover { background: var(--accent-hover); }
.auth-form button[type="submit"]:active { transform: scale(0.98); }
.auth-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 0; }

/* ---------- App layout ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }

.menu-toggle {
  display: none;
  position: fixed; z-index: 30;
  top: calc(max(12px, var(--safe-top)) + 4px); left: max(12px, var(--safe-left));
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); width: 44px; height: 44px; cursor: pointer;
  flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.menu-toggle span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 1px; }

.sidebar {
  width: var(--sidebar-width); flex-shrink: 0;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: max(16px, var(--safe-top)) 14px 14px max(14px, var(--safe-left));
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; padding: 0 4px; }
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 9px; letter-spacing: -0.01em; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: var(--accent); flex-shrink: 0; }
.icon-btn {
  background: none; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); text-decoration: none; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-elevated); color: var(--text); }

.new-chat-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); cursor: pointer; font-size: 14px;
  font-family: inherit; font-weight: 500; margin-bottom: 14px; text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.new-chat-btn .plus { color: var(--accent); font-weight: 700; font-size: 16px; }
.new-chat-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.new-chat-btn:active { transform: scale(0.99); }

.conversation-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; margin: 0 -4px; padding: 0 4px; }
.conversation-item {
  padding: 10px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; justify-content: space-between; align-items: center; gap: 6px;
  transition: background 0.12s, color 0.12s;
}
.conversation-item:hover { background: var(--bg-elevated); color: var(--text); }
.conversation-item.active { background: var(--accent-soft); color: var(--text); }
.conversation-item .delete-btn {
  background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 15px; visibility: hidden;
  width: 22px; height: 22px; border-radius: 5px; flex-shrink: 0; line-height: 1;
}
.conversation-item:hover .delete-btn { visibility: visible; }
.conversation-item .delete-btn:hover { color: var(--danger); background: var(--danger-soft); }
.day-label { font-size: 12px; color: var(--text-faint); margin: 14px 0 6px; padding: 0 10px; font-weight: 500; }
.day-label:first-child { margin-top: 4px; }

.sidebar-footer {
  border-top: 1px solid var(--border-soft); padding-top: 12px; margin-top: 12px;
  display: flex; align-items: center; justify-content: space-between; font-size: 13px; padding-left: 4px; padding-right: 4px;
}
.username { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn {
  background: none; border: none; color: var(--text-faint); cursor: pointer; font-size: 13px;
  font-family: inherit; padding: 4px 0; transition: color 0.15s;
}
.logout-btn:hover { color: var(--danger); }

.sidebar-overlay { display: none; }

/* ---------- Main chat area ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.chat-header {
  padding: max(14px, var(--safe-top)) max(20px, var(--safe-right)) 14px 20px;
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 600;
  flex-shrink: 0;
}
.model-badge {
  font-size: 11px; font-weight: 500; color: var(--text-dim); background: var(--bg-elevated);
  padding: 4px 9px; border-radius: 999px; border: 1px solid var(--border-soft);
}

.messages { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 18px; -webkit-overflow-scrolling: touch; }

.empty-state { margin: auto; text-align: center; color: var(--text-dim); max-width: 320px; }
.empty-mark {
  width: 52px; height: 52px; margin: 0 auto 18px; border-radius: 16px;
  background: var(--accent-soft); position: relative;
}
.empty-mark::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 20px; height: 20px;
  transform: translate(-50%, -50%); border-radius: 50%; background: var(--accent);
}
.empty-state h2 { color: var(--text); font-weight: 700; font-size: 18px; margin: 0 0 8px; letter-spacing: -0.01em; }
.empty-state p { font-size: 14px; margin: 0; line-height: 1.5; }

.message {
  max-width: 760px; width: 100%; margin: 0 auto; display: flex; gap: 12px;
  animation: message-in 0.25s ease-out;
}
@keyframes message-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.message .role-label { font-size: 12px; font-weight: 700; color: var(--text-faint); margin-bottom: 5px; }
.message .bubble {
  padding: 13px 16px; border-radius: var(--radius-md); line-height: 1.65; font-size: 15px; word-wrap: break-word;
}
.message.user .bubble { background: var(--user-bubble); }
.message.assistant .bubble { background: var(--assistant-bubble); border: 1px solid var(--border-soft); }
.message-body { flex: 1; min-width: 0; }

.message-actions { display: flex; gap: 8px; margin-top: 8px; }
.message-actions button {
  background: none; border: 1px solid var(--border); color: var(--text-faint); font-size: 11.5px;
  padding: 4px 10px; border-radius: 999px; cursor: pointer; font-family: inherit; transition: color 0.15s, border-color 0.15s;
}
.message-actions button:hover { color: var(--text); border-color: var(--accent); }

.bubble pre {
  position: relative; border-radius: var(--radius-sm); overflow-x: auto; margin: 10px 0;
  border: 1px solid var(--border-soft);
}
.bubble .copy-code-btn {
  position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 4px 9px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; cursor: pointer; font-family: inherit;
}
.bubble table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13.5px; }
.bubble th, .bubble td { border: 1px solid var(--border-soft); padding: 7px 11px; }
.bubble th { background: var(--bg-inset); font-weight: 600; }
.bubble code { background: rgba(255,255,255,0.07); padding: 2px 6px; border-radius: 5px; font-size: 0.88em; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--accent); }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }

.typing-indicator { display: inline-flex; gap: 5px; align-items: center; padding: 4px 0; }
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.banner {
  margin: 0 20px 10px; padding: 11px 15px; background: var(--danger-soft);
  border: 1px solid var(--danger); color: #ffb9ae; border-radius: var(--radius-sm); font-size: 13px; text-align: center;
}

.chat-input-area {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 14px max(20px, var(--safe-right)) max(16px, var(--safe-bottom)) max(20px, var(--safe-left));
  border-top: 1px solid var(--border-soft); flex-shrink: 0;
}
.chat-input-area textarea {
  flex: 1; resize: none; max-height: 200px; padding: 13px 16px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text);
  font-size: 15px; font-family: inherit; line-height: 1.4; transition: border-color 0.15s;
}
.chat-input-area textarea:focus { border-color: var(--accent); outline: none; }
.chat-input-area textarea::placeholder { color: var(--text-faint); }

.send-btn {
  width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--accent);
  color: #1a0f06; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.94); }
.send-btn.stop { background: var(--danger); color: #fff; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Tablet ---------- */
@media (max-width: 1024px) {
  :root { --sidebar-width: 260px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .menu-toggle { display: flex; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 25;
    transform: translateX(-100%); transition: transform 0.22s ease;
    width: min(85vw, 320px); box-shadow: 0 0 40px rgba(0,0,0,0.4);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 20;
    backdrop-filter: blur(1px);
  }
  .sidebar-overlay.visible { display: block; }
  .chat-header { padding-left: 64px; }
  .messages { padding: 18px 14px; gap: 16px; }
  .message { max-width: 100%; }
  .chat-input-area { padding-left: max(14px, var(--safe-left)); padding-right: max(14px, var(--safe-right)); }
  .chat-input-area textarea { font-size: 16px; } /* 16px prevents iOS auto-zoom on focus */
  .auth-card { padding: 30px 22px 24px; }
}

@media (max-width: 420px) {
  .empty-state h2 { font-size: 17px; }
}
