/* 補助資源查詢 · 晴藍工作台（Sky Clarity）正式版樣式表 */
:root {
  --bg: #f4f8fb;
  --surface: #ffffff;
  --elevated: #f8fbfd;
  --line: #dfe9f2;
  --line-strong: #c8daea;
  --ink: #0f2537;
  --sub: #4e677b;
  --muted: #7b93a6;
  --pri: #0e5a8a;
  --pri-ink: #094166;
  --pri-soft: #e7f5fa;
  --cyan: #0ea5c6;
  --cyan-soft: #e0f7fc;
  --fund-ink: #9a4706;
  --fund-bg: #fef4d8;
  --fund-line: #f7d98a;
  --free-ink: #047857;
  --free-bg: #dcfce7;
  --free-line: #9fe8be;
  --danger: #b42318;
  --shadow-sm: 0 2px 8px rgba(14, 90, 138, 0.06);
  --shadow-md: 0 12px 32px rgba(15, 37, 55, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
mark { background: #ffe58f; color: var(--ink); border-radius: 3px; padding: 0 2px; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.85; stroke-linecap: round; stroke-linejoin: round; }

/* Subtle thin scrollbars */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd9e6; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #a8bed2; }

/* ---------- Desktop App Shell (>= 901px) ---------- */
.shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 392px;
  grid-template-rows: 1fr;
  overflow: hidden;
  transition: grid-template-columns 0.18s ease;
}
body.ai-collapsed .shell {
  grid-template-columns: 240px minmax(0, 1fr) 0px;
}

/* Left Rail */
.rail {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--line);
}
.rail-brand img { width: 34px; height: 34px; object-fit: contain; flex: none; }
.rail-brand h1 { font-size: 16px; font-weight: 750; line-height: 1.25; color: var(--ink); }
.rail-brand small { display: block; font-size: 11.5px; font-weight: 500; color: var(--sub); margin-top: 1px; }

.rail-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
}
.rail-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 6px 10px;
}
.rail-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--sub);
  transition: background 0.14s, color 0.14s;
}
.rail-btn:hover { background: var(--elevated); color: var(--ink); }
.rail-btn.active { background: var(--pri-soft); color: var(--pri-ink); font-weight: 700; }
.rail-btn .cnt {
  margin-left: auto;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--sub);
}
.rail-btn.active .cnt { background: #fff; color: var(--pri); font-weight: 700; }
.rail-divider { height: 1px; background: var(--line); margin: 10px 8px; }
.cat-no { font: 600 11.5px ui-monospace, monospace; color: var(--muted); width: 20px; flex: none; }
.rail-btn.active .cat-no { color: var(--cyan); }

.rail-foot {
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--sub);
  display: flex;
  align-items: center;
  gap: 7px;
}
.rail-foot b { color: var(--ink); font-weight: 700; }

/* Center Workspace */
.center {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

/* Command Top Bar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.m-brand-mini { display: none; align-items: center; gap: 7px; flex: none; }
.m-brand-mini img { width: 26px; height: 26px; }
.m-brand-mini span { font-weight: 750; font-size: 14.5px; color: var(--ink); white-space: nowrap; }

.search-box {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
}
.search-box .s-ico {
  position: absolute;
  left: 13px;
  color: var(--muted);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  height: 40px;
  padding: 0 36px 0 38px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--elevated);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.search-box input:focus {
  background: #fff;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(14, 165, 198, 0.14);
}
.search-clear {
  position: absolute;
  right: 8px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: var(--line);
  color: var(--sub);
  font-size: 13px;
  display: none;
  align-items: center;
  justify-content: center;
}
.search-clear.show { display: inline-flex; }

.top-select {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px;
  color: var(--ink);
  max-width: 168px;
}
.top-select:focus { border-color: var(--cyan); }

.count-pill {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--pri-ink);
  background: var(--pri-soft);
  padding: 5px 11px;
  border-radius: 999px;
  white-space: nowrap;
}

.ai-launch-btn {
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--pri), var(--cyan));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(14, 90, 138, 0.2);
}
.ai-launch-btn:hover { filter: brightness(1.06); }

.m-filter-btn {
  display: none;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex: none;
}
.m-filter-btn .badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--pri);
  color: #fff;
  font-size: 11px;
  display: none;
  align-items: center;
  justify-content: center;
}
.m-filter-btn .badge.show { display: inline-flex; }

/* Quick Hot Keywords / Mobile Chips Strip */
.substrip {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 7px 18px;
  display: flex;
  align-items: center;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: none;
}
.substrip::-webkit-scrollbar { display: none; }
.substrip-label { font-size: 12px; color: var(--muted); white-space: nowrap; margin-right: 2px; }
.qchip {
  flex: none;
  padding: 4px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--elevated);
  font-size: 12.5px;
  color: var(--sub);
  white-space: nowrap;
}
.qchip:hover { border-color: var(--cyan); color: var(--pri-ink); }
.qchip.active { background: var(--pri); border-color: var(--pri); color: #fff; font-weight: 600; }
.m-only-chips { display: none; }

/* Saved Banner inside list */
.saved-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(90deg, var(--pri-soft), var(--cyan-soft));
  border-bottom: 1px solid var(--line);
  flex: none;
}
.saved-banner.show { display: flex; }
.saved-banner span { font-size: 13px; font-weight: 600; color: var(--pri-ink); }
.saved-compare-btn {
  padding: 6px 13px;
  border: 0;
  border-radius: 999px;
  background: var(--pri);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}
.saved-compare-btn:hover { background: var(--pri-ink); }

/* Split Master-Detail */
.split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(300px, 356px) minmax(0, 1fr);
}

.list-pane {
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.p-card {
  text-align: left;
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, box-shadow 0.14s;
  position: relative;
}
.p-card:hover { border-color: var(--line-strong); background: var(--elevated); }
.p-card.on {
  border-color: var(--cyan);
  background: var(--pri-soft);
  box-shadow: inset 3px 0 0 var(--pri);
}
.p-card-top {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
}
.p-no {
  font: 700 11.5px ui-monospace, monospace;
  color: var(--pri);
  background: var(--pri-soft);
  padding: 1px 7px;
  border-radius: 6px;
}
.p-card.on .p-no { background: #fff; }
.p-cat { color: var(--sub); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.star-btn {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.star-btn:hover { background: rgba(14, 90, 138, 0.08); color: var(--pri); }
.star-btn.saved { color: #d97706; }
.star-btn.saved svg { fill: #fbbf24; stroke: #d97706; }

.p-title {
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.p-badges { display: flex; flex-wrap: wrap; gap: 5px; }
.pill-fund {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--fund-bg);
  color: var(--fund-ink);
  border: 1px solid var(--fund-line);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill-free {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--free-bg);
  color: var(--free-ink);
  border: 1px solid var(--free-line);
}
.p-meta {
  font-size: 12px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.empty-state {
  margin: auto;
  text-align: center;
  padding: 40px 20px;
  color: var(--sub);
}
.empty-state p { margin-bottom: 12px; }
.empty-reset {
  padding: 8px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
  color: var(--pri);
  font-weight: 600;
  font-size: 13px;
}

/* Detail Canvas */
.detail-pane {
  overflow-y: auto;
  padding: 20px 24px 56px;
  container-type: inline-size;
  scroll-behavior: smooth;
}
.m-detail-bar { display: none; }

.d-hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.d-hero-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.d-cat-badge {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--pri-soft);
  color: var(--pri-ink);
  font-size: 12px;
  font-weight: 700;
}
.d-page-badge {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--elevated);
  border: 1px solid var(--line);
  font: 600 12px ui-monospace, monospace;
  color: var(--sub);
}
.d-hero h2 { font-size: 22px; line-height: 1.35; margin: 10px 0 4px; color: var(--ink); }
.d-agency-line { font-size: 13.5px; color: var(--sub); }

.d-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.btn {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { border-color: var(--cyan); background: var(--elevated); }
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.pri:hover { background: var(--pri-ink); }
.btn.ai-ask { background: linear-gradient(135deg, #fff5df, #ffe9b8); border-color: #f3cc73; color: #784200; }
.btn.ai-ask:hover { filter: brightness(0.98); }
.btn.saved { background: #fef3c7; border-color: #f59e0b; color: #92400e; }

.view-switch {
  margin-left: auto;
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.view-switch button {
  border: 0;
  background: transparent;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--sub);
}
.view-switch button.on { background: #fff; color: var(--pri); box-shadow: var(--shadow-sm); }

/* At-a-Glance Summary Strip */
.glance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.glance-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 15px;
}
.glance-card.fund { background: var(--fund-bg); border-color: var(--fund-line); }
.glance-card.free { background: var(--free-bg); border-color: var(--free-line); }
.glance-k { font-size: 11.5px; font-weight: 700; color: var(--sub); margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.glance-card.fund .glance-k { color: var(--fund-ink); }
.glance-card.free .glance-k { color: var(--free-ink); }
.glance-v { font-size: 13.5px; font-weight: 600; color: var(--ink); line-height: 1.5; }
.summary-box {
  margin-top: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 16px;
}
.summary-box p { font-size: 14px; color: var(--ink); margin-top: 4px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.tag-pill {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--elevated);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--sub);
}

/* Detail Body (Structured Markdown + Original Page) */
.d-body {
  display: grid;
  gap: 18px;
  margin-top: 16px;
  align-items: start;
}
@container (min-width: 780px) {
  .d-body.mode-split { grid-template-columns: minmax(0, 1fr) minmax(290px, 42%); }
  .d-body.mode-split .d-page-card { position: sticky; top: 0; }
}
.d-body.mode-text .d-page-card { display: none; }
.d-body.mode-page .d-sections { display: none; }

.d-sections { display: grid; gap: 12px; }
.md-sec {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.md-sec h3 {
  font-size: 14px;
  font-weight: 750;
  color: var(--pri-ink);
  background: var(--elevated);
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  border-left: 4px solid var(--cyan);
}
.md-sec[data-sec="contact"] { background: #f7fcfe; border-color: #cde7f2; }
.md-body { padding: 11px 16px 14px; font-size: 14.5px; }
.md-body h4 { font-size: 14px; color: var(--pri); margin: 11px 0 4px; }
.md-body h4:first-child { margin-top: 2px; }
.md-body p { margin: 6px 0; }
.md-body ul, .md-body ol { margin: 5px 0; padding-left: 20px; }
.md-body li { margin: 3px 0; }
.md-body li::marker { color: var(--cyan); font-weight: 700; }
.md-body strong { color: var(--pri-ink); }
.tel-link {
  color: var(--pri);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: rgba(14, 165, 198, 0.45);
}

.d-page-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.d-page-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.d-page-head b { font-size: 13.5px; }
.d-page-head small { display: block; font-size: 11.5px; color: var(--sub); font-weight: 400; }
.zoom-trigger {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: var(--bg);
  overflow: hidden;
  position: relative;
  display: block;
}
.zoom-trigger img { width: 100%; display: block; height: auto; }
.zoom-pill {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(15, 37, 55, 0.78);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

/* Right AI Panel */
.ai-scrim { display: none; }
.ai-pane {
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
body.ai-collapsed .ai-pane { border-left: 0; }
.ai-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f9fdff, #fff);
}
.ai-badge-dot {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--pri), var(--cyan));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex: none;
}
.ai-head-txt { flex: 1; min-width: 0; }
.ai-head-txt b { display: block; font-size: 14.5px; line-height: 1.2; }
.ai-head-txt small { display: block; font-size: 11.5px; color: var(--sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-icon-btn {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 12px;
  font-weight: 600;
  color: var(--sub);
  white-space: nowrap;
}
.ai-icon-btn:hover { border-color: var(--cyan); color: var(--pri); }

.chat-scroll {
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg { font-size: 14px; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 15px 15px 4px 15px;
  background: var(--pri);
  color: #fff;
  white-space: pre-wrap;
}
.msg.bot {
  padding: 11px 14px;
  border-radius: 4px 15px 15px 15px;
  background: var(--elevated);
  border: 1px solid var(--line);
}
.msg.bot p { margin: 5px 0; }
.msg.bot ul, .msg.bot ol { margin: 5px 0; padding-left: 18px; }
.msg.bot li { margin: 3px 0; }
.msg.bot h3, .msg.bot h4 { font-size: 14px; margin: 9px 0 3px; color: var(--pri-ink); }
.cite {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 2px;
  padding: 1px 7px;
  border: 1px solid var(--fund-line);
  border-radius: 999px;
  background: var(--fund-bg);
  color: var(--fund-ink);
  font: 700 11.5px/1.5 ui-monospace, monospace;
  vertical-align: 1px;
}
.cite:hover { background: #fde68a; }
.cite-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--fund-ink); }
.refs { margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line-strong); display: grid; gap: 5px; }
.refs b { font-size: 11.5px; color: var(--sub); }
.cite.ref {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 6px 10px;
  border-radius: 10px;
  text-align: left;
  font: 13px/1.4 inherit;
}
.cite.ref span { font: 700 11.5px ui-monospace, monospace; flex: none; }
.cite.ref em { font-style: normal; font-weight: 600; color: var(--ink); }
.err { color: var(--danger); font-size: 13px; margin-top: 6px; }
.wait { color: var(--sub); font-size: 13px; margin-right: 6px; }
.cursor { display: inline-block; width: 7px; height: 14px; background: var(--cyan); vertical-align: -2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.hints { display: grid; gap: 7px; }
.hints small { font-size: 12px; color: var(--sub); font-weight: 600; }
.hints button {
  text-align: left;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink);
}
.hints button:hover { border-color: var(--cyan); background: var(--pri-soft); }

.ai-form {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.ai-form textarea {
  flex: 1;
  height: 44px;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--elevated);
  font-size: 14px;
  line-height: 1.45;
  outline: none;
}
.ai-form textarea:focus { border-color: var(--cyan); background: #fff; }
.ai-send {
  height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--pri);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}
.ai-send:disabled { opacity: 0.45; cursor: wait; }

.m-bottom-nav, .sheet-backdrop, .m-sticky-detail-foot, .m-detail-seg { display: none; }

/* Toast Notification */
.toast {
  position: fixed;
  right: 20px;
  bottom: 22px;
  z-index: 90;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(15, 37, 55, 0.9);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Medium Desktop (901px - 1379px): AI becomes slide-over drawer */
@media (max-width: 1379px) and (min-width: 901px) {
  .shell { grid-template-columns: 224px minmax(0, 1fr); }
  body.ai-collapsed .shell { grid-template-columns: 224px minmax(0, 1fr); }
  body.ai-drawer-open .ai-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 38;
    background: rgba(15, 37, 55, 0.28);
  }
  .ai-pane {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(420px, 95vw);
    z-index: 40;
    box-shadow: -16px 0 44px rgba(15, 37, 55, 0.18);
    transform: translateX(100%);
    transition: transform 0.22s ease;
  }
  body.ai-drawer-open .ai-pane { transform: translateX(0); }
}

/* Mobile App Layout (<= 900px) */
@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .rail, .top-select, .count-pill, .ai-launch-btn { display: none; }
  .m-brand-mini { display: flex; }
  .m-filter-btn { display: inline-flex; }
  .topbar {
    padding: calc(8px + var(--safe-top)) 12px 8px;
    gap: 8px;
  }
  .search-box input { height: 38px; font-size: 14px; }
  .substrip { padding: 6px 12px; }
  .substrip-label, .desktop-only-chips { display: none; }
  .m-only-chips { display: flex; gap: 7px; align-items: center; }

  .split { grid-template-columns: 1fr; position: relative; }
  .list-pane {
    border-right: 0;
    padding: 10px 12px 18px;
    background: var(--bg);
  }
  .p-card { padding: 13px 14px; box-shadow: var(--shadow-sm); }
  .p-title { font-size: 15.5px; }

  /* Fullscreen Slide-in Detail Sheet */
  .detail-pane {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--bg);
    padding: 0 0 calc(84px + var(--safe-bottom));
    transform: translateX(100%);
    transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }
  body.m-detail-open .detail-pane { transform: translateX(0); }
  .m-detail-bar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: calc(10px + var(--safe-top)) 12px 10px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .m-back-btn {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: #fff;
    font-size: 13px;
    font-weight: 700;
    color: var(--pri-ink);
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }
  .m-share-btn {
    height: 34px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--elevated);
    font-size: 12px;
    font-weight: 600;
    color: var(--sub);
    margin-left: auto;
  }
  .m-detail-inner { padding: 12px 12px 18px; }
  .d-hero { padding: 15px; }
  .d-hero h2 { font-size: 19px; }
  .d-actions { display: none; }
  .m-detail-seg {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 4px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    margin-top: 12px;
  }
  .m-detail-seg button {
    height: 36px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    font-size: 13.5px;
    font-weight: 700;
    color: var(--sub);
  }
  .m-detail-seg button.on { background: var(--pri); color: #fff; }
  .m-sticky-detail-foot {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 55;
    display: none;
    gap: 8px;
    padding: 10px 12px calc(10px + var(--safe-bottom));
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  body.m-detail-open .m-sticky-detail-foot { display: flex; }
  .m-sticky-detail-foot .btn { flex: 1; justify-content: center; height: 42px; font-size: 14px; }

  /* Mobile Tab 2: AI Consultant Full View */
  .ai-pane {
    display: none;
    border-left: 0;
    grid-row: 1;
    grid-column: 1;
  }
  body.m-tab-ai .center { display: none; }
  body.m-tab-ai .ai-pane { display: grid; }
  #ai-collapse-btn { display: none; }
  .ai-head { padding-top: calc(12px + var(--safe-top)); }
  .ai-form { padding: 9px 12px 10px; }

  /* Mobile Bottom Tab Navigation */
  .m-bottom-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + var(--safe-bottom));
    gap: 4px;
    z-index: 30;
  }
  .m-tab-btn {
    min-height: 50px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--sub);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 11.5px;
    font-weight: 600;
    position: relative;
  }
  .m-tab-btn.active { color: var(--pri); background: var(--pri-soft); font-weight: 700; }
  .m-tab-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 24px);
    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    border-radius: 999px;
    background: #d97706;
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
  }
  .m-tab-badge.show { display: inline-flex; }

  /* Mobile Filter Bottom Sheet */
  .sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(15, 37, 55, 0.45);
    display: none;
    align-items: flex-end;
  }
  .sheet-backdrop.open { display: flex; }
  .filter-sheet {
    width: 100%;
    max-height: 82dvh;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.2s ease;
  }
  @keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
  .sheet-handle {
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: var(--line-strong);
    margin: 8px auto 2px;
  }
  .sheet-head {
    padding: 8px 16px 12px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .sheet-head b { font-size: 16px; }
  .sheet-body { overflow-y: auto; padding: 14px 16px; display: grid; gap: 16px; }
  .sheet-sec h4 { font-size: 12.5px; color: var(--sub); margin-bottom: 8px; }
  .sheet-pills { display: flex; flex-wrap: wrap; gap: 7px; }
  .sheet-pill {
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--elevated);
    font-size: 13px;
  }
  .sheet-pill.on { background: var(--pri); border-color: var(--pri); color: #fff; font-weight: 600; }
  .sheet-brand { font-size: 12px; color: var(--muted); text-align: center; padding-top: 4px; }
  .sheet-foot {
    padding: 12px 16px calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--line);
    display: flex;
    gap: 10px;
  }
  .sheet-foot button { height: 44px; border-radius: 12px; font-weight: 700; font-size: 14px; }
  .sheet-reset { flex: 0 0 92px; border: 1px solid var(--line-strong); background: #fff; }
  .sheet-apply { flex: 1; border: 0; background: var(--pri); color: #fff; }

  .toast {
    left: 50%;
    right: auto;
    bottom: calc(74px + var(--safe-bottom));
    transform: translate(-50%, 10px);
  }
  .toast.show { transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
