/* Yans Dashboard */
:root {
  --bg: #f6f6f9;
  --panel: #ffffff;
  --text: #1c1d26;
  --muted: #7a7c8a;
  --line: #e3e4ec;
  --accent: #4f5dd4;
  --accent-soft: #eceefb;
  --user-bubble: #4f5dd4;
  --user-text: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12131c;
    --panel: #1b1d2a;
    --text: #e8e9f0;
    --muted: #8f92a3;
    --line: #2a2c3c;
    --accent: #8b97ff;
    --accent-soft: #232742;
    --user-bubble: #4f5dd4;
    --user-text: #ffffff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column;
  height: 100dvh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand img { width: 24px; height: 24px; border-radius: 6px; }
.logout { color: var(--muted); font-size: 13px; text-decoration: none; }
.logout:hover { color: var(--accent); }

.tabs { display: flex; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; padding: 10px; border: none; background: none; color: var(--muted);
  font-size: 15px; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { flex: 1; overflow: hidden; display: flex; }
.view { flex: 1; display: flex; overflow: hidden; }

/* ---- Vault ---- */
#viewVault { display: flex; }
.pane { overflow-y: auto; }
#treePane { width: 300px; border-right: 1px solid var(--line); background: var(--panel); flex-shrink: 0; }
#notePane { flex: 1; background: var(--bg); }
.pane-head {
  position: sticky; top: 0; background: inherit; padding: 10px 14px;
  font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--line); z-index: 1;
}
.note-head { display: flex; align-items: center; gap: 8px; background: var(--bg); }
.back-btn { display: none; border: none; background: none; color: var(--accent); font-size: 20px; cursor: pointer; padding: 0 4px; }

.tree-list { list-style: none; margin: 0; padding: 4px 0 4px 10px; }
.tree-list .tree-list { padding-left: 16px; }
.tree-dir, .tree-file {
  display: block; width: 100%; text-align: left; border: none; background: none;
  color: var(--text); font-size: 14.5px; padding: 7px 8px; cursor: pointer; border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tree-dir { font-weight: 600; }
.tree-dir:hover, .tree-file:hover { background: var(--accent-soft); }

.markdown { padding: 18px 22px 60px; max-width: 780px; line-height: 1.65; font-size: 15.5px; }
.markdown h1 { font-size: 1.55em; } .markdown h2 { font-size: 1.3em; } .markdown h3 { font-size: 1.12em; }
.markdown a { color: var(--accent); }
.markdown code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.markdown pre { background: var(--panel); border: 1px solid var(--line); padding: 12px; border-radius: 10px; overflow-x: auto; }
.markdown pre code { background: none; padding: 0; }
.markdown blockquote { border-left: 3px solid var(--accent); margin-left: 0; padding-left: 14px; color: var(--muted); }
.markdown img { max-width: 100%; border-radius: 10px; }
.markdown table { border-collapse: collapse; display: block; overflow-x: auto; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: 6px 10px; }
.markdown input[type=checkbox] { accent-color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---- Chat ---- */
.chat-wrap { flex: 1; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; width: 100%; }
.chat-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
}
.ghost-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  padding: 5px 12px; border-radius: 999px; font-size: 12.5px; cursor: pointer;
}
.ghost-btn:hover { color: var(--accent); border-color: var(--accent); }
#messages { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.chat-empty { text-align: center; color: var(--muted); margin-top: 60px; line-height: 1.8; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 16px; line-height: 1.55; font-size: 15px; overflow-wrap: break-word; }
.msg-user { align-self: flex-end; background: var(--user-bubble); color: var(--user-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg-ai { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-ai p:first-child { margin-top: 0; } .msg-ai p:last-child { margin-bottom: 0; }
.msg-ai code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; font-size: .88em; }
.msg-ai pre { background: var(--bg); border: 1px solid var(--line); padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg-busy .dot {
  display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%;
  background: var(--muted); animation: pulse 1.2s infinite;
}
.msg-busy .dot:nth-child(2) { animation-delay: .2s; }
.msg-busy .dot:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

#composer {
  display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); background: var(--panel);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
#msgInput {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  border-radius: 14px; padding: 10px 14px; font-size: 15px; font-family: inherit; outline: none;
}
#msgInput:focus { border-color: var(--accent); }
#sendBtn {
  border: none; background: var(--accent); color: #fff; width: 44px; border-radius: 12px;
  font-size: 17px; cursor: pointer; flex-shrink: 0;
}
#sendBtn:hover { filter: brightness(1.1); }

/* ---- Login / Setup ---- */
.auth-body { display: flex; align-items: center; justify-content: center; }
.auth-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 32px 28px; width: min(92vw, 380px); text-align: center;
}
.auth-card img { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 10px; }
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-card p { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.auth-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); border-radius: 12px; font-size: 15px; outline: none;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card button {
  width: 100%; padding: 12px; border: none; background: var(--accent); color: #fff;
  border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.auth-error { color: #e5484d; font-size: 13.5px; min-height: 18px; margin-top: 10px; }

/* ---- Mobil ---- */
@media (max-width: 720px) {
  #treePane { width: 100%; border-right: none; }
  #notePane { position: absolute; inset: 0; top: 0; }
  #viewVault { position: relative; }
  #notePane { background: var(--bg); }
  .hidden-mobile { display: none; }
  .back-btn { display: block; }
  .markdown { padding: 14px 16px 80px; }
  .msg { max-width: 92%; }
}
@media (min-width: 721px) {
  .hidden-mobile { display: block; }
  #notePane.hidden-mobile { display: block; }
  #treePane.hidden-mobile { display: block; }
}
