/* nyay design system — professional, WCAG AA, light/dark */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #e2e5ea;
  --text: #16181d;
  --text-2: #5b6270;
  --text-3: #8a92a0;
  --accent: #2f3ce5;
  --accent-2: #2630b8;
  --accent-soft: #eef0ff;
  --ok: #157f4a;
  --warn: #a86500;
  --warn-bg: #fff4e0;
  --danger: #c6362e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 8px 24px rgba(16, 20, 30, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #101318;
  --surface: #171b22;
  --surface-2: #1f2430;
  --border: #2a303c;
  --text: #e8eaf0;
  --text-2: #a6adba;
  --text-3: #6f7887;
  --accent: #7a85ff;
  --accent-2: #5a63e0;
  --accent-soft: #20263f;
  --ok: #3ecf8e;
  --warn: #e8a23d;
  --warn-bg: #33270f;
  --danger: #ef6b63;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
svg { width: 20px; height: 20px; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--text-2); font-size: .875rem; }

/* layout */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  font-weight: 500; font-size: .9rem; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn.icon { padding: 8px; border: none; background: transparent; color: var(--text-2); }
.btn.icon:hover { background: var(--surface-2); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: default; }

/* sidebar */
.sidebar-head { display: flex; gap: 4px; padding: 12px; align-items: center; }
#btn-new { flex: 1; justify-content: flex-start; }
.sidebar-close { display: none; }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.chat-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-size: .875rem; text-align: left;
}
.chat-item:hover { background: var(--surface-2); color: var(--text); }
.chat-item.active { background: var(--accent-soft); color: var(--accent); }
.chat-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .del { opacity: 0; }
.chat-item:hover .del { opacity: 1; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; flex-shrink: 0;
}
.avatar svg { width: 17px; height: 17px; }
.user-email { flex: 1; font-size: .8rem; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
}
.brand-mark svg { width: 19px; height: 19px; }
.brand-name { font-weight: 700; font-size: 1.1rem; letter-spacing: -.02em; }
.brand-badge {
  font-size: .68rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-soft);
  padding: 3px 8px; border-radius: 999px;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.lang-picker {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 10px; color: var(--text-2);
}
.lang-icon { width: 16px; height: 16px; }
.lang-picker select { border: none; background: none; outline: none; color: var(--text); font-size: .85rem; cursor: pointer; }

/* thread */
.thread {
  flex: 1; overflow-y: auto; padding: 24px 16px 8px;
  display: flex; flex-direction: column; gap: 20px;
  scroll-behavior: smooth;
}
.msg { display: flex; gap: 14px; max-width: 820px; width: 100%; margin: 0 auto; }
.msg .avatar { width: 30px; height: 30px; }
.msg-body { flex: 1; min-width: 0; }
.msg-user .msg-body { background: var(--surface-2); padding: 12px 16px; border-radius: var(--radius); }
.msg-assistant .msg-body { padding: 2px 0; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-actions { display: flex; gap: 4px; margin-top: 8px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }

/* citations / sources */
.sources { margin-top: 12px; }
.source-item { margin-bottom: 6px; }
.source-head {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  font-size: .82rem; color: var(--text-2); width: 100%; text-align: left;
}
.source-head:hover { border-color: var(--accent); color: var(--text); }
.source-head .chev { margin-left: auto; width: 15px; height: 15px; transition: transform .15s; }
.source-item.open .chev { transform: rotate(180deg); }
.source-body {
  display: none; margin-top: 4px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .82rem; color: var(--text-2);
  max-height: 220px; overflow-y: auto;
}
.source-item.open .source-body { display: block; }

/* warning banner */
.warning {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  color: var(--warn); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: .85rem; margin-top: 12px;
}
.warning svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: 2px; }

/* typing */
.typing { display: inline-flex; gap: 5px; align-items: center; padding: 6px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* composer */
.composer { padding: 8px 16px 14px; max-width: 820px; width: 100%; margin: 0 auto; }
.composer-form {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 8px 8px 8px 16px; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.composer-form:focus-within { border-color: var(--accent); }
.composer-form textarea {
  flex: 1; border: none; outline: none; background: none; resize: none;
  max-height: 180px; padding: 8px 0; line-height: 1.5;
}
.btn.send {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
  background: var(--accent); color: #fff; border: none; display: grid; place-items: center;
}
.btn.send:hover { background: var(--accent-2); }
.btn.send:disabled { background: var(--text-3); cursor: default; }
.btn.send svg { width: 18px; height: 18px; }
.disclaimer { text-align: center; font-size: .72rem; color: var(--text-3); margin-top: 10px; }

/* splash */
.splash {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; flex: 1; gap: 14px; padding: 32px 16px; max-width: 640px; margin: 0 auto;
}
.splash.show { display: flex; }
.splash-mark {
  width: 64px; height: 64px; border-radius: 18px;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
}
.splash-mark svg { width: 34px; height: 34px; }
.splash h1 { font-size: 1.6rem; letter-spacing: -.02em; }
.splash-sub { color: var(--text-2); max-width: 440px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface);
  padding: 9px 14px; border-radius: 999px; font-size: .85rem; color: var(--text-2);
  transition: border-color .15s, color .15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* modals */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 12, 16, .5);
  display: grid; place-items: center; padding: 16px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  width: 100%; max-width: 420px; position: relative; padding: 12px;
}
.modal.wide { max-width: 640px; }
.modal-close { position: absolute; top: 10px; right: 10px; }
.modal-body { padding: 20px 8px 8px; }
.modal h2 { font-size: 1.2rem; margin-bottom: 4px; }
.modal .muted { margin-bottom: 16px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px; color: var(--text-2); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.dev-code { font-family: var(--mono); font-size: 1.1rem; margin-bottom: 12px; padding: 8px; background: var(--surface-2); border-radius: var(--radius-sm); text-align: center; }
.draft-types { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.draft-types .chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.draft-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.draft-fields .field.full { grid-column: 1 / -1; }
.draft-doc {
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 16px; font-family: var(--mono); font-size: .78rem;
  white-space: pre-wrap; max-height: 320px; overflow-y: auto;
  margin-bottom: 12px;
}
.empty-state { text-align: center; color: var(--text-3); padding: 40px 0; font-size: .85rem; }

/* responsive */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .sidebar.open ~ .main { display: none; }
  .draft-fields { grid-template-columns: 1fr; }
}
