:root {
  --bg: #0b0d12;
  --surface: #12151d;
  --surface-2: #191d28;
  --surface-3: #222838;
  --text: #eef1f7;
  --muted: #8a94a6;
  --accent: #4f7cff;
  --accent-hover: #3d6bf2;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mobile-only {
  display: none !important;
}

.mobile-backdrop {
  display: none;
}

.mobile-icon-btn {
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.mobile-icon-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg);
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  height: 24px;
  width: auto;
  display: block;
}

.welcome-logo {
  height: 52px;
  width: auto;
  margin: 0 auto 14px;
  display: block;
}

.brand h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.status-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.status-pill.ok .dot {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.status-pill.ok {
  color: var(--text);
}

.status-pill.warn .dot {
  background: var(--amber);
}

.pill-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 13px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.pill-btn:hover {
  background: var(--surface-3);
}

.pill-btn.active {
  background: rgba(52, 211, 153, 0.18);
  color: #6ee7b7;
}

.pill-btn.active:hover {
  background: rgba(52, 211, 153, 0.28);
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-select {
  appearance: auto;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.lang-select:focus {
  outline: none;
  border-color: var(--accent);
}

.login-lang-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 4px;
}

.pill-btn-accent {
  background: var(--accent);
  color: #fff;
}

.pill-btn-accent:hover {
  background: var(--accent-hover);
}

.pill-btn-danger {
  background: rgba(248, 113, 113, 0.18);
  color: #fca5a5;
}

.pill-btn-danger:hover {
  background: rgba(248, 113, 113, 0.3);
}

.ghost-icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 7px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.ghost-icon-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.link-btn {
  background: none;
  border: none;
  color: #93c5fd;
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
}

/* Main Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 230px 1fr 340px;
  gap: 12px;
  padding: 0 14px 14px;
  min-height: 0;
}

.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 10px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 10px;
}

.icon-pill-btn {
  border: none;
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.icon-pill-btn:hover {
  background: var(--surface-3);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-item {
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  background: transparent;
  transition: background 0.15s;
}

.session-item:hover {
  background: var(--surface-2);
}

.session-item.active {
  background: var(--surface-3);
}

.session-meta {
  min-width: 0;
  flex: 1;
}

.session-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.session-source-badge {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(56, 189, 248, 0.18);
  color: #7dd3fc;
}

.session-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.session-item:hover .session-del {
  opacity: 1;
}

.session-del:hover {
  color: var(--red);
  background: rgba(248, 113, 113, 0.14);
}

/* Chat Pane */
.chat-pane {
  background: var(--surface);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.key-warning {
  margin: 12px 18px 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(251, 191, 36, 0.12);
  color: #fde68a;
  font-size: 12px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}

.msg {
  max-width: 82%;
  line-height: 1.55;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  padding: 10px 15px;
  border-radius: 18px 18px 4px 18px;
  font-size: 14px;
}

.msg.assistant {
  align-self: flex-start;
  background: transparent;
  color: var(--text);
  padding: 4px 2px;
  max-width: 92%;
}

.msg.error {
  align-self: flex-start;
  max-width: 92%;
}

.error-card {
  background: rgba(248, 113, 113, 0.1);
  border-left: 3px solid var(--red);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.error-head {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #fca5a5;
  font-size: 13px;
  font-weight: 600;
}

.error-head svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.error-body {
  color: #fecaca;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.error-details {
  margin-top: 4px;
}

.error-details summary {
  cursor: pointer;
  font-size: 11px;
  color: #fca5a5;
  opacity: 0.8;
}

.error-details pre {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  color: #fecaca;
  font-size: 11px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.welcome {
  align-self: center;
  text-align: center;
  color: var(--muted);
  margin: auto 0;
  max-width: 420px;
}

.msg.welcome h3 {
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 6px;
}

.msg-body.user-text {
  white-space: pre-wrap;
}

.md-content > *:first-child {
  margin-top: 0;
}

.md-content > *:last-child {
  margin-bottom: 0;
}

.md-content p {
  margin: 0.45em 0;
}

.md-content h1,
.md-content h2,
.md-content h3,
.md-content h4,
.md-content h5,
.md-content h6 {
  margin: 0.9em 0 0.4em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

.md-content h1 { font-size: 1.3em; }
.md-content h2 { font-size: 1.15em; }
.md-content h3 { font-size: 1.05em; }

.md-content strong {
  font-weight: 600;
  color: #ffffff;
}

.md-content ul,
.md-content ol {
  margin: 0.45em 0;
  padding-left: 1.35em;
  display: flex;
  flex-direction: column;
  gap: 0.25em;
}

.md-content li::marker {
  color: var(--muted);
}

.md-content a {
  color: #93c5fd;
  text-decoration: none;
}

.md-content a:hover {
  text-decoration: underline;
}

.md-image-link {
  display: inline-block;
  margin: 8px 0;
}

.md-image {
  display: block;
  max-width: 100%;
  max-height: 460px;
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.md-content code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  color: #c7d2fe;
}

.md-content pre {
  margin: 0.65em 0;
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  overflow-x: auto;
}

.md-content pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 12px;
  color: #dbe3f0;
  line-height: 1.5;
}

.md-content blockquote {
  margin: 0.55em 0;
  padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: rgba(79, 124, 255, 0.08);
  border-radius: 0 8px 8px 0;
  color: #cbd5e1;
}

.md-content hr {
  border: none;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0.9em 0;
}

.md-table-wrap {
  margin: 0.65em 0;
  overflow-x: auto;
  border-radius: 10px;
  background: var(--bg);
}

.md-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.md-content th,
.md-content td {
  text-align: left;
  padding: 8px 12px;
}

.md-content thead {
  background: var(--surface-2);
  color: var(--text);
}

.md-content tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

.traces {
  margin-top: 8px;
}

.traces summary {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: 999px;
  list-style: none;
  transition: background 0.15s, color 0.15s;
}

.traces summary:hover {
  background: var(--surface-3);
  color: var(--text);
}

.trace-list {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.trace-item {
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: #b7c0d0;
}

/* Composer */
.composer-wrap {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 8px 20px 16px;
}

.agent-activity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: rgba(79, 124, 255, 0.12);
  font-size: 12px;
  color: #bfdbfe;
}

.agent-activity span {
  flex: 1;
}

.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(191, 219, 254, 0.25);
  border-top-color: #93c5fd;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.composer-box {
  background: var(--surface-2);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.22);
  transition: box-shadow 0.15s, background 0.15s;
}

.composer-box:focus-within {
  background: #1d2230;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.32), 0 0 0 1.5px rgba(79, 124, 255, 0.45);
}

.composer-box textarea {
  width: 100%;
  resize: none;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  padding: 12px 14px 6px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
}

.composer-box textarea::placeholder {
  color: var(--muted);
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px 8px;
  flex-wrap: wrap;
}

.model-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}

.model-controls select {
  background: var(--surface-3);
  border: none;
  outline: none;
  color: var(--text);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  cursor: pointer;
  max-width: 220px;
}

.model-controls select:hover {
  background: #2b3246;
}

.model-source-hint {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.model-source-hint.live {
  color: var(--green);
}

.send-btn {
  border: none;
  border-radius: 10px;
  padding: 7px 16px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.send-btn:hover {
  background: var(--accent-hover);
}

/* Device Pane */
.device-pane {
  background: var(--surface);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
  gap: 10px;
}

.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.device-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.device-dims {
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, monospace;
  margin-right: 4px;
}

.screen-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
}

.phone-frame {
  position: relative;
  height: 100%;
  width: 100%;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

#screen-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: crosshair;
  display: none;
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.screen-placeholder {
  text-align: center;
  color: var(--muted);
  padding: 20px;
  font-size: 13px;
}

.screen-placeholder small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  opacity: 0.7;
}

.touch-ripple {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(79, 124, 255, 0.45);
  box-shadow: 0 0 0 4px rgba(79, 124, 255, 0.2);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.device-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-pill-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.nav-pill {
  border: none;
  border-radius: 10px;
  padding: 7px 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.15s;
}

.nav-pill svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.85;
  flex-shrink: 0;
}

.nav-pill-type {
  padding: 7px 12px;
}

.nav-pill:hover {
  background: var(--surface-3);
}

.quick-type-row {
  display: flex;
  gap: 6px;
}

.quick-type-row input {
  flex: 1;
  border: none;
  outline: none;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 12px;
}

.quick-type-row input:focus {
  box-shadow: 0 0 0 1.5px rgba(79, 124, 255, 0.45);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 7vh 16px 24px;
}

.modal {
  background: var(--surface);
  border-radius: 18px;
  width: 100%;
  max-width: 620px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.modal-lg {
  max-width: 820px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 10px;
  background: var(--bg);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 16px 20px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
}

.modal-desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.modal-settings {
  max-width: 720px;
}

.modal-tabs {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 4px 14px 0;
  background: var(--bg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-shrink: 0;
}

.modal-tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  border: none;
  border-radius: 11px 11px 0 0;
  padding: 9px 14px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.tab-btn svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.8;
  flex-shrink: 0;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}

.tab-btn.active svg {
  color: var(--accent);
  opacity: 1;
}

.keys-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keys-empty {
  padding: 14px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-2);
}

.key-row-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.key-row-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.key-row-mask {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
}

.add-key-card {
  background: var(--bg);
  border-radius: 14px;
  padding: 10px;
}

.add-key-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-key-row select {
  width: 170px;
  flex-shrink: 0;
}

.add-key-row input {
  flex: 1;
  min-width: 0;
}

.models-default-grid {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 12px;
}

.default-model-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.default-model-row select {
  flex: 1;
  min-width: 0;
}

.prompt-field textarea {
  min-height: 290px;
  line-height: 1.55;
  resize: vertical;
}

.settings-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 12px;
}

.settings-row-2 {
  grid-template-columns: 1fr 1fr;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.modal input,
.modal select,
.modal textarea {
  background: var(--surface-2);
  border: none;
  outline: none;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 13px;
  font-family: inherit;
}

.modal input:focus,
.modal select:focus,
.modal textarea:focus {
  box-shadow: 0 0 0 1.5px rgba(79, 124, 255, 0.5);
}

.key-status {
  color: var(--green);
  font-weight: 500;
}

.checkbox-field label {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  color: var(--text);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 6px;
}

.save-msg {
  font-size: 12px;
  color: var(--green);
}

.code-box {
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  font-size: 12px;
  max-height: 65vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.hidden {
  display: none !important;
}

/* App Memory Tab */
.memory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-card {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.memory-pkg {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--muted);
}

.memory-purpose {
  font-size: 12.5px;
  color: #93c5fd;
  background: rgba(79, 124, 255, 0.1);
  padding: 5px 9px;
  border-radius: 8px;
}

.memory-notes {
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: #cbd5e1;
}

/* Security Tab */
.security-card {
  background: var(--surface-2);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.security-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.security-card-head h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 3px;
}

.security-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.security-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mfa-setup-box {
  display: flex;
  gap: 16px;
  align-items: center;
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  flex-wrap: wrap;
}

.mfa-qr-wrap {
  background: #ffffff;
  padding: 8px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mfa-qr-wrap svg {
  width: 156px;
  height: 156px;
  display: block;
}

.mfa-setup-details {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mfa-secret {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: #c7d2fe;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  word-break: break-all;
  user-select: all;
}

.mfa-verify-row {
  display: flex;
  gap: 8px;
}

.mfa-verify-row input {
  width: 130px;
  text-align: center;
  letter-spacing: 0.16em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 11, 16, 0.92);
  backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 26px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-logo {
  height: 44px;
  width: auto;
  align-self: center;
  margin-bottom: 2px;
}

.login-card h2 {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
}

.login-card .modal-desc {
  text-align: center;
  margin-top: -6px;
}

.login-card input {
  background: var(--surface-2);
  border: none;
  outline: none;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
}

.login-card input:focus {
  box-shadow: 0 0 0 1.5px rgba(79, 124, 255, 0.55);
}

.login-error {
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.14);
  color: #fca5a5;
  font-size: 12.5px;
}

.login-submit {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  margin-top: 2px;
}

@media (max-width: 900px) {
  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: flex !important;
  }

  .topbar {
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    min-height: 52px;
  }

  .brand h1 {
    font-size: 15px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    padding: 0;
    gap: 0;
    position: relative;
    overflow: hidden;
  }

  /* Main view: Full-screen Android display with zero scroll */
  .device-pane {
    flex: 1;
    width: 100%;
    height: 100%;
    background: var(--bg);
    border-radius: 0;
    padding: 2px 6px 56px;
    gap: 0;
    overflow: hidden;
  }

  .device-header {
    display: none;
  }

  .screen-stage {
    touch-action: none;
  }

  /* Top-right floating Device Controls popover */
  .device-controls {
    display: none;
    position: fixed;
    top: calc(56px + env(safe-area-inset-top));
    right: 12px;
    width: 288px;
    max-width: calc(100vw - 24px);
    background: rgba(18, 21, 29, 0.94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-radius: 18px;
    padding: 14px;
    gap: 10px;
    box-shadow:
      0 20px 48px rgba(0, 0, 0, 0.65),
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
    z-index: 65;
    overflow: hidden;
  }

  .device-controls.mobile-open {
    display: flex;
  }

  .device-controls-mobile-head {
    align-items: center;
    justify-content: space-between;
    padding-bottom: 2px;
  }

  .device-controls .nav-pill-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .device-controls .nav-pill {
    padding: 11px 10px;
    border-radius: 12px;
    font-size: 13px;
    gap: 7px;
    background: rgba(34, 40, 56, 0.85);
    min-width: 0;
  }

  .device-controls .nav-pill:active {
    background: rgba(79, 124, 255, 0.25);
  }

  .device-controls .quick-type-row {
    gap: 8px;
  }

  .device-controls .quick-type-row input {
    min-width: 0;
    padding: 9px 12px;
    border-radius: 12px;
    font-size: 13px;
    background: rgba(11, 13, 18, 0.85);
  }

  .device-controls .nav-pill-type {
    padding: 9px 14px;
    flex-shrink: 0;
  }

  /* Left slide-out hamburger drawer (Sessions + Topbar controls) */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100%;
    width: 290px;
    max-width: 84vw;
    border-radius: 0 18px 18px 0;
    padding: calc(14px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
    z-index: 70;
    transform: translateX(-108%);
    transition: transform 0.22s ease;
    box-shadow: 16px 0 42px rgba(0, 0, 0, 0.65);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-mobile-panel {
    flex-direction: column;
    gap: 10px;
    padding-bottom: 12px;
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  }

  .sidebar-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .sidebar-mobile-title {
    font-size: 14px;
    font-weight: 600;
  }

  .sidebar-mobile-status {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .sidebar-mobile-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .session-del {
    opacity: 0.75;
  }

  /* Backdrop behind open drawers/popovers */
  .mobile-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(5, 7, 11, 0.55);
    backdrop-filter: blur(3px);
    z-index: 55;
  }

  /* Bottom-center collapsible Chat sheet */
  .chat-pane {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: max(10px, calc(env(safe-area-inset-bottom) - 10px));
    width: 148px;
    height: 38px;
    border-radius: 999px;
    background: linear-gradient(135deg, #4f7cff 0%, #3b63e6 100%);
    box-shadow:
      0 10px 28px rgba(59, 99, 230, 0.42),
      inset 0 1px 0 rgba(255, 255, 255, 0.22);
    z-index: 60;
    transition: width 0.22s ease, height 0.22s ease, border-radius 0.22s ease, bottom 0.22s ease, background 0.22s ease, box-shadow 0.22s ease;
    overflow: hidden;
  }

  .chat-pane:not(.mobile-expanded) .chat-messages,
  .chat-pane:not(.mobile-expanded) .composer-wrap,
  .chat-pane:not(.mobile-expanded) .key-warning,
  .chat-pane:not(.mobile-expanded) .chat-handle-bar {
    display: none;
  }

  .chat-pane.mobile-expanded {
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
    width: 100%;
    height: 82%;
    border-radius: 22px 22px 0 0;
    padding-bottom: max(8px, calc(env(safe-area-inset-bottom) - 10px));
    background: var(--surface);
    box-shadow:
      0 -16px 48px rgba(0, 0, 0, 0.72),
      inset 0 1px 0 rgba(255, 255, 255, 0.08);
    z-index: 65;
  }

  .mobile-chat-handle {
    border: none;
    background: transparent;
    color: #ffffff;
    width: 100%;
    height: 38px;
    padding: 0 18px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    flex-shrink: 0;
  }

  .chat-pane.mobile-expanded .mobile-chat-handle {
    height: auto;
    padding: 10px 16px 8px;
    color: var(--text);
  }

  .chat-handle-bar {
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
  }

  .chat-handle-row {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
  }

  .chat-handle-icon {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.1;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
  }

  .chat-handle-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.9);
  }

  .chat-pane.mobile-expanded .chat-handle-dot {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
  }

  .chat-handle-chevron {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.85;
    transition: transform 0.2s ease;
  }

  .chat-pane.mobile-expanded .chat-handle-chevron {
    transform: rotate(180deg);
  }

  .chat-messages {
    padding: 10px 14px 8px;
  }

  .composer-wrap {
    padding: 6px 10px 10px;
  }

  .model-controls select {
    max-width: 140px;
  }

  .provider-grid, .settings-row, .models-default-grid {
    grid-template-columns: 1fr;
  }

  /* Mobile Settings modal fixes */
  .modal-backdrop {
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
  }

  .modal {
    max-height: calc(100% - 8px);
    border-radius: 16px;
  }

  .modal-header {
    padding: 12px 14px 8px;
  }

  .modal-tabs {
    padding: 2px 10px 0;
  }

  .tab-btn {
    padding: 8px 11px;
    font-size: 12.5px;
    gap: 5px;
  }

  .modal-body {
    padding: 14px;
    gap: 12px;
  }

  .key-row-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .add-key-row {
    flex-direction: column;
    align-items: stretch;
  }

  .add-key-row select,
  .add-key-row input,
  .add-key-row .send-btn {
    width: 100%;
  }

  .security-card-head {
    flex-direction: column;
    align-items: flex-start;
  }
}
