:root {
  color-scheme: dark;
  --ink: #07101d;
  --panel: #0c1828;
  --panel-2: #101f32;
  --line: rgba(168, 198, 226, 0.16);
  --text: #edf5fb;
  --muted: #94a8bb;
  --ice: #76d7f7;
  --amber: #eabf70;
  --danger: #ff9292;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at 80% 8%, rgba(45, 130, 169, 0.16), transparent 34rem),
    linear-gradient(145deg, #050b13, var(--ink));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
.is-hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.eyebrow { margin: 0; color: var(--ice); font-size: .75rem; font-weight: 700; letter-spacing: .18em; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background-image:
    linear-gradient(rgba(118,215,247,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(118,215,247,.035) 1px, transparent 1px);
  background-size: 48px 48px;
}
.login-card {
  width: min(100%, 440px);
  padding: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(12, 24, 40, .88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.brand-mark {
  width: 64px; height: 64px; display: grid; place-items: center;
  margin-bottom: 2rem; border: 1px solid rgba(118,215,247,.55); border-radius: 20px;
  background: linear-gradient(145deg, rgba(118,215,247,.18), rgba(234,191,112,.08));
  box-shadow: inset 0 0 30px rgba(118,215,247,.08), 0 0 30px rgba(118,215,247,.08);
}
.brand-mark span, .signal-orb span { color: var(--ice); font-weight: 700; letter-spacing: .06em; }
.brand-mark.compact { width: 42px; height: 42px; margin: 0; border-radius: 14px; }
.login-card h1 { margin: .35rem 0 0; font-size: clamp(2.25rem, 8vw, 3.5rem); line-height: 1; letter-spacing: -.045em; }
.login-copy { margin: 1rem 0 2rem; color: var(--muted); }
label { display: block; margin: 1rem 0 .45rem; color: #c8d7e4; font-size: .9rem; font-weight: 650; }
input, textarea {
  width: 100%; color: var(--text); background: rgba(4, 11, 20, .72);
  border: 1px solid var(--line); border-radius: 12px; outline: none;
}
input { height: 48px; padding: 0 .9rem; }
input:focus, textarea:focus { border-color: var(--ice); box-shadow: 0 0 0 3px rgba(118,215,247,.12); }
.primary-button {
  width: 100%; height: 50px; margin-top: 1.25rem; border: 0; border-radius: 12px;
  color: #06101a; background: linear-gradient(100deg, var(--ice), #b6eafa); font-weight: 800;
}
.form-error { min-height: 1.5rem; margin: .65rem 0 0; color: var(--danger); font-size: .9rem; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.sidebar {
  height: 100vh; position: sticky; top: 0; display: flex; flex-direction: column;
  padding: 1.25rem; background: rgba(7, 16, 29, .92); border-right: 1px solid var(--line);
}
.sidebar-brand { display: flex; align-items: center; gap: .8rem; }
.sidebar-brand strong, .account-panel strong { display: block; }
.sidebar-brand small, .account-panel small { display: block; color: var(--muted); font-size: .78rem; }
.new-chat-button {
  margin: 1.75rem 0; padding: .72rem 1rem; border: 1px solid rgba(118,215,247,.3);
  border-radius: 12px; color: var(--text); background: rgba(118,215,247,.07); text-align: left;
}
.memory-button {
  margin: -1rem 0 1.5rem; padding: .7rem 1rem; border: 0; border-radius: 12px;
  color: #c8d7e4; background: transparent; text-align: left;
}
.memory-button:hover { background: rgba(255,255,255,.045); color: var(--text); }
.memory-button span, .memory-button small { display: block; }
.memory-button span { font-weight: 700; }
.memory-button small { margin-top: .15rem; color: var(--muted); font-size: .75rem; }
.nav-label { color: var(--muted); font-size: .76rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.conversation-list { display: grid; gap: .35rem; overflow-y: auto; }
.conversation-item {
  width: 100%; padding: .7rem .8rem; border: 0; border-radius: 10px;
  color: #b8c8d6; background: transparent; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conversation-item:hover, .conversation-item.active { color: var(--text); background: rgba(255,255,255,.055); }
.account-panel { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.text-button { padding: .35rem; color: var(--muted); background: transparent; border: 0; }

.workspace { min-width: 0; min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: 1.1rem 2rem; border-bottom: 1px solid var(--line); background: rgba(7,16,29,.66); backdrop-filter: blur(15px); }
.topbar h2 { margin: .15rem 0 0; font-size: 1.05rem; }
.system-status { margin-left: auto; color: #b9c9d7; font-size: .86rem; }
.system-status span { display: inline-block; width: 7px; height: 7px; margin-right: .4rem; border-radius: 50%; background: #75e0a7; box-shadow: 0 0 12px rgba(117,224,167,.7); }
.menu-button { display: none; color: var(--text); background: transparent; border: 0; font-size: 1.2rem; }
.empty-state { align-self: center; justify-self: center; width: min(90%, 760px); text-align: center; padding: 3rem 1rem; }
.signal-orb {
  width: 108px; height: 108px; display: grid; place-items: center; margin: 0 auto 2rem;
  border: 1px solid rgba(118,215,247,.45); border-radius: 50%;
  background: radial-gradient(circle, rgba(118,215,247,.17), rgba(118,215,247,.025) 58%, transparent 60%);
  box-shadow: 0 0 70px rgba(65,169,207,.17), inset 0 0 40px rgba(118,215,247,.1);
}
.signal-orb span { font-size: 1.8rem; }
.greeting { color: var(--amber); margin: 0 0 .35rem; }
.empty-state h1 { margin: 0 0 2rem; font-size: clamp(2rem, 5vw, 3.4rem); line-height: 1.05; letter-spacing: -.045em; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: .7rem; }
.suggestions button { padding: .7rem 1rem; border: 1px solid var(--line); border-radius: 999px; color: #c8d7e4; background: rgba(255,255,255,.025); }
.suggestions button:hover { border-color: rgba(118,215,247,.5); color: var(--text); }
.messages { width: min(100%, 900px); margin: 0 auto; padding: 2rem 1.5rem 8rem; overflow-y: auto; }
.message { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: .9rem; margin: 0 0 1.7rem; }
.message-avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--panel-2); color: var(--ice); font-weight: 800; }
.message.user .message-avatar { color: var(--amber); }
.message-body strong { display: block; margin-bottom: .32rem; font-size: .86rem; color: #b9cbd9; }
.message-body p { margin: 0; color: #e4edf4; white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { width: min(calc(100% - 2rem), 900px); margin: 0 auto 1.2rem; padding: .65rem; border: 1px solid var(--line); border-radius: 18px; background: rgba(12,24,40,.94); box-shadow: 0 18px 50px rgba(0,0,0,.28); }
.composer textarea { min-height: 54px; max-height: 180px; resize: none; padding: .85rem 6rem .75rem .9rem; border: 0; background: transparent; }
.composer button { float: right; margin: -47px .25rem 0 0; position: relative; height: 38px; padding: 0 1rem; border: 0; border-radius: 10px; color: #06101a; background: var(--ice); font-weight: 800; }
.composer button:disabled { opacity: .45; cursor: wait; }
.composer-status { clear: both; margin: .35rem .7rem 0; color: var(--muted); font-size: .76rem; text-align: center; }

.memory-overlay {
  position: fixed; z-index: 30; inset: 0; display: flex; justify-content: flex-end;
  background: rgba(2, 7, 13, .72); backdrop-filter: blur(5px);
}
.memory-panel {
  width: min(100%, 560px); height: 100%; overflow-y: auto; padding: 2rem;
  background: #0a1625; border-left: 1px solid var(--line); box-shadow: var(--shadow);
}
.memory-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.memory-header h2 { margin: .3rem 0 0; font-size: 1.45rem; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: transparent; font-size: 1.6rem; }
.memory-copy { color: var(--muted); }
.memory-form { padding: 1rem 0 1.25rem; border-bottom: 1px solid var(--line); }
.memory-add-row { display: grid; grid-template-columns: 1fr auto; gap: .6rem; }
.memory-add-row button, .memory-actions button { border: 0; border-radius: 10px; padding: .65rem .9rem; font-weight: 750; }
.memory-add-row button, .memory-actions button:first-child { color: #06101a; background: var(--ice); }
.memory-status { min-height: 1.5rem; margin: .5rem 0 0; color: var(--muted); font-size: .85rem; }
.memory-list { display: grid; gap: .8rem; padding-top: 1.2rem; }
.memory-item { padding: 1rem; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.025); }
.memory-item textarea { min-height: 78px; padding: .75rem; resize: vertical; }
.memory-actions { display: flex; justify-content: flex-end; gap: .55rem; margin-top: .65rem; }
.memory-actions .danger-button { color: var(--danger); background: rgba(255,146,146,.08); border: 1px solid rgba(255,146,146,.22); }
.memory-empty { color: var(--muted); text-align: center; padding: 2rem 1rem; }

@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 10; width: min(86vw, 300px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .menu-button { display: block; }
  .topbar { padding: .9rem 1rem; }
  .system-status { font-size: .78rem; }
  .messages { padding-inline: 1rem; }
  .login-card { padding: 2rem 1.4rem; }
  .memory-panel { padding: 1.4rem 1rem; }
  .memory-add-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
