:root {
  --bg: #0a0c11;
  --card: #141822;
  --card2: #1a2030;
  --line: #2a3348;
  --text: #f0f3fa;
  --muted: #8f98ad;
  --accent: #7c5cff;
  --accent2: #3dd6c6;
  --danger: #ff5c7a;
  --ok: #3dd68c;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(700px 320px at 0% 0%, #1b1540 0%, transparent 55%),
    radial-gradient(600px 280px at 100% 0%, #0c2a28 0%, transparent 50%),
    var(--bg);
}

.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px;
  backdrop-filter: blur(14px);
  background: rgba(10,12,17,.82);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.logo {
  width: 38px; height: 38px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center; font-weight: 800;
}
.brand h1 { margin: 0; font-size: 1.05rem; }
.brand small { color: var(--muted); font-size: .75rem; }

.screens { flex: 1; overflow: auto; padding: 12px 14px calc(18px + var(--safe-b)); }
.screen { display: none; }
.screen.active { display: block; animation: in .16s ease; }
@keyframes in { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

.quick {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px;
}
.qbtn {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 14px; padding: 14px 10px; font-weight: 700; font-size: .92rem;
  text-align: left; cursor: pointer; text-decoration: none; display: block;
}
.qbtn span { display: block; color: var(--muted); font-weight: 500; font-size: .75rem; margin-top: 4px; }
.qbtn.primary { background: linear-gradient(135deg,#5b3dff,#4f7cff); border: none; }
.qbtn.primary span { color: rgba(255,255,255,.8); }

.row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.row input, .field input, .field textarea, .field select {
  width: 100%; background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px; font: inherit; outline: none;
}
.field { margin-bottom: 10px; }
.field label { display: block; color: var(--muted); font-size: .8rem; margin-bottom: 5px; font-weight: 600; }
.btn {
  border: none; border-radius: 12px; padding: 12px 14px; font-weight: 700; font: inherit;
  background: linear-gradient(135deg,#6a4dff,#4f7cff); color: #fff; cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; }
.btn.ghost { background: var(--card); border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: linear-gradient(135deg,#ff4d6d,#c73b55); }
.btn.sm { padding: 8px 10px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; }

.list { display: grid; gap: 10px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.card h3 { margin: 0 0 4px; font-size: 1.05rem; }
.card .meta { color: var(--muted); font-size: .8rem; margin-bottom: 10px; }
.card .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.tabs {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: .88rem; cursor: pointer;
}
.tab.active { background: #2a2258; border-color: #6a4dff; }

.files { display: grid; gap: 6px; }
.file {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  background: var(--card2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; cursor: pointer;
}
.file .name { font-weight: 600; word-break: break-all; }
.file .sz { color: var(--muted); font-size: .75rem; }

.editor-wrap { display: flex; flex-direction: column; gap: 8px; min-height: 50vh; }
#editor {
  width: 100%; min-height: 48vh; resize: vertical;
  background: #0e121a; border: 1px solid var(--line); color: #e8ecf7;
  border-radius: 12px; padding: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px; line-height: 1.45;
}

.chat {
  display: flex; flex-direction: column; gap: 8px;
  min-height: 40vh; max-height: 55vh; overflow: auto; padding: 4px 0 8px;
}
.bubble {
  max-width: 92%; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line);
  white-space: pre-wrap; word-break: break-word; line-height: 1.4; font-size: .95rem;
}
.bubble.user { align-self: flex-end; background: #1e2740; }
.bubble.note { align-self: stretch; background: #1a2430; border-color: #355; }
.bubble .who { font-size: .7rem; color: var(--muted); margin-bottom: 4px; font-weight: 700; text-transform: uppercase; }
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  position: sticky; bottom: 0; padding-top: 6px;
  background: linear-gradient(180deg, transparent, rgba(10,12,17,.95) 30%);
}
.composer textarea {
  flex: 1; min-height: 44px; max-height: 120px; resize: none;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 10px; font: inherit;
}

.toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%);
  background: #222a3d; border: 1px solid var(--line); color: var(--text);
  padding: 10px 14px; border-radius: 999px; font-size: .88rem; z-index: 50;
  opacity: 0; pointer-events: none; transition: .2s;
  max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; place-items: center;
  z-index: 60; padding: 20px;
}
.overlay.show { display: grid; }
.modal {
  width: min(400px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 18px;
}
.modal h2 { margin: 0 0 8px; font-size: 1.15rem; }
.modal p { margin: 0 0 12px; color: var(--muted); font-size: .9rem; }

.back {
  border: none; background: transparent; color: var(--accent2); font-weight: 700;
  font-size: .95rem; padding: 0; cursor: pointer;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block;
}
