/* =======================================================================
   PORKA AI — V2 theme
   Monochrome, modern, slightly futuristic. Dark default + light mode.
   All color comes from CSS variables so [data-theme] flips the whole UI.
   ======================================================================= */

/* ---------- Design tokens ---------- */
:root,
[data-theme="dark"] {
  --bg: #000000;
  --bg-1: #0a0a0b;
  --bg-2: #131316;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.07);
  --surface-3: rgba(255, 255, 255, 0.10);
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.20);
  --text: #f4f4f5;
  --text-dim: #a6a6ae;
  --muted: #6a6a73;
  --accent: #ffffff;
  --on-accent: #000000;
  --logo-a: #ffffff;
  --logo-b: #8a8a92;
  --glow: rgba(255, 255, 255, 0.22);
  --danger: #ff6b75;
  --user-bubble: rgba(255, 255, 255, 0.085);
  --grid-line: rgba(255, 255, 255, 0.035);
  --orb: rgba(255, 255, 255, 0.06);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --shadow-sm: 0 6px 20px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 11px;
  --radius-lg: 22px;
}

[data-theme="light"] {
  --bg: #eef0f3;
  --bg-1: #ffffff;
  --bg-2: #f3f4f6;
  --surface: rgba(10, 12, 20, 0.035);
  --surface-2: rgba(10, 12, 20, 0.06);
  --surface-3: rgba(10, 12, 20, 0.09);
  --border: rgba(10, 12, 20, 0.11);
  --border-strong: rgba(10, 12, 20, 0.22);
  --text: #0c0d10;
  --text-dim: #51525c;
  --muted: #8a8b93;
  --accent: #0b0c0f;
  --on-accent: #ffffff;
  --logo-a: #0b0c0f;
  --logo-b: #9a9ba2;
  --glow: rgba(0, 0, 0, 0.16);
  --danger: #d4323c;
  --user-bubble: rgba(10, 12, 20, 0.055);
  --grid-line: rgba(10, 12, 20, 0.045);
  --orb: rgba(10, 12, 20, 0.05);
  --shadow: 0 18px 50px rgba(20, 25, 40, 0.16);
  --shadow-sm: 0 6px 20px rgba(20, 25, 40, 0.12);
}

* { box-sizing: border-box; }
/* Make the [hidden] attribute win over author display rules (flex/grid),
   so toggling .hidden actually hides forms, menu items, popovers, etc. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.muted { color: var(--muted); }
kbd {
  font-family: inherit; font-size: 0.85em; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; color: var(--text-dim);
}
.dot { color: var(--muted); }
.grad {
  background: linear-gradient(95deg, var(--text), var(--muted));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- Animated backdrop ---------- */
.bg-fx { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bg-grid {
  position: absolute; inset: -2px;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(120% 90% at 50% 0%, #000 35%, transparent 78%);
  -webkit-mask-image: radial-gradient(120% 90% at 50% 0%, #000 35%, transparent 78%);
}
.bg-orb { position: absolute; border-radius: 50%; filter: blur(70px); background: var(--orb); }
.orb-1 { width: 540px; height: 540px; top: -200px; right: -120px; animation: drift1 22s ease-in-out infinite alternate; }
.orb-2 { width: 460px; height: 460px; bottom: -200px; left: -120px; animation: drift2 26s ease-in-out infinite alternate; }
@keyframes drift1 { to { transform: translate(-60px, 80px) scale(1.15); } }
@keyframes drift2 { to { transform: translate(70px, -50px) scale(1.1); } }

/* ---------- Theme toggle (floating) ---------- */
.theme-toggle {
  position: fixed; top: 16px; right: 16px; z-index: 90;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; display: grid; place-items: center;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  transition: transform .18s ease, background .2s, border-color .2s;
}
.theme-toggle:hover { transform: translateY(-1px); border-color: var(--border-strong); background: var(--surface-3); }
.theme-toggle .ico-moon { display: none; }
[data-theme="light"] .theme-toggle .ico-sun { display: none; }
[data-theme="light"] .theme-toggle .ico-moon { display: block; }

/* ---------- Logo badge ---------- */
.logo-badge {
  position: relative; width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 13px; overflow: hidden;
  background: radial-gradient(120% 120% at 30% 20%, var(--surface-3), var(--surface));
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
}
.logo-badge.lg { width: 60px; height: 60px; border-radius: 18px; }
.logo-badge.xl { width: 76px; height: 76px; border-radius: 22px; }
.logo-badge svg { display: block; }
.logo-p {
  stroke-dasharray: 150; stroke-dashoffset: 150;
  filter: drop-shadow(0 0 6px var(--glow));
  animation: drawP 1s ease .25s forwards;
}
.logo-shine {
  position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 35%, var(--glow) 50%, transparent 65%);
  transform: translateX(-120%); animation: shine 1.2s ease 1s 1;
}
@keyframes drawP { to { stroke-dashoffset: 0; } }
@keyframes shine { to { transform: translateX(120%); } }

/* =======================================================================
   AUTH SCREEN
   ======================================================================= */
.auth-screen {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px; animation: fadeIn .3s ease;
}
.auth-screen[hidden] { display: none; }
.auth-card {
  position: relative; width: 100%; max-width: 410px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 30px 28px 26px; box-shadow: var(--shadow);
  backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
  animation: popIn .35s cubic-bezier(.2,1,.3,1);
}
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.auth-titles h1 { margin: 0; font-family: "Space Grotesk", "Inter", sans-serif; font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.auth-tag { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.auth-form { display: flex; flex-direction: column; }
.auth-form.tight label:first-child { margin-top: 0; }
.auth-form label { font-size: 12.5px; color: var(--text-dim); font-weight: 600; margin: 14px 0 6px; }
.auth-form input, .auth-form select {
  background: var(--bg-1); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 14.5px; font-family: inherit; outline: none;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
[data-theme="dark"] .auth-form input, [data-theme="dark"] .auth-form select { background: rgba(255,255,255,.03); }
.auth-form input:focus, .auth-form select:focus {
  border-color: var(--border-strong); box-shadow: 0 0 0 3px var(--glow);
}
.auth-note {
  font-size: 13px; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 4px;
}
.auth-msg { min-height: 0; font-size: 13px; color: var(--danger); margin-top: 10px; line-height: 1.4; }
.auth-msg.ok { color: var(--text-dim); }
.auth-msg:empty { margin: 0; }
.auth-foot { margin-top: 16px; text-align: center; font-size: 13px; color: var(--muted); }
.auth-foot a { color: var(--text-dim); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.auth-foot a:hover { color: var(--text); }
.auth-credit { font-size: 11.5px; color: var(--muted); letter-spacing: .2px; text-align: center; }

/* ---------- Buttons ---------- */
.btn-primary {
  position: relative; overflow: hidden; margin-top: 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--on-accent);
  border: none; border-radius: var(--radius-sm); padding: 13px 18px;
  font-size: 14.5px; font-weight: 700; cursor: pointer;
  transition: transform .15s ease, box-shadow .25s ease, opacity .2s;
}
.btn-primary.sm { padding: 10px 16px; margin-top: 0; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 26px var(--glow); }
.btn-primary:active { transform: translateY(0) scale(.99); }
.btn-primary:disabled { opacity: .6; cursor: progress; transform: none; box-shadow: none; }
.btn-primary::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.25) 50%, transparent 70%);
  transform: translateX(-130%); transition: transform .6s ease;
}
[data-theme="dark"] .btn-primary::after { background: linear-gradient(120deg, transparent 30%, rgba(0,0,0,.18) 50%, transparent 70%); }
.btn-primary:hover::after { transform: translateX(130%); }
.btn-ghost {
  background: var(--surface); color: var(--text-dim); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

/* ---- "Continue with Google" (login screen) ---- */
.auth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0 14px;
  color: var(--muted); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 12px 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.btn-google:hover { background: var(--surface-2); border-color: var(--text-dim); transform: translateY(-1px); }
.btn-google:active { transform: translateY(0); }
.btn-google:disabled { opacity: .6; cursor: progress; transform: none; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--on-accent) 35%, transparent);
  border-top-color: var(--on-accent); animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =======================================================================
   APP LAYOUT
   ======================================================================= */
.app { position: relative; z-index: 1; display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.app[hidden] { display: none; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 280px; flex-shrink: 0; display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border-right: 1px solid var(--border);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  transition: transform .3s cubic-bezier(.4,0,.2,1); z-index: 30;
}
.sidebar-header { padding: 18px 16px 12px; }
.brand { display: flex; align-items: center; gap: 11px; margin-bottom: 16px; }
.brand .logo-badge { width: 38px; height: 38px; }
.brand-name { font-family: "Space Grotesk", "Inter", sans-serif; font-weight: 700; letter-spacing: -.3px; font-size: 17px; }

.btn-new {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--on-accent);
  border: none; font-weight: 700; font-size: 14px; cursor: pointer;
  position: relative; overflow: hidden;
  transition: transform .15s ease, box-shadow .25s ease;
}
.btn-new:hover { transform: translateY(-1px); box-shadow: 0 8px 22px var(--glow); }
.btn-new:active { transform: translateY(0) scale(.98); }

.history-wrap { flex: 1; overflow-y: auto; padding: 6px 10px 10px; display: flex; flex-direction: column; }
.history-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); padding: 8px 10px 6px; font-weight: 700; }
.history { display: flex; flex-direction: column; gap: 2px; }
.history-empty { color: var(--muted); font-size: 13px; padding: 12px; text-align: center; }
.history-item {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--text-dim);
  font-size: 13.5px; border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
}
.history-item:hover { background: var(--surface-2); color: var(--text); }
.history-item.active { background: var(--surface-3); border-color: var(--border); color: var(--text); }
.history-item .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .del {
  opacity: 0; background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 2px; border-radius: 6px; transition: opacity .15s, color .15s; display: grid; place-items: center;
}
.history-item:hover .del { opacity: 1; }
.history-item .del:hover { color: var(--danger); }

/* ---------- User chip + account menu ---------- */
.sidebar-footer { padding: 10px; border-top: 1px solid var(--border); }
.user-chip {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 10px; cursor: pointer; color: var(--text); text-align: left;
  transition: background .15s, border-color .15s;
}
.user-chip:hover { background: var(--surface-2); border-color: var(--border-strong); }
.avatar {
  width: 34px; height: 34px; flex-shrink: 0; border-radius: 10px; display: grid; place-items: center;
  font-size: 13px; font-weight: 800; background: var(--accent); color: var(--on-accent);
}
.user-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-email { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .chev { color: var(--muted); flex-shrink: 0; }

.popover {
  position: fixed; z-index: 95; width: 250px;
  background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 8px; animation: popIn .16s ease;
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}
.popover[hidden] { display: none; }
.popover-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.popover-head .user-name { font-size: 13.5px; }
.role-badge {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
  background: var(--accent); color: var(--on-accent); padding: 3px 7px; border-radius: 999px; margin-left: auto;
}
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 11px;
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 10px 10px; border-radius: 10px; font-size: 13.5px; font-weight: 500; text-align: left;
  transition: background .14s, color .14s;
}
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item svg { color: var(--muted); flex-shrink: 0; }
.menu-item:hover svg { color: var(--text); }
.menu-item.danger:hover { color: var(--danger); }
.menu-item.danger:hover svg { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }

/* ---------- Mobile toggle + scrim ---------- */
.sidebar-toggle {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 40;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 11px; padding: 9px; cursor: pointer;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.scrim { position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.5); animation: fadeIn .2s ease; }
.scrim[hidden] { display: none; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.messages { flex: 1; overflow-y: auto; padding: 30px 0 8px; scroll-behavior: smooth; }

.welcome { max-width: 760px; margin: 7vh auto 0; padding: 0 24px; text-align: center; animation: fadeUp .5s ease; }
.welcome-badge { display: flex; justify-content: center; margin-bottom: 20px; }
.welcome h1 { font-family: "Space Grotesk", "Inter", sans-serif; font-size: 36px; margin: 0 0 8px; font-weight: 700; letter-spacing: -.6px; }
.welcome .muted { font-size: 15px; }
.suggestions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 26px; }
.chip {
  background: var(--surface); color: var(--text-dim); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 999px; font-size: 13px; cursor: pointer; font-weight: 500;
  transition: transform .15s, border-color .15s, color .15s, background .15s;
}
.chip:hover { transform: translateY(-2px); border-color: var(--border-strong); color: var(--text); background: var(--surface-2); }

/* ---------- Message rows ---------- */
.msg { max-width: 800px; margin: 0 auto 22px; padding: 0 24px; display: flex; gap: 13px; animation: fadeUp .3s ease; }
.msg.user { flex-direction: row-reverse; }
.msg .avatar { width: 30px; height: 30px; border-radius: 9px; }
.msg.user .avatar { background: var(--surface-3); color: var(--text-dim); }
.msg.ai .avatar { background: var(--accent); color: var(--on-accent); }
.msg .body { flex: 1; min-width: 0; }
.msg.user .body { display: flex; flex-direction: column; align-items: flex-end; flex: 0 1 auto; max-width: 82%; }
.msg .name { font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.msg.user .name { display: none; }
.bubble {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 16px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.ai .bubble { border-top-left-radius: 5px; }
.msg.user .bubble { background: var(--user-bubble); border-color: var(--border); border-top-right-radius: 5px; }
.bubble img { max-width: 100%; border-radius: 12px; margin-top: 8px; display: block; }
.bubble .gen-img { max-width: 440px; box-shadow: var(--shadow-sm); }
.attach-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.attach-thumbs img { width: 92px; height: 92px; object-fit: cover; border-radius: 10px; margin: 0; }

/* markdown */
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble .md-gap { height: 8px; }
.bubble .md-h { margin: 8px 0 2px; font-size: 1.05em; }
.bubble code { background: var(--surface-3); border-radius: 6px; padding: 1px 6px; font-size: .9em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.bubble a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }

/* streaming caret */
.stream-caret {
  display: inline-block; width: 7px; height: 1.05em; margin-left: 2px; vertical-align: -0.12em;
  border-radius: 2px; background: var(--accent); box-shadow: 0 0 8px var(--glow);
  animation: caretBlink 1.05s steps(1, end) infinite;
}
@keyframes caretBlink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* typing dots */
.typing { display: inline-flex; gap: 5px; padding: 4px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); animation: blink 1.3s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* image-generation loader */
.img-loading { display: flex; flex-direction: column; gap: 10px; }
.img-skeleton {
  position: relative; width: 230px; max-width: 60vw; border-radius: 14px; overflow: hidden;
  display: grid; place-items: center; background: var(--surface-2);
}
.img-skeleton::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, var(--surface-3) 50%, transparent 70%);
  transform: translateX(-100%); animation: imgShimmer 1.4s ease-in-out infinite;
}
.img-skeleton-icon { color: var(--text-dim); opacity: .6; position: relative; animation: imgIconPulse 1.8s ease-in-out infinite; }
.img-loading-label { color: var(--text-dim); font-size: 13.5px; display: inline-flex; align-items: baseline; }
.img-dots span { animation: blink 1.3s infinite both; }
.img-dots span:nth-child(2) { animation-delay: .2s; }
.img-dots span:nth-child(3) { animation-delay: .4s; }
.img-progress { width: 230px; max-width: 60vw; height: 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.img-progress-fill { height: 100%; width: 0; border-radius: 999px; background: var(--accent); box-shadow: 0 0 10px var(--glow); animation: imgProgress 16s cubic-bezier(.12,.8,.2,1) forwards; }
@keyframes imgShimmer { to { transform: translateX(100%); } }
@keyframes imgProgress { 0% { width: 0; } 55% { width: 72%; } 100% { width: 93%; } }
@keyframes imgIconPulse { 0%,100% { opacity: .45; transform: scale(1); } 50% { opacity: .9; transform: scale(1.12); } }

/* ---------- Composer ---------- */
.composer-wrap { padding: 0 20px 18px; max-width: 840px; margin: 0 auto; width: 100%; }
.attachments { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.attachments .thumb { position: relative; }
.attachments .thumb img { width: 66px; height: 66px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.attachments .thumb .remove {
  position: absolute; top: -7px; right: -7px; background: var(--danger); color: #fff; border: none;
  border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 12px; line-height: 1; display: grid; place-items: center;
}

.composer {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 10px 12px 10px; box-shadow: var(--shadow-sm);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.composer:focus-within { border-color: var(--border-strong); box-shadow: 0 0 0 3px var(--glow); }
.input {
  width: 100%; resize: none; border: none; outline: none; background: transparent; color: var(--text);
  font-family: inherit; font-size: 15px; line-height: 1.5; max-height: 220px; padding: 6px 6px 2px;
}
.input::placeholder { color: var(--muted); }

.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.composer-tools { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  background: transparent; color: var(--text-dim); border: 1px solid transparent; cursor: pointer;
  height: 38px; min-width: 38px; padding: 0 10px; border-radius: 11px; display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; transition: background .15s, color .15s, border-color .15s, transform .15s;
}
.icon-btn .tool-label { display: inline; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.toggle-img.active, .toggle-search.active {
  background: var(--accent); color: var(--on-accent); border-color: var(--accent); box-shadow: 0 0 14px var(--glow);
}

.send-btn {
  background: var(--accent); color: var(--on-accent); border: none;
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; cursor: pointer;
  flex-shrink: 0; transition: transform .15s, box-shadow .25s, background .2s;
}
.send-btn:hover { transform: translateY(-1px) scale(1.04); box-shadow: 0 8px 20px var(--glow); }
.send-btn:active { transform: scale(.92); }
.send-btn.stop { background: var(--danger); color: #fff; animation: stopPulse 1.6s ease-in-out infinite; }
.send-btn.stop:hover { box-shadow: 0 8px 20px rgba(255,93,108,.45); }
@keyframes stopPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,93,108,.45); } 50% { box-shadow: 0 0 0 6px rgba(255,93,108,0); } }

.composer-hint { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 9px; }
#modeHint { color: var(--text-dim); font-weight: 600; }

/* =======================================================================
   MODALS
   ======================================================================= */
.modal-overlay {
  position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.55);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px; animation: fadeIn .15s ease;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-1); border: 1px solid var(--border); border-radius: var(--radius-lg);
  width: 100%; max-width: 470px; max-height: 84vh; display: flex; flex-direction: column;
  padding: 22px; box-shadow: var(--shadow); animation: popIn .2s ease;
}
.modal-wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 18px; font-family: "Space Grotesk", "Inter", sans-serif; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 26px; line-height: 1; cursor: pointer; padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-sub { color: var(--muted); font-size: 12.5px; margin: 8px 0 16px; line-height: 1.5; }
.modal-sub em { color: var(--text-dim); font-style: italic; }

/* memory */
.mem-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; min-height: 40px; }
.mem-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 8px; }
.mem-item {
  display: flex; align-items: flex-start; gap: 10px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px; line-height: 1.4;
}
.mem-item span { flex: 1; word-break: break-word; }
.mem-del { background: none; border: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; flex-shrink: 0; }
.mem-del:hover { color: var(--danger); }
.mem-add { display: flex; gap: 8px; }
.mem-add input {
  flex: 1; background: var(--bg-1); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 12px; font-size: 13.5px; outline: none;
}
[data-theme="dark"] .mem-add input { background: rgba(255,255,255,.03); }
.mem-add input:focus { border-color: var(--border-strong); }
.mem-add button {
  background: var(--accent); color: var(--on-accent); border: none; border-radius: var(--radius-sm);
  padding: 0 18px; font-weight: 700; cursor: pointer;
}
.mem-clear { background: none; border: none; color: var(--muted); font-size: 12.5px; cursor: pointer; margin-top: 12px; align-self: flex-start; }
.mem-clear:hover { color: var(--danger); }

/* admin */
.admin-users { overflow-y: auto; max-height: 42vh; display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.admin-user {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
}
.admin-user .au-info { flex: 1; min-width: 0; }
.admin-user .au-name { font-size: 13.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.admin-user .au-sub { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-user .au-actions { display: flex; gap: 6px; flex-shrink: 0; }
.tag { font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 2px 6px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); }
.tag.admin { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.tag.locked { color: var(--danger); border-color: var(--danger); }
.tag.pending { color: var(--text-dim); }
.mini-btn { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 12px; cursor: pointer; transition: .15s; }
.mini-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-3); }
.mini-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.admin-add { border-top: 1px solid var(--border); padding-top: 16px; }
.admin-add-title { font-size: 12.5px; font-weight: 700; color: var(--text-dim); margin-bottom: 10px; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.admin-grid input, .admin-grid select {
  background: var(--bg-1); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13.5px; outline: none; font-family: inherit;
}
[data-theme="dark"] .admin-grid input, [data-theme="dark"] .admin-grid select { background: rgba(255,255,255,.03); }
.admin-grid input:focus, .admin-grid select:focus { border-color: var(--border-strong); }
.admin-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 100;
  background: var(--bg-1); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 14px; box-shadow: var(--shadow); opacity: 0; max-width: 90vw;
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); background-clip: padding-box; }

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); box-shadow: var(--shadow); width: 84vw; max-width: 320px; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: grid; place-items: center; transition: opacity .2s ease; }
  /* while the drawer is open the hamburger would sit right on top of the
     brand logo — fade it out; tapping the scrim (or a chat) closes. */
  .sidebar.open + .sidebar-toggle { opacity: 0; pointer-events: none; }
  .messages { padding-top: 62px; }
  .welcome h1 { font-size: 28px; }
  .theme-toggle { top: 12px; right: 12px; }
  .composer-hint kbd { display: none; }
  .admin-grid { grid-template-columns: 1fr; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .logo-p { stroke-dashoffset: 0; }
}

/* ============================================================
   Smooth light/dark switch
   ------------------------------------------------------------
   js/common.js puts .theme-fade on <html> for ~600ms when the
   toggle is clicked, so every color eases into the new palette
   instead of snapping. Skipped for reduced-motion users.
   ============================================================ */
@media (prefers-reduced-motion: no-preference) {
  html.theme-fade,
  html.theme-fade *,
  html.theme-fade *::before,
  html.theme-fade *::after {
    transition:
      background-color .5s ease,
      color .5s ease,
      border-color .5s ease,
      fill .5s ease,
      stroke .5s ease,
      box-shadow .5s ease !important;
  }
}

/* ============================================================
   Landing page (index.html)
   ============================================================ */
body.landing-body { overflow-y: auto; }

.landing {
  position: relative; z-index: 1;
  max-width: 1060px; margin: 0 auto;
  padding: 22px 22px 40px;
  display: flex; flex-direction: column; min-height: 100dvh;
}

.landing-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 4px 0 0;
}
.landing-nav .brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.landing-nav .brand-name { font-family: "Space Grotesk", Inter, sans-serif; font-weight: 700; font-size: 18px; }
.landing-nav-actions { display: flex; align-items: center; gap: 10px; margin-right: 54px; }
.landing-nav-actions span[data-when] { display: inline-flex; align-items: center; gap: 10px; }
.landing-nav-actions span[data-when][hidden] { display: none; }
.nav-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

.hero { text-align: center; padding: 84px 10px 58px; }
.hero-eyebrow {
  display: inline-block; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font-size: 12px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; margin-bottom: 26px;
}
.hero-title {
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: clamp(40px, 7vw, 68px); line-height: 1.05;
  font-weight: 700; letter-spacing: -0.02em; margin: 0 0 20px;
}
.hero-title .grad {
  background: linear-gradient(120deg, var(--logo-a), var(--logo-b));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub {
  max-width: 620px; margin: 0 auto 30px;
  color: var(--text-dim); font-size: 16.5px; line-height: 1.65;
}
.hero-ctas span[data-when] { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: center; }
.hero-ctas span[data-when][hidden] { display: none; }
.hero-btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; margin-top: 0; padding: 13px 26px; font-size: 15px; }

.features {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
  padding: 10px 0 30px;
}
.feature-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 22px 20px;
  transition: transform .18s ease, border-color .18s ease, box-shadow .25s ease;
}
.feature-card:hover { transform: translateY(-3px); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.feature-ico { font-size: 20px; color: var(--text-dim); margin-bottom: 12px; }
.feature-card h3 { margin: 0 0 8px; font-size: 15.5px; font-weight: 700; }
.feature-card p { margin: 0; color: var(--text-dim); font-size: 13.5px; line-height: 1.6; }

.landing-foot {
  margin-top: auto; padding-top: 34px; text-align: center;
  color: var(--muted); font-size: 13px;
}
.landing-foot a { color: var(--text-dim); text-decoration: underline; text-underline-offset: 3px; }
.landing-foot a:hover { color: var(--text); }
.landing-foot .sep { margin: 0 8px; }

@media (max-width: 860px) {
  .features { grid-template-columns: repeat(2, 1fr); }
  .hero { padding: 56px 4px 44px; }
}
@media (max-width: 560px) {
  .features { grid-template-columns: 1fr; }
  .landing-nav-actions { margin-right: 50px; }
  .landing-nav-actions [data-when="out"] .btn-ghost { display: none; } /* keep nav tidy on phones */
}

/* ============================================================
   404 page
   ============================================================ */
.notfound {
  position: relative; z-index: 1; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 6px;
}
.nf-code {
  font-family: "Space Grotesk", Inter, sans-serif;
  font-size: clamp(84px, 18vw, 150px); font-weight: 700; line-height: 1;
  letter-spacing: -0.04em; margin-top: 18px;
  background: linear-gradient(180deg, var(--logo-a), var(--logo-b));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.nf-title { font-size: 22px; font-weight: 700; margin: 8px 0 0; }
.nf-sub { color: var(--text-dim); font-size: 14.5px; margin: 8px 0 26px; }
.nf-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ============================================================
   Alive ✨ — ambient animations (chat page)
   ------------------------------------------------------------
   Looping shine + breathing glow on the logo badges, a floating
   welcome badge, shimmering title, and the rolling prompt deck.
   All of it is disabled by the global reduced-motion rule above.
   ============================================================ */

/* Sidebar brand: shine sweeps by every few seconds, badge "breathes",
   and hovering the brand re-draws the P stroke. */
.brand .logo-badge .logo-shine,
.welcome-badge .logo-shine { animation: shineLoop 5.5s ease 2.2s infinite; }
.brand .logo-badge { animation: badgeGlow 4s ease-in-out infinite; }
.brand:hover .logo-p { animation: drawPAgain .9s ease forwards; }

.welcome-badge .logo-badge {
  animation: badgeGlow 4s ease-in-out infinite, floaty 5.5s ease-in-out infinite;
}

@keyframes shineLoop {
  0% { transform: translateX(-120%); }
  20% { transform: translateX(120%); }
  100% { transform: translateX(120%); }
}
@keyframes badgeGlow {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 0 0 rgba(0,0,0,0); }
  50% { box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 0 20px var(--glow); }
}
@keyframes drawPAgain { from { stroke-dashoffset: 150; } to { stroke-dashoffset: 0; } }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

/* Welcome title: the gradient slowly sweeps through "Porka AI". */
.welcome h1 .grad {
  background: linear-gradient(95deg, var(--text), var(--muted), var(--text));
  background-size: 200% auto;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: gradShift 5.5s linear infinite;
}
@keyframes gradShift { to { background-position: -200% center; } }

/* Rolling prompt deck */
.chip.swap-in { animation: chipIn .32s ease backwards; }
.chip.swap-out {
  opacity: 0; transform: translateY(-8px) scale(.94); pointer-events: none;
  transition: opacity .24s ease, transform .24s ease;
}
@keyframes chipIn { from { opacity: 0; transform: translateY(10px) scale(.94); } }

/* LIVE chips: pulsing dot = this one asks the real internet */
.live-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--text); margin-right: 8px; vertical-align: 1px;
  animation: livePulse 1.6s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: .35; box-shadow: 0 0 0 0 var(--glow); }
  50% { opacity: 1; box-shadow: 0 0 8px 1px var(--glow); }
}
