:root {
  --bg: #1a1210;
  --bg-elevated: #241a17;
  --bg-soft: #2e221e;
  --panel: #2a1f1b;
  --border: #4a342c;
  --text: #f7efe8;
  --muted: #c4a99a;
  --accent: #d4a574;
  --accent-strong: #e8b88a;
  --accent-dim: #8b5e3c;
  --danger: #c45c5c;
  --success: #6a9e6a;
  --user-bubble: #3d2a22;
  --assistant-bubble: #2f241f;
  --radius: 16px;
  --font: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --sidebar-w: 300px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font);
  background: radial-gradient(ellipse at top, #3a241c 0%, var(--bg) 55%);
  color: var(--text);
}
body.chat-page {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: auto;
}
.login-card {
  width: min(420px, 100%);
  background: linear-gradient(160deg, rgba(56,38,32,0.95), rgba(28,20,18,0.98));
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 36px 32px 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
  text-align: center;
}
.login-card img.logo {
  width: 96px; height: 96px; object-fit: contain;
  border-radius: 50%; background: #fff; padding: 8px; margin-bottom: 12px;
}
.login-card h1 {
  margin: 8px 0 4px; font-weight: 650; letter-spacing: 0.08em; color: var(--accent-strong);
}
.login-card .subtitle { color: var(--muted); font-size: 0.95rem; margin-bottom: 24px; }

.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 1rem;
}
.field textarea { min-height: 90px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 12px; padding: 12px 18px;
  font-size: 1rem; font-weight: 600; cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #1a100c; margin-top: 8px;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-small { padding: 8px 12px; font-size: 0.85rem; border-radius: 10px; }

.error {
  color: #ffb4b4; background: rgba(196,92,92,0.15);
  border: 1px solid rgba(196,92,92,0.35); border-radius: 10px;
  padding: 10px 12px; margin: 12px 0; font-size: 0.9rem; display: none;
}
.error.show { display: block; }
.apk-link { margin-top: 20px; font-size: 0.9rem; color: var(--muted); }
.apk-link a {
  display: inline-block; margin-top: 6px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-soft);
}

/* ===== Chat shell: fixed fullscreen so WebView always shows composer+messages ===== */
.app-shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  overflow: hidden;
  background: var(--bg);
}
.sidebar {
  width: var(--sidebar-w);
  max-width: 88vw;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
  z-index: 30;
  flex-shrink: 0;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 4px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar .brand img {
  width: 40px; height: 40px; border-radius: 50%; background: #fff; object-fit: contain; padding: 3px;
}
.sidebar .brand strong { letter-spacing: 0.06em; color: var(--accent-strong); }
.brand-sub { font-size: 0.75rem; color: var(--muted); }
.sidebar-close { margin-left: auto; display: none; }
.sidebar-section-title {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin-top: 4px; flex-shrink: 0;
}
.project-list {
  flex: 0 1 34%;
  min-height: 80px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  -webkit-overflow-scrolling: touch;
}
.project-row {
  display: flex; align-items: stretch; gap: 4px; border-radius: 10px;
}
.project-row.active { background: var(--bg-soft); border: 1px solid var(--border); }
.project-item {
  flex: 1; text-align: left; padding: 10px 12px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--text);
  cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.project-item:hover { background: var(--bg-soft); border-color: var(--border); }
.project-row.active .project-item { border-color: transparent; background: transparent; }
.project-edit {
  flex-shrink: 0; width: 36px; border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.project-edit:hover { background: var(--bg-soft); border-color: var(--border); color: var(--accent-strong); }

.memory-box {
  flex: 1 1 30%;
  min-height: 120px;
  display: flex; flex-direction: column; gap: 8px;
  border: 1px solid var(--border); border-radius: 12px; padding: 8px;
  background: rgba(0,0,0,0.15); overflow: hidden;
}
.memory-list {
  flex: 1; min-height: 40px; overflow-y: auto; font-size: 0.8rem; color: var(--muted);
  -webkit-overflow-scrolling: touch;
}
.memory-list .mem-item {
  padding: 6px 0; border-bottom: 1px solid rgba(74,52,44,0.5); color: var(--text);
}
.memory-box textarea {
  width: 100%; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); padding: 8px; font: inherit; resize: none;
  flex-shrink: 0;
}
.sidebar-footer {
  border-top: 1px solid var(--border); padding-top: 10px;
  display: flex; flex-direction: column; gap: 8px;
  font-size: 0.85rem; color: var(--muted); flex-shrink: 0;
}

.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 25;
}

.main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(36,26,23,0.4), transparent 180px);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: rgba(26,18,16,0.92);
  flex-shrink: 0;
  z-index: 5;
}
.menu-btn { display: none; flex-shrink: 0; min-width: 42px; }
.topbar .title-wrap {
  display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1;
}
.topbar h2 {
  margin: 0; font-size: 1rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  max-width: min(720px, 94%);
  padding: 12px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user { align-self: flex-end; background: var(--user-bubble); border: 1px solid var(--border); }
.msg.assistant { align-self: flex-start; background: var(--assistant-bubble); border: 1px solid #3d2d26; }
.msg .meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 6px; }
.composer {
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: rgba(26,18,16,0.96);
  flex-shrink: 0;
  z-index: 5;
}
.composer-row {
  display: flex; gap: 8px; max-width: 900px; margin: 0 auto; align-items: flex-end;
}
.composer textarea {
  flex: 1; min-height: 48px; max-height: 120px;
  padding: 12px 14px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font: inherit; resize: none;
}
.composer .btn-primary { width: auto; min-width: 88px; margin-top: 0; height: 48px; }
.empty-hint {
  margin: auto; text-align: center; color: var(--muted); max-width: 420px; padding: 28px 16px;
}
.empty-hint img {
  width: 72px; height: 72px; border-radius: 50%; background: #fff; padding: 6px; margin-bottom: 12px;
}
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-soft); border: 1px solid var(--border);
  font-size: 0.75rem; color: var(--muted); flex-shrink: 0;
}

/* Mobile / WebView */
@media (max-width: 860px) {
  .menu-btn { display: inline-flex !important; }
  .sidebar-close { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,0.35);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .main { width: 100%; }
  .composer-row { flex-direction: row; }
}

/* Config page */
.config-wrap { max-width: 900px; margin: 0 auto; padding: 28px 20px 60px; }
.config-wrap h1 { color: var(--accent-strong); margin-top: 0; }
.config-grid { display: grid; gap: 20px; grid-template-columns: 1fr; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 20px;
}
.asset-list { list-style: none; padding: 0; margin: 0; }
.asset-list li {
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.92rem;
}
