:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-soft: #f2f2f7;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --primary: #0071e3;
  --primary-strong: #005bb5;
  --accent: #bf5a00;
  --danger: #d70015;
  --success: #008a42;
  --blue: #0071e3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 24px rgba(0, 0, 0, 0.05);
  --radius: 8px;
}

[data-theme='dark'] {
  --bg: #000000;
  --panel: #1c1c1e;
  --panel-soft: #2c2c2e;
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --line: #38383a;
  --primary: #0a84ff;
  --primary-strong: #409cff;
  --accent: #ff9f0a;
  --danger: #ff453a;
  --success: #30d158;
  --blue: #0a84ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.28), 0 12px 28px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

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

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 14px;
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(22px);
}

.brand,
.mobile-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-weight: 800;
}

.brand {
  padding: 6px 12px 20px;
  font-size: 17px;
  letter-spacing: 0;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  color: white;
  background: var(--primary);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.side-nav {
  display: grid;
  gap: 4px;
}

.side-nav a,
.bottom-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 600;
}

.side-nav a.active,
.side-nav a:hover,
.bottom-nav a.active {
  color: var(--primary);
  background: var(--panel-soft);
}

.main-shell {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: saturate(180%) blur(22px);
}

.mobile-brand {
  display: none;
}

.mobile-menu {
  position: relative;
  display: none;
}

.mobile-menu summary {
  list-style: none;
}

.mobile-menu summary::-webkit-details-marker {
  display: none;
}

.mobile-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 30;
  width: min(260px, calc(100vw - 24px));
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: saturate(180%) blur(22px);
  box-shadow: var(--shadow);
}

.mobile-menu-panel a {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 600;
}

.mobile-menu-panel a.active,
.mobile-menu-panel a:hover {
  color: var(--primary);
  background: var(--panel-soft);
}

.global-search {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 620px;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  color: var(--muted);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.global-search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.content {
  width: min(1220px, 100%);
  margin: 0 auto;
  padding: 34px 28px 76px;
}

.page-head,
.section-title,
.action-row,
.card-topline,
.card-actions,
.row-actions,
.form-actions,
.title-line,
.mini-split {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-head {
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-head h1,
.section-title h2,
.content-card h2,
.list-card h2,
.list-card h3,
.login-brand h1 {
  margin: 0;
  line-height: 1.2;
}

.page-head h1 {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
}

.section-title {
  justify-content: space-between;
  margin: 2px 0 12px;
}

.section-title h2 {
  font-size: 17px;
  font-weight: 700;
}

.section-title a {
  color: var(--primary);
  font-weight: 600;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 600;
  white-space: nowrap;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  padding: 0 13px;
}

.primary-button {
  color: white;
  background: var(--primary);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
}

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

.secondary-button {
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-color: var(--line);
}

.ghost-button {
  color: var(--muted);
  background: transparent;
}

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

.icon-button {
  width: 36px;
  padding: 0;
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-color: var(--line);
}

.icon-button.success {
  color: var(--success);
}

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

.wide {
  width: 100%;
}

.flash {
  width: min(1220px, calc(100% - 48px));
  margin: 18px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  box-shadow: var(--shadow);
}

.flash.success {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 35%, var(--line));
}

.flash.error {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}

.metric-grid.small {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric-card {
  min-height: 104px;
  padding: 18px 18px 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.inline-metric {
  min-height: 88px;
  padding: 14px;
  background: var(--panel-soft);
  box-shadow: none;
}

.metric-card span {
  color: var(--muted);
  font-weight: 600;
}

.metric-card strong {
  display: block;
  margin-top: 12px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
}

.metric-card.income strong,
.income-text {
  color: var(--success);
}

.metric-card.expense strong,
.expense-text {
  color: var(--danger);
}

.metric-card.balance strong {
  color: var(--blue);
}

.two-column,
.three-column {
  display: grid;
  gap: 18px;
}

.two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three-column {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card-grid,
.tag-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.tag-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.content-card,
.list-card,
.detail-panel,
.editor-form,
.empty-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.content-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 220px;
  padding: 17px;
}

.card-title-link {
  display: grid;
  gap: 8px;
}

.card-title-link h2 {
  font-size: 19px;
  font-weight: 700;
}

.content-card p,
.list-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.58;
}

.card-actions {
  margin-top: auto;
  flex-wrap: wrap;
}

.item-list {
  display: grid;
  gap: 12px;
}

.list-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 86px;
  padding: 15px;
}

.link-card {
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.link-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--primary) 32%, var(--line));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 14px 30px rgba(0, 0, 0, 0.06);
}

.item-main {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.meta-line,
.detail-footer,
.meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 13px;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--badge-color, var(--primary));
  background: color-mix(in srgb, var(--badge-color, var(--primary)) 10%, transparent);
  font-size: 12px;
  font-weight: 600;
}

.badge.rose {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.badge.green {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent);
}

.filter-bar,
.editor-form {
  margin-bottom: 20px;
  padding: 17px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 11px;
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 88%, var(--bg));
  outline: 0;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.inline-check {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.inline-check input {
  width: 18px;
  min-height: 18px;
}

.inline-check.tight {
  min-height: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.form-grid.five {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.span-2 {
  grid-column: span 2;
}

.form-actions {
  margin-top: 16px;
  flex-wrap: wrap;
}

.compact-form {
  margin-bottom: 18px;
}

.detail-panel {
  padding: 18px;
}

.prose {
  margin: 18px 0;
  white-space: pre-wrap;
  line-height: 1.8;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

.data-table th,
.data-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  background: var(--panel-soft);
}

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

.row-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}

.empty-state.compact {
  padding: 18px;
  box-shadow: none;
}

.segmented-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.segmented-tabs a {
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--panel);
  font-weight: 600;
}

.segmented-tabs a.active {
  color: white;
  border-color: var(--primary);
  background: var(--primary);
}

.todo-card {
  border-left: 4px solid var(--line);
}

.priority-high {
  border-left-color: var(--danger);
}

.priority-medium {
  border-left-color: var(--accent);
}

.priority-low {
  border-left-color: var(--success);
}

.status-completed h2,
.status-completed h3 {
  text-decoration: line-through;
  color: var(--muted);
}

.bar-list,
.trend-list {
  display: grid;
  gap: 14px;
}

.bar-row {
  display: grid;
  gap: 7px;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 64%, transparent);
}

.bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--bar-color, var(--danger));
}

.trend-list {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  min-height: 260px;
}

.trend-row {
  display: grid;
  grid-template-rows: auto 150px auto;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.trend-bars {
  display: flex;
  align-items: end;
  gap: 5px;
  min-height: 150px;
}

.trend-bars i {
  display: block;
  width: 14px;
  min-height: 6px;
  border-radius: 999px 999px 0 0;
}

.income-bar {
  background: var(--success);
}

.expense-bar {
  background: var(--danger);
}

.stat-pack strong {
  margin-top: 7px;
}

.mini-split {
  justify-content: space-between;
  margin-top: 10px;
  font-size: 13px;
}

.inline-edit {
  display: grid;
  gap: 12px;
}

.bottom-nav {
  display: none;
}

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: grid;
  gap: 10px;
}

.toast {
  max-width: 320px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
}

.login-brand p {
  margin: 5px 0 0;
  color: var(--muted);
}

.stack-form {
  display: grid;
  gap: 16px;
}

@media (max-width: 1020px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    grid-template-columns: 1fr auto auto;
  }

  .mobile-brand {
    display: flex;
    grid-column: 1 / -1;
  }

  .mobile-menu {
    display: block;
  }

  .metric-grid,
  .metric-grid.small,
  .two-column,
  .three-column,
  .card-grid,
  .tag-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid.four,
  .form-grid.five {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body {
    padding-bottom: 72px;
  }

  .topbar {
    padding: 12px;
  }

  .content {
    padding: 22px 12px 34px;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-head h1 {
    font-size: 28px;
  }

  .action-row,
  .form-actions,
  .card-actions {
    width: 100%;
  }

  .action-row > *,
  .form-actions > *,
  .card-actions > * {
    flex: 1 1 auto;
  }

  .primary-button,
  .secondary-button,
  .danger-button,
  .ghost-button {
    min-width: 0;
  }

  .metric-grid,
  .metric-grid.small,
  .two-column,
  .three-column,
  .card-grid,
  .tag-grid,
  .form-grid,
  .form-grid.three,
  .form-grid.four,
  .form-grid.five {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .filter-bar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .list-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .row-actions {
    width: 100%;
  }

  .row-actions .icon-button {
    flex: 1 1 38px;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
    box-shadow: none;
  }

  .data-table {
    min-width: 0;
    display: block;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  .data-table td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px;
    border-bottom: 1px solid var(--line);
  }

  .data-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
  }

  .data-table td:last-child {
    border-bottom: 0;
  }

  .trend-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 88%, transparent);
    backdrop-filter: saturate(180%) blur(22px);
  }

  .bottom-nav a {
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    min-height: 60px;
    padding: 6px 2px;
    border-radius: 0;
    font-size: 12px;
    font-weight: 600;
  }

  .toast-root {
    left: 12px;
    right: 12px;
    bottom: 76px;
  }

  .toast {
    max-width: none;
  }
}
