/* Kiwion Chat — web UI styles */
:root {
  --green: #4caf50; --green-strong: #2e8b3e; --green-soft: #e8f5e1; --green-ink: #1f5f2a;
  --bg: #f6f8f3; --surface: #ffffff; --surface-2: #f0f4ec; --text: #1c2419; --muted: #66705f;
  --border: #dfe6d8; --danger: #d64545; --warn: #c98a12; --shadow: 0 8px 28px rgba(30, 60, 20, .10);
  --radius: 16px; --radius-sm: 10px; --sidebar: 290px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --green: #6cc76f; --green-strong: #8bd450; --green-soft: #1d2b1c; --green-ink: #b9eaa0;
  --bg: #0f1410; --surface: #171d17; --surface-2: #1f271f; --text: #e6eee2; --muted: #9aa894;
  --border: #2b362a; --shadow: 0 8px 28px rgba(0, 0, 0, .45); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; transition: background .25s, color .25s; }
a { color: var(--green-strong); }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer;
  border-radius: 12px; padding: 10px 18px; background: var(--green); color: #fff; font-weight: 600;
  transition: transform .12s, background .2s, opacity .2s, box-shadow .2s; box-shadow: 0 2px 8px rgba(76,175,80,.25); }
.btn:hover { background: var(--green-strong); } .btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; transform: none; }
.btn.ghost { background: transparent; color: var(--text); box-shadow: none; border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); box-shadow: none; } .btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.icon-btn { border: 0; background: transparent; cursor: pointer; border-radius: 10px; padding: 7px; display: inline-flex;
  color: var(--muted); transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.input { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(76,175,80,.18); }
.hint { font-size: 12px; color: var(--muted); }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 12px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.ok .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(76,175,80,.2); }
.pill.warn .dot { background: var(--warn); } .pill.bad .dot { background: var(--danger); }

/* splash / full screens */
.screen { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.splash { flex-direction: column; gap: 10px; text-align: center; animation: fadeIn .4s ease; }
.splash .mascot { width: 150px; animation: hop 1.1s ease-in-out infinite; }
.brand-title { font-size: 30px; font-weight: 800; letter-spacing: -.5px; margin: 0; }
.brand-title span { color: var(--green-strong); }
.brand-sub { color: var(--muted); margin: 0; font-size: 14px; }
.loader-dots { display: inline-flex; gap: 6px; margin-top: 8px; }
.loader-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: blink 1s infinite; }
.loader-dots i:nth-child(2) { animation-delay: .15s; } .loader-dots i:nth-child(3) { animation-delay: .3s; }

.auth-wrap { width: 100%; max-width: 410px; animation: rise .35s ease; }
.auth-head { text-align: center; margin-bottom: 18px; }
.auth-head img, .auth-head svg { width: 84px; height: 84px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 12px; font-size: 14px; flex-wrap: wrap; gap: 8px; }
.notice { padding: 12px 14px; border-radius: 12px; background: var(--green-soft); color: var(--green-ink); font-size: 14px; margin-bottom: 14px; }
.notice.warn { background: rgba(201,138,18,.12); color: var(--warn); }
.notice.bad { background: rgba(214,69,69,.1); color: var(--danger); }

/* layout */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0;
  transition: transform .25s ease; z-index: 20; }
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; }
.sidebar-head .logo { width: 36px; height: 36px; }
.sidebar-head b { font-size: 17px; }
.chat-search { margin: 4px 14px 8px; }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.chat-item { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 12px; cursor: pointer;
  color: var(--text); text-decoration: none; transition: background .15s; margin-bottom: 2px; }
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--green-soft); color: var(--green-ink); font-weight: 600; }
.chat-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-item .actions { display: none; } .chat-item:hover .actions, .chat-item.active .actions { display: flex; }
.chat-item .actions .icon-btn { padding: 4px; } .chat-item .actions svg { width: 15px; height: 15px; }
.list-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 10px 6px; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px; display: flex; align-items: center; gap: 8px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--green-soft); color: var(--green-ink);
  display: grid; place-items: center; font-weight: 700; flex: none; }
.user-mini { flex: 1; min-width: 0; font-size: 13px; } .user-mini div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-mini .muted { color: var(--muted); font-size: 12px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); }
.topbar .chat-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 24px 16px 12px; scroll-behavior: smooth; }
.messages-inner { max-width: 820px; margin: 0 auto; }
.msg { display: flex; gap: 12px; margin-bottom: 18px; animation: rise .25s ease; }
.msg .bubble { max-width: 100%; min-width: 0; }
.msg.user { justify-content: flex-end; }
.msg.user .user-col { display: flex; flex-direction: column; align-items: flex-end; max-width: 80%; min-width: 0; }
.msg.user .bubble { background: var(--green); color: #fff; padding: 10px 14px; border-radius: 18px 18px 4px 18px;
  white-space: pre-wrap; word-wrap: break-word; }
.msg.assistant .bubble { flex: 1; padding-top: 4px; }
.msg .kiwi-avatar { width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--green-soft); display: grid; place-items: center; }
.msg .kiwi-avatar svg { width: 30px; height: 30px; }
.msg-tools { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-tools, .msg:focus-within .msg-tools, .msg.last .msg-tools { opacity: 1; }
.msg.user .msg-tools { justify-content: flex-end; }
.msg-meta { font-size: 12px; color: var(--muted); margin-left: 6px; align-self: center; }
.msg .status-note { font-size: 12px; color: var(--muted); margin-top: 4px; }
.msg .edit-box textarea { width: 100%; min-height: 80px; }
.msg .edit-box .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

.md { overflow-wrap: anywhere; } .md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; } .md ul, .md ol { padding-left: 1.4em; margin: 0 0 .7em; }
.md code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 6px; }
.md pre { position: relative; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px; overflow-x: auto; margin: .6em 0 1em; }
.md pre code { background: none; padding: 0; font-size: 13px; line-height: 1.55; }
.md pre .code-head { position: absolute; top: 6px; right: 6px; display: flex; gap: 6px; align-items: center; }
.md pre .lang { font-size: 11px; color: var(--muted); }
.md pre .copy-code { font-size: 11px; padding: 3px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  cursor: pointer; color: var(--muted); }
.md table { border-collapse: collapse; margin: .6em 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; }
.md blockquote { margin: .5em 0; padding: .2em 1em; border-left: 3px solid var(--green); color: var(--muted); }
.md a { word-break: break-all; }
.cursor::after { content: ""; display: inline-block; width: 8px; height: 1em; background: var(--green); margin-left: 2px;
  vertical-align: -2px; border-radius: 2px; animation: blink 1s steps(2) infinite; }

.typing { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.typing .hops { display: inline-flex; gap: 4px; }
.typing .hops i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: hopdot .9s infinite ease-in-out; }
.typing .hops i:nth-child(2) { animation-delay: .12s; } .typing .hops i:nth-child(3) { animation-delay: .24s; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); animation: fadeIn .4s ease; }
.empty .mascot { width: 130px; animation: hop 2.2s ease-in-out infinite; }
.empty h2 { color: var(--text); margin: 10px 0 4px; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; max-width: 640px; margin: 22px auto 0; }
.suggestion { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 12px 14px;
  cursor: pointer; transition: border-color .15s, transform .15s; }
.suggestion:hover { border-color: var(--green); transform: translateY(-1px); }

.composer-wrap { padding: 8px 16px 16px; }
.composer { max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px; padding: 8px 8px 8px 14px; box-shadow: var(--shadow); transition: border-color .15s; }
.composer:focus-within { border-color: var(--green); }
.composer textarea { flex: 1; border: 0; outline: none; resize: none; background: transparent; max-height: 220px; min-height: 24px; padding: 6px 0; }
.composer .send { border-radius: 14px; width: 42px; height: 42px; padding: 0; }
.composer .send svg { width: 20px; height: 20px; }
.composer-note { max-width: 820px; margin: 6px auto 0; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }

/* settings */
.settings { flex: 1; overflow-y: auto; padding: 20px 16px 40px; }
.settings-inner { max-width: 760px; margin: 0 auto; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 7px 14px; cursor: pointer; font-size: 14px; }
.tab.active { background: var(--green); border-color: var(--green); color: #fff; }
.section { margin-bottom: 16px; animation: fadeIn .25s ease; } .section h3 { margin: 0 0 12px; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.row-item:last-child { border-bottom: 0; } .row-item .grow { flex: 1; min-width: 0; }
.row-item .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.version-row { cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; border-radius: 10px; }
.version-row:active { background: var(--surface-2); }
.theme-options { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-options button { flex: 1; min-width: 100px; }
.theme-options button.active { outline: 2px solid var(--green); }
.keybox { font-family: var(--mono); background: var(--surface-2); padding: 10px; border-radius: 10px; word-break: break-all; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 12px; } .stat b { font-size: 22px; display: block; }
.stat span { color: var(--muted); font-size: 12px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--green-soft); color: var(--green-ink); } .badge.bad { background: rgba(214,69,69,.12); color: var(--danger); }
.badge.warn { background: rgba(201,138,18,.14); color: var(--warn); }

/* toasts & modals */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 14px; padding: 12px 14px;
  display: flex; gap: 10px; align-items: flex-start; animation: rise .25s ease; font-size: 14px; }
.toast.bad { border-color: rgba(214,69,69,.5); } .toast.warn { border-color: rgba(201,138,18,.5); }
.toast .t-icon { font-size: 20px; line-height: 1; }
.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 8, .45); z-index: 90; display: grid; place-items: center; padding: 16px; animation: fadeIn .2s; }
.modal { width: 100%; max-width: 440px; }
.modal h3 { margin-top: 0; } .modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

.offline-bar { background: var(--warn); color: #fff; text-align: center; padding: 6px; font-size: 13px; }
.scrim { display: none; }

/* error screen */
.error-screen { flex-direction: column; text-align: center; gap: 8px; }
.error-screen .mascot { width: 140px; filter: grayscale(.2); animation: sway 3s ease-in-out infinite; }
.error-screen .code { font-size: 64px; font-weight: 800; color: var(--green-strong); margin: 0; line-height: 1; }

/* animations */
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: none } }
@keyframes hop { 0%, 100% { transform: translateY(0) } 40% { transform: translateY(-14px) } 60% { transform: translateY(-14px) scaleY(.98) } }
@keyframes hopdot { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }
@keyframes blink { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }
@keyframes sway { 0%, 100% { transform: rotate(-4deg) } 50% { transform: rotate(4deg) } }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); transform: translateX(-102%); box-shadow: var(--shadow); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15; }
  .menu-btn { display: inline-flex; }
  .msg.user .user-col { max-width: 88%; }
  .messages { padding: 16px 10px 8px; } .composer-wrap { padding: 6px 10px 10px; }
  .msg .kiwi-avatar { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
