:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --border: #e2e5eb;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --bubble-user: #4f46e5;
  --bubble-user-text: #ffffff;
  --bubble-ai: #eef0f5;
  --bubble-ai-text: #1c1e21;
  --danger: #dc2626;
}

[data-theme="dark"] {
  --bg: #14161c;
  --surface: #1e2028;
  --text: #e8e9ee;
  --muted: #9aa0ac;
  --border: #33353f;
  --accent: #7c6cf0;
  --accent-text: #ffffff;
  --bubble-user: #7c6cf0;
  --bubble-user-text: #ffffff;
  --bubble-ai: #2a2c36;
  --bubble-ai-text: #e8e9ee;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-header h1 {
  font-size: 18px;
  margin: 0;
}

.icon-btn {
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  border: none;
  background: none;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  font-weight: 600;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

.summary-card strong {
  color: var(--text);
}

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
}

.chat-toolbar button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 300px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 12px 4px;
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bubble-ai);
  color: var(--bubble-ai-text);
  border-bottom-left-radius: 4px;
}

.chat-loading {
  font-size: 13px;
  color: var(--muted);
  padding: 4px 8px;
}

.hidden {
  display: none;
}

.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.chat-form input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

.chat-form button,
.data-form button,
.export-buttons button {
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.data-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.data-form input {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.export-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.export-buttons button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.trend-chart {
  width: 100%;
  height: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
}

td.actions-cell {
  display: flex;
  gap: 6px;
}

td.actions-cell button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}

td.actions-cell button.delete-btn {
  color: var(--danger);
  border-color: var(--danger);
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.history-item .meta {
  font-size: 12px;
  color: var(--muted);
}

.history-item .title {
  font-size: 14px;
  font-weight: 600;
}

.history-item .actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.history-item button {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
}

.history-item button.delete-btn {
  color: var(--danger);
  border-color: var(--danger);
}

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