:root {
  --bg: #0b0f14;
  --bg-elev: #121820;
  --bg-msg: #161d27;
  --bg-user: #1a2a22;
  --border: #243041;
  --text: #e7eef7;
  --muted: #8b9bb0;
  --accent: #3dd68c;
  --accent-2: #5b9dff;
  --danger: #ff6b6b;
  --warn: #f0c14b;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}
body {
  overscroll-behavior: none;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand strong { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; }
.logo {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, #1f3b2d, #16304d);
  color: var(--accent);
  font-size: 18px;
}
.top-actions { display: flex; gap: 8px; }

.panel.login {
  margin: 48px 16px;
  padding: 24px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel h1 { margin: 0 0 8px; font-size: 22px; }
.panel p { color: var(--muted); line-height: 1.45; }
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
  font-size: 13px;
  color: var(--muted);
}
input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #0d1218;
  color: var(--text);
  border-radius: 10px;
  padding: 12px 12px;
  font: inherit;
  outline: none;
}
input:focus, textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(91, 157, 255, 0.15);
}
textarea {
  resize: none;
  max-height: 160px;
  line-height: 1.4;
}

button {
  border: 1px solid var(--border);
  background: var(--bg-msg);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary {
  background: linear-gradient(135deg, #1f8f5f, #2bb673);
  border-color: transparent;
  color: #04140c;
  font-weight: 600;
}
button.ghost { background: transparent; }
button.danger {
  background: transparent;
  border-color: #5a2a2a;
  color: var(--danger);
}
.hint { color: var(--muted); font-size: 13px; min-height: 1.2em; }
.hint.error { color: var(--danger); }

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.hidden { display: none !important; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
  background: var(--bg-msg);
}
.msg.user {
  align-self: flex-end;
  background: var(--bg-user);
  border-color: #264536;
}
.msg.assistant { align-self: flex-start; }
.msg.system {
  align-self: center;
  background: transparent;
  border-style: dashed;
  color: var(--muted);
  font-size: 13px;
}
.msg .role {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 4px;
}
.msg.streaming::after {
  content: "▍";
  animation: blink 1s steps(1) infinite;
  color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

.activity {
  margin: 0 12px 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  color: var(--warn);
  font-size: 12px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 12px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: rgba(11, 15, 20, 0.96);
  position: sticky;
  bottom: 0;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-elev);
  color: var(--text);
  width: min(420px, calc(100vw - 24px));
  padding: 0;
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
.settings { padding: 18px; }
.settings h2 { margin: 0 0 8px; font-size: 18px; }
.settings .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* Current workspace bar */
.cwd-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: #0e141c;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  font: inherit;
  border-radius: 0;
}
.cwd-bar:active { background: #15202c; }
.cwd-icon { flex-shrink: 0; }
.cwd-label {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--accent-2);
}

/* Full-screen-ish folder picker (mobile) */
dialog.folder-dialog {
  width: min(520px, calc(100vw - 12px));
  max-height: min(88vh, 720px);
  margin: auto;
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
}
.folder-sheet {
  display: flex;
  flex-direction: column;
  max-height: min(88vh, 720px);
  min-height: 360px;
}
.folder-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--border);
}
.folder-title { flex: 1; min-width: 0; }
.folder-title strong { display: block; font-size: 15px; }
.folder-title small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder-path-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.folder-path-row input {
  padding: 10px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.folder-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0;
  min-height: 180px;
}
.folder-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-bottom: 1px solid rgba(36, 48, 65, 0.55);
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
  border-radius: 0;
}
.folder-item:active,
.folder-item:hover { background: #15202c; }
.folder-item .fi-icon { width: 1.4em; text-align: center; flex-shrink: 0; }
.folder-item .fi-name {
  flex: 1;
  min-width: 0;
  word-break: break-all;
  font-size: 14px;
}
.folder-item.file {
  color: var(--muted);
  opacity: 0.75;
  cursor: default;
}
.folder-item.drive .fi-name { font-weight: 600; }
.folder-section {
  padding: 8px 14px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.folder-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.folder-foot {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: #0e141c;
}
.folder-foot .primary { flex: 1; }
#folderError {
  margin: 0;
  padding: 6px 12px;
  font-size: 12px;
}
#folderError.hidden { display: none !important; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #0d1218;
  padding: 1px 5px;
  border-radius: 5px;
}

@media (max-width: 520px) {
  .msg { max-width: 96%; }
  .brand strong { font-size: 14px; }
}
