:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #10131a;
  --panel-2: #151923;
  --line: rgba(255,255,255,.085);
  --muted: #8e95a6;
  --text: #f5f6f8;
  --accent: #b9ff66;
  --accent-2: #7ee787;
  --danger: #ff6b78;
  --shadow: 0 32px 90px rgba(0,0,0,.48);
  --app-height: 100vh;
  --app-offset-top: 0px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@supports (height: 100dvh) {
  :root { --app-height: 100dvh; }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: var(--app-height); overflow-x: hidden; }
body.app-active { overflow: hidden; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.ambient { position: fixed; width: 38vw; height: 38vw; border-radius: 50%; filter: blur(120px); opacity: .1; pointer-events: none; }
.ambient-one { background: #a6ff58; right: -12vw; top: -14vw; }
.ambient-two { background: #4d6aff; left: -18vw; bottom: -20vw; }

.brand { display: flex; align-items: center; gap: 12px; letter-spacing: .15em; font-weight: 700; font-size: 13px; }
.brand b { color: var(--accent); }
.brand-mark, .empty-mark { display: grid; place-items: center; background: var(--accent); color: #0b0d12; font-family: Georgia, serif; font-weight: 900; font-style: italic; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px 2px 9px 2px; font-size: 20px; }

.auth-layout { min-height: var(--app-height); display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(380px, .75fr); position: relative; }
.auth-copy { padding: clamp(38px, 6vw, 92px); display: flex; flex-direction: column; justify-content: center; max-width: 950px; }
.auth-copy .brand { position: absolute; top: 38px; }
.hero-kicker { color: var(--accent); font-size: 12px; letter-spacing: .16em; text-transform: uppercase; display: flex; align-items: center; gap: 10px; }
.hero-kicker span { width: 32px; height: 1px; background: var(--accent); }
.auth-copy h1 { font-size: clamp(48px, 6.2vw, 92px); line-height: .98; letter-spacing: -.065em; margin: 24px 0 28px; max-width: 900px; font-weight: 680; }
.auth-copy h1 em { color: var(--accent); font-family: Georgia, serif; font-weight: 400; }
.auth-copy > p { color: #a7adbb; font-size: 18px; line-height: 1.7; max-width: 660px; }
.trust-row { display: flex; gap: 42px; margin-top: 52px; }
.trust-row div { display: flex; flex-direction: column; gap: 6px; }
.trust-row strong { font-size: 12px; color: var(--accent); letter-spacing: .14em; }
.trust-row span { font-size: 12px; color: #72798a; }

.auth-card-wrap { border-left: 1px solid var(--line); background: rgba(14,17,23,.72); backdrop-filter: blur(24px); display: grid; place-items: center; padding: 38px; }
.auth-card { width: min(390px, 100%); }
.auth-heading { margin-bottom: 34px; }
.eyebrow { color: var(--accent); font-size: 11px; letter-spacing: .18em; text-transform: uppercase; font-weight: 750; }
.auth-heading h2 { font-size: 32px; letter-spacing: -.04em; margin: 10px 0 8px; }
.auth-heading p { color: var(--muted); margin: 0; line-height: 1.5; }
.auth-card label { display: block; color: #b9bfcb; font-size: 13px; margin: 18px 0 8px; }
.auth-card input, .id-connect input, .settings-panel input, .settings-panel textarea { width: 100%; background: #0d1016; border: 1px solid var(--line); color: var(--text); border-radius: 11px; outline: none; transition: .18s ease; }
.auth-card input { height: 52px; padding: 0 15px; }
input:focus, textarea:focus, select:focus { border-color: rgba(185,255,102,.62) !important; box-shadow: 0 0 0 3px rgba(185,255,102,.08); }
.primary, .secondary { border: 0; border-radius: 11px; cursor: pointer; height: 50px; font-weight: 700; }
.primary { background: var(--accent); color: #0b0d12; }
.primary:hover { background: #c7ff85; transform: translateY(-1px); }
.wide { width: 100%; margin-top: 24px; }
.primary.wide { display: flex; align-items: center; justify-content: space-between; padding: 0 18px; }
.secondary { background: transparent; border: 1px solid var(--line); color: #c5c9d2; }
.secondary.wide { margin-top: 12px; }
.secondary:hover { background: rgba(255,255,255,.04); }
.link-button { width: 100%; border: 0; background: none; color: var(--accent); cursor: pointer; margin: 16px 0 0; }
.form-status { min-height: 22px; color: var(--muted); font-size: 13px; margin-top: 16px; text-align: center; }
.form-status.error { color: var(--danger); }

.app-layout { height: var(--app-height); min-height: 0; display: grid; grid-template-columns: 292px 1fr; overflow: hidden; }
.sidebar { position: relative; z-index: 10; background: #0d1016; border-right: 1px solid var(--line); min-height: 0; height: 100%; display: flex; flex-direction: column; padding: 22px 18px calc(16px + env(safe-area-inset-bottom)); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 22px; }
.new-chat { width: 100%; height: 45px; border: 0; border-radius: 10px; font-size: 13px; text-align: left; padding: 0 14px; }
.new-chat span { font-size: 20px; vertical-align: -1px; margin-right: 8px; }
.id-connect { margin: 24px 2px 26px; }
.id-connect label, .section-title { color: #71798b; text-transform: uppercase; letter-spacing: .12em; font-size: 10px; font-weight: 800; }
.id-connect > div { display: flex; margin-top: 9px; }
.id-connect input { height: 40px; padding: 0 10px; border-radius: 9px 0 0 9px; font-variant-numeric: tabular-nums; letter-spacing: .08em; }
.id-connect button { width: 42px; border: 1px solid var(--line); border-left: 0; border-radius: 0 9px 9px 0; background: #171b24; cursor: pointer; }
.section-title { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 9px; }
.text-icon, .icon-button { background: transparent; border: 0; cursor: pointer; color: #8a91a1; }
.text-icon:hover, .icon-button:hover { color: var(--text); }
.device-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; max-height: 160px; }
.device-empty { color: #686f7e; font-size: 12px; padding: 12px 8px; line-height: 1.5; }
.device-item { border: 1px solid transparent; background: transparent; border-radius: 10px; display: flex; align-items: center; gap: 10px; padding: 10px; text-align: left; cursor: pointer; width: 100%; }
.device-item:hover { background: #131720; }
.device-item.active { background: rgba(185,255,102,.075); border-color: rgba(185,255,102,.17); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #4b5260; box-shadow: 0 0 0 4px rgba(75,82,96,.12); flex: 0 0 auto; }
.status-dot.online { background: var(--accent); box-shadow: 0 0 0 4px rgba(185,255,102,.11); }
.device-item div { min-width: 0; }
.device-item b, .profile b, .sidebar-action b { display: block; font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.device-item small, .profile small, .sidebar-action small { display: block; color: #71798a; font-size: 10px; margin-top: 3px; }
.history-title { margin-top: 18px; }
.history-list { min-height: 54px; flex: 1 1 auto; overflow-y: auto; }
.history-item { display: grid; grid-template-columns: minmax(0, 1fr) 28px; align-items: center; border-radius: 9px; }
.history-open { min-width: 0; border: 0; background: transparent; color: #bfc4ce; padding: 8px; text-align: left; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 11px; }
.history-delete { border: 0; background: transparent; color: #596171; cursor: pointer; opacity: 0; }
.history-item:hover { background: #131720; }
.history-item:hover .history-delete { opacity: 1; }
.history-item.active { background: rgba(185,255,102,.075); }
.history-item.active .history-open { color: var(--accent); }
.history-delete:hover { color: var(--danger); }
.admin-users { flex: 0 0 auto; margin-top: 16px; }
.user-list { max-height: 150px; overflow-y: auto; }
.user-item { display: grid; grid-template-columns: minmax(0, 1fr) 30px; align-items: center; padding: 7px 5px 7px 8px; border-radius: 9px; }
.user-item:hover { background: #131720; }
.user-item b, .user-item small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.user-item b { color: #c8cdd6; font-size: 11px; }
.user-item small { color: #697181; font-size: 9px; margin-top: 3px; }
.user-delete { width: 28px; height: 28px; border: 0; border-radius: 7px; background: transparent; color: #697181; cursor: pointer; }
.user-delete:hover { color: var(--danger); background: rgba(255,107,120,.08); }
.user-role { color: var(--accent); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.sidebar-foot { margin-top: auto; }
.sidebar-action { width: 100%; display: flex; gap: 10px; align-items: center; text-align: left; border: 1px solid var(--line); background: #11151d; color: #d6d9e0; border-radius: 10px; padding: 11px; cursor: pointer; margin-bottom: 12px; }
.sidebar-action > span { color: var(--accent); font-size: 20px; }
.profile { border-top: 1px solid var(--line); padding: 15px 5px 0; display: grid; grid-template-columns: 34px 1fr 26px; gap: 9px; align-items: center; }
.avatar { display: grid; place-items: center; height: 34px; background: #232936; border-radius: 9px; font-size: 12px; font-weight: 800; }

.chat-shell { min-width: 0; min-height: 0; height: 100%; display: grid; grid-template-rows: auto auto minmax(0, 1fr) max-content; overflow: hidden; background: radial-gradient(circle at 50% -20%, rgba(113,143,255,.07), transparent 42%), #0b0d12; }
.chat-header { grid-row: 1; min-height: 74px; padding: 12px 24px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; background: rgba(11,13,18,.82); backdrop-filter: blur(16px); z-index: 3; }
.chat-identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.device-orb { width: 38px; height: 38px; background: #171b24; border: 1px solid var(--line); border-radius: 12px; display: grid; place-items: center; }
.device-orb span { width: 8px; height: 8px; background: #596071; border-radius: 50%; }
.device-orb.online span { background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.chat-identity h2 { font-size: 14px; margin: 0 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-identity p { color: #7c8494; font-size: 11px; margin: 0; }
.header-controls { display: flex; align-items: center; gap: 10px; }
.model-control { display: flex; align-items: center; gap: 9px; color: #777f90; text-transform: uppercase; letter-spacing: .1em; font-size: 9px; }
.model-control select { width: min(300px, 28vw); height: 38px; border-radius: 9px; border: 1px solid var(--line); background: #11151d; color: #d8dce4; padding: 0 30px 0 10px; outline: none; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 9px; background: #11151d; }
.power-button { height: 38px; border-radius: 9px; border: 1px solid rgba(255,107,120,.24); background: rgba(255,107,120,.07); color: #ff9ba5; padding: 0 12px; font-size: 11px; cursor: pointer; white-space: nowrap; }
.power-button:hover:not(:disabled) { background: rgba(255,107,120,.14); border-color: rgba(255,107,120,.42); }
.power-button.start { color: var(--accent); border-color: rgba(185,255,102,.25); background: rgba(185,255,102,.07); }
.power-button:disabled { opacity: .45; cursor: default; }
.mobile-only { display: none; }
.settings-panel { grid-row: 2; display: grid; grid-template-columns: 1fr 180px minmax(260px, 1.4fr); gap: 22px; align-items: end; padding: 14px 24px; background: #0e1118; border-bottom: 1px solid var(--line); }
.settings-panel label { color: #858d9d; font-size: 11px; }
.settings-panel label > span { display: flex; justify-content: space-between; margin-bottom: 7px; }
.settings-panel input[type="number"], .settings-panel textarea { border-radius: 8px; padding: 8px 10px; }
.settings-panel textarea { resize: vertical; min-height: 36px; }
.settings-panel input[type="range"] { accent-color: var(--accent); }

.messages { grid-row: 3; min-height: 0; overflow-y: auto; padding: 38px clamp(20px, 8vw, 130px) calc(54px + env(safe-area-inset-bottom)); scroll-padding-bottom: calc(54px + env(safe-area-inset-bottom)); scroll-behavior: smooth; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.empty-chat { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding-bottom: 20px; }
.empty-mark { width: 52px; height: 52px; border-radius: 16px 3px 16px 3px; font-size: 32px; box-shadow: 0 10px 40px rgba(185,255,102,.12); margin-bottom: 24px; }
.empty-chat h1 { font-size: clamp(32px, 4vw, 50px); letter-spacing: -.055em; margin: 9px 0 12px; }
.empty-chat > p { color: #7f8798; line-height: 1.65; margin: 0; }
.suggestions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(760px, 100%); margin-top: 32px; }
.suggestions button { border: 1px solid var(--line); background: rgba(18,22,30,.72); border-radius: 12px; padding: 16px; text-align: left; cursor: pointer; }
.suggestions button:hover { border-color: rgba(185,255,102,.32); transform: translateY(-2px); }
.suggestions b { display: block; color: var(--accent); font-size: 11px; margin-bottom: 7px; }
.suggestions span { color: #959cac; font-size: 11px; line-height: 1.45; }
.message { width: min(860px, 100%); margin: 0 auto 28px; display: grid; grid-template-columns: 34px 1fr; gap: 13px; }
.message-avatar { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 10px; font-weight: 900; background: #232936; color: #b8bfcc; }
.message.assistant .message-avatar { background: var(--accent); color: #0b0d12; font-family: Georgia, serif; font-style: italic; font-size: 16px; }
.message-label { color: #8e96a7; font-size: 10px; letter-spacing: .09em; text-transform: uppercase; margin-bottom: 7px; font-weight: 800; }
.message-content { color: #e5e8ed; font-size: 15px; line-height: 1.72; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .message-content { color: #c9ced8; }
.message-content.streaming::after { content: ""; display: inline-block; width: 7px; height: 15px; background: var(--accent); margin-left: 3px; vertical-align: -2px; animation: blink .8s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer-wrap { grid-row: 4; position: relative; z-index: 4; align-self: end; width: 100%; padding: 10px clamp(18px, 8vw, 130px) calc(20px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, #0b0d12 18%); }
.connection-notice { width: min(860px, 100%); margin: 0 auto 8px; color: #727a8a; font-size: 11px; text-align: center; }
.connection-notice.ready { color: #778168; }
.composer { width: min(860px, 100%); min-height: 58px; margin: 0 auto; background: #141821; border: 1px solid var(--line); border-radius: 15px; display: flex; align-items: flex-end; padding: 9px 10px 9px 16px; box-shadow: 0 18px 50px rgba(0,0,0,.28); }
.composer:focus-within { border-color: rgba(185,255,102,.32); }
.composer textarea { flex: 1; color: var(--text); background: transparent; border: 0; outline: 0; resize: none; line-height: 1.5; max-height: 180px; padding: 8px 6px 6px 0; }
.send-button, .stop-button { width: 39px; height: 39px; border: 0; border-radius: 11px; cursor: pointer; flex: 0 0 auto; }
.send-button { background: var(--accent); color: #0b0d12; font-size: 20px; font-weight: 900; }
.send-button:disabled { background: #2a303b; color: #656d7c; cursor: default; }
.stop-button { background: #2b303b; color: #e6e9ef; margin-right: 6px; font-size: 11px; }
.composer-note { color: #5f6675; text-align: center; font-size: 10px; margin: 8px 0 0; }
.toast { position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #202530; border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; font-size: 12px; z-index: 50; box-shadow: var(--shadow); transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { color: #ffc2c8; border-color: rgba(255,107,120,.3); }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.62); z-index: 8; }

@media (max-width: 900px) {
  .auth-layout { grid-template-columns: 1fr; }
  .auth-copy { min-height: 48vh; padding-bottom: 28px; }
  .auth-copy .brand { position: static; margin-bottom: 70px; }
  .auth-copy h1 { font-size: clamp(42px, 12vw, 70px); }
  .trust-row { margin-top: 28px; flex-wrap: wrap; gap: 22px; }
  .auth-card-wrap { border-left: 0; border-top: 1px solid var(--line); padding: 50px 24px 70px; }
  .app-layout { position: fixed; left: 0; top: var(--app-offset-top); width: 100%; height: var(--app-height); grid-template-columns: 1fr; }
  .sidebar { position: absolute; left: 0; top: 0; bottom: 0; width: min(310px, 88vw); transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-grid; place-items: center; }
  .chat-header { padding: 10px 14px; gap: 10px; }
  .chat-identity { flex: 1; }
  .device-orb { display: none; }
  .model-control span { display: none; }
  .model-control select { width: min(36vw, 200px); }
  .power-button { width: 38px; padding: 0; overflow: hidden; color: transparent; position: relative; }
  .power-button::after { content: "⏻"; color: currentColor; position: absolute; inset: 0; display: grid; place-items: center; font-size: 17px; }
  .power-button:not(.start)::after { color: #ff9ba5; }
  .power-button.start::after { color: var(--accent); }
  .settings-panel { grid-template-columns: 1fr 1fr; padding: 14px; }
  .system-field { grid-column: 1 / -1; }
  .messages { padding: 26px 17px calc(72px + env(safe-area-inset-bottom)); scroll-padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .composer-wrap { padding: 8px 13px calc(12px + env(safe-area-inset-bottom)); }
  .suggestions { grid-template-columns: 1fr; }
  .suggestions button:nth-child(n+3) { display: none; }
}

@media (max-width: 560px) {
  .auth-copy { padding: 28px 22px 34px; }
  .auth-copy > p { font-size: 15px; }
  .trust-row div:last-child { display: none; }
  .chat-identity h2 { max-width: 150px; }
  .chat-identity p { max-width: 150px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .model-control select { width: 112px; }
  .settings-panel { grid-template-columns: 1fr; }
  .system-field { grid-column: auto; }
  .empty-chat > p br { display: none; }
  .composer-note { display: none; }
  .keyboard-open .chat-header { min-height: 58px; padding-block: 7px; }
  .keyboard-open .messages { padding-top: 14px; padding-bottom: calc(48px + env(safe-area-inset-bottom)); scroll-padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
  .keyboard-open .connection-notice { display: none; }
  .keyboard-open .composer-wrap { padding-top: 6px; }
}
