/* ============ 基础 ============ */
:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #22d3ee;
  --accent-hover: #06b6d4;
  --up: #4ade80;
  --down: #f87171;
  --err: #f87171;
  --border: #475569;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, "SF Pro Text", "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button {
  cursor: pointer;
  font-family: inherit;
}

/* ============ 登录 ============ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  background: var(--panel);
  padding: 2rem 1.75rem;
  border-radius: 12px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.login-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.login-card .hint {
  margin: 0 0 1.5rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.login-card input,
.editor-top input,
.editor-top select,
.editor-rows input,
.editor-rows select {
  padding: 0.65rem 0.9rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.login-card input {
  width: 100%;
  margin-bottom: 0.75rem;
}

.login-card input:focus,
.editor-top input:focus,
.editor-top select:focus,
.editor-rows input:focus,
.editor-rows select:focus {
  border-color: var(--accent);
}

.login-card button.primary,
.modal-foot .primary,
header .primary {
  padding: 0.55rem 1.15rem;
  background: var(--accent);
  color: #0f172a;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s;
}

.login-card button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: #0f172a;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0.5rem;
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.err {
  color: var(--err);
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  text-align: center;
}

/* ============ 主视图 ============ */
.main-wrap {
  min-height: 100vh;
}

header {
  background: var(--panel);
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-dim);
  font-size: 0.9rem;
}

button.ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.4rem 0.9rem;
  border-radius: 6px;
  font-size: 0.85rem;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}

button.ghost:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

button.ghost.mini {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

main {
  padding: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}

.placeholder {
  color: var(--text-dim);
  text-align: center;
  padding: 3rem 1rem;
  line-height: 1.7;
}

.placeholder-small {
  color: var(--text-dim);
  padding: 1rem 0;
  font-size: 0.9rem;
  text-align: center;
}

/* ============ 人切换 ============ */
.toggle-group {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding: 0.35rem;
  background: var(--panel);
  border-radius: 10px;
  width: fit-content;
}

.toggle-group button {
  padding: 0.5rem 1.25rem;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
}

.toggle-group button:hover {
  color: var(--text);
}

.toggle-group button.active {
  background: var(--accent);
  color: #0f172a;
  font-weight: 600;
}

/* ============ 卡片 ============ */
.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 900px) {
  .cards {
    grid-template-columns: 1fr 1fr;
  }
  .cards .summary,
  .cards .details {
    grid-column: 1 / -1;
  }
}

.card {
  background: var(--panel);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--border);
}

.card-label {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  letter-spacing: 0.02em;
}

.card-label.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dim {
  color: var(--text-dim);
}

.card.summary {
  padding: 1.75rem 1.5rem;
}

.big-number {
  font-size: 2.75rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.big-number .unit {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: 0.35rem;
}

.card-sub {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.compare-group {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.compare-item {
  background: rgba(51, 65, 85, 0.5);
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  flex: 1;
  min-width: 150px;
}

.compare-label {
  color: var(--text-dim);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.compare-label .dim {
  font-size: 0.7rem;
}

.change {
  padding: 0.15rem 0.5rem;
  border-radius: 5px;
  font-size: 0.9rem;
  font-weight: 600;
  align-self: flex-start;
}

.change.up {
  color: var(--up);
  background: rgba(74, 222, 128, 0.1);
}

.change.down {
  color: var(--down);
  background: rgba(248, 113, 113, 0.1);
}

.chart-wrap {
  position: relative;
  height: 300px;
  width: 100%;
}

@media (min-width: 900px) {
  .chart-wrap {
    height: 340px;
  }
}

/* ============ 明细表 ============ */
.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.detail-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.detail-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid rgba(71, 85, 105, 0.4);
}

.detail-table tr:last-child td {
  border-bottom: none;
}

.detail-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============ 模态框 ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  overflow-y: auto;
}

.modal {
  background: var(--panel);
  border-radius: 12px;
  width: 100%;
  max-width: 800px;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-head {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.close {
  font-size: 1.4rem;
  padding: 0.1rem 0.6rem;
  line-height: 1;
}

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-foot {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.editor-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
}

.field label {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
}

.field-hint {
  grid-column: 1 / -1;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-style: italic;
}

/* ============ 编辑表 ============ */
.editor-rows-wrap {
  overflow-x: auto;
  margin: 0 -1.5rem;
  padding: 0 1.5rem;
}

.editor-rows {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.4rem;
  min-width: 500px;
}

.editor-rows th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.8rem;
  padding: 0 0.4rem 0.35rem;
}

.editor-rows th.num {
  text-align: right;
}

.editor-rows td {
  padding: 0 0.25rem;
}

.editor-rows input,
.editor-rows select {
  width: 100%;
  padding: 0.45rem 0.65rem;
  font-size: 0.9rem;
}

.editor-rows input.num,
.editor-rows td.num input {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.editor-rows td.num {
  width: 130px;
}

.editor-rows tr.row-deleted input,
.editor-rows tr.row-deleted select {
  text-decoration: line-through;
  opacity: 0.5;
}

.add-row {
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--border);
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-top: 0.5rem;
  transition: all 0.15s;
  width: 100%;
}

.add-row:hover {
  border-color: var(--accent);
  background: rgba(34, 211, 238, 0.05);
}

/* ============ 危险操作 ============ */
.danger-bar {
  margin: 0 0 1rem;
  padding: 0.4rem;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 8px;
}

button.danger {
  width: 100%;
  padding: 0.55rem 1rem;
  background: transparent;
  color: var(--err);
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s;
  font-family: inherit;
}

button.danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.15);
}

button.danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============ 响应式 ============ */
@media (max-width: 640px) {
  header {
    padding: 0.75rem 1rem;
  }
  header h1 {
    font-size: 1.1rem;
  }
  .user {
    font-size: 0.8rem;
    gap: 0.5rem;
  }
  main {
    padding: 1rem;
  }
  .big-number {
    font-size: 2.25rem;
  }
  .toggle-group button {
    padding: 0.45rem 1rem;
    font-size: 0.85rem;
  }
  .modal {
    max-height: calc(100vh - 1rem);
  }
  .modal-body {
    padding: 1rem;
  }
  .modal-head, .modal-foot {
    padding: 0.85rem 1rem;
  }
  .editor-top {
    grid-template-columns: 1fr;
  }
}
