:root { color-scheme: light dark; }
:root {
  --sidebar-width: 300px;
  --sidebar-gap: 14px;
  --background: 0 0% 100%;
  --foreground: 222.2 84% 4.9%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 84% 4.9%;
  --muted: 210 40% 96.1%;
  --muted-foreground: 215.4 16.3% 46.9%;
  --border: 214.3 31.8% 91.4%;
  --input: 214.3 31.8% 91.4%;
  --primary: 222.2 47.4% 11.2%;
  --primary-foreground: 210 40% 98%;
  --ring: 215 20.2% 65.1%;
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: 222.2 84% 4.9%;
    --foreground: 210 40% 98%;
    --card: 222.2 84% 4.9%;
    --card-foreground: 210 40% 98%;
    --muted: 217.2 32.6% 17.5%;
    --muted-foreground: 215 20.2% 65.1%;
    --border: 217.2 32.6% 17.5%;
    --input: 217.2 32.6% 17.5%;
    --primary: 210 40% 98%;
    --primary-foreground: 222.2 47.4% 11.2%;
    --ring: 217.2 32.6% 17.5%;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 34px 20px 56px; }
header { margin: 0 0 18px; }
h1 { font-size: 24px; line-height: 1.2; margin: 0 0 8px; letter-spacing: -0.02em; }
.subtitle { margin: 0; color: hsl(var(--muted-foreground)); }

.appShell {
  position: relative;
  min-height: calc(100vh - 120px);
}
.shellMain {
  display: grid;
  gap: 14px;
  margin-left: calc(var(--sidebar-width) + var(--sidebar-gap));
  transition: margin-left 0.2s ease;
}
.card {
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  padding: 16px;
}

.field {
  width: 100%;
  padding: 10px 12px;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid hsl(var(--input));
  background: transparent;
  color: hsl(var(--foreground));
  outline: none;
}
textarea.field { min-height: 96px; resize: vertical; line-height: 1.45; font-size: 14px; }
textarea.field.small { min-height: 74px; }
.field::placeholder { color: hsl(var(--muted-foreground)); }
.field:focus-visible {
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.35);
  border-color: hsl(var(--ring));
}

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-top: 12px;
}
.controls.noTopMargin { margin-top: 0; }
.controls-left { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.noMargin { margin: 0; }

label { display: inline-flex; align-items: center; gap: 8px; color: hsl(var(--muted-foreground)); font-size: 13px; }
.segmented {
  display: inline-flex;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted));
  border-radius: calc(var(--radius) - 2px);
  padding: 2px;
  gap: 2px;
}
.segmented button {
  background: transparent;
  color: hsl(var(--muted-foreground));
  border: 0;
  padding: 8px 10px;
  border-radius: calc(var(--radius) - 4px);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.02em;
  font-family: var(--mono);
}
.segmented button[aria-pressed="true"] {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
}

button {
  border: 1px solid transparent;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  padding: 10px 14px;
  border-radius: calc(var(--radius) - 4px);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.04s ease, opacity 0.15s ease;
}
button:hover { opacity: 0.92; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button:focus-visible { box-shadow: 0 0 0 3px hsl(var(--ring) / 0.35); }
.btnSecondary {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}

.authFields { width: 100%; }
.authInput { max-width: 280px; }
.authGate {
  max-width: 680px;
  margin: 24px auto 0;
}
.authFeedback {
  margin-top: 10px;
  font-size: 13px;
  color: #ef4444;
}
.sessionDock {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  border-radius: calc(var(--radius) - 4px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.smallBtn {
  padding: 7px 10px;
  font-size: 12px;
}

.historyList {
  display: grid;
  gap: 8px;
  align-content: start;
  grid-auto-rows: max-content;
  overflow: auto;
  max-height: none;
  flex: 1;
  padding-right: 2px;
  min-height: 0;
}
.historySidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  max-height: none;
  overflow: hidden;
  border-radius: 0;
  border-left: 0;
  z-index: 24;
  padding-top: 62px;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.historySidebar .controls {
  margin-top: 10px;
}
.newSearchBtn {
  width: 100%;
  margin-bottom: 10px;
}
.historySidebar .controls-left {
  width: 100%;
}
.historySidebar .controls-left button {
  flex: 1;
}
.historyRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}
.historyContent {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.historyItem {
  width: 100%;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border-radius: calc(var(--radius) - 4px);
  padding: 10px;
  text-align: left;
  cursor: pointer;
}
.historyItemTitle {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.historyMeta {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
}
.historyDelete {
  align-self: stretch;
  padding: 8px 10px;
  min-width: 44px;
  font-size: 16px;
  line-height: 1;
}
.historyDetailMeta {
  margin: 4px 0 10px;
  padding: 10px;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 4px);
  background: hsl(var(--muted));
}
.historyDetailTitle {
  font-size: 14px;
  font-weight: 700;
}
.historyDetailDate {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  margin-top: 2px;
}
.historyDetailUrl {
  display: inline-block;
  margin-top: 6px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebarToggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 30;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1;
}
.sidebarToggleIcon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  line-height: 0;
}
.sidebarToggleIcon svg {
  display: block;
  width: 14px;
  height: 14px;
}
.sidebarToggleLabel {
  line-height: 1;
}
.appShell[data-sidebar="closed"] .historySidebar {
  transform: translateX(calc(-1 * var(--sidebar-width)));
  opacity: 0;
  pointer-events: none;
}
.appShell[data-sidebar="closed"] .shellMain {
  margin-left: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid hsl(var(--border));
  color: hsl(var(--muted-foreground));
  background: hsl(var(--muted));
}
.status[data-tone="ok"] { color: hsl(var(--foreground)); }
.status[data-tone="err"] { color: #ef4444; }

.chips { display: inline-flex; gap: 6px; align-items: center; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--background));
  color: hsl(var(--muted-foreground));
  font-size: 12px;
  line-height: 1;
  user-select: none;
}
.chip svg { opacity: 0.85; }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: hsl(var(--border));
  box-shadow: 0 0 0 2px hsl(var(--background));
}
.chip[data-enabled="1"] .dot { background: #22c55e; }
.chip[data-enabled="0"] { opacity: 0.6; }
.statusText { font-size: 12px; }

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(127,127,127,0.25);
  border-top-color: hsl(var(--muted-foreground));
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

h2 { font-size: 12px; margin: 0 0 10px; color: hsl(var(--muted-foreground)); font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }
.hint { font-size: 12px; color: hsl(var(--muted-foreground)); }

.prose {
  color: hsl(var(--foreground));
  font-size: 14px;
  line-height: 1.7;
}
.prose > :first-child { margin-top: 0; }
.prose h1, .prose h2, .prose h3 { line-height: 1.25; margin: 18px 0 10px; letter-spacing: -0.01em; }
.prose h1 { font-size: 18px; }
.prose h2 { font-size: 16px; }
.prose h3 { font-size: 14px; }
.prose p { margin: 10px 0; }
.prose ul, .prose ol { margin: 10px 0 10px 18px; padding: 0; }
.prose li { margin: 4px 0; }
.prose hr { border: 0; border-top: 1px solid hsl(var(--border)); margin: 14px 0; }
.prose code {
  font-family: var(--mono);
  font-size: 0.92em;
  padding: 0.15em 0.35em;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted));
  border-radius: 8px;
}
.prose pre {
  margin: 12px 0;
  padding: 12px;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted));
  overflow: auto;
}
.prose pre code {
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: 13px;
  display: block;
  white-space: pre;
}

.summaryBox {
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted));
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
  min-height: 180px;
  position: relative;
  overflow: hidden;
}
.summaryBox[data-loading="1"] { animation: pulse 1.35s ease-in-out infinite; }
.summaryBox[data-loading="1"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, hsl(var(--background) / 0.55), transparent);
  transform: translateX(-60%);
  animation: shimmer 1.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes shimmer { 0% { transform: translateX(-60%); } 100% { transform: translateX(60%); } }
@keyframes pulse { 0%, 100% { filter: saturate(1); } 50% { filter: saturate(1.08); } }

.skeleton { display: grid; gap: 10px; }
.skeleton .line { height: 12px; border-radius: 999px; background: hsl(var(--border)); opacity: 0.9; }
.skeleton .w90 { width: 90%; }
.skeleton .w72 { width: 72%; }
.skeleton .w86 { width: 86%; }
.skeleton .w60 { width: 60%; }

details {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 10px 12px;
  background: hsl(var(--card));
}
summary {
  cursor: pointer;
  color: hsl(var(--muted-foreground));
  font-size: 13px;
  user-select: none;
}
details[open] summary { margin-bottom: 10px; }
.transcript {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  padding: 12px;
  border-radius: calc(var(--radius) - 4px);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--muted));
}

@media (max-width: 640px) {
  .sessionDock {
    top: auto;
    right: 10px;
    bottom: 10px;
  }
}

@media (max-width: 900px) {
  .shellMain { margin-left: 0; }
  .historySidebar {
    width: min(86vw, 340px);
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
  }
  .appShell[data-sidebar="open"] .historySidebar {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }
  .historyList {
    max-height: none;
  }
}
