:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #ffffff;
  --ink: #20231f;
  --muted: #66716a;
  --line: #d9ddd7;
  --accent: #1f7a6d;
  --accent-strong: #155d54;
  --warn: #9b5b13;
  --soft: #edf5f2;
  --vh: 1svh;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", Arial, sans-serif;
}

html,
body {
  height: 100%;
  height: 100svh;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

.shell {
  display: block;
  height: 100vh;
  height: 100svh;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  overflow: auto;
  padding: 24px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(32, 35, 31, 0.32);
}

.floating-panel {
  position: fixed;
  z-index: 50;
  top: 16px;
  bottom: 16px;
  left: 16px;
  width: min(420px, calc(100vw - 32px));
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(32, 35, 31, 0.22);
  transform: translateX(calc(-100% - 24px));
  transition: transform 180ms ease, opacity 180ms ease;
  opacity: 0;
  pointer-events: none;
}

.floating-panel.is-open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.floating-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin: -24px -24px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
  padding: 14px 16px;
}

.floating-header strong {
  display: block;
  font-size: 15px;
}

.floating-header span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 2px;
}

.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 6px;
  background: #eef1ec;
  color: var(--ink);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 28px;
}

.mark {
  display: block;
  overflow: hidden;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
}

.mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

.brand p,
.eyebrow {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  border-top: 1px solid var(--line);
  padding: 18px 0;
}

.panel h2,
.inspector h3 {
  font-size: 14px;
  margin-bottom: 12px;
}

.channel,
.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
}

.channel.active {
  background: var(--soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.status-row strong {
  color: var(--accent-strong);
  font-size: 12px;
}

.model-list,
.sidebar-tool-list {
  display: grid;
  gap: 8px;
}

.model-row {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 8px;
}

.model-row span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.model-row strong {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-row small,
.sidebar-tool small {
  border-radius: 999px;
  background: #eef1ec;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  padding: 3px 7px;
  text-transform: uppercase;
}

.model-row small.ready {
  background: var(--soft);
  color: var(--accent-strong);
}

.model-row small.muted {
  background: #f4ede5;
  color: var(--warn);
}

.sidebar-tool {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 10px;
}

.sidebar-tool div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.sidebar-tool strong {
  font-size: 13px;
}

.sidebar-tool p,
.note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  margin-top: 7px;
}

.workspace {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100svh;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  flex-shrink: 0;
  min-width: 0;
}

.topbar h2 {
  font-size: 22px;
  margin-top: 4px;
}

.home-identity {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.home-avatar {
  overflow: hidden;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.home-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#currentDateTime {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-top: 4px;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 10px;
  text-decoration: none;
}

.link-button.secondary {
  background: #eef1ec;
  color: var(--muted);
}

.gmail-actions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.connect-form {
  display: grid;
  margin: 0;
}

.copy-url {
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  padding: 8px;
  user-select: all;
}

.source-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.source-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--muted);
  font-size: 12px;
  padding: 6px 8px;
}

.source-row strong {
  color: var(--accent-strong);
  font-size: 11px;
  text-transform: uppercase;
}

.panel-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.memory-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 8px;
  font-size: 12px;
  color: var(--muted);
}

.memory-card .memory-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--accent-strong);
  text-transform: uppercase;
}

.memory-card .memory-content {
  color: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}

.changelog-list {
  display: grid;
  gap: 10px;
}

.changelog-entry {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 10px;
}

.changelog-entry div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}

.changelog-entry strong {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
}

.changelog-entry small {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.changelog-entry ul {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  margin: 8px 0 0;
  padding-left: 18px;
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

.model-badge {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent-soft, #e6f4ef);
  color: var(--accent, #155d54);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

/* ── Balance Bar ── */
.balance-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  background: #f8faf8;
  padding: 0 20px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.balance-bar::-webkit-scrollbar { display: none; }

.bal-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 16px 7px 0;
  flex-shrink: 0;
}
.bal-item + .bal-item {
  border-left: 1px solid var(--line);
  padding-left: 16px;
}

.bal-name {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  min-width: 44px;
}

.bal-track {
  width: 72px;
  height: 6px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  flex-shrink: 0;
}

.bal-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 600ms ease;
}
.bal-fill.low   { background: #e67e22; }
.bal-fill.critical { background: #c0392b; }
.bal-fill.free  { background: #2980b9; }
.bal-fill.local { background: #8e44ad; }
.bal-fill.unknown { background: var(--line); }

.bal-pct {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  min-width: 28px;
  white-space: nowrap;
}
.bal-pct.muted { color: var(--muted); }

@media (max-width: 640px) {
  .balance-bar {
    padding: 0 12px;
  }
  .bal-item {
    padding: 6px 12px 6px 0;
  }
  .bal-item + .bal-item {
    padding-left: 12px;
  }
  .bal-track { width: 48px; }
  .bal-name  { min-width: 36px; font-size: 10px; }
  .bal-pct   { font-size: 10px; }
}

select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 0 12px;
}

button:hover {
  background: var(--accent-strong);
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1120px);
  justify-content: center;
  gap: 0;
  padding: 20px;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.chat,
.inspector {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chat {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px;
  scroll-behavior: smooth;
}

.message {
  max-width: 760px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 8px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.message span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.message.assistant {
  background: var(--soft);
}

.message.user {
  margin-left: auto;
  background: #f7f0e6;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.composer input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 14px;
}

.voice-status {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  min-height: 18px;
}

.inspector {
  min-height: 0;
  padding: 18px;
  overflow: auto;
}

.inspector.floating-panel {
  left: auto;
  right: 16px;
  width: min(460px, calc(100vw - 32px));
  background: var(--surface);
  transform: translateX(calc(100% + 24px));
}

.inspector.floating-panel.is-open {
  transform: translateX(0);
}

.inspector .floating-header {
  margin: -18px -18px 18px;
  background: var(--surface);
}

.inspector section + section {
  margin-top: 24px;
}

.tool-list {
  display: grid;
  gap: 10px;
}

.tool {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.tool strong {
  display: block;
  margin-bottom: 4px;
}

.tool small {
  color: var(--warn);
  font-weight: 700;
}

.tool p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 6px;
}

ol {
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.9;
}

@media (max-width: 900px) {
  html,
  body {
    overflow: hidden;
  }

  .topbar {
    padding: 12px 16px;
  }

  .topbar h2 {
    font-size: 17px;
  }

  .home-avatar {
    width: 42px;
    height: 42px;
  }

  .eyebrow {
    font-size: 11px;
  }

  .grid {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .chat {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .home-identity {
    min-width: 0;
    flex: 1;
  }

  .home-avatar {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
  }

  .topbar h2 {
    font-size: 15px;
  }

  #currentDateTime {
    display: none;
  }

  .eyebrow {
    display: none;
  }

  /* 頂部工具列：模型徽章 + 系統按鈕 + 選單 */
  .actions {
    gap: 6px;
    flex-wrap: nowrap;
  }

  /* 在手機上隱藏「路線」按鈕，節省空間 */
  .actions button[data-open-panel="roadmapPanel"] {
    display: none;
  }

  .actions button {
    padding: 8px 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .actions select {
    min-height: 36px;
    font-size: 13px;
    padding: 0 8px;
    max-width: 100px;
  }

  .model-badge {
    font-size: 11px;
    height: 28px;
    padding: 0 8px;
  }

  .grid {
    padding: 8px;
  }

  .messages {
    padding: 12px;
  }

  .message {
    max-width: 100%;
    padding: 10px 12px;
    font-size: 15px;
    line-height: 1.6;
  }

  .composer {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .composer input {
    grid-column: 1 / -1;
    min-height: 44px;
    font-size: 16px; /* 避免 iOS 自動縮放 */
  }

  .voice-status {
    grid-column: 1 / -1;
  }

  .floating-panel,
  .inspector.floating-panel {
    inset: 8px;
    width: auto;
    border-radius: 10px;
  }

  .sidebar {
    padding: 16px;
  }

  .floating-header {
    margin: -16px -16px 14px;
    padding: 12px 14px;
  }
}

@media (max-width: 400px) {
  .actions select {
    display: none;
  }

  .topbar h2 {
    font-size: 14px;
  }
}
