/* ===== Pocket Claude — claude.ai-inspired mobile-first PWA ===== */

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* Live-updated by app.js from window.visualViewport for keyboard handling. */
  --app-height: 100dvh;
}
@supports not (height: 100dvh) {
  body { --app-height: 100vh; }
}

/* Tati Labs brand — light theme, charcoal contrast, violet/blue accent (branding.txt) */
:root {
  --bg: #f5f7fb;
  --bg-elev: #ffffff;
  --bg-sidebar: #eef1f8;
  --bg-input: #ffffff;
  --fg: #1c1c22;
  --fg-muted: #6b6f8a;
  --fg-dim: #9aa0b5;
  --border: #e4e8f2;
  --border-strong: #ccd2e2;
  --accent: #7c5cfc;
  --accent-2: #4a9efc;
  --accent-fg: #ffffff;
  --grad: linear-gradient(135deg, #4a3fbf 0%, #8b6cf0 55%, #e48acb 100%);
  --bubble-user: #eaeef6;
  --bubble-asst: transparent;
  --code-bg: #eef1f8;
  --tool-bg: #f0f3f9;
  --tool-border: #e0e5f0;
  --danger: #e5484d;
  --shadow-sm: 0 1px 2px rgba(20,20,30,0.05);
  --shadow-md: 0 6px 20px rgba(74,63,191,0.10);
  --radius: 12px;
  --radius-lg: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121215;
    --bg-elev: #1a1a1f;
    --bg-sidebar: #17171b;
    --bg-input: #2a2a2f;
    --fg: #ffffff;
    --fg-muted: #9aa0b5;
    --fg-dim: #6b6f8a;
    --border: #2a2a2f;
    --border-strong: #35353b;
    --accent: #8b6cf0;
    --accent-2: #5da8f7;
    --accent-fg: #ffffff;
    --grad: linear-gradient(135deg, #4a3fbf 0%, #8b6cf0 55%, #e48acb 100%);
    --bubble-user: #2a2a2f;
    --bubble-asst: transparent;
    --code-bg: #2a2a2f;
    --tool-bg: #1f1f24;
    --tool-border: #35353b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 6px 24px rgba(0,0,0,0.5);
  }
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

.screen { position: fixed; inset: 0; }
[hidden] { display: none !important; }

/* ===== LOGIN ===== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) 28px env(safe-area-inset-bottom);
  overflow: hidden;
}
.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(124, 92, 252, 0.18), transparent 60%),
    radial-gradient(ellipse 70% 50% at 90% 100%, rgba(124, 92, 252, 0.12), transparent 60%);
  pointer-events: none;
  z-index: 0;
}
.login-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 36px;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.brand-mark {
  width: 56px;
  height: 56px;
  color: var(--accent);
  filter: drop-shadow(0 2px 8px rgba(124, 92, 252, 0.35));
}
.brand-name {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--fg);
}
.brand-tagline {
  margin: 0;
  font-size: 14px;
  color: var(--fg-muted);
  letter-spacing: -0.005em;
}
.field { display: block; }
.field input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--bg-elev);
  outline: none;
  font-size: 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 120ms, box-shadow 120ms;
}
.field input::placeholder { color: var(--fg-dim); }
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.18);
}
#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
/* Password field with a show/hide eye. The input keeps its full width; the
   button floats over its right edge so the layout does not shift. */
.field-password { position: relative; display: block; }
.field-password input { padding-right: 54px; }
.pw-toggle {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; color: var(--fg-muted); cursor: pointer;
}
.pw-toggle:hover { color: var(--fg); background: rgba(124, 92, 252, 0.12); }
.pw-toggle .pw-eye-off { display: none; }
.pw-toggle.is-shown .pw-eye { display: none; }
.pw-toggle.is-shown .pw-eye-off { display: inline; }
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--grad);
  color: var(--accent-fg);
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.005em;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08), 0 4px 14px rgba(124, 92, 252, 0.35);
  transition: transform 80ms, box-shadow 120ms;
}
.btn-primary:hover { box-shadow: 0 1px 0 rgba(0,0,0,0.08), 0 6px 18px rgba(124, 92, 252, 0.45); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.login-error {
  background: rgba(192, 57, 43, 0.12);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
}

/* ===== APP LAYOUT ===== */
#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  overflow: hidden;
}
@supports not (height: 100dvh) {
  #app { height: var(--app-height, 100vh); }
}
@media (max-width: 768px) {
  #app { grid-template-columns: 1fr; }
}

/* ===== SIDEBAR ===== */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
  overflow-x: hidden;
  padding-top: env(safe-area-inset-top);
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 30;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
}

.sidebar-head { padding: 14px 12px 8px; }
.btn-new {
  width: 100%; padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--fg);
  font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.btn-new:hover { background: var(--bg-input); }

.sidebar-search { padding: 6px 12px 10px; }
.sidebar-search input {
  width: 100%; padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none; font-size: 14px;
}

.sidebar-list {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 4px 8px 12px;
  -webkit-overflow-scrolling: touch;
}
.sidebar-list .empty {
  padding: 24px 12px; color: var(--fg-dim); font-size: 13px; text-align: center;
}
.project-group { margin: 12px 0 4px; }
.project-label {
  padding: 6px 12px 4px;
  font-size: 11px; font-weight: 600;
  color: var(--fg-dim);
  text-transform: uppercase; letter-spacing: 0.05em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item {
  display: block;
  width: 100%;
  max-width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--fg);
  font-size: 14px;
  line-height: 1.35;
  margin-bottom: 1px;
  min-height: 44px;
  overflow: hidden;
}
.session-item:hover { background: rgba(0,0,0,0.04); }
@media (prefers-color-scheme: dark) {
  .session-item:hover { background: rgba(255,255,255,0.04); }
}
.session-item.active { background: var(--bg-elev); }
.session-item.no-transcript .title { opacity: 0.55; }
.session-item .title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.session-item .meta {
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-foot { padding: 10px 12px env(safe-area-inset-bottom); border-top: 1px solid var(--border); }
.btn-ghost {
  padding: 8px 10px; border-radius: 8px;
  color: var(--fg-muted); font-size: 13px;
}
.btn-ghost:hover { background: rgba(0,0,0,0.04); color: var(--fg); }

.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 25;
}

/* ===== CHAT ===== */
.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}
.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  min-height: 52px;
  flex-shrink: 0;
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 8px;
  color: var(--fg-muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(0,0,0,0.04); color: var(--fg); }
@media (min-width: 769px) {
  #open-drawer { display: none; }
}
.chat-title {
  flex: 1; font-size: 15px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-align: center;
  min-width: 0;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 14px 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
@media (min-width: 769px) {
  .messages { padding: 24px max(24px, calc((100% - 760px) / 2)) 24px; }
}

.welcome {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 32px 16px;
}
.welcome-mark {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--accent); position: relative; margin-bottom: 18px;
}
.welcome-mark::after {
  content: ""; position: absolute; inset: 11px;
  border: 3px solid var(--accent-fg); border-radius: 7px;
  border-top-color: transparent; transform: rotate(45deg);
}
.welcome h2 { margin: 0 0 8px; font-weight: 600; }
.welcome p { color: var(--fg-muted); margin: 0; max-width: 320px; }

.msg { margin-bottom: 14px; max-width: 100%; }
.msg-user .bubble {
  background: var(--bubble-user);
  padding: 10px 14px;
  border-radius: 18px;
  display: inline-block;
  max-width: 88%;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  text-align: left;
}
.msg-user { text-align: right; }
.msg-images {
  display: flex; flex-wrap: wrap; gap: 6px;
  justify-content: flex-end;
  margin-bottom: 6px;
}
.msg-image {
  max-width: 200px; max-height: 200px;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: cover;
}
.msg-assistant .bubble {
  background: var(--bubble-asst);
  padding: 0;
  display: block;
  max-width: 100%;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg-assistant .bubble p {
  margin: 0 0 10px;
  white-space: pre-wrap;
}
.msg-assistant .bubble pre {
  background: var(--code-bg);
  padding: 12px;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 13px;
  margin: 6px 0;
  max-width: 100%;
}
.msg-assistant .bubble code {
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  word-break: break-word;
}
.msg-assistant .bubble pre code { background: none; padding: 0; word-break: normal; }

.tool-call {
  background: var(--tool-bg);
  border: 1px solid var(--tool-border);
  border-radius: 10px;
  padding: 8px 12px;
  margin: 6px 0;
  font-size: 13px;
  max-width: 100%;
  overflow: hidden;
}
.tool-call summary {
  cursor: pointer; color: var(--fg-muted);
  font-family: ui-monospace, monospace; font-size: 12px;
  list-style: none;
}
.tool-call summary::before { content: "▸ "; color: var(--fg-dim); }
.tool-call[open] summary::before { content: "▾ "; }
.tool-call pre {
  margin: 8px 0 0; padding: 8px;
  background: var(--bg); border-radius: 6px;
  font-size: 12px; overflow-x: auto;
}

.thinking {
  color: var(--fg-dim);
  font-style: italic;
  font-size: 13px;
  border-left: 2px solid var(--border-strong);
  padding-left: 10px;
  margin: 6px 0 10px;
  white-space: pre-wrap;
}

.typing-cursor::after {
  content: "▋";
  animation: blink 1s infinite;
  color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

.banner {
  background: rgba(124, 92, 252, 0.1);
  color: var(--accent);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin: 6px 0 14px;
  text-align: center;
}
.banner.error {
  background: rgba(192, 57, 43, 0.1);
  color: var(--danger);
}

/* ===== LOOP-BACK TOAST (worker finished) ===== */
.deck-toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
  pointer-events: none;
}
.deck-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .28s ease, transform .28s ease;
}
.deck-toast.in { opacity: 1; transform: translateY(0); }
.deck-toast .dt-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(124, 92, 252, 0.12);
  color: var(--accent);
}
.deck-toast.warn .dt-icon {
  background: rgba(229, 72, 77, 0.12);
  color: var(--danger);
}
.deck-toast .dt-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  line-height: 1.35;
  min-width: 0;
}
.deck-toast .dt-text b { font-weight: 600; }
.deck-toast .dt-sub {
  color: var(--fg-muted);
  font-size: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== COMPOSER ===== */
.composer {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
@media (min-width: 769px) {
  .composer { padding-left: max(24px, calc((100% - 760px) / 2)); padding-right: max(24px, calc((100% - 760px) / 2)); }
}
.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  padding: 6px 6px 6px 6px;
  max-width: 100%;
}
.attach-btn {
  width: 40px; height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  color: var(--fg-muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.attach-btn:active { transform: scale(0.92); }
.attach-btn:hover { color: var(--fg); background: rgba(0,0,0,0.05); }
@media (prefers-color-scheme: dark) {
  .attach-btn:hover { background: rgba(255,255,255,0.06); }
}

.attach-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 4px 8px;
}
.attach-chip {
  position: relative;
  width: 60px; height: 60px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: var(--code-bg);
  flex-shrink: 0;
}
.attach-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-chip.uploading { opacity: 0.5; }
.attach-chip .remove {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 14px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.16);
}
.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  border: none; background: none; outline: none; resize: none;
  padding: 9px 0;
  line-height: 1.4;
  max-height: 35vh;
  font-family: inherit;
  font-size: 16px; /* prevents iOS auto-zoom on focus */
}
.composer-send {
  width: 40px; height: 40px;
  background: var(--accent); color: var(--accent-fg);
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(124, 92, 252, 0.32);
  transition: transform 80ms;
}
.composer-send:active { transform: scale(0.92); }
.composer-send:disabled { background: var(--border-strong); cursor: not-allowed; box-shadow: none; }
.composer-status {
  font-size: 11px; color: var(--fg-dim);
  padding: 5px 4px 0; text-align: center;
  min-height: 0;
  height: auto;
}
.composer-status:empty { display: none; }
