@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --sidebar: #171717;
  --sidebar-hover: #2a2a2a;
  --sidebar-muted: #a6a6a6;
  --canvas: #212121;
  --canvas-soft: #2b2b2b;
  --canvas-raised: #303030;
  --text: #ececec;
  --muted: #a7a7a7;
  --border: rgba(255, 255, 255, .12);
  --accent: #8c3fc5;
  --accent-light: #b48bdd;
  --lime: #b9ee59;
  --font-body: 'DM Sans', sans-serif;
  --font-display: 'Space Grotesk', sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--text); font: 15px/1.55 var(--font-body); -webkit-font-smoothing: antialiased; }
button, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 3px; }
::selection { background: rgba(180, 139, 221, .45); color: #fff; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: 272px; display: flex; flex-direction: column; padding: 17px 12px 12px; background: var(--sidebar); color: var(--sidebar-muted); }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 0 9px 18px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: #f4f4f4; font: 600 1.02rem var(--font-display); letter-spacing: -.035em; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center; overflow: hidden; border-radius: 9px; background: #fff; }
.brand-mark img { width: 26px; height: 26px; object-fit: contain; }
.icon-button { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 8px; background: transparent; color: var(--sidebar-muted); font-size: 1.1rem; transition: background .2s var(--ease), color .2s var(--ease); }
.icon-button:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-close { display: none; font-size: 1.55rem; line-height: 1; }
.new-chat { width: 100%; display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 8px; background: transparent; color: #f2f2f2; text-align: left; transition: background .2s var(--ease); }
.new-chat:hover { background: var(--sidebar-hover); }
.new-chat-icon { font-size: 1.35rem; font-weight: 300; line-height: 1; }
.shortcut { margin-left: auto; color: #777; font-size: .72rem; }
.history { flex: 1; overflow-y: auto; padding: 26px 0 20px; }
.history-label { margin: 0 10px 8px; color: #777; font-size: .7rem; font-weight: 600; letter-spacing: .04em; }
.history-label.older { margin-top: 24px; }
.history-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 7px; background: transparent; color: #c7c7c7; text-align: left; font-size: .86rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; transition: background .2s var(--ease), color .2s var(--ease); }
.history-item:hover, .history-item.selected { background: var(--sidebar-hover); color: #fff; }
.history-icon { width: 17px; color: #878787; font-size: 1rem; }
.sidebar-bottom { border-top: 1px solid rgba(255, 255, 255, .1); padding-top: 10px; }
.sidebar-link { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 7px; color: #b7b7b7; font-size: .83rem; transition: background .2s var(--ease), color .2s var(--ease); }
.sidebar-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-link-icon { width: 16px; color: #8c8c8c; text-align: center; font-size: 1rem; }
.user-card { display: flex; align-items: center; gap: 10px; margin-top: 9px; padding: 10px; border-top: 1px solid rgba(255, 255, 255, .08); }
.avatar { width: 28px; height: 28px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: linear-gradient(135deg, var(--accent), #542682); color: #fff; font-weight: 700; }
.user-copy { display: flex; flex: 1; min-width: 0; flex-direction: column; }
.user-copy strong { color: #ddd; font-size: .78rem; font-weight: 500; }
.user-copy small { color: #777; font-size: .68rem; }
.more-button { color: #777; letter-spacing: 2px; }
.sidebar-scrim { display: none; }

.chat-area { min-height: 100vh; display: flex; flex: 1; flex-direction: column; margin-left: 272px; background: var(--canvas); }
.chat-header { height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 26px; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.menu-button { display: none; color: #aaa; }
.header-actions { display: flex; gap: 4px; }
.header-actions .icon-button { color: #aaa; font-size: 1.05rem; }
.connection-status { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; margin-right: 10px; color: #8d8d8d; font-size: .7rem; }
.connection-status i { width: 7px; height: 7px; display: inline-block; border-radius: 50%; background: #d6a54d; box-shadow: 0 0 0 3px rgba(214, 165, 77, .13); }
.connection-status.connected i { background: #63c174; box-shadow: 0 0 0 3px rgba(99, 193, 116, .13); }
.connection-status.fallback i { background: #d6a54d; box-shadow: 0 0 0 3px rgba(214, 165, 77, .13); }

.conversation { width: min(100% - 48px, 820px); flex: 1; margin: 0 auto; padding: 60px 0 30px; }
.welcome-state { display: flex; min-height: 100%; flex-direction: column; align-items: center; justify-content: center; padding: 5vh 0 4vh; text-align: center; }
.welcome-mark { width: 54px; height: 54px; display: grid; place-items: center; margin-bottom: 21px; border-radius: 17px; background: #fff; box-shadow: 0 0 0 1px rgba(255, 255, 255, .15), 0 10px 30px rgba(0, 0, 0, .25); }
.welcome-mark img { width: 47px; height: 47px; object-fit: contain; }
.welcome-state h1 { margin: 0; color: #f0f0f0; font: 500 clamp(1.55rem, 3vw, 2rem) var(--font-display); letter-spacing: -.045em; }
.welcome-state > p { margin-top: 9px; color: #999; font-size: .92rem; }
.prompt-grid { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 40px; }
.prompt-card { min-height: 76px; display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 11px; background: rgba(255, 255, 255, .025); color: var(--text); text-align: left; transition: background .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease); }
.prompt-card:hover { transform: translateY(-2px); border-color: rgba(255, 255, 255, .24); background: var(--canvas-soft); }
.prompt-icon { width: 31px; height: 31px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 9px; font-size: 1.05rem; }
.prompt-icon.purple { background: rgba(140, 63, 197, .18); color: var(--accent-light); }
.prompt-icon.lime { background: rgba(185, 238, 89, .13); color: var(--lime); }
.prompt-icon.blue { background: rgba(92, 163, 239, .15); color: #8ec6ff; }
.prompt-icon.orange { background: rgba(242, 160, 91, .14); color: #f2b17b; }
.prompt-card span:nth-child(2) { display: flex; min-width: 0; flex-direction: column; }
.prompt-card strong { font-size: .82rem; font-weight: 500; }
.prompt-card small { margin-top: 2px; color: #8c8c8c; font-size: .72rem; }
.prompt-arrow { margin-left: auto; align-self: flex-start; color: #777; font-size: .95rem; }
.message-list { padding-bottom: 24px; }
.message { display: flex; gap: 16px; padding: 20px 0; }
.message + .message { border-top: 1px solid rgba(255, 255, 255, .06); }
.message-avatar { width: 30px; height: 30px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 8px; font-weight: 700; }
.message.user .message-avatar { background: #444; color: #ddd; font-size: .78rem; }
.message.assistant .message-avatar { background: #fff; overflow: hidden; }
.message.assistant .message-avatar img { width: 27px; height: 27px; object-fit: contain; }
.message-body { min-width: 0; flex: 1; padding-top: 3px; color: #e1e1e1; white-space: pre-wrap; }
.message-body p { margin: 0; }
.message-label { display: block; margin-bottom: 5px; color: #8e8e8e; font-size: .73rem; font-weight: 600; }
.typing-dots { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing-dots i { width: 6px; height: 6px; border-radius: 50%; background: #a0a0a0; animation: pulse 1.1s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }.typing-dots i:nth-child(3) { animation-delay: .3s; }

.composer-wrap { width: min(100% - 48px, 820px); margin: 0 auto; padding: 8px 0 22px; }
.composer { position: relative; overflow: hidden; border: 1px solid rgba(255, 255, 255, .17); border-radius: 13px; background: var(--canvas-raised); box-shadow: 0 6px 24px rgba(0, 0, 0, .13); transition: border-color .2s, box-shadow .2s; }
.composer:focus-within { border-color: rgba(255, 255, 255, .3); box-shadow: 0 8px 30px rgba(0, 0, 0, .2); }
.composer textarea { width: 100%; min-height: 48px; max-height: 190px; display: block; padding: 16px 17px 5px; resize: none; border: 0; outline: 0; background: transparent; color: #efefef; font-size: .95rem; }
.composer textarea::placeholder { color: #909090; }
.composer-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 5px 9px 9px 12px; }
.composer-tools, .composer-actions { display: flex; align-items: center; gap: 4px; }
.composer-tool { display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 7px; background: transparent; color: #999; font-size: .74rem; }
.composer-tool:hover, .composer-tool.active { background: rgba(255, 255, 255, .08); color: #e5e5e5; }
.composer-tool span:first-child { font-size: 1rem; }
.char-count { margin-right: 6px; color: #777; font-size: .67rem; }
.send-button { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; background: #5b5b5b; color: #242424; font-size: 1.22rem; line-height: 1; transition: background .2s, color .2s, transform .2s; }
.send-button:not(:disabled) { background: #eee; color: #222; }
.send-button:not(:disabled):hover { transform: translateY(-1px); background: #fff; }
.send-button:disabled { cursor: not-allowed; opacity: .7; }
.composer-note { margin: 9px 0 0; color: #777; text-align: center; font-size: .68rem; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: 300px; padding: 11px 15px; border: 1px solid rgba(255, 255, 255, .15); border-radius: 9px; background: #3a3a3a; color: #eee; box-shadow: 0 8px 25px rgba(0, 0, 0, .25); font-size: .8rem; opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .2s, transform .2s; }
.toast.visible { opacity: 1; transform: translateY(0); }

@keyframes pulse { 0%, 100% { opacity: .3; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; } }
@media (max-width: 760px) {
  .sidebar { width: min(300px, 86vw); transform: translateX(-100%); box-shadow: 14px 0 40px rgba(0, 0, 0, .4); transition: transform .25s var(--ease); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-grid; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 10; display: block; background: rgba(0, 0, 0, .55); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .sidebar-scrim.open { opacity: 1; pointer-events: auto; }
  .chat-area { margin-left: 0; }
  .chat-header { height: 58px; padding: 0 12px; }
  .menu-button { display: inline-grid; }
  .header-actions .icon-button:first-child { display: none; }
  .conversation, .composer-wrap { width: min(100% - 28px, 820px); }
  .conversation { padding-top: 30px; }
  .welcome-state { padding: 3vh 0 2vh; }
  .prompt-grid { grid-template-columns: 1fr; margin-top: 30px; }
  .prompt-card { min-height: 64px; }
  .composer-wrap { padding-bottom: 13px; }
  .composer-tool span:last-child, .char-count { display: none; }
}
@media (max-width: 420px) {
  .connection-status { display: none; }
  .welcome-state h1 { font-size: 1.45rem; }
  .welcome-state > p { font-size: .84rem; }
  .message { gap: 10px; }
}

body.light-mode {
  --sidebar: #f7f7f8;
  --sidebar-hover: #e8e8eb;
  --sidebar-muted: #65656b;
  --canvas: #fff;
  --canvas-soft: #f4f4f5;
  --canvas-raised: #fff;
  --text: #252525;
  --muted: #6c6c72;
  --border: rgba(0, 0, 0, .12);
}
body.light-mode .brand,
body.light-mode .new-chat,
body.light-mode .welcome-state h1,
body.light-mode .prompt-card { color: #252525; }
body.light-mode .history-item,
body.light-mode .sidebar-link { color: #505056; }
body.light-mode .history-item:hover,
body.light-mode .history-item.selected,
body.light-mode .sidebar-link:hover,
body.light-mode .new-chat:hover { color: #202024; }
body.light-mode .welcome-state > p,
body.light-mode .prompt-card small,
body.light-mode .message-label,
body.light-mode .composer-note { color: #77777e; }
body.light-mode .message-body { color: #303036; }
body.light-mode .message + .message { border-color: rgba(0, 0, 0, .08); }
body.light-mode .composer textarea { color: #252525; }
body.light-mode .composer textarea::placeholder { color: #88888f; }
body.light-mode .send-button:not(:disabled) { background: #252525; color: #fff; }
body.light-mode .sidebar-bottom,
body.light-mode .user-card { border-color: rgba(0, 0, 0, .1); }

/* Auth / modal styles */
.auth-modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); z-index: 60; }
.auth-modal[aria-hidden="true"] { display: none; }
.auth-panel { width: 420px; max-width: 94%; background: var(--canvas-raised); border-radius: 12px; padding: 18px; box-shadow: 0 18px 50px rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.04); }
.auth-panel h2 { margin: 0 0 8px; font: 600 1.05rem var(--font-display); }
.auth-panel label { display: block; margin-top: 8px; color: var(--muted); }
.auth-panel input, .auth-panel select { width: 100%; padding: 9px 10px; margin-top: 6px; border-radius: 8px; border: 1px solid rgba(255,255,255,.06); background: transparent; color: var(--text); font: inherit; }
.auth-panel select option { background: var(--canvas-raised); color: var(--text); }
.auth-actions { display:flex; gap:8px; margin-top: 12px; }
.auth-actions button { flex: 1; padding: 9px; border-radius: 8px; border: 0; cursor: pointer; font: inherit; font-weight: 600; }
.auth-actions button:first-child { background: var(--accent); color: #fff; }
.auth-actions button:first-child:hover { background: var(--accent-light); }
.auth-actions button:last-child { background: rgba(255,255,255,.08); color: var(--text); }
.auth-close { position: absolute; right: 18px; top: 14px; background: transparent; border: 0; font-size: 1.3rem; color: var(--muted); }
.auth-error { color: #ffb4b4; margin-top: 8px; }

/* Model menu */
.model-menu { position: absolute; bottom: 64px; left: 12px; min-width: 240px; background: var(--canvas-raised); border: 1px solid rgba(255,255,255,.1); border-radius: 10px; padding: 6px; display: none; z-index: 40; max-height: 320px; overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.model-item { display: block; width: 100%; padding: 8px 10px; text-align: left; color: var(--text); background: transparent; border: 0; border-radius: 6px; margin: 2px 0; font-size: .82rem; }
.model-item:hover { background: rgba(255,255,255,.05); }
.model-item.active { background: rgba(185, 238, 89, .1); color: var(--lime); }

/* Model picker in composer */
.composer-tool.model-picker { gap: 6px; }
.composer-tool.model-picker .model-badge { color: inherit; font-size: .74rem; font-weight: 500; }
.composer-tool.model-picker .chevron { font-size: .85rem; opacity: .6; }
.composer-wrap { position: relative; }
.provider-switch { display: inline-flex; gap: 2px; padding: 2px; border-radius: 8px; background: rgba(255,255,255,.06); }
.provider-tab { padding: 5px 12px; border-radius: 6px; background: transparent; color: var(--muted); font-size: .72rem; font-weight: 600; letter-spacing: .02em; transition: background .2s var(--ease), color .2s var(--ease); }
.provider-tab:hover { color: var(--text); }
.provider-tab.active { background: var(--canvas-raised); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.15); }

/* Small action buttons inside history items (will be added dynamically) */
.history-actions { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; }
.history-action { display: inline-grid; width: 28px; height: 28px; place-items: center; border-radius: 6px; color: #9a9a9a; }
.history-item:hover .history-action { color: #fff; background: rgba(255,255,255,.03); }

/* Memories list */
#memories-list .memory { padding: 8px; border-bottom: 1px solid rgba(255,255,255,.03); display:flex; justify-content:space-between; gap:8px; }
#memories-list .memory .content { flex:1; color:var(--text); }
#memories-list .memory .meta { color:var(--muted); font-size: .8rem; }

/* Header action tweaks */
.header-actions .icon-button { width: 36px; height: 36px; }
