:root {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-deep: #09101f;
  --surface: #121d35;
  --surface-2: #16223d;
  --surface-glass: rgba(18, 29, 53, .84);
  --primary: #3b82f6;
  --primary-strong: #2563eb;
  --accent: #10b981;
  --danger: #ef4444;
  --text: #f8fafc;
  --text-soft: #cbd5e1;
  --muted: #94a3b8;
  --line: rgba(255, 255, 255, .09);
  --line-strong: rgba(96, 165, 250, .32);
  --ring: rgba(59, 130, 246, .28);
  --shadow: 0 20px 70px rgba(0, 0, 0, .28);
  --radius: 16px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { width: 100%; height: 100%; min-height: 0; overflow: hidden; background: var(--bg); }
body { width: 100%; height: 100%; min-height: 0; margin: 0; overflow: hidden; background: radial-gradient(circle at 10% 0%, rgba(30, 64, 175, .25), transparent 34%), radial-gradient(circle at 100% 100%, rgba(5, 150, 105, .12), transparent 32%), var(--bg); color: var(--text); font: 16px/1.5 var(--font); }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:active:not(:disabled) { opacity: .78; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }
[hidden] { display: none !important; }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.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; }
.skip-link { position: fixed; z-index: 30; top: 8px; left: 8px; transform: translateY(-140%); padding: 9px 12px; border-radius: 8px; background: #fff; color: #0f172a; font-size: .78rem; font-weight: 750; text-decoration: none; transition: transform .2s; }
.skip-link:focus { transform: translateY(0); }
.eyebrow { margin: 0; color: #93c5fd; font-size: .69rem; font-weight: 700; letter-spacing: .16em; }

.login-view { min-height: var(--app-height, 100dvh); display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 24px; background: linear-gradient(145deg, rgba(22, 34, 61, .96), rgba(12, 21, 39, .96)); box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 42px; color: var(--text-soft); font-size: .75rem; font-weight: 750; letter-spacing: .16em; }
.brand-glyph { width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid rgba(96, 165, 250, .32); border-radius: 12px; background: linear-gradient(145deg, rgba(59, 130, 246, .26), rgba(16, 185, 129, .16)); color: #dbeafe; font-weight: 800; box-shadow: inset 0 1px rgba(255,255,255,.08); }
.login-icon { width: 50px; height: 50px; display: grid; place-items: center; margin-bottom: 20px; border-radius: 15px; background: rgba(59, 130, 246, .13); color: #93c5fd; }
.login-icon svg { width: 26px; height: 26px; }
.login-card h1 { margin: 7px 0 9px; font-size: clamp(1.7rem, 5vw, 2.15rem); line-height: 1.15; letter-spacing: -.035em; }
.login-copy { margin: 0 0 24px; color: var(--text-soft); font-size: .92rem; }
.login-card form { display: grid; gap: 10px; }
.login-card label { color: var(--text-soft); font-size: .82rem; font-weight: 650; }
.password-field { min-height: 48px; display: grid; grid-template-columns: 38px 1fr; align-items: center; border: 1px solid var(--line); border-radius: 11px; background: rgba(4, 10, 22, .55); transition: border-color .2s, box-shadow .2s; }
.password-field:focus-within { border-color: #60a5fa; box-shadow: 0 0 0 4px var(--ring); }
.password-field svg { justify-self: end; width: 18px; color: var(--muted); }
.password-field input { min-width: 0; height: 46px; padding: 0 13px; border: 0; outline: 0; background: transparent; color: var(--text); }
.form-error { min-height: 21px; margin: 0; color: #fca5a5; font-size: .78rem; }
.primary-button, .secondary-button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; border-radius: 10px; padding: 0 16px; text-decoration: none; font-weight: 700; transition: background .2s, border-color .2s, color .2s, opacity .2s, box-shadow .2s; }
.primary-button { border: 1px solid #3b82f6; background: linear-gradient(180deg, #3b82f6, #2563eb); color: white; box-shadow: 0 10px 24px rgba(37, 99, 235, .2); }
.primary-button:hover { background: linear-gradient(180deg, #60a5fa, #2563eb); }
.primary-button:disabled, .send-button:disabled { cursor: not-allowed; opacity: .45; }
.secondary-button { border: 1px solid var(--line); background: rgba(255,255,255,.025); color: var(--text-soft); }
.secondary-button:hover { border-color: var(--line-strong); color: var(--text); background: rgba(59,130,246,.08); }
.secondary-button svg, .primary-button svg { width: 17px; height: 17px; }
.secure-note { display: flex; align-items: center; gap: 8px; margin-top: 22px; color: var(--muted); font-size: .7rem; }
.secure-note svg { width: 15px; height: 15px; color: var(--accent); }

.app-shell { width: 100%; height: var(--app-height, 100dvh); min-height: 0; overflow: hidden; display: grid; grid-template: 72px minmax(0, 1fr) / 310px minmax(0, 1fr); }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; border-bottom: 1px solid var(--line); background: rgba(9, 16, 31, .72); backdrop-filter: blur(18px); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .brand-glyph { width: 42px; height: 42px; }
.brand div { display: grid; }
.brand strong { font-size: .98rem; letter-spacing: -.01em; }
.brand small { color: var(--muted); font-size: .69rem; }
.topbar-actions { display: flex; align-items: center; gap: 9px; }
.update-link { min-height: 38px; font-size: .72rem; }
.status-pill { min-height: 34px; display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--line); border-radius: 99px; background: rgba(255,255,255,.025); color: var(--muted); font-size: .72rem; font-weight: 650; }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #64748b; box-shadow: 0 0 0 4px rgba(100,116,139,.12); }
.status-pill.online { color: #a7f3d0; border-color: rgba(16,185,129,.25); }
.status-pill.online i { background: var(--accent); box-shadow: 0 0 0 4px rgba(16,185,129,.12), 0 0 14px rgba(16,185,129,.5); }
.icon-button { width: 44px; height: 44px; display: inline-grid; place-items: center; border: 1px solid transparent; border-radius: 11px; background: transparent; color: var(--muted); transition: color .2s, border-color .2s, background .2s; }
.icon-button:hover { color: var(--text); border-color: var(--line); background: rgba(255,255,255,.035); }
.icon-button.spinning svg { animation: spin .8s linear infinite; }

.resource-panel { min-height: 0; overflow-y: auto; padding: 25px 20px; border-right: 1px solid var(--line); background: rgba(9, 16, 31, .46); }
.panel-title { display: flex; align-items: center; justify-content: space-between; }
.panel-title h2, .modal h2 { margin: 3px 0 0; font-size: 1.08rem; }
.panel-copy { margin: 12px 0 20px; color: var(--muted); font-size: .78rem; }
.resource-list { display: grid; gap: 10px; }
.resource-card { padding: 15px; border: 1px solid var(--line); border-radius: 13px; background: linear-gradient(145deg, rgba(22,34,61,.84), rgba(14,24,43,.84)); transition: border-color .2s, background .2s; }
.resource-card.active { border-color: rgba(16,185,129,.3); background: linear-gradient(145deg, rgba(14,52,54,.48), rgba(14,24,43,.9)); }
.resource-head { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; }
.provider-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: rgba(59,130,246,.13); color: #93c5fd; }
.provider-icon svg { width: 18px; height: 18px; }
.resource-head div { display: grid; min-width: 0; }
.resource-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .79rem; }
.resource-head small { color: var(--muted); font-size: .67rem; }
.state { padding: 4px 7px; border-radius: 99px; background: rgba(100,116,139,.12); color: #cbd5e1; font-size: .58rem; font-weight: 800; letter-spacing: .08em; }
.state.online { background: rgba(16,185,129,.12); color: #6ee7b7; }
.state.warning { background: rgba(245,158,11,.12); color: #fcd34d; }
.resource-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; color: var(--muted); font-size: .67rem; }
.resource-meta strong { color: var(--text-soft); }
.meter { height: 4px; margin-top: 8px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.07); }
.meter i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--accent)); }
.connect-button { width: 100%; min-height: 40px; margin-top: 12px; border: 1px solid rgba(59,130,246,.26); border-radius: 9px; background: rgba(59,130,246,.09); color: #bfdbfe; font-size: .73rem; font-weight: 700; }
.connect-button:hover { background: rgba(59,130,246,.16); }
.privacy-card { display: flex; gap: 10px; margin-top: 18px; padding: 13px; border: 1px solid rgba(16,185,129,.14); border-radius: 12px; background: rgba(16,185,129,.045); }
.privacy-card > svg { flex: 0 0 auto; width: 18px; color: #6ee7b7; }
.privacy-card strong { display: block; color: #a7f3d0; font-size: .75rem; }
.privacy-card p { margin: 3px 0 0; color: var(--muted); font-size: .67rem; line-height: 1.5; }
.privacy-card code { color: var(--text-soft); }

.chat-panel { min-width: 0; min-height: 0; overflow: hidden; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.chat-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px clamp(18px, 4vw, 48px) 15px; }
.chat-header h1 { margin: 3px 0 0; font-size: clamp(1.28rem, 2vw, 1.6rem); letter-spacing: -.025em; }
.chat-header .secondary-button { min-height: 40px; font-size: .72rem; }
.messages { min-height: 0; overflow-y: auto; scroll-behavior: smooth; padding: 12px clamp(18px, 4vw, 48px) 28px; }
.welcome-card { width: min(670px, 100%); min-height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; margin: 0 auto; padding: 32px 0; }
.welcome-icon { width: 54px; height: 54px; display: grid; place-items: center; margin-bottom: 23px; border: 1px solid rgba(96,165,250,.22); border-radius: 17px; background: linear-gradient(145deg, rgba(59,130,246,.18), rgba(16,185,129,.09)); color: #93c5fd; box-shadow: 0 16px 45px rgba(30,64,175,.15); }
.welcome-icon svg { width: 28px; height: 28px; }
.welcome-card h2 { margin: 7px 0 9px; font-size: clamp(2rem, 5vw, 3rem); line-height: 1.08; letter-spacing: -.055em; }
.welcome-card > p:not(.eyebrow) { max-width: 560px; margin: 0; color: var(--text-soft); }
.suggestions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 25px; }
.suggestions button { min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 14px; background: rgba(255,255,255,.025); color: var(--text-soft); font-size: .76rem; transition: border-color .2s, background .2s, color .2s; }
.suggestions button:hover { border-color: var(--line-strong); background: rgba(59,130,246,.08); color: var(--text); }
.message { width: min(760px, 100%); display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px; margin: 0 auto 20px; }
.message.user { grid-template-columns: minmax(0, 1fr); justify-items: end; }
.message-avatar { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); color: #93c5fd; font-weight: 800; }
.message-card { min-width: 0; padding: 13px 15px; border: 1px solid var(--line); border-radius: 13px; background: rgba(18,29,53,.72); box-shadow: 0 8px 30px rgba(0,0,0,.1); }
.message.user .message-card { max-width: 85%; border-color: rgba(59,130,246,.24); background: rgba(30,64,175,.23); }
.message-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; color: var(--muted); font-size: .65rem; }
.message-meta strong { color: var(--text-soft); font-size: .7rem; }
.message-content { overflow-wrap: anywhere; white-space: pre-wrap; color: #e2e8f0; font-size: .9rem; line-height: 1.66; }
.message-activity { margin: 0 0 9px; }
.activity-details { border: 1px solid rgba(96,165,250,.16); border-radius: 10px; background: rgba(8,15,29,.46); }
.activity-details > summary { cursor: pointer; padding: 9px 11px; color: #bfdbfe; font-size: .72rem; font-weight: 700; }
.activity-list { display: grid; gap: 7px; padding: 0 9px 9px; }
.activity-row { padding: 8px 9px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.018); }
.activity-row > div { display: flex; justify-content: space-between; gap: 10px; }
.activity-row strong { color: var(--text-soft); font-size: .7rem; }
.activity-row span { color: #6ee7b7; font-size: .62rem; }
.activity-row.inProgress span { color: #fde68a; }
.activity-row.failed span { color: #fca5a5; }
.activity-row pre { max-height: 180px; overflow: auto; margin: 7px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font: .68rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.activity-row ol { margin: 7px 0 0; padding-left: 20px; color: var(--muted); font-size: .68rem; }
.message.streaming .message-content::after { content: ""; display: inline-block; width: 7px; height: 16px; margin-left: 4px; vertical-align: text-bottom; border-radius: 2px; background: #60a5fa; animation: blink .8s step-end infinite; }
.composer { width: min(850px, calc(100% - 36px)); margin: 0 auto 20px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(18,29,53,.91); box-shadow: 0 18px 60px rgba(0,0,0,.25); backdrop-filter: blur(18px); transition: border-color .2s, box-shadow .2s; }
.composer:focus-within { border-color: rgba(96,165,250,.46); box-shadow: 0 0 0 4px var(--ring), 0 18px 60px rgba(0,0,0,.25); }
.composer textarea { width: 100%; min-height: 64px; max-height: 180px; resize: none; display: block; padding: 16px 16px 6px; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.5; }
.composer textarea::placeholder { color: #94a3b8; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 5px 7px 7px 16px; }
.composer-footer > span { color: var(--muted); font-size: .68rem; }
.send-button { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 10px; background: linear-gradient(180deg, #3b82f6, #2563eb); color: white; transition: background .2s, opacity .2s; }
.send-button:hover { background: linear-gradient(180deg, #60a5fa, #2563eb); }
.send-button svg { width: 18px; height: 18px; }

.modal { width: min(480px, calc(100% - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; border: 1px solid var(--line-strong); border-radius: 18px; padding: 22px; background: #111c33; color: var(--text); box-shadow: 0 30px 100px rgba(0,0,0,.58); }
.modal::backdrop { background: rgba(3,8,18,.78); backdrop-filter: blur(9px); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.modal > p { margin: 14px 0 18px; color: var(--text-soft); font-size: .82rem; }
.resource-modal { width: min(540px, calc(100% - 24px)); }
.device-code { display: block; margin: 16px 0; padding: 15px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--bg-deep); color: #bfdbfe; text-align: center; font: 800 1.35rem ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .12em; }
.modal .primary-button.wide, .modal .secondary-button.wide, .modal > .primary-button, .modal > .secondary-button { width: 100%; margin-top: 10px; }
.modal pre { max-height: 230px; overflow: auto; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-deep); color: var(--text-soft); white-space: pre-wrap; overflow-wrap: anywhere; font: .72rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(520px, calc(100% - 28px)); padding: 11px 15px; border: 1px solid var(--line-strong); border-radius: 11px; background: #16223d; box-shadow: var(--shadow); color: var(--text-soft); font-size: .78rem; }
.mobile-only { display: none; }
@keyframes blink { 50% { opacity: .2; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  body { overflow: hidden; }
  .app-shell { grid-template: 64px minmax(0, 1fr) / 1fr; }
  .topbar { padding: 0 12px; }
  .brand .brand-glyph { width: 38px; height: 38px; }
  .resource-panel { display: none; }
  .mobile-only { display: inline-grid; }
  .status-pill { padding: 0 9px; }
  .update-link span { display: none; }
  .update-link { width: 44px; padding: 0; }
  .chat-header { padding: 16px 15px 9px; }
  .chat-header .secondary-button span { display: none; }
  .chat-header .secondary-button { width: 44px; padding: 0; }
  .messages { padding: 8px 15px 20px; }
  .welcome-card { padding: 20px 0; }
  .composer { width: calc(100% - 24px); margin-bottom: max(12px, env(safe-area-inset-bottom)); }
  .composer-footer > span { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

@media (max-width: 480px) {
  .login-view { padding: 14px; }
  .login-card { padding: 24px 20px; border-radius: 20px; }
  .login-brand { margin-bottom: 30px; }
  .brand small { display: none; }
  .status-pill > span { display: none; }
  .status-pill { width: 34px; justify-content: center; padding: 0; }
  .message { grid-template-columns: 30px minmax(0,1fr); gap: 9px; }
  .message-avatar { width: 30px; height: 30px; border-radius: 9px; font-size: .75rem; }
  .message.user .message-card { max-width: 92%; }
  .suggestions { display: grid; width: 100%; }
  .suggestions button { text-align: left; }
}

@media (max-width: 820px) and (max-height: 500px) {
  .chat-header { padding-top: 8px; padding-bottom: 5px; }
  .chat-header .eyebrow { display: none; }
  .messages { padding-top: 4px; padding-bottom: 8px; }
  .message { margin-bottom: 10px; }
  .composer { margin-bottom: max(7px, env(safe-area-inset-bottom)); }
  .composer textarea { min-height: 44px; padding-top: 10px; }
  .composer-footer { min-height: 43px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
