/* ========================================================
   KinSoft AI - Mobile-Native Chat Studio CSS
   Strict Responsive Fixes, Zero Overlaps, Clean UI
   ======================================================== */

:root {
  --header-height: 46px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Cairo', system-ui, sans-serif;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App Header - 46px Solid Single Row */
.app-header {
  height: var(--header-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 50;
}
.app-header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
}
.app-header-start { display: flex; align-items: center; gap: 8px; }
.app-header-end { display: flex; align-items: center; gap: 6px; }

.sidebar-toggle {
  display: flex; flex-direction: column; justify-content: center; gap: 3px;
  background: transparent; border: 1px solid var(--border); padding: 5px;
  cursor: pointer; border-radius: 4px;
}
.sidebar-toggle span { display: block; width: 16px; height: 2px; background: var(--text); }

.brand { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 0.88rem; }
.brand-mark { width: 22px; height: 22px; border-radius: 4px; }
.brand-sub { color: var(--accent); }

/* Badges - Completely Flat & Inline */
.badge-free-daily {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #dcfce7;
  color: #166534;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  white-space: nowrap;
}
.badge-credits {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  white-space: nowrap;
}
.ctrl-btn {
  background: transparent; border: none; font-size: 0.9rem; cursor: pointer; padding: 2px;
}

/* Layout */
.app-layout {
  flex: 1;
  display: flex;
  height: calc(100vh - var(--header-height));
  position: relative;
  overflow: hidden;
}

/* Desktop Sidebar */
.app-sidebar {
  width: 180px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 8px 0;
  height: 100%;
  overflow-y: auto;
  z-index: 40;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 6px; }
.sidebar-link {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: 5px;
  color: var(--text-muted); text-decoration: none;
  font-size: 0.78rem; font-weight: 500;
}
.sidebar-link:hover { background: var(--surface-muted); color: var(--text); }
.sidebar-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-icon { font-size: 0.85rem; }

/* Main Chat Area */
.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}

/* Model Picker Strip (Ultra-Thin 36px) */
.model-picker-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.model-picker-strip::-webkit-scrollbar { display: none; }

.model-select-input {
  height: 28px;
  padding: 2px 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  max-width: 220px;
}
.model-select-input:focus { outline: none; border-color: var(--accent); }

.chips-scroll {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips-scroll::-webkit-scrollbar { display: none; }

.chip-btn {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 7px;
  font-size: 0.68rem;
  font-family: inherit;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
}
.chip-btn:hover { color: var(--accent); border-color: var(--accent); }

/* Messages Scroll Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-welcome {
  margin: auto;
  text-align: center;
  max-width: 380px;
  padding: 14px;
  color: var(--text-muted);
}
.welcome-emoji { font-size: 1.8rem; margin-bottom: 4px; }
.chat-welcome h3 { font-size: 0.95rem; color: var(--text); margin-bottom: 2px; }
.chat-welcome p { font-size: 0.74rem; line-height: 1.4; }

/* Message Rows */
.message-row {
  display: flex;
  gap: 6px;
  max-width: 88%;
  animation: fadeIn 0.15s ease;
}
.message-row.user {
  margin-left: auto;
  flex-direction: row-reverse;
}
.message-row.assistant {
  margin-right: auto;
}
.message-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
}
.message-bubble-wrap { display: flex; flex-direction: column; gap: 2px; max-width: 100%; }

.message-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
}
.message-row.user .message-bubble {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  border-top-left-radius: 2px;
}
.message-row.assistant .message-bubble {
  border-top-right-radius: 2px;
}

/* Token Stats Bar below response */
.token-stat-pill {
  font-size: 0.64rem;
  color: var(--text-light);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-muted);
  border-radius: 4px;
  padding: 1px 5px;
  width: fit-content;
  margin-top: 2px;
}

.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}
.msg-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.65rem;
  color: var(--text-muted);
  cursor: pointer;
}
.msg-btn:hover { background: var(--surface-muted); color: var(--text); }

/* Typing Dots */
.typing-dots { display: inline-flex; gap: 3px; padding: 4px 6px; }
.typing-dots span {
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
  animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-3px); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

/* Chat Bottom Input Bar */
.chat-bottom-bar {
  padding: 6px 8px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-input-form {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
}
.chat-input-form:focus-within { border-color: var(--accent); }

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--text);
  max-height: 80px;
  line-height: 1.35;
}
.btn-clear {
  background: transparent; border: none; font-size: 0.85rem; cursor: pointer; padding: 3px; opacity: 0.6;
}
.btn-clear:hover { opacity: 1; }

.btn-send {
  width: 30px;
  height: 30px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-send:hover { background: var(--accent-hover); }

/* Mobile Drawer (Clean Sliding from Right) */
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4); z-index: 90;
}
.sidebar-backdrop.active { display: block; }

@media (max-width: 768px) {
  .app-sidebar {
    position: fixed; top: 0; right: 0; bottom: 0;
    width: 220px; height: 100vh;
    z-index: 100; background: var(--surface);
    transform: translateX(100%);
    transition: transform 0.2s ease-out;
    padding: 0;
    box-shadow: -3px 0 15px rgba(0,0,0,0.2);
  }
  .app-sidebar.open { transform: translateX(0); }
  .sidebar-header-mobile {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-bottom: 1px solid var(--border);
  }
  .sidebar-close-btn { background: transparent; border: none; font-size: 1.1rem; color: var(--text); cursor: pointer; }
  .sidebar-nav { padding: 6px; gap: 2px; }
  .sidebar-link { padding: 7px 8px; font-size: 0.82rem; }

  .message-row { max-width: 94%; }
  .model-select-input { max-width: 140px; font-size: 0.68rem; }
}

.toast-container { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); z-index: 999; }
.toast { background: var(--text); color: var(--bg); padding: 4px 10px; border-radius: 4px; font-size: 0.7rem; }
.toast.success { background: #166534; color: #fff; }
.toast.error { background: #dc2626; color: #fff; }
.hidden { display: none !important; }
