/* --- SVG Icons --- */
.icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: middle;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

/* --- Layout --- */
#app { height: 100dvh; display: flex; flex-direction: column; position: relative; }

/* --- Header --- */
.header { height: var(--header-h); display: flex; align-items: center; padding: 0 12px; background: #1F4E79; color: white; flex-shrink: 0; gap: 8px; z-index: 10; }
[data-theme="dark"] .header { background: #0d2b45; }
.header h1 { font-size: 16px; font-weight: 600; flex: 1; }
.header-btn { color: white; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 10px; transition: background 0.15s; font-size: 14px; }
.header-btn:hover { background: rgba(255,255,255,0.12); }
.lang-toggle { font-size: 13px; font-weight: 600; letter-spacing: 0.5px; }
.user-menu { position: relative; }
.user-menu-btn { font-size: 13px; padding: 6px 10px; border-radius: 6px; }
.user-menu-dropdown {
  position: absolute; top: 100%; right: 0; margin-top: 4px;
  background: var(--surface); color: var(--text); border-radius: 6px;
  box-shadow: var(--shadow-md); min-width: 200px; display: none; z-index: 100;
}
.user-menu.open .user-menu-dropdown { display: block; }
.user-menu-dropdown .user-email { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text2); word-break: break-all; }
.user-menu-dropdown button {
  display: block; width: 100%; text-align: left; padding: 10px 14px;
  background: none; border: none; cursor: pointer; font-size: 14px; color: var(--text);
}
.user-menu-dropdown button:hover { background: var(--bg); }
.cpw-modal-backdrop { position: fixed; inset: 0; background: var(--backdrop); display: flex; align-items: center; justify-content: center; z-index: 200; }
.cpw-modal { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 380px; max-width: 90vw; }
.cpw-modal h3 { margin: 0 0 12px; }
.cpw-modal label { display: block; margin-top: 10px; font-size: 13px; color: var(--text2); }
.cpw-modal input { width: 100%; padding: 8px 10px; margin-top: 4px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px; background: var(--bg); color: var(--text); }
.cpw-modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.cpw-modal .actions button { padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text); }
.cpw-modal .actions button.primary { background: var(--primary); color: white; border-color: var(--primary); }
.cpw-modal .error { color: var(--red); font-size: 12px; margin-top: 8px; min-height: 16px; }

/* --- Views --- */
.view { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.view.active { display: flex; }

/* --- Session List --- */
#session-list { padding: 16px; overflow-y: auto; flex: 1; }
.session-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 12px; cursor: pointer; min-height: 64px; transition: background 0.15s; }
.session-card:hover { background: var(--bg); }
.session-card:active { background: var(--primary-light); }
.session-info { flex: 1; min-width: 0; }
.session-title { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-date { font-size: 12px; color: var(--text2); margin-top: 3px; }
.session-delete { color: var(--text2); font-size: 20px; padding: 8px; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 8px; }
.session-delete:hover { color: var(--red); background: var(--red-bg); }
.empty-state { text-align: center; color: var(--text2); margin-top: 80px; font-size: 15px; line-height: 1.6; }

/* --- Chat Header --- */
.chat-header { height: var(--header-h); display: flex; align-items: center; padding: 0 8px; background: #1F4E79; color: white; flex-shrink: 0; gap: 4px; }
[data-theme="dark"] .chat-header { background: #0d2b45; }
.chat-back { font-size: 24px; padding: 8px; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; color: white; border-radius: 8px; }
.chat-back:hover { background: rgba(255,255,255,0.15); }
.chat-title { flex: 1; font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.chat-title-input { flex: 1; background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.4); border-radius: 8px; color: white; font-size: 16px; padding: 6px 10px; font-family: inherit; outline: none; }
.chat-rename { font-size: 18px; padding: 8px; min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; color: white; border-radius: 8px; }
.chat-rename:hover { background: rgba(255,255,255,0.15); }

/* --- Messages --- */
#messages { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px; scroll-behavior: smooth; }
.msg { max-width: 90%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5; word-wrap: break-word; position: relative; margin-bottom: 10px; }
.msg:last-child { margin-bottom: 0; }
.msg-user { margin-left: auto; background: var(--primary-pale); color: var(--text); border-bottom-right-radius: 4px; }
.msg-assistant { margin-right: auto; background: var(--surface); color: var(--text); border-bottom-left-radius: 4px; width: 100%; max-width: 100%; box-shadow: var(--shadow-sm); }
.msg-warning { align-self: center; background: var(--amber-bg); color: var(--orange-text); font-size: 13px; padding: 8px 16px; border-radius: 8px; text-align: center; }
.msg-error { align-self: center; background: var(--red-bg); color: var(--red); font-size: 13px; padding: 8px 16px; border-radius: 8px; text-align: center; }
.email-confirm-banner { background: var(--amber-bg); border: 1px solid var(--amber); color: var(--orange-text); padding: 12px 16px; margin: 0 16px 12px; border-radius: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.email-confirm-banner input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; width: 100px; text-align: center; letter-spacing: 4px; background: var(--surface); color: var(--text); }
.email-confirm-banner button { padding: 6px 10px; border-radius: 4px; font-size: 12px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.email-confirm-banner button.primary { background: var(--primary); color: white; border-color: var(--primary); }
.email-confirm-banner .banner-spacer { flex: 1; }

/* File messages */
.msg-files { align-self: flex-start; background: var(--surface); padding: 12px 16px; border-radius: var(--radius); max-width: 90%; box-shadow: var(--shadow-sm); }
.file-item { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.file-icon { display: flex; align-items: center; justify-content: center; width: 18px; height: 18px; }
.file-name { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.file-btn { background: var(--primary); color: white; border: none; padding: 6px 12px; border-radius: 6px; font-size: 13px; cursor: pointer; min-height: 32px; }
.file-btn:hover { opacity: 0.9; }

/* Typing indicator */
.typing-dots { display: flex; gap: 6px; padding: 16px 20px; }
.typing-dots span { width: 8px; height: 8px; background: var(--text2); border-radius: 50%; animation: pulse 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 100% { opacity: 0.3; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1); } }

/* Expand button */
.msg-expand { position: absolute; bottom: 8px; right: 8px; font-size: 12px; color: var(--primary); background: var(--surface); border: 1px solid var(--border); padding: 4px 10px; border-radius: 6px; opacity: 0.8; }
.msg-expand:hover { opacity: 1; background: var(--primary-light); }

/* Markdown inside messages */
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3 { margin: 0.8em 0 0.4em; }
.msg-assistant h1 { font-size: 1.3em; }
.msg-assistant h2 { font-size: 1.15em; }
.msg-assistant h3 { font-size: 1.05em; }
.msg-assistant p { margin: 0.5em 0; }
.msg-assistant ul, .msg-assistant ol { margin: 0.5em 0; padding-left: 1.3em; }
.msg-assistant li { margin: 0.2em 0; }
.msg-assistant code { background: rgba(0,0,0,0.06); padding: 2px 5px; border-radius: 4px; font-size: 0.9em; font-family: 'SF Mono', Menlo, monospace; }
.msg-assistant pre { background: #1e1e1e; color: #d4d4d4; padding: 12px; border-radius: 8px; overflow-x: auto; margin: 0.6em 0; }
.msg-assistant pre code { background: none; padding: 0; color: inherit; }
.msg-assistant table { border-collapse: collapse; width: 100%; margin: 0.6em 0; font-size: 0.9em; }
.msg-assistant th, .msg-assistant td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg-assistant th { background: var(--primary-light); font-weight: 600; }
.msg-assistant blockquote { border-left: 3px solid var(--primary); margin: 0.6em 0; padding-left: 12px; color: var(--text2); }
.msg-assistant strong { font-weight: 600; }
.msg-assistant hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.msg-assistant a { color: var(--primary); text-decoration: none; }
.msg-assistant a:hover { text-decoration: underline; }

/* --- Input bar --- */
.input-bar { display: flex; align-items: flex-end; padding: 8px 12px; gap: 8px; border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.input-bar textarea { flex: 1; border: 1px solid var(--border); border-radius: 20px; padding: 10px 16px; font-size: 14px; font-family: inherit; resize: none; max-height: 100px; min-height: 44px; line-height: 1.4; outline: none; background: var(--bg); color: var(--text); }
.input-bar textarea:focus { border-color: var(--primary); }
.send-btn { background: var(--primary); color: white; border-radius: 50%; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
[data-theme="dark"] .send-btn { color: #121212; }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn:not(:disabled):hover { opacity: 0.85; }

/* --- Fullscreen modal --- */
.fullscreen-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 100; display: none; flex-direction: column; }
.fullscreen-overlay.active { display: flex; }
.fullscreen-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid rgba(255,255,255,0.1); flex-shrink: 0; }
.fullscreen-header button { color: white; font-size: 15px; padding: 8px 12px; border-radius: 8px; min-height: 44px; }
.fullscreen-header button:hover { background: rgba(255,255,255,0.1); }
.fullscreen-body { flex: 1; overflow-y: auto; padding: 20px 16px; color: #E0E0E0; font-size: 15px; line-height: 1.7; }
.fullscreen-body h1, .fullscreen-body h2, .fullscreen-body h3 { color: white; margin: 1em 0 0.4em; }
.fullscreen-body h1 { font-size: 1.5em; border-bottom: 1px solid rgba(255,255,255,0.15); padding-bottom: 0.3em; }
.fullscreen-body h2 { font-size: 1.3em; }
.fullscreen-body p { margin: 0.6em 0; }
.fullscreen-body ul, .fullscreen-body ol { padding-left: 1.4em; margin: 0.6em 0; }
.fullscreen-body code { background: rgba(255,255,255,0.1); padding: 2px 5px; border-radius: 4px; font-family: 'SF Mono', Menlo, monospace; font-size: 0.9em; }
.fullscreen-body pre { background: #111; padding: 14px; border-radius: 8px; overflow-x: auto; margin: 0.8em 0; }
.fullscreen-body pre code { background: none; }
.fullscreen-body table { border-collapse: collapse; width: 100%; margin: 0.8em 0; }
.fullscreen-body th, .fullscreen-body td { border: 1px solid rgba(255,255,255,0.15); padding: 8px 12px; text-align: left; }
.fullscreen-body th { background: rgba(255,255,255,0.08); }
.fullscreen-body blockquote { border-left: 3px solid var(--primary); padding-left: 12px; margin: 0.6em 0; color: #AAA; }
.fullscreen-body strong { color: white; }
.fullscreen-body a { color: #6CB4EE; }
.fullscreen-body hr { border: none; border-top: 1px solid rgba(255,255,255,0.15); margin: 1.2em 0; }

/* --- Confirm dialog --- */
.confirm-overlay { position: fixed; inset: 0; background: var(--backdrop); z-index: 90; display: none; align-items: center; justify-content: center; }
.confirm-overlay.active { display: flex; }
.confirm-box { background: var(--surface); border-radius: var(--radius); padding: 24px; max-width: 320px; width: 90%; text-align: center; }
.confirm-box p { margin-bottom: 20px; font-size: 15px; }
.confirm-actions { display: flex; gap: 12px; justify-content: center; }
.confirm-actions button { padding: 10px 24px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; min-height: 44px; }
.btn-cancel { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--red); color: white; }

/* --- Developer Info Panel --- */
.dev-info { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; font-size: 12px; color: var(--text2); }
.dev-info-toggle { background: none; border: none; color: var(--primary); font-size: 11px; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.dev-info-toggle:hover { background: var(--primary-light); }
.dev-info-content { display: none; margin-top: 6px; padding: 8px; background: var(--bg); border-radius: 6px; }
.dev-info-content.open { display: block; }
.dev-info-row { margin: 4px 0; display: flex; flex-wrap: wrap; gap: 4px; }
.dev-info-label { font-weight: 600; min-width: 70px; }
.dev-info-value { flex: 1; word-break: break-word; }
.dev-info-thinking { white-space: pre-wrap; font-family: 'SF Mono', Menlo, monospace; font-size: 11px; max-height: 200px; overflow-y: auto; background: #1e1e1e; color: #d4d4d4; padding: 8px; border-radius: 4px; margin-top: 4px; }
.dev-info-pill { display: inline-block; background: var(--primary-light); color: var(--primary); padding: 2px 6px; border-radius: 4px; margin: 2px; font-size: 11px; }
.dev-info-phase { margin: 8px 0; padding: 8px; background: rgba(0,0,0,0.05); border-radius: 4px; }
.dev-info-phase-header { font-weight: 600; color: var(--primary); margin-bottom: 4px; }
.dev-info-section { margin: 8px 0; }
.dev-info-tools-detail { margin-top: 4px; }
.dev-info-tool { margin: 4px 0; padding: 6px; background: rgba(0,0,0,0.03); border-radius: 4px; font-size: 11px; }
.dev-info-tool-output { margin-top: 4px; max-height: 100px; overflow-y: auto; font-family: 'SF Mono', Menlo, monospace; font-size: 10px; white-space: pre-wrap; word-break: break-word; }
.dev-info-streaming { font-style: italic; color: var(--text2); font-size: 11px; }

/* --- Step indicators (normal mode) --- */
.msg-step {
  font-size: 13px;
  color: var(--text2);
  padding: 6px 12px;
  margin: 4px 0;
  background: var(--bg);
  border-radius: 6px;
  display: inline-block;
}
.msg-step[data-type="thinking"] { border-left: 3px solid #9b59b6; }
.msg-step[data-type="skill"] { border-left: 3px solid #3498db; }
.msg-step[data-type="tool"] { border-left: 3px solid #e67e22; }
.msg-step[data-type="agent"] { border-left: 3px solid #2ecc71; }

/* --- Streaming step indicators (live progress) --- */
.streaming-steps { margin: 4px 0; }
.streaming-step {
  font-size: 12px;
  color: var(--text2);
  padding: 4px 10px;
  margin: 2px 0;
  border-left: 3px solid var(--text2);
  background: var(--bg);
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.streaming-step[data-type="thinking"] { border-left-color: #9b59b6; }
.streaming-step[data-type="skill"] { border-left-color: #3498db; }
.streaming-step[data-type="tool"] { border-left-color: #e67e22; }
.streaming-step[data-type="agent"] { border-left-color: #2ecc71; }
.streaming-step.active { opacity: 1; }
.streaming-step.completed { opacity: 0.6; }
.streaming-step .step-spinner {
  width: 12px; height: 12px;
  border: 2px solid var(--text2);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.streaming-step.completed .step-spinner { animation: none; border-color: #2ecc71; border-top-color: #2ecc71; }
@keyframes spin { to { transform: rotate(360deg); } }
.streaming-thinking-label {
  font-size: 12px; color: #9b59b6; font-style: italic;
  padding: 4px 10px; margin: 2px 0;
  border-left: 3px solid #9b59b6; background: rgba(155,89,182,0.05);
  border-radius: 4px;
  max-height: 60px; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis;
}

.step-time {
  font-size: 11px;
  color: var(--text2);
  opacity: 0.7;
  margin-left: 4px;
}
.step-time-total {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  margin-left: 4px;
}
.streaming-step-total {
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  padding: 2px 10px 4px;
}

/* --- Collapsible steps (dev mode) --- */
.dev-info-step { margin: 4px 0; border-left: 3px solid var(--text2); }
.dev-info-step[data-type="thinking"] { border-left-color: #9b59b6; }
.dev-info-step[data-type="skill"] { border-left-color: #3498db; }
.dev-info-step[data-type="tool"] { border-left-color: #e67e22; }
.dev-info-step[data-type="agent"] { border-left-color: #2ecc71; }

.dev-info-step-toggle {
  background: var(--bg);
  border: none;
  border-left: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  display: block;
  width: 100%;
  text-align: left;
}
.dev-info-step-toggle:hover { background: var(--primary-light); }

.dev-info-step-content { display: none; margin: 4px 0; padding: 8px; background: var(--bg); border-radius: 6px; }
.dev-info-step-content.open { display: block; }

.dev-info-step-field { margin: 4px 0; }
.dev-info-step-label { font-weight: 600; font-size: 11px; color: var(--text2); }
.dev-info-step-value {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 11px;
  white-space: pre-wrap;
  max-height: 150px;
  overflow-y: auto;
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 8px;
  border-radius: 4px;
  margin-top: 4px;
}
.dev-info-step-prop { color: #9cdcfe; }

/* --- Card component --- */
.suggestion-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px; cursor: pointer; transition: all 0.2s;
  box-shadow: var(--shadow-sm); border-left: 3px solid #1F4E79;
  display: flex; align-items: flex-start; gap: 10px; min-height: 44px; flex-shrink: 0;
}
[data-theme="dark"] .suggestion-card { border-left-color: var(--primary); }
.suggestion-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.suggestion-card:active { background: var(--primary-pale); }
.suggestion-card.disabled {
  opacity: 0.5; filter: grayscale(30%); cursor: default; pointer-events: none;
}
.suggestion-card.disabled:hover { box-shadow: var(--shadow-sm); transform: none; }
.suggestion-card.disabled:active { background: var(--surface); }
.suggestion-card.outlined {
  border-left: none; border: 2px dashed var(--border); background: var(--bg);
  box-shadow: none;
}
.suggestion-card.outlined:hover { border-color: #1F4E79; background: var(--surface); }
[data-theme="dark"] .suggestion-card.outlined:hover { border-color: var(--primary); }
.card-icon { font-size: 22px; flex-shrink: 0; margin-top: 1px; }
.card-body { flex: 1; min-width: 0; }
.card-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 2px; overflow-wrap: anywhere; }
.card-desc { font-size: 12px; color: var(--text2); line-height: 1.4; overflow-wrap: anywhere; }
.card-badge { font-size: 10px; color: var(--text2); margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.card-arrow { font-size: 18px; color: var(--text2); flex-shrink: 0; align-self: center; }

/* --- Mobile breakpoint --- */
@media (max-width: 375px) {
  .suggestion-card { padding: 12px 14px; gap: 8px; }
}

/* --- Chip component --- */
.template-chip {
  background: var(--primary-pale); color: #1F4E79; border: none; padding: 7px 14px;
  border-radius: 16px; font-size: 12px; font-weight: 500; white-space: nowrap;
  cursor: pointer; transition: all 0.15s; min-height: 32px;
}
[data-theme="dark"] .template-chip { color: var(--primary); }
.template-chip:hover { background: var(--primary-light); }
.template-chip:active { transform: scale(0.96); }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #202124; color: white; padding: 10px 20px; border-radius: 20px;
  font-size: 13px; z-index: 100; opacity: 0; transition: opacity 0.3s;
  pointer-events: none;
}
[data-theme="dark"] .toast { background: #e8eaed; color: #202124; }
.toast.show { opacity: 1; }

/* --- iOS install banner --- */
/* In-flow drawer that lives inside the active view, directly below its
   header, so it pushes page content down instead of overlaying it. */
.ios-install-banner {
  flex-shrink: 0; width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px; overflow: hidden;
  background: #F069B4; color: #202124;
  font-size: 14px; z-index: 15;
  max-height: 0; opacity: 0;
}
.ios-install-banner.show { animation: drawerOpen 0.25s ease forwards; }
.ios-install-banner.closing { animation: drawerClose 0.25s ease forwards; }
@keyframes drawerOpen {
  from { max-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0; }
  to   { max-height: 120px; opacity: 1; padding-top: 10px; padding-bottom: 10px; }
}
@keyframes drawerClose {
  from { max-height: 120px; opacity: 1; padding-top: 10px; padding-bottom: 10px; }
  to   { max-height: 0; opacity: 0; padding-top: 0; padding-bottom: 0; }
}
.ios-install-banner-icon {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  background: rgba(32,33,36,0.18);
  display: flex; align-items: center; justify-content: center;
}
.ios-install-banner-icon svg { display: block; fill: #fff; }
.ios-install-banner-msg { flex: 1; min-width: 0; color: #202124; }
.ios-install-banner-close {
  background: none; border: none; color: #202124;
  font-size: 24px; line-height: 1; cursor: pointer;
  width: 44px; min-width: 44px; min-height: 44px;
  flex-shrink: 0; margin: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
[data-theme="dark"] .ios-install-banner { background: #4d0b2e; }
[data-theme="dark"] .ios-install-banner-icon { background: rgba(0,0,0,0.25); }
[data-theme="dark"] .ios-install-banner-msg { color: #f5d5e8; }
[data-theme="dark"] .ios-install-banner-close { color: #f5d5e8; }

/* login.html has no #app/header bar — full-width strip pinned to the top,
   in normal document flow so it pushes the centered login card down. */
body > .ios-install-banner {
  position: sticky; top: 0; z-index: 500;
}

/* --- Toggle switch --- */
.toggle-switch { position: relative; width: 48px; height: 26px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 26px; cursor: pointer; transition: background 0.3s; }
.toggle-slider::before { content: ''; position: absolute; left: 3px; bottom: 3px; width: 20px; height: 20px; background: white; border-radius: 50%; transition: transform 0.3s; }
.toggle-switch input:checked + .toggle-slider { background: #1F4E79; }
[data-theme="dark"] .toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(22px); }

/* --- Animations --- */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: fadeIn 0.3s ease; }

/* --- Home view --- */
.home-content { flex: 1; overflow-y: auto; padding: 24px 16px 16px; display: flex; flex-direction: column; align-items: center; }
.home-header { display: flex; align-items: center; gap: 14px; width: 100%; max-width: 360px; margin-bottom: 20px; flex-shrink: 0; }
.home-header-info { flex: 1; min-width: 0; text-align: left; }
.home-icon { width: 56px; height: 56px; object-fit: contain; }
.home-icon-box { background: #ECEDEF; border-radius: 20px; padding: 8px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.home-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 4px; overflow-wrap: anywhere; }
.home-subtitle { font-size: 13px; color: var(--text2); overflow-wrap: anywhere; white-space: pre-line; }
.home-features { text-align: left; margin-bottom: 24px; width: 100%; max-width: 320px; flex-shrink: 0; }
.home-features li { font-size: 13px; color: var(--text2); margin: 5px 0; list-style: none; }
.home-features li::before { content: "•  "; color: #1F4E79; font-weight: 700; }
[data-theme="dark"] .home-features li::before { color: var(--primary); }

/* --- Prompt view --- */
.prompt-content { flex: 1; overflow-y: auto; padding: 24px 16px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.prompt-card {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 20px; display: flex; flex-direction: column;
}
.prompt-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.prompt-card-icon { font-size: 24px; }
.prompt-card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.prompt-textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 14px; line-height: 1.6; resize: none;
  min-height: 120px; max-height: 300px; outline: none; color: var(--text);
  background: var(--bg); transition: border-color 0.2s;
}
.prompt-textarea:focus { border-color: #1F4E79; }
[data-theme="dark"] .prompt-textarea:focus { border-color: var(--primary); }
.prompt-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 12px; }
.prompt-mic, .prompt-send {
  width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; transition: all 0.15s;
}
.prompt-mic { color: var(--text2); border: 1px solid var(--border); }
.prompt-mic:hover { background: var(--bg); }
.prompt-mic svg { width: 20px; height: 20px; fill: var(--text2); }
.prompt-send { background: #1F4E79; color: white; }
[data-theme="dark"] .prompt-send { background: var(--primary); color: #121212; }
.prompt-send:disabled { opacity: 0.3; cursor: not-allowed; }
.prompt-send:not(:disabled):hover { opacity: 0.85; }
.prompt-send svg { width: 20px; height: 20px; fill: white; }
[data-theme="dark"] .prompt-send svg { fill: #121212; }
.prompt-templates { width: 100%; max-width: 380px; margin-top: 16px; }
.prompt-templates-label { font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.template-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- Cases view --- */
.case-list-content { flex: 1; overflow-y: auto; padding: 16px; }
.case-list-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.case-card {
  background: var(--surface); border-radius: var(--radius); padding: 14px 16px;
  margin-bottom: 10px; box-shadow: var(--shadow-sm); cursor: pointer;
  transition: all 0.2s; display: flex; align-items: center; gap: 12px;
}
.case-card:hover { box-shadow: var(--shadow-md); }
.case-card:active { background: var(--bg); }
.case-status { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.case-status.active { background: var(--green); }
.case-info { flex: 1; min-width: 0; }
.case-name { font-size: 14px; font-weight: 600; color: var(--text); }
.case-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.case-open { font-size: 13px; font-weight: 500; color: #1F4E79; flex-shrink: 0; }
[data-theme="dark"] .case-open { color: var(--primary); }
.new-case-btn {
  width: 100%; padding: 12px; border: 2px dashed var(--border); border-radius: var(--radius);
  font-size: 14px; font-weight: 500; color: var(--text2); cursor: pointer;
  transition: all 0.2s; margin-top: 4px; background: none;
}
.new-case-btn:hover { border-color: #1F4E79; color: #1F4E79; }
[data-theme="dark"] .new-case-btn:hover { border-color: var(--primary); color: var(--primary); }

/* --- Hamburger Menu --- */
.menu-backdrop {
  position: fixed; inset: 0; background: var(--backdrop); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.menu-backdrop.open { opacity: 1; pointer-events: auto; }
.menu-panel {
  position: fixed; top: 0; left: 0; bottom: 0; width: 300px; max-width: 85vw;
  background: var(--surface); z-index: 60; transform: translateX(-100%);
  transition: transform 0.3s ease; display: flex; flex-direction: column;
  box-shadow: 4px 0 24px rgba(0,0,0,0.15);
}
.menu-panel.open { transform: translateX(0); }
.menu-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.menu-header h2 { font-size: 16px; font-weight: 600; color: var(--text); }
.menu-close { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 10px; cursor: pointer; color: var(--text2); }
.menu-close:hover { background: var(--bg); }
.menu-close svg { width: 20px; height: 20px; fill: var(--text2); }
.menu-body { flex: 1; overflow-y: auto; padding: 12px 16px; }
.menu-card {
  width: 100%; background: var(--surface); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: 8px; cursor: pointer; transition: all 0.15s;
  border: 1px solid var(--border); display: flex; align-items: center; gap: 10px;
}
.menu-card:hover { background: var(--bg); border-color: #1F4E79; }
[data-theme="dark"] .menu-card:hover { border-color: var(--primary); }
.menu-card.disabled { opacity: 0.5; cursor: default; pointer-events: none; }
.menu-card.disabled:hover { background: var(--surface); border-color: var(--border); }
.menu-card.outlined { border-style: dashed; background: var(--bg); }
.menu-card-icon { font-size: 18px; flex-shrink: 0; }
.menu-card-text { font-size: 13px; font-weight: 500; color: var(--text); flex: 1; }
.menu-card-badge { font-size: 10px; color: var(--text2); }
.menu-divider { height: 1px; background: var(--border); margin: 12px 0; }
.menu-footer { padding: 12px 16px; border-top: 1px solid var(--border); }
.menu-user { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.menu-user-avatar { width: 36px; height: 36px; border-radius: 50%; background: #1F4E79; color: white; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 600; }
[data-theme="dark"] .menu-user-avatar { background: var(--primary); color: #121212; }
.menu-user-info { flex: 1; }
.menu-user-name { font-size: 14px; font-weight: 600; color: var(--text); }
.menu-user-email { font-size: 12px; color: var(--text2); }
.menu-theme-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.menu-theme-label { font-size: 13px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.menu-theme-icon { font-size: 18px; }
.menu-bottom-actions { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.menu-bottom-btn {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text); cursor: pointer; transition: background 0.15s; width: 100%;
}
.menu-bottom-btn:hover { background: var(--bg); }
.menu-bottom-btn svg { width: 18px; height: 18px; fill: var(--text2); }

/* --- AI response card --- */
.msg-ai {
  align-self: flex-start; background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); width: 100%; max-width: 100%; padding: 0;
}
.ai-header { display: flex; align-items: center; gap: 8px; padding: 12px 14px 6px; }
.ai-avatar { font-size: 18px; }
.ai-name { font-size: 12px; font-weight: 600; color: var(--text2); }
.ai-time { font-size: 11px; color: var(--text2); margin-left: auto; }
.assessment-box { margin: 0 14px 10px; background: var(--primary-bg); border-radius: var(--radius-sm); padding: 12px; }
.assessment-label { font-size: 10px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.assessment-text { font-size: 14px; font-weight: 600; color: var(--text); }
.confidence { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; }
.conf-dots { color: var(--green); letter-spacing: 2px; font-weight: 700; }
.conf-label { color: var(--text2); }
.section { border-top: 1px solid var(--border); }
.section-toggle {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px 11px 11px; cursor: pointer; width: 100%; background: none; border: none;
  border-left: 3px solid var(--primary);
  font-size: 13px; font-weight: 600; color: var(--primary); text-align: left; min-height: 44px;
}
.section-toggle:hover { background: var(--bg); }
.section.open .section-toggle { background: var(--primary-bg); }
.section-chevron { transition: transform 0.2s; }
.section-chevron svg { width: 14px; height: 14px; fill: var(--text2); }
.section.open .section-chevron { transform: rotate(180deg); }
.section.open .section-chevron svg { fill: var(--primary); }
.section-content { display: none; padding: 0 14px 12px; font-size: 13px; line-height: 1.6; color: var(--text); }
.section.open .section-content { display: block; }
.section-content ul, .section-content ol { padding-left: 18px; }
.section-content li { margin: 4px 0; padding-left: 2px; }
.ai-actions {
  display: flex; gap: 2px; padding: 8px 14px; border-top: 1px solid var(--border);
}
.ai-action {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border-radius: 8px; cursor: pointer; transition: all 0.15s; color: var(--text2);
}
.ai-action:hover { background: var(--bg); }
.ai-action:active { transform: scale(0.92); }
.ai-action svg { width: 18px; height: 18px; fill: var(--text2); }
.ai-action.active svg { fill: var(--green); }
.ai-action.negative.active svg { fill: var(--red); }

/* --- Desktop sidebar --- */
@media (min-width: 768px) {
  #app { flex-direction: row; }
  #view-list.active { width: 320px; border-right: 1px solid var(--border); flex-shrink: 0; }
  #view-chat.active { flex: 1; }
  .chat-back { display: none; }
}
