:root {
  --bg: #f4f1e8;
  --surface: rgba(255, 252, 246, 0.94);
  --surface-strong: #fffdf8;
  --line: rgba(56, 47, 38, 0.14);
  --ink: #231b14;
  --muted: #6c6255;
  --accent: #a04e1a;
  --accent-deep: #6b2d06;
  --shadow: 0 18px 40px rgba(74, 56, 34, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Noto Sans TC", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(204, 111, 34, 0.16), transparent 32%),
    radial-gradient(circle at bottom right, rgba(74, 98, 67, 0.16), transparent 28%),
    linear-gradient(135deg, #f3efe6, #efe7db 42%, #e7ddd0 100%);
}

button,
textarea,
input {
  font: inherit;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 2rem;
}

.login-card,
.sidebar,
.query-panel,
.answer-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.login-card {
  width: min(100%, 420px);
  padding: 2rem;
  border-radius: 28px;
}

.login-form {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

.login-form input,
textarea {
  width: 100%;
  border: 1px solid rgba(56, 47, 38, 0.18);
  border-radius: 18px;
  padding: 1rem 1.1rem;
  background: rgba(255, 255, 255, 0.66);
  color: var(--ink);
}

.app-shell {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: 100vh;
  gap: 1.2rem;
  padding: 1.2rem;
}

.sidebar {
  border-radius: 28px;
  padding: 1.1rem;
  overflow: hidden;
}

.sidebar-header,
.answer-header,
.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.history-list {
  display: grid;
  gap: 0.75rem;
  margin-top: 1rem;
  max-height: calc(100vh - 140px);
  overflow: auto;
  padding-right: 0.35rem;
}

.history-item {
  border: 1px solid rgba(56, 47, 38, 0.12);
  background: rgba(255, 248, 238, 0.86);
  border-radius: 20px;
  padding: 0.75rem;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.history-item:hover,
.history-item.active {
  transform: translateY(-2px);
  border-color: rgba(160, 78, 26, 0.45);
  background: rgba(255, 242, 227, 0.96);
}

.history-main {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 0.2rem 0.2rem 0.65rem;
  cursor: pointer;
}

.history-item h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.history-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.history-delete {
  border: 1px solid rgba(168, 29, 34, 0.15);
  background: rgba(255, 255, 255, 0.72);
  color: #8d1f23;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}

.history-delete:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.empty-history {
  padding: 0.95rem;
}

.main-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 1.2rem;
}

.query-panel,
.answer-panel {
  border-radius: 32px;
  padding: 1.5rem;
}

.panel-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.status-text {
  margin: 0.9rem 0 0;
}

.question-box {
  display: grid;
  gap: 1rem;
  margin-top: 1.25rem;
}

textarea {
  min-height: 160px;
  resize: vertical;
}

.primary-button,
.ghost-button {
  border: none;
  border-radius: 999px;
  padding: 0.82rem 1.35rem;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff8f0;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  border: 1px solid rgba(56, 47, 38, 0.1);
}

.answer-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.answer-meta {
  color: var(--muted);
  text-align: right;
  font-size: 0.92rem;
}

.answer-content {
  margin-top: 1rem;
  padding: 1.25rem;
  border-radius: 24px;
  background: var(--surface-strong);
  border: 1px solid rgba(56, 47, 38, 0.08);
  white-space: pre-wrap;
  line-height: 1.7;
  overflow: auto;
}

.empty-state {
  color: var(--muted);
}

.error {
  color: #a81d22;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .panel-top {
    flex-direction: column;
  }

  .history-list {
    max-height: 280px;
  }

  .actions {
    justify-content: flex-start;
  }
}
