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

:root {
  --bg: #f9f8f6;
  --bg-input: #ffffff;
  --bg-hover: #f0efed;
  --bg-chip: #f0efed;
  --bg-chip-active: #e8e0d8;
  --bg-badge: #f0efed;
  --bg-user-msg: #d4714c;
  --text: #1a1a1a;
  --text-2: #6b6560;
  --text-3: #9b9590;
  --accent: #d4714c;
  --border: #e8e4e0;
  --border-focus: #d4714c;
  --composer-bg: #ffffff;
  --nav-track: #ece8e4;
  --nav-active: #ffffff;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-full: 9999px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
  --mono: 'SF Mono', 'Menlo', monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #2d2925;
    --bg-input: #2d2925;
    --bg-hover: #38342f;
    --bg-chip: #38342f;
    --bg-chip-active: #443f3a;
    --bg-badge: #38342f;
    --bg-user-msg: #d4714c;
    --text: #ece8e4;
    --text-2: #a09a94;
    --text-3: #7a7470;
    --border: #4e4944;
    --border-focus: #d4714c;
    --composer-bg: #38342f;
    --nav-track: #38342f;
    --nav-active: #1e1c19;
  }
}

html { font-size: 16px; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

#app {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Sidebar (mobile: bottom tab bar concept, but we keep it simple) ── */

/* ── Login ── */
.login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}
.login-logo { width: 160px; height: auto; margin-bottom: 32px; }
.login-form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; }
.login-err { color: #c0392b; font-size: 0.8125rem; text-align: center; }

/* ── Input (shared) ── */
.field {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
.field:focus { border-color: var(--border-focus); }
.field::placeholder { color: var(--text-3); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-full);
  padding: 11px 24px;
  font-size: 0.9375rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.4; cursor: default; }

/* ── Home: Claude-style centered input ── */
.home {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  position: relative;
}
.home-body {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.home-logo { width: 200px; height: auto; }
@media (prefers-color-scheme: dark) {
  .home-logo { filter: brightness(0) invert(1); }
}
.home-mark {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-2);
  letter-spacing: -0.01em;
  text-align: center;
}
.home-bottom {
  flex-shrink: 0;
  padding: 0 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}
/* ── Composer (Claude-style input card + external pills) ── */
.composer { width: 100%; }

.composer-card {
  background: var(--composer-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 20px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.composer-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.0625rem;
  font-family: var(--font);
  outline: none;
  resize: none;
  line-height: 1.6;
  max-height: 200px;
  min-height: 72px;
}
.composer-input::placeholder { color: var(--text-3); }
.composer-send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.composer-send:disabled { opacity: 0.25; cursor: default; }

.composer-actions {
  display: flex;
  align-items: center;
  padding-top: 6px;
}
.composer-attach {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.composer-attach:hover { color: var(--text); background: var(--bg-chip); }

.attach-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  background: var(--bg-chip);
  border-radius: 12px;
  margin-bottom: 4px;
  width: fit-content;
  max-width: 100%;
  color: var(--text-2);
}
.attach-row .attach-chip { margin-bottom: 0; }
.attach-name {
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.attach-remove {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.attach-remove:hover { background: var(--bg-chip-active); color: var(--text); }

/* ── Nav (Claude-style segmented control) ── */
.nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 12px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  .login-logo { filter: brightness(0) invert(1); }
}
.nav-seg {
  display: inline-flex;
  align-items: center;
  background: var(--nav-track);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
  position: relative;
}
.nav-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  height: calc(100% - 6px);
  border-radius: var(--radius-full);
  background: var(--nav-active);
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 0;
}
.nav-item {
  padding: 7px 14px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: color 0.2s;
  white-space: nowrap;
  position: relative;
  z-index: 1;
}
@media (max-width: 420px) {
  .nav-item { padding: 6px 10px; font-size: 0.75rem; }
  .nav { padding: 8px 8px; gap: 2px; }
}
.nav-item:hover { color: var(--text-2); }
.nav-item--on { color: var(--text); }

.nav-logout {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
  display: flex;
  align-items: center;
  margin-left: 12px;
  flex-shrink: 0;
}
.nav-logout:hover { color: var(--text-2); }

/* ── Bottom tab bar (mobile, native app pattern) ── */
.nav-bottom {
  display: none;
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 90;
}
.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px 6px;
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.6875rem;
  font-weight: 500;
  min-height: 52px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}
.nav-tab svg { width: 22px; height: 22px; }
.nav-tab--on { color: var(--accent); }
.nav-tab:active { background: var(--bg-chip); }
.nav-tab span {
  white-space: nowrap;
  letter-spacing: 0.01em;
}

/* Home sağ üst logout (mobile) */
.home-logout {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 14px;
  z-index: 50;
  background: none;
  border: none;
  padding: 8px;
  border-radius: 50%;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.home-logout:hover, .home-logout:active {
  color: var(--text);
  background: var(--bg-chip);
}

/* Responsive: mobile <768px bottom bar, desktop >=768px top */
@media (max-width: 767px) {
  .nav-top { display: none !important; }
  .nav-bottom { display: flex; }
}
@media (min-width: 768px) {
  .nav-bottom { display: none !important; }
  .home-logout { display: none; }
}

/* ── App Shell ── */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Chat ── */
.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.875rem;
  font-family: var(--font);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 3px;
  transition: opacity 0.15s;
}
.chat-back:hover { opacity: 0.7; }
.chat-back svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.msg-u {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0;
}
.msg-u-inner {
  background: var(--bg-user-msg);
  color: #fff;
  border-radius: 20px 20px 6px 20px;
  padding: 10px 16px;
  font-size: 0.9375rem;
  max-width: 85%;
  line-height: 1.55;
}
.msg-a {
  margin: 8px 0;
  padding: 6px 0;
  font-size: 0.9375rem;
  line-height: 1.7;
}
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin: 8px 0;
  font-size: 0.8125rem;
  color: var(--text-3);
  background: var(--bg-chip);
  border-radius: var(--radius);
}
.think-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.4s infinite;
}
@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

.chat-foot {
  padding: 10px 20px;
  padding-bottom: calc(10px + var(--safe-bottom));
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}
.chat-card {
  padding: 16px 14px 14px 20px;
}
.chat-card .composer-input {
  min-height: 24px;
}

/* ── Vault ── */
.vault {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}
.vault-search {
  padding: 8px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
}
.vault-search-box {
  position: relative;
}
.vault-search-box svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  stroke: var(--text-3);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.vault-search-box .field { padding-left: 38px; }

.vault-tags {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 16px 10px;
  scrollbar-width: none;
}
.vault-tags::-webkit-scrollbar { display: none; }
.vtag {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8125rem;
  background: var(--bg-chip);
  color: var(--text-2);
  border: none;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}
.vtag:hover { background: var(--bg-chip-active); }
.vtag-on { background: var(--accent); color: #fff; }

.vault-list { padding: 0 12px; }
.vault-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}
.vault-row:hover { background: var(--bg-hover); }
.vault-row:active { opacity: 0.6; }
.vault-row-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}
.vault-row-body { flex: 1; min-width: 0; }
.vault-row-t { font-size: 0.9375rem; font-weight: 450; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vault-row-m { font-size: 0.75rem; color: var(--text-3); }

.vault-count {
  font-size: 0.75rem;
  color: var(--text-3);
  text-align: right;
  padding-top: 4px;
}
.vault-more {
  display: block;
  width: 100%;
  padding: 14px;
  margin: 8px 0 16px;
  background: var(--bg-chip);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 0.875rem;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
}
.vault-more:hover { background: var(--bg-chip-active); color: var(--text); }

/* Topic detail */
.topic-detail { padding: 0 20px 32px; }
.topic-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.tbadge {
  font-size: 0.6875rem;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-badge);
  color: var(--text-2);
  font-weight: 500;
}
.tbadge-ok { color: #16a34a; }
.topic-date { font-size: 0.75rem; color: var(--text-3); margin-bottom: 16px; }

/* ── Markdown ── */
.md h2 { font-size: 1rem; font-weight: 600; margin: 20px 0 8px; letter-spacing: -0.01em; }
.md h3 { font-size: 0.9375rem; font-weight: 600; margin: 14px 0 6px; }
.md p { margin-bottom: 8px; }
.md ul, .md ol { margin: 6px 0; padding-left: 20px; }
.md li { margin-bottom: 3px; font-size: 0.9375rem; }
.md strong { font-weight: 600; }
.md a { color: var(--accent); text-decoration: none; }
.md code { background: var(--bg-chip); padding: 2px 6px; border-radius: 5px; font-size: 0.8125rem; font-family: var(--mono); }
.md pre { background: var(--bg-chip); padding: 14px; border-radius: var(--radius-sm); overflow-x: auto; margin: 10px 0; font-size: 0.8125rem; }
.md table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 0.8125rem; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.md th { background: var(--bg-chip); font-weight: 600; }
.md blockquote { border-left: 3px solid var(--accent); padding-left: 12px; margin: 10px 0; color: var(--text-2); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Assistant message actions (copy) ── */
.msg-a-wrap { display: flex; flex-direction: column; }
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 2px;
  margin-bottom: 4px;
  padding-left: 2px;
}
.msg-copy {
  background: none;
  border: none;
  color: var(--text-3);
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.msg-copy:hover, .msg-copy:active { color: var(--text); background: var(--bg-chip); }
.msg-copy svg { flex-shrink: 0; }

/* ── History ── */
.history-detail {
  padding: 0 20px 32px;
  max-width: 600px;
  margin: 0 auto;
}
.history-detail-q {
  font-size: 1.0625rem;
  font-weight: 600;
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  color: var(--accent);
}
.history-detail-meta {
  font-size: 0.75rem;
  color: var(--text-3);
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
.history-delete {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}
.history-delete:hover { background: var(--bg-chip); color: var(--text); }
.history-resume {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.history-resume:hover { opacity: 0.85; }
.history-thread-badge {
  background: var(--bg-chip);
  color: var(--accent);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 0.6875rem;
  font-weight: 600;
}
.history-turn { margin-bottom: 24px; padding-bottom: 18px; border-bottom: 1px dashed var(--border); }
.history-turn:last-of-type { border-bottom: none; margin-bottom: 8px; }
.history-turn .history-detail-q { border-bottom: none; padding: 0 0 10px; margin-bottom: 8px; }
.history-clear {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 0.75rem;
  font-family: var(--font);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.history-clear:hover { color: #ef4444; }

/* ── Utility ── */
.empty { text-align: center; padding: 48px 24px; color: var(--text-3); font-size: 0.875rem; }
