:root {
  color-scheme: light dark;
  --canvas: light-dark(#edf1f7, #0b0e13);
  --bg: light-dark(#f7f9fc, #12161d);
  --surface: light-dark(#ffffff, #1b2029);
  --surface-soft: light-dark(#f0f4fa, #232a35);
  --text: light-dark(#172033, #f2f5fa);
  --muted: light-dark(#6d7688, #aab2c1);
  --border: light-dark(#e2e7ef, #2c3441);
  --primary: light-dark(#335cff, #829bff);
  --primary-text: light-dark(#ffffff, #101525);
  --primary-soft: light-dark(#e9eeff, #25305a);
  --success: light-dark(#17864b, #68df9c);
  --danger: light-dark(#ce334b, #ff7890);
  --shadow: light-dark(rgba(37, 49, 74, .13), rgba(0, 0, 0, .34));
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--canvas); color: var(--text); }
button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.app-frame { width: 100%; height: 100dvh; display: grid; place-items: center; }
.app-shell { width: min(100%, 480px); height: 100dvh; min-height: 0; display: flex; flex-direction: column; position: relative; overflow: hidden; background: var(--bg); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.topbar { min-height: 68px; display: flex; align-items: center; gap: 10px; padding: max(14px, env(safe-area-inset-top)) 16px 10px; }
.brand { min-width: 0; display: flex; align-items: center; gap: 10px; }
.brand > span:last-child { display: grid; gap: 1px; }
.brand small { color: var(--muted); font-size: 12px; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; color: var(--primary-text); background: var(--primary); font-weight: 600; }
.page-title { white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; position: relative; border: 0; border-radius: 11px; color: var(--text); background: transparent; cursor: pointer; }
.icon-button:active { background: var(--surface-soft); }
.notification-button > span { position: absolute; top: 7px; right: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.sync-state { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; color: var(--muted); background: var(--surface-soft); font-size: 11px; }
.sync-state > span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.sync-state.is-online > span { background: var(--success); }
.sync-state.is-error > span { background: var(--danger); }

.screen { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 18px; touch-action: pan-y; will-change: transform, opacity; }
.screen-heading { margin-bottom: 15px; }
.screen-heading h1 { margin: 0 0 4px; font-size: 24px; font-weight: 600; }
.screen-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.card-stack { display: grid; gap: 11px; }
.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.home-card { width: 100%; min-width: 0; display: grid; gap: 9px; padding: 15px; text-align: left; border: 1px solid var(--border); border-radius: 18px; color: var(--text); background: var(--surface); box-shadow: 0 8px 22px var(--shadow); cursor: pointer; }
.home-card:active { transform: scale(.985); }
.home-card.is-primary { color: var(--primary-text); border-color: transparent; background: var(--primary); }
.card-top, .card-footer, .list-item, .project-head, .capture-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; color: var(--primary); background: var(--primary-soft); }
.is-primary .card-icon { color: var(--primary-text); background: color-mix(in srgb, var(--primary-text) 18%, transparent); }
.card-count { color: var(--muted); font-size: 12px; }
.is-primary .card-count, .is-primary .card-copy p, .is-primary .card-footer { color: color-mix(in srgb, var(--primary-text) 76%, transparent); }
.card-copy h2 { margin: 0 0 3px; font-size: 16px; font-weight: 600; }
.card-copy p { margin: 0; color: var(--muted); font-size: 13px; }
.card-footer { color: var(--muted); font-size: 12px; }
.card-progress { height: 5px; overflow: hidden; border-radius: 999px; background: var(--surface-soft); }
.card-progress span { display: block; height: 100%; border-radius: inherit; background: var(--primary); }

.list-panel { display: grid; padding: 0 14px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); }
.list-item { min-height: 66px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-main { min-width: 0; display: grid; gap: 2px; }
.list-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-main small, .list-meta { color: var(--muted); font-size: 12px; }
.list-meta { flex: 0 0 auto; }
.empty-state { display: grid; justify-items: center; gap: 9px; padding: 44px 18px; text-align: center; color: var(--muted); }
.empty-state .card-icon { width: 46px; height: 46px; }
.empty-state h2, .empty-state p { margin: 0; }
.empty-state h2 { color: var(--text); font-size: 17px; }
.empty-state p { font-size: 13px; }

.capture-panel { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); }
.capture-panel textarea { width: 100%; min-height: 190px; resize: vertical; padding: 12px; border: 1px solid var(--border); border-radius: 13px; outline: none; color: var(--text); background: var(--bg); }
.capture-panel textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.primary-button, .secondary-button { min-height: 42px; padding: 0 14px; border-radius: 13px; cursor: pointer; }
.primary-button { border: 0; color: var(--primary-text); background: var(--primary); }
.secondary-button { border: 1px solid var(--border); color: var(--text); background: var(--surface); }
.capture-actions { flex-wrap: wrap; }
.capture-kind { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.media-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; justify-self: start; }
.photo-picker { position: relative; overflow: hidden; }
.photo-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-preview { display: grid; gap: 6px; margin: 0; }
.photo-preview img { width: 100%; max-height: 300px; object-fit: cover; border-radius: 13px; background: var(--surface-soft); }
.photo-preview figcaption { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.project-card { display: grid; gap: 10px; padding: 15px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: 0 8px 22px var(--shadow); }
.project-card + .project-card { margin-top: 11px; }
.project-head h2, .project-head p { margin: 0; }
.project-head h2 { font-size: 16px; }
.project-head p { color: var(--muted); font-size: 12px; }
.status-badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; color: var(--primary); background: var(--primary-soft); font-size: 11px; }

.integration-detail { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.integration-detail strong { color: var(--text); font-weight: 600; }
.settings-panel { margin-bottom: 12px; padding: 15px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); }
.settings-panel summary { cursor: pointer; font-weight: 600; }
.settings-panel[open] summary { margin-bottom: 14px; }
.open-panel h2 { margin: 0 0 8px; font-size: 16px; }
.form-stack { display: grid; gap: 11px; }
.form-stack label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.form-stack input, .form-stack select { width: 100%; min-height: 43px; padding: 0 12px; border: 1px solid var(--border); border-radius: 12px; outline: none; color: var(--text); background: var(--bg); }
.form-stack input:focus, .form-stack select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.form-note, .form-error { margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.form-error { color: var(--danger); }
.form-separator { display: flex; align-items: center; gap: 9px; margin: 14px 0; color: var(--muted); font-size: 11px; }
.form-separator::before, .form-separator::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.pairing-code { display: grid; justify-items: center; gap: 4px; margin-top: 12px; padding: 16px; border-radius: 14px; background: var(--primary-soft); }
.pairing-code strong { color: var(--primary); font-size: 30px; letter-spacing: .18em; }
.pairing-code small { color: var(--muted); }
.text-button { margin-top: 8px; padding: 8px 0; border: 0; color: var(--muted); background: transparent; cursor: pointer; }
.compact-card { margin-top: 12px; }
.endpoint-code { display: block; overflow-x: auto; padding: 10px; border-radius: 10px; color: var(--text); background: var(--surface-soft); font-size: 11px; }

.integration-hero { border-color: color-mix(in srgb, var(--primary) 32%, var(--border)); }
.idea-preview-list { display: grid; }
.idea-preview { display: grid; gap: 3px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.idea-preview:last-child { border-bottom: 0; }
.idea-preview strong { overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; }
.idea-preview small { color: var(--muted); font-size: 11px; }

.permission-list { display: grid; gap: 0; }
.permission-list > label { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.permission-list > label > span { display: grid; gap: 2px; }
.permission-list strong { font-size: 13px; }
.permission-list small { color: var(--muted); font-size: 11px; line-height: 1.35; }
.permission-list input[type="checkbox"] { width: 21px; height: 21px; flex: 0 0 auto; accent-color: var(--primary); }
.permission-list .secondary-button { margin-top: 12px; }
.audit-list { display: grid; margin-top: 14px; padding-top: 4px; border-top: 1px solid var(--border); }
.audit-list > div { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.audit-list > div > span { min-width: 0; display: grid; gap: 2px; }
.audit-list strong { font-size: 12px; }
.audit-list small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.audit-list time { flex: 0 0 auto; color: var(--muted); font-size: 10px; }

.chat-panel { display: grid; min-height: 390px; overflow: hidden; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); }
.chat-history { display: grid; align-content: start; gap: 10px; min-height: 280px; max-height: 52dvh; overflow-y: auto; padding: 14px; }
.chat-message { max-width: 86%; padding: 10px 12px; border-radius: 14px; background: var(--surface-soft); }
.chat-message:has(.agent-action) { width: 100%; max-width: 100%; }
.chat-message.is-user { justify-self: end; color: var(--primary-text); background: var(--primary); }
.chat-message small { opacity: .72; font-size: 10px; }
.chat-message p { margin: 3px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.55; }
.agent-action { display: grid; gap: 9px; margin-top: 10px; padding: 11px; border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--border)); border-radius: 12px; color: var(--text); background: var(--surface); }
.agent-action > span { min-width: 0; display: grid; gap: 3px; }
.agent-action strong { overflow-wrap: anywhere; font-size: 12px; line-height: 1.45; }
.agent-action small { color: var(--primary); font-size: 10px; }
.agent-action.is-executed { border-color: color-mix(in srgb, var(--success) 38%, var(--border)); }
.agent-action.is-executed small { color: var(--success); }
.agent-action.is-rejected, .agent-action.is-expired, .agent-action.is-failed { opacity: .68; }
.agent-action-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.agent-action-buttons button { min-height: 36px; }
button:disabled, textarea:disabled { cursor: not-allowed; opacity: .55; }
.chat-composer { display: grid; grid-template-columns: 1fr auto; gap: 9px; align-items: end; padding: 11px; border-top: 1px solid var(--border); }
.chat-composer textarea { min-height: 44px; max-height: 130px; resize: vertical; padding: 10px; border: 1px solid var(--border); border-radius: 12px; outline: none; color: var(--text); background: var(--bg); }
.chat-composer textarea:focus { border-color: var(--primary); }
.chat-composer .primary-button { min-width: 68px; }
.empty-state.compact { padding: 36px 12px; }

.bottom-nav { min-height: 72px; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; padding: 8px 10px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.bottom-nav button { min-width: 0; display: grid; justify-items: center; gap: 3px; padding: 6px 2px; border: 0; color: var(--muted); background: transparent; font-size: 11px; cursor: pointer; }
.bottom-nav button[aria-pressed="true"] { color: var(--primary); }
.bottom-nav .main-action { width: 48px; height: 48px; justify-self: center; align-self: center; place-items: center; padding: 0; border-radius: 15px; color: var(--primary-text); background: var(--primary); box-shadow: 0 8px 20px var(--shadow); touch-action: none; user-select: none; }
.bottom-nav .main-action svg { width: 23px; height: 23px; }

.tool-overlay { position: absolute; inset: 0; z-index: 20; overflow: hidden; background: light-dark(rgba(23, 31, 49, .58), rgba(2, 5, 10, .72)); backdrop-filter: blur(12px) saturate(.72); }
.tool-dismiss { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: transparent; }
.tool-wheel { position: absolute; left: 50%; bottom: max(48px, env(safe-area-inset-bottom)); width: min(94%, 350px); height: 290px; transform: translateX(-50%); color: #fff; }
.tool-option, .tool-close { position: absolute; z-index: 2; border: 0; cursor: pointer; }
.tool-option { width: 76px; display: grid; justify-items: center; gap: 7px; padding: 0; color: inherit; background: transparent; font-size: 12px; }
.tool-option > span { width: 60px; height: 60px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.5); border-radius: 50%; color: var(--primary-text); background: var(--primary); box-shadow: 0 10px 24px rgba(0,0,0,.3); animation: tool-rise 180ms ease-out; }
.tool-option > span svg { width: 24px; height: 24px; }
.tool-top { left: 50%; top: 0; transform: translateX(-50%); }
.tool-top > span { color: var(--text); background: var(--surface); }
.tool-upper-left { left: 7%; top: 76px; }
.tool-upper-right { right: 7%; top: 76px; }
.tool-lower-left { left: 0; top: 174px; }
.tool-lower-right { right: 0; top: 174px; }
.tool-upper-left > span, .tool-lower-left > span { color: #0c3824; background: #62e394; }
.tool-close { left: 50%; bottom: 5px; width: 60px; height: 60px; display: grid; place-items: center; transform: translateX(-50%); border: 1px solid rgba(255,255,255,.18); border-radius: 50%; color: #fff; background: rgba(61,71,89,.8); animation: tool-close-rise 180ms ease-out; }
@keyframes tool-rise { from { transform: translateY(14px) scale(.86); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
@keyframes tool-close-rise { from { transform: translateX(-50%) translateY(14px) scale(.86); opacity: 0; } to { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; } }

.toast { position: absolute; left: 50%; bottom: 92px; z-index: 30; max-width: calc(100% - 32px); transform: translateX(-50%); padding: 9px 13px; border-radius: 11px; color: var(--text); background: var(--surface); box-shadow: 0 10px 30px var(--shadow); font-size: 13px; }

@media (min-width: 600px) {
  .app-frame { padding: 22px; }
  .app-shell { height: min(850px, calc(100dvh - 44px)); border: 1px solid var(--border); border-radius: 28px; box-shadow: 0 22px 58px var(--shadow); }
}

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