/* ==========================================================================
   style.css - 计算器前端样式
   主题通过 CSS 变量实现：:root 为浅色，html[data-theme="dark"] 为深色
   ========================================================================== */

:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #8a93a5;
  --border: #e3e7ef;
  --btn: #f4f6fa;
  --btn-hover: #e8ecf3;
  --accent: #3b82f6;
  --accent-soft: #eaf2ff;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --shadow: 0 8px 24px rgba(30, 41, 59, 0.08);
}

html[data-theme="dark"] {
  --bg: #12161f;
  --card: #1c2230;
  --text: #e8ecf4;
  --muted: #8a93a5;
  --border: #2a3142;
  --btn: #262e3f;
  --btn-hover: #323b50;
  --accent: #5b9bff;
  --accent-soft: #22304a;
  --danger: #f87171;
  --danger-soft: #3a2430;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.25s ease, color 0.25s ease;
}

/* ---------- 整体布局：左侧计算器 + 右侧历史，窄屏改为上下 ---------- */

.app {
  display: flex;
  gap: 20px;
  max-width: 920px;
  margin: 0 auto;
  padding: 32px 16px;
  align-items: flex-start;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.calculator {
  flex: 0 0 360px;
}

.history {
  flex: 1;
  min-width: 320px;
}

@media (max-width: 860px) {
  .app {
    flex-direction: column;
    align-items: stretch;
  }
  .calculator {
    flex: none;
  }
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

/* ---------- 显示区 ---------- */

.display {
  background: var(--btn);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  min-height: 108px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  overflow-wrap: anywhere;
}

.display-expression {
  font-size: 1.9rem;
  font-weight: 600;
  text-align: right;
  min-height: 2.4rem;
  word-break: break-all;
}

.display-result {
  font-size: 1.15rem;
  color: var(--accent);
  text-align: right;
  min-height: 1.4rem;
}

.display-message {
  font-size: 0.85rem;
  color: var(--danger);
  text-align: right;
  min-height: 1.1rem;
}

/* ---------- 按键区 ---------- */

.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.key {
  height: 56px;
  font-size: 1.25rem;
  font-family: inherit;
  border: none;
  border-radius: 12px;
  background: var(--btn);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.key:hover {
  background: var(--btn-hover);
}

.key:active {
  transform: scale(0.96);
}

.key.op {
  color: var(--accent);
  background: var(--accent-soft);
}

.key.fn {
  color: var(--danger);
  background: var(--danger-soft);
}

.key.equals {
  background: var(--accent);
  color: #ffffff;
}

.key.equals:hover {
  filter: brightness(1.08);
}

/* ---------- 历史记录 ---------- */

.count-badge {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  text-align: center;
}

.text-btn {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.text-btn:hover {
  background: var(--btn-hover);
  color: var(--text);
}

.text-btn.danger:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.icon-btn {
  border: none;
  background: var(--btn);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 1.05rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.icon-btn:hover {
  background: var(--btn-hover);
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--btn);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.search-input:focus {
  border-color: var(--accent);
}

.history-list {
  list-style: none;
  max-height: 480px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.history-item:hover {
  background: var(--btn);
}

.history-main {
  flex: 1;
  min-width: 0;
}

.history-expr {
  font-size: 0.98rem;
  font-weight: 600;
  word-break: break-all;
}

.history-result {
  font-size: 0.9rem;
  color: var(--accent);
  margin-top: 2px;
}

.history-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.history-time {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.history-delete {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}

.history-delete:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.history-empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 28px 0;
}

.history-error {
  text-align: center;
  color: var(--danger);
  font-size: 0.9rem;
  padding: 28px 0;
}
