:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --header-bg: #1a1f2c;
  --border: #2d3a4d;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-dim: #2563c4;
  --link-accent: #7e5bef;
  --link-accent-hover: #9b7fff;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

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

body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.login-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
}

.login-sub {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.login-card input {
  padding: 0.5rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font: inherit;
}

.login-actions {
  margin-top: 0.5rem;
  justify-content: stretch;
}

.login-actions .primary {
  width: 100%;
}

.login-err {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--danger);
}

.report-toolbar input[type="month"] {
  margin-left: 0.35rem;
  padding: 0.35rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
}

.report-summary {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

/* Invoices: sidebar + main */
.invoices-layout {
  display: flex;
  align-items: flex-start;
  gap: 1.25rem;
}

.invoices-sidebar {
  flex: 0 0 auto;
  min-width: 11rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.invoices-nav-btn {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 0.92rem;
  cursor: pointer;
}

.invoices-nav-btn:hover {
  background: rgba(126, 91, 239, 0.1);
  border-color: var(--border);
  color: var(--text);
}

.invoices-nav-btn.active {
  background: rgba(126, 91, 239, 0.2);
  border-color: var(--link-accent);
  color: #fff;
}

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

.invoices-view {
  min-width: 0;
}

.invoices-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.invoices-subtitle {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.invoices-customers-table-wrap {
  max-height: 60vh;
  overflow: auto;
}

.customer-edit-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.customer-inline-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

#dlg-customer label {
  display: block;
  margin-bottom: 0.65rem;
}

#dlg-customer input[type="email"],
#dlg-customer input[type="text"],
#dlg-customer textarea {
  width: 100%;
  max-width: 28rem;
  box-sizing: border-box;
}

.invoices-customers-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.invoice-new-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.invoice-new-hint {
  font-size: 0.88rem;
  color: var(--muted);
  flex: 1;
  min-width: 12rem;
}

.invoices-view .col-check {
  width: 2.25rem;
}

.inv-multi-table-wrap {
  margin-top: 0.35rem;
}

.price-sync-pending-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.75rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1.4;
}

.price-sync-pending-label input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.task-customer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.task-customer-row .flex-grow {
  flex: 1;
  min-width: 12rem;
}

.task-no-edit-wrap {
  margin: 0 0 0.5rem;
  font-size: 0.92rem;
  color: var(--muted);
}

button.primary:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.85;
}

button.ghost.small {
  padding: 0.3rem 0.5rem;
  font-size: 0.82rem;
}

.top {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}

/* 顶栏文字链接（与「退出登录」ghost 按钮并列，紫色下划线） */
.top-actions a.top-nav-link {
  color: var(--link-accent);
  text-decoration: underline;
  text-underline-offset: 0.18em;
  font-size: 0.95rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.top-actions a.top-nav-link:hover {
  color: var(--link-accent-hover);
}

.top-actions a.top-nav-link:focus-visible {
  outline: 2px solid var(--link-accent);
  outline-offset: 2px;
}

.top-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.top-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.app-version {
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  line-height: 1.3;
}

.app-header-logo img {
  height: 36px;
  width: auto;
  max-width: 120px;
  object-fit: contain;
  display: block;
}

.login-brand-logo {
  text-align: center;
  margin-bottom: 0.75rem;
}

.login-brand-logo img {
  max-height: 64px;
  max-width: 180px;
  object-fit: contain;
}

.settings-page {
  max-width: min(1100px, 100%);
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
  box-sizing: border-box;
}

.settings-layout {
  align-items: stretch;
}

.settings-main .settings-view {
  min-width: 0;
}

.settings-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  background: var(--surface);
}

.settings-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.settings-subh {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.settings-micr-group {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.settings-micr-group:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.settings-logo-preview {
  margin: 0.5rem 0;
}

.settings-logo-preview img {
  max-height: 80px;
  max-width: 220px;
  object-fit: contain;
  border-radius: 4px;
}

.settings-card label.inline-check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.settings-subtoolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.settings-card input[type="text"],
.settings-card input[type="url"],
.settings-card input[type="number"],
.settings-card input[type="password"],
.settings-card input[type="email"] {
  padding: 0.5rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font: inherit;
}

.settings-card input[type="file"] {
  font-size: 0.88rem;
  color: var(--muted);
}

.cheque-panel-toolbar {
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem;
}

.cheque-panel-intro {
  flex: 1;
  min-width: 200px;
  margin: 0;
}

.cheque-iframe {
  display: block;
  width: 100%;
  min-height: min(120vh, 1400px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.settings-card textarea {
  padding: 0.5rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font: inherit;
  width: 100%;
  min-height: 3rem;
  resize: vertical;
}

#panel-trend.panel {
  max-height: calc(100vh - 7.5rem);
  overflow-y: auto;
  padding-right: 0.15rem;
}

.trend-page {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.trend-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  background: var(--surface);
  flex-shrink: 0;
}

.trend-card--pies {
  max-height: min(320px, 46vh);
  overflow-y: auto;
  overflow-x: hidden;
}

.trend-card--bar {
  max-height: min(300px, 42vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.trend-card--invoice {
  max-height: min(160px, 22vh);
  padding-bottom: 0.75rem;
}

.trend-title {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.trend-subtitle {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.trend-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.65rem;
  align-items: start;
}

.trend-pie h3 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
}

.trend-kpi {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.trend-pie-chart {
  position: relative;
  height: 112px;
  max-height: 112px;
  width: 100%;
}

.trend-chart-wrap {
  flex: 1;
  min-height: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
}

.trend-chart-inner {
  position: relative;
  height: 200px;
  max-height: 200px;
  width: 100%;
}

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

.trend-big-number {
  font-size: 1.35rem;
  font-weight: 600;
}

.trend-summary-note {
  margin-top: 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.top h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.tabs {
  display: flex;
  gap: 0.5rem;
}

.tab {
  padding: 0.45rem 1rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}

.tab:hover {
  color: var(--text);
  border-color: var(--muted);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

main {
  padding: 1rem 1.25rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.expense-toolbar {
  justify-content: space-between;
}

.toolbar label {
  font-size: 0.9rem;
  color: var(--muted);
}

.toolbar select {
  margin-left: 0.35rem;
  padding: 0.35rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
}

button {
  font: inherit;
  cursor: pointer;
}

button.primary {
  padding: 0.45rem 1rem;
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 6px;
}

button.primary:hover {
  background: var(--accent-dim);
}

/** 与 primary 同尺寸与圆角，绿底白字（任务行 Expense 等） */
button.primary-green {
  padding: 0.45rem 1rem;
  background: #22c55e;
  border: none;
  color: #fff;
  border-radius: 6px;
}

button.primary-green:hover {
  background: #16a34a;
}

button.primary-green:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.ghost {
  padding: 0.35rem 0.65rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  font-size: 0.85rem;
}

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

button.ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.danger {
  color: var(--danger);
  border-color: var(--danger);
}

button.ghost.success {
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.55);
}

button.ghost.success:hover {
  color: #86efac;
  border-color: rgba(134, 239, 172, 0.75);
}

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

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.data th,
table.data td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data th {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

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

table.data tbody tr:hover td {
  background: rgba(61, 139, 253, 0.06);
}

.status-pending {
  color: #fbbf24;
}

.status-done {
  color: #4ade80;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  max-width: min(480px, 94vw);
}

dialog.dlg-task-wide {
  max-width: min(720px, 96vw);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

dialog form {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

dialog h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}

dialog .dlg-head-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

dialog .dlg-head-row h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
}

dialog label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.88rem;
  color: var(--muted);
}

dialog input,
dialog select {
  padding: 0.45rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font: inherit;
}

dialog textarea {
  padding: 0.45rem 0.55rem;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  font: inherit;
  resize: vertical;
}

dialog input[readonly] {
  opacity: 0.75;
}

.dlg-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.row-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: nowrap;
}

.exchange-rates-toolbar {
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: flex-end;
}

table.data.exchange-rates-table th.num,
table.data.exchange-rates-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

table.data.exchange-rates-table td:first-child,
table.data.exchange-rates-table th:first-child {
  text-align: left;
}

.exchange-code {
  color: var(--muted);
  font-size: 0.85em;
}

table.data.exchange-rates-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.035);
}

.exchange-footnote {
  margin: 0.75rem 0 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

.settings-subtoolbar .erc-add-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-right: 0.5rem;
}

.price-pick-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
}

.price-pick-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 0.35rem;
}

button.small {
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
}

.hint {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.price-pick-list {
  max-height: 280px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.price-pick-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.86rem;
  line-height: 1.35;
}

/* dialog label 默认为纵向，需显式覆盖价目多选行 */
dialog label.price-pick-row {
  flex-direction: row;
  align-items: flex-start;
}

dialog label.price-pick-row > span {
  flex: 1;
  min-width: 0;
}

.price-pick-row input {
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.price-pick-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.price-preview {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted);
}
