:root {
  --bg: #f4efe4;
  --panel: rgba(255, 252, 247, 0.82);
  --panel-strong: #fffaf0;
  --line: rgba(43, 35, 23, 0.12);
  --ink: #1f1a14;
  --muted: #685d4d;
  --accent: #0f766e;
  --accent-2: #be7b34;
  --danger: #b91c1c;
  --shadow: 0 20px 60px rgba(60, 40, 10, 0.12);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.18), transparent 28%),
    radial-gradient(circle at top right, rgba(190, 123, 52, 0.22), transparent 24%),
    linear-gradient(160deg, #efe5cf 0%, #f8f4ea 48%, #f0ecdf 100%);
}

#app {
  min-height: 100vh;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(460px, 100%);
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 28px;
  background: rgba(255, 252, 247, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-kicker {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.auth-card h1 {
  margin: 0;
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: 34px;
  line-height: 1.08;
}

.auth-copy {
  margin: 16px 0 20px;
  color: var(--muted);
  line-height: 1.7;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  font: inherit;
}

.auth-error {
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.hero {
  padding: 40px 28px;
  border-right: 1px solid var(--line);
  background: rgba(255, 248, 235, 0.55);
  backdrop-filter: blur(10px);
}

.eyebrow,
.panel-kicker {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1,
.panel-header h2 {
  margin: 0;
  font-family: Georgia, "Noto Serif SC", serif;
  font-weight: 700;
}

.hero h1 {
  font-size: 42px;
  line-height: 1.05;
}

.lede {
  margin: 18px 0 28px;
  color: var(--muted);
  line-height: 1.7;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  font-size: 14px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.status-idle {
  background: #9ca3af;
}

.status-live {
  background: var(--accent);
  box-shadow: 0 0 0 8px rgba(15, 118, 110, 0.14);
}

.status-error {
  background: var(--danger);
  box-shadow: 0 0 0 8px rgba(185, 28, 28, 0.14);
}

.hero-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
  gap: 22px;
  padding: 24px;
  min-height: 100vh;
}

.mobile-switcher {
  display: none;
}

.switcher-button {
  border: 1px solid transparent;
  background: rgba(31, 26, 20, 0.08);
  color: var(--ink);
}

.switcher-button.is-active {
  background: linear-gradient(135deg, var(--accent-2), #d2944a);
  color: white;
}

.panel {
  min-height: 0;
  height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 24px 20px;
  border-bottom: 1px solid var(--line);
}

.messages,
.logs {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  max-width: 88%;
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.message[data-role="用户"],
.message[data-role="User"] {
  align-self: flex-end;
  background: linear-gradient(145deg, #0f766e, #166b64);
  color: white;
  border: none;
}

.message[data-role="Agent"] {
  align-self: flex-start;
}

.message-meta {
  margin-bottom: 8px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.74;
}

.message-body,
.log-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 18px;
  background: rgba(255, 250, 240, 0.74);
}

.voice-status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
}

.voice-status[data-state="listening"] {
  border-color: rgba(15, 118, 110, 0.28);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent);
}

.voice-status[data-state="error"] {
  border-color: rgba(185, 28, 28, 0.22);
  background: rgba(185, 28, 28, 0.08);
  color: var(--danger);
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font: inherit;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  gap: 12px;
}

.composer-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

button {
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--accent-2), #d2944a);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

button.secondary {
  background: rgba(31, 26, 20, 0.08);
  color: var(--ink);
}

button.is-listening {
  background: linear-gradient(135deg, var(--accent), #169084);
  color: white;
}

.logs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.log-entry {
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.log-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.log-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.log-usage {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.1);
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-entry[data-type="tool_call_started"] {
  border-left: 6px solid #d97706;
}

.log-entry[data-type="tool_call_completed"] {
  border-left: 6px solid var(--accent);
}

.log-entry[data-type="tool_call_failed"],
.log-entry[data-type="run_failed"] {
  border-left: 6px solid var(--danger);
}

.log-entry[data-type="model_usage"] {
  border-left: 6px solid #2563eb;
}

.log-name {
  margin-bottom: 8px;
  font-weight: 700;
}

.log-body {
  max-height: 320px;
  overflow: auto;
  padding-right: 4px;
}

@media (max-width: 1080px) {
  .shell,
  .workspace {
    grid-template-columns: 1fr;
  }

  .hero {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .panel {
    min-height: 60vh;
  }

  .auth-card {
    padding: 24px;
  }
}

@media (max-width: 820px) {
  body {
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
  }

  .shell {
    min-height: 100dvh;
    height: 100dvh;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  .hero {
    padding: 14px 16px 10px;
  }

  .hero h1 {
    font-size: 28px;
  }

  .lede {
    margin: 14px 0 18px;
    font-size: 14px;
    line-height: 1.6;
    max-width: 34ch;
  }

  .hero-actions {
    margin-bottom: 0;
  }

  .workspace {
    align-content: start;
    gap: 14px;
    padding: 14px;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .mobile-switcher {
    position: sticky;
    top: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 18px;
    background: rgba(255, 252, 247, 0.88);
    backdrop-filter: blur(18px);
    box-shadow: var(--shadow);
  }

  .panel {
    height: 100%;
    min-height: 0;
    border-radius: 20px;
  }

  .panel-header {
    padding: 18px 18px 16px;
  }

  .messages,
  .logs {
    padding: 14px;
  }

  .message {
    max-width: 94%;
    padding: 14px 15px;
    border-radius: 18px;
  }

  .composer {
    position: sticky;
    bottom: 0;
    padding: 14px;
    background: rgba(255, 250, 240, 0.92);
    backdrop-filter: blur(16px);
  }

  textarea {
    min-height: 84px;
    padding: 14px;
    border-radius: 16px;
  }

  .voice-status {
    margin-top: 10px;
    font-size: 12px;
  }

  .log-entry {
    padding: 12px 13px;
    border-radius: 16px;
  }

  .log-body {
    max-height: 220px;
  }

  .workspace[data-mobile-view="chat"] .logs-panel,
  .workspace[data-mobile-view="logs"] .conversation-panel {
    display: none;
  }

  .auth-shell {
    padding: 16px;
  }

  .auth-card {
    padding: 22px 18px;
    border-radius: 22px;
  }

  .auth-card h1 {
    font-size: 28px;
  }
}

@media (max-width: 640px) {
  .shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 8px;
    min-height: 52px;
  }

  .eyebrow {
    display: none;
  }

  .hero h1 {
    flex: 0 1 auto;
    font-size: 18px;
    line-height: 1;
    max-width: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .lede {
    display: none;
  }

  .hero-actions {
    flex: 0 0 auto;
    margin: 0;
    order: 3;
  }

  .hero-actions button {
    padding: 8px 12px;
    font-size: 11px;
    white-space: nowrap;
  }

  .status-bar {
    flex: 0 0 auto;
    margin: 0;
    font-size: 11px;
    gap: 6px;
    white-space: nowrap;
  }

  .workspace {
    padding: 8px;
    gap: 8px;
    height: calc(100dvh - 52px);
  }

  .mobile-switcher {
    gap: 8px;
    padding: 5px;
    border-radius: 16px;
  }

  .panel {
    height: 100%;
    min-height: 0;
  }

  .composer-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .composer-buttons {
    justify-content: stretch;
  }

  .composer-buttons button {
    flex: 1;
  }

  .hint {
    display: none;
  }

  .auth-card h1 {
    font-size: 24px;
  }
}

@media (max-width: 420px) {
  .hero {
    gap: 8px;
    padding: 8px 10px 6px;
    min-height: 48px;
  }

  .hero h1 {
    font-size: 16px;
  }

  .hero-actions {
    order: 2;
  }

  .hero-actions button {
    width: auto;
    padding: 7px 10px;
    font-size: 10px;
  }

  .status-bar {
    order: 3;
    gap: 4px;
  }

  .status-bar span:last-child {
    display: none;
  }

  .workspace {
    height: calc(100dvh - 48px);
    padding: 6px;
    gap: 6px;
  }

  .panel-header {
    padding: 14px 12px 12px;
  }

  .messages,
  .logs,
  .composer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .message-body,
  .log-body {
    font-size: 12px;
  }

  .auth-shell {
    padding: 12px;
  }

  .auth-card {
    padding: 18px 14px;
  }

  .auth-card h1 {
    font-size: 21px;
  }
}
