/* 财务助手 PWA 样式 */

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #202124;
  --text-2: #5f6368;
  --border: #dadce0;
  --danger: #d93025;
  --success: #188038;
  --warn: #f9ab00;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body { overscroll-behavior-y: contain; }

/* ---------- 页面切换 ---------- */
.page { display: none; min-height: 100vh; }
.page.active { display: block; }

/* ---------- 登录 ---------- */
#page-login {
  display: none;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a73e8 0%, #4285f4 50%, #669df6 100%);
  padding: 20px;
}
#page-login.active { display: flex; }

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: 16px;
  padding: 36px 28px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  text-align: center;
}

.logo {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #4285f4);
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.subtitle { color: var(--text-2); font-size: 13px; margin-bottom: 24px; }

#login-form { text-align: left; }
#login-form label { display: block; margin-bottom: 14px; }
#login-form label span {
  display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px;
}
#login-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
#login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,.15);
}

.hint { margin-top: 18px; font-size: 12px; color: var(--text-2); }
.error {
  margin-top: 12px; padding: 10px 12px;
  background: #fce8e6; color: var(--danger);
  border-radius: 8px; font-size: 13px;
}

/* ---------- 按钮 ---------- */
.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { background: #9aa0a6; cursor: not-allowed; }

.btn-ghost {
  padding: 8px 14px;
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.btn-ghost:hover { background: rgba(26,115,232,.06); }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 17px; font-weight: 600; color: var(--primary); }
.user-info { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-2); }

/* ---------- Tabs ---------- */
.tabs {
  position: sticky; top: calc(49px + env(safe-area-inset-top)); z-index: 9;
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 1; min-width: 70px;
  padding: 12px 8px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

.content { padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); max-width: 900px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- 语音 ---------- */
.voice-box {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.mic-btn {
  width: 88px; height: 88px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary), #4285f4);
  color: #fff;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(26,115,232,.35);
  transition: transform .1s, box-shadow .15s;
}
.mic-btn:active { transform: scale(.94); }
.mic-btn.recording {
  background: linear-gradient(135deg, var(--danger), #ea4335);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(217,48,37,.5); }
  50% { box-shadow: 0 0 0 16px rgba(217,48,37,0); }
}
.mic-btn:disabled { background: #9aa0a6; box-shadow: none; cursor: not-allowed; }

.voice-status { margin: 14px 0 10px; font-size: 13px; color: var(--text-2); min-height: 18px; }
.voice-status.error { color: var(--danger); }

.voice-text {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  text-align: left;
}
.voice-text:focus { outline: none; border-color: var(--primary); }

.voice-actions { display: flex; gap: 10px; margin-top: 12px; }
.voice-actions .btn-primary { flex: 1; }
.voice-actions .btn-ghost { flex: 0 0 auto; }

.answer-card {
  margin-top: 16px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.answer-text { font-size: 15px; line-height: 1.7; white-space: pre-wrap; }
.mode-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #e8f0fe;
  color: var(--primary);
  margin-bottom: 8px;
  font-weight: 500;
}
.answer-data {
  margin-top: 10px; padding: 10px;
  background: #f8f9fa; border-radius: 6px;
  font-size: 12px; color: var(--text-2);
  overflow-x: auto;
  font-family: "SF Mono", Consolas, monospace;
}

.tips { margin-top: 20px; padding: 16px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.tips h3 { font-size: 14px; color: var(--text-2); margin-bottom: 10px; font-weight: 500; }
.tips ul { list-style: none; }
.tips li {
  padding: 8px 12px; margin-bottom: 6px;
  background: #f1f3f4; border-radius: 16px;
  font-size: 13px; color: var(--text);
  cursor: pointer;
  display: inline-block;
  margin-right: 6px;
}
.tips li:hover { background: #e8eaed; }

/* ---------- 看板 ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.card .label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.card .value { font-size: 20px; font-weight: 600; }
.card .value.in { color: var(--success); }
.card .value.out { color: var(--danger); }
.card .sub { font-size: 11px; color: var(--text-2); margin-top: 4px; }

.chart-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.chart-section h3 { font-size: 14px; margin-bottom: 12px; color: var(--text); }

.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 60px 1fr 90px; align-items: center; gap: 8px; font-size: 12px; }
.bar-label { color: var(--text-2); text-align: right; }
.bar-track { background: #f1f3f4; border-radius: 4px; height: 18px; position: relative; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width .4s; }
.bar-fill.in { background: linear-gradient(90deg, #34a853, #188038); }
.bar-fill.out { background: linear-gradient(90deg, #ea4335, #d93025); }
.bar-fill.net-pos { background: linear-gradient(90deg, #4285f4, #1a73e8); }
.bar-fill.net-neg { background: linear-gradient(90deg, #f9ab00, #e37400); }
.bar-value { font-variant-numeric: tabular-nums; color: var(--text); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f8f9fa; font-weight: 500; color: var(--text-2); font-size: 12px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num.pos { color: var(--success); }
td.num.neg { color: var(--danger); }

/* ---------- 明细 ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 12px;
}
.filters select, .filters input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--card);
  flex: 1; min-width: 120px;
}
.filters .btn-primary { width: auto; flex: 0 0 auto; padding: 8px 18px; }

.txn-summary {
  padding: 10px 12px;
  background: var(--card);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.txn-list { display: flex; flex-direction: column; gap: 8px; }
.txn-item {
  background: var(--card);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}
.txn-item .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.txn-item .cp { font-weight: 500; font-size: 14px; }
.txn-item .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.txn-item .amt.pos { color: var(--success); }
.txn-item .amt.neg { color: var(--danger); }
.txn-item .meta { font-size: 12px; color: var(--text-2); grid-column: 1 / -1; }
.txn-item .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; grid-column: 1 / -1; }
.tag {
  font-size: 11px; padding: 2px 8px;
  background: #e8f0fe; color: var(--primary);
  border-radius: 10px;
}
.tag.cat { background: #fef7e0; color: #b06000; }

#btn-more { width: 100%; margin-top: 12px; }

/* ---------- 方案 ---------- */
.plan-editor {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.plan-editor input, .plan-editor textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 10px;
}
.plan-editor textarea { resize: vertical; line-height: 1.6; }
.plan-editor input:focus, .plan-editor textarea:focus { outline: none; border-color: var(--primary); }
.plan-actions { display: flex; align-items: center; gap: 12px; }
.plan-actions .btn-primary { width: auto; padding: 10px 20px; }
.msg { font-size: 13px; color: var(--success); }
.msg.error { color: var(--danger); }

.plan-list { display: flex; flex-direction: column; gap: 8px; }
.plan-item {
  background: var(--card);
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
}
.plan-item:hover { background: #f8f9fa; }
.plan-item .title { font-weight: 500; }
.plan-item .time { font-size: 12px; color: var(--text-2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(32,33,36,.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 100;
  animation: toastIn .2s;
  max-width: 90vw;
  text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 资金预测 ---------- */
.fc-controls {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.fc-field { display: flex; flex-direction: column; gap: 5px; }
.fc-field > span { font-size: 12px; color: var(--text-2); }
.fc-field input, .fc-field select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: var(--card); min-width: 90px;
}
.fc-field input:focus, .fc-field select:focus { outline: none; border-color: var(--primary); }
.fc-start { display: flex; gap: 6px; }
.fc-gen-btn { width: auto; flex: 0 0 auto; padding: 10px 22px; margin-left: auto; }

.fc-box {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.fc-box-head { font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 10px; }
.fc-count { color: var(--primary); }
.fc-box textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; font-family: inherit; resize: vertical;
}
.fc-box textarea:focus { outline: none; border-color: var(--primary); }
.fc-box-actions { display: flex; gap: 10px; margin-top: 10px; }
.fc-box-actions .btn-primary { width: auto; flex: 1; padding: 10px; }
.fc-box-actions .btn-ghost { flex: 0 0 auto; }
.fc-mic-status { font-size: 12px; color: var(--text-2); margin-top: 8px; min-height: 16px; }
#fc-mic.recording { background: var(--danger); color: #fff; border-color: var(--danger); }

.fc-draft {
  margin-top: 12px; padding: 12px; background: #f8f9fa;
  border: 1px solid var(--border); border-radius: 10px;
}
.fc-draft-head { font-size: 13px; font-weight: 500; margin-bottom: 8px; }
.fc-draft-warn { font-size: 12px; color: var(--warn); margin-bottom: 8px; }
.fc-draft-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.fc-draft-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.fc-draft-grid input, .fc-draft-grid select {
  padding: 7px 9px; border: 1px solid var(--border); border-radius: 7px; font-size: 13px; background: var(--card);
}
.fc-draft-actions { display: flex; gap: 10px; margin-top: 12px; }
.fc-draft-actions .btn-primary { width: auto; flex: 1; padding: 9px; }
.fc-draft-actions .btn-ghost { flex: 0 0 auto; }

.fc-items-list { display: flex; flex-direction: column; gap: 8px; }
.fc-item {
  position: relative; display: grid; grid-template-columns: 1fr auto; gap: 4px;
  padding: 10px 34px 10px 12px; background: #f8f9fa; border-radius: 9px;
  border-left: 3px solid var(--primary);
}
.fc-item-main { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; font-size: 13px; }
.fc-item-cat { font-weight: 600; }
.fc-item-when { color: var(--text-2); }
.fc-item-amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.fc-item-amt.pos { color: var(--success); }
.fc-item-amt.neg { color: var(--danger); }
.fc-item-cp { font-size: 12px; color: var(--text-2); background: #e8f0fe; padding: 1px 7px; border-radius: 9px; }
.fc-item-sub { grid-column: 1 / -1; font-size: 11px; color: var(--text-2); }
.fc-item-src { opacity: .7; }
.fc-item-del {
  position: absolute; right: 8px; top: 8px; width: 22px; height: 22px;
  border: none; background: transparent; color: var(--text-2); cursor: pointer;
  border-radius: 50%; font-size: 13px; line-height: 1;
}
.fc-item-del:hover { background: #fce8e6; color: var(--danger); }

.fc-empty { color: var(--text-2); font-size: 13px; padding: 6px 0; }
.fc-sub { font-size: 12px; color: var(--text-2); font-weight: 400; }

/* 现金余额走势 */
.fc-cash-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.fc-cash-row { display: flex; gap: 3px; min-width: min-content; align-items: stretch; }
.fc-col { display: flex; flex-direction: column; align-items: center; width: 30px; flex: 0 0 auto; }
.fc-bar-top, .fc-bar-bot { height: 68px; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.fc-bar-bot { align-items: flex-start; border-top: 1px dashed var(--border); }
.fc-bar { width: 16px; border-radius: 3px; }
.fc-bar.pos { background: linear-gradient(180deg, #34a853, #188038); }
.fc-bar.neg { background: linear-gradient(180deg, #ea4335, #d93025); }
.fc-col-label { font-size: 9px; color: var(--text-2); margin-top: 4px; white-space: nowrap; }
.fc-cash-legend { display: flex; gap: 16px; font-size: 11px; color: var(--text-2); margin-top: 10px; flex-wrap: wrap; }
.fc-cash-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.fc-cash-legend .dot.pos { background: var(--success); }
.fc-cash-legend .dot.neg { background: var(--danger); }

/* 网格 */
.fc-grid-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: 8px; }
.fc-table { border-collapse: separate; border-spacing: 0; font-size: 12px; width: max-content; min-width: 100%; }
.fc-table th, .fc-table td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 6px 8px; white-space: nowrap; }
.fc-table thead th {
  position: sticky; top: 0; z-index: 3; background: #f1f3f4;
  font-weight: 500; color: var(--text-2); font-size: 11px; text-align: center;
}
.fc-sticky { position: sticky; left: 0; z-index: 2; background: #f8f9fa; text-align: left !important; font-weight: 500; }
.fc-table thead .fc-sticky { z-index: 4; background: #e8eaed; }
.fc-corner { min-width: 92px; }
.fc-rowhead { min-width: 92px; max-width: 120px; }
.fc-mcol { min-width: 62px; }
.fc-cell { text-align: right; font-variant-numeric: tabular-nums; cursor: pointer; min-width: 62px; }
.fc-cell:hover { background: #e8f0fe; }
.fc-cell.pos { color: var(--success); }
.fc-cell.neg { color: var(--danger); }
.fc-cell.locked { background: #fef7e0; font-weight: 600; }
.fc-cell.locked:hover { background: #feefc0; }
.fc-cell.total { font-weight: 600; background: #f8f9fa; cursor: default; }
.fc-cell.total:hover { background: #f8f9fa; }
.fc-total .fc-rowhead { background: #e8eaed; font-weight: 600; }

.fc-note { font-size: 12px; color: var(--text-2); line-height: 1.6; margin: 12px 4px 0; }

/* ---------- 响应式 ---------- */
@media (max-width: 480px) {
  .content { padding: 12px; }
  .bar-row { grid-template-columns: 48px 1fr 76px; font-size: 11px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .fc-gen-btn { margin-left: 0; width: 100%; }
}
