:root {
  --bg: #ffffff;
  --side: #f6f6f4;
  --hover: #ececE8;
  --active: #e6e6e1;
  --surface: #f3f3f0;
  --ink: #181816;
  --muted: #6b6b66;
  --accent: #0b7a5a;
  --accent-ink: #ffffff;
  --negative: #b4361f;
  --radius: 14px;
  --font: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b19; --side: #141413; --hover: #232321; --active: #2c2c29; --surface: #242422;
    --ink: #ecece8; --muted: #9a9a93; --accent: #2fb88a; --accent-ink: #0c1f18; --negative: #ef7c64;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: 268px 1fr; height: 100vh; height: 100dvh; }

/* sidebar */
.side { background: var(--side); display: flex; flex-direction: column; padding: 14px 10px; min-height: 0; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.mark { width: 28px; height: 28px; }
.new-chat { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: transparent; border-radius: 10px; font-weight: 500; text-align: left; }
.new-chat:hover { background: var(--hover); }
.history { flex: 1; overflow: auto; margin-top: 14px; display: flex; flex-direction: column; gap: 2px; }
.history h2 { font-size: 13px; font-weight: 500; color: var(--muted); margin: 10px 10px 6px; }
.h-item { display: flex; align-items: center; gap: 6px; border-radius: 10px; }
.h-item:hover { background: var(--hover); }
.h-item.on { background: var(--active); }
.h-item button.open { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 10px; }
.h-item .t { display: block; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-item .s { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-item .del { opacity: 0; border: 0; background: none; color: var(--muted); padding: 6px; margin-right: 4px; border-radius: 8px; }
.h-item:hover .del, .h-item .del:focus-visible { opacity: 1; }
.h-item .del:hover { color: var(--negative); }
.side-foot { font-size: 12.5px; color: var(--muted); margin: 10px 10px 4px; line-height: 1.4; }
.history .none { font-size: 14px; color: var(--muted); margin: 8px 10px; }

.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; border: 0; background: transparent; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
#closeSide, .menu, .scrim { display: none; }

/* main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.bar { display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 20px; flex: none; }
.bar h1 { margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scroll { flex: 1; overflow-y: auto; padding: 8px 20px 24px; scroll-behavior: smooth; }
.thread { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }

/* welcome */
.welcome { min-height: 52vh; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 22px; padding-top: 6vh; }
.welcome h2 { margin: 0; font-size: clamp(28px, 4.2vw, 40px); line-height: 1.1; letter-spacing: -0.03em; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 560px; }
.chip { border: 0; background: var(--surface); padding: 9px 16px; border-radius: 999px; font-size: 14.5px; }
.chip:hover { background: var(--active); }

/* messages */
.msg-user { align-self: flex-end; max-width: 80%; background: var(--surface); padding: 10px 16px; border-radius: 20px 20px 6px 20px; overflow-wrap: anywhere; }
.msg-ai { display: flex; gap: 14px; align-items: flex-start; }
.msg-ai .avatar { flex: none; width: 28px; height: 28px; margin-top: 1px; }
.msg-ai .body { flex: 1; min-width: 0; }
.msg-ai p { margin: 0 0 12px; }
.msg-ai .sub { color: var(--muted); font-size: 14.5px; }

.typing { display: inline-flex; gap: 5px; padding: 10px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 16px; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border: 0; border-radius: 999px; background: var(--surface); font-size: 14.5px; font-weight: 500; text-decoration: none; color: var(--ink); }
.btn:hover { background: var(--active); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: progress; }
.seg { display: inline-flex; background: var(--surface); border-radius: 999px; padding: 3px; margin-left: auto; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 999px; font-size: 13.5px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--ink); }

/* grid */
.grid { columns: 3 200px; column-gap: 10px; }
.tile { position: relative; break-inside: avoid; margin: 0 0 10px; border-radius: 12px; overflow: hidden; background: var(--surface); cursor: zoom-in; min-height: 70px; }
.tile img { display: block; width: 100%; height: auto; }
.tile.checker img { background: repeating-conic-gradient(var(--surface) 0 25%, var(--bg) 0 50%) 0 0 / 16px 16px; padding: 14px; }
.tile .over { position: absolute; inset: auto 0 0 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 26px 10px 8px; background: linear-gradient(transparent, rgba(0,0,0,.55)); opacity: 0; transition: opacity .15s; color: #fff; font-size: 12.5px; }
.tile:hover .over, .tile:focus-within .over { opacity: 1; }
@media (hover: none) { .tile .over { opacity: 1; } }
.tile .over a { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: #fff; color: #111; flex: none; }
.tile .over a:hover { background: var(--accent); color: #fff; }
.tile .open-hit { position: absolute; inset: 0; border: 0; background: none; }
.tile .over { pointer-events: none; } .tile .over a { pointer-events: auto; position: relative; z-index: 2; }
.tile.in { animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* empty / error */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 18px 0 8px; }
.empty svg { width: min(300px, 80%); height: auto; }
.empty h3 { margin: 10px 0 0; font-size: 22px; letter-spacing: -0.02em; font-weight: 600; }
.empty p { margin: 0; color: var(--muted); max-width: 420px; }
.err { color: var(--negative); }
@media (prefers-reduced-motion: no-preference) {
  .swing { transform-origin: 150px 22px; animation: swing 4.5s ease-in-out infinite; }
  .bob { animation: bob 3s ease-in-out infinite; }
}
@keyframes swing { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* composer */
.composer-wrap { flex: none; padding: 0 20px 14px; }
.composer, .hint { max-width: 860px; margin-left: auto; margin-right: auto; }
.composer { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 28px; padding: 8px 8px 8px 22px; }
.composer:focus-within { background: var(--active); }
.composer input { flex: 1; min-width: 0; border: 0; background: none; outline: 0; padding: 8px 0; font-size: 16px; }
.composer input::placeholder { color: var(--muted); }
.send { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--ink); color: var(--bg); display: grid; place-items: center; flex: none; }
.send:disabled { opacity: .25; cursor: default; }
.hint { font-size: 12.5px; color: var(--muted); text-align: center; margin-top: 8px; margin-bottom: 0; }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(12,12,11,.92); display: grid; place-items: center; padding: 56px 64px; color: #fff; }
.lightbox figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 100%; max-height: 100%; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 170px); object-fit: contain; border-radius: 6px; }
.lightbox figcaption { display: flex; align-items: center; gap: 16px; font-size: 14px; color: #cfcfc8; }
.lightbox .btn { background: var(--accent); color: var(--accent-ink); }
.lb-close { position: absolute; top: 14px; right: 14px; color: #fff; }
.lb-nav { position: absolute; top: 50%; translate: 0 -50%; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255,255,255,.12); color: #fff; font-size: 28px; line-height: 1; }
.lb-nav:hover { background: rgba(255,255,255,.24); }
.lb-nav.prev { left: 12px; } .lb-nav.next { right: 12px; }

/* phone */
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40; transform: translateX(-100%); transition: transform .22s ease; }
  .app.open .side { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; opacity: 0; pointer-events: none; transition: opacity .2s; }
  .app.open .scrim { opacity: 1; pointer-events: auto; }
  .menu, #closeSide { display: grid; }
  .bar { padding: 0 10px; }
  .scroll, .composer-wrap { padding-left: 14px; padding-right: 14px; }
  .grid { columns: 2 140px; column-gap: 8px; }
  .tile { margin-bottom: 8px; }
  .seg { margin-left: 0; }
  .lightbox { padding: 56px 12px 16px; }
  .lb-nav { top: auto; bottom: 14px; translate: none; }
  .msg-user { max-width: 92%; }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
