:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2196f3;
  --accent-dark: #1976d2;
  --accent-soft: #f3f4f6;
  --warning: #9a6700;
  --danger: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input { font: inherit; letter-spacing: 0; }

.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar-inner {
  width: 100%;
  padding: 0 28px;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar-leading { display: flex; align-items: center; gap: 12px; }
.menu-toggle, .sidebar-header, .sidebar-backdrop { display: none; }
.brand { font-size: 20px; font-weight: 800; color: var(--ink); }
.brand span { color: var(--accent); }
.brand small { margin-left: 10px; color: var(--muted); font-size: 12px; font-weight: 600; }

.top-actions { display: flex; align-items: center; gap: 12px; }
.top-actions form { margin: 0; }
.account-name { color: var(--muted); }
.refresh-link {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 20px;
  text-decoration: none;
}
.refresh-link:hover { border-color: #c6cbd2; color: var(--ink); background: #f9fafb; }
.refresh-link img { width: 17px; height: 17px; }
.link-button { display: inline-flex; align-items: center; gap: 5px; border: 0; background: transparent; color: var(--danger); cursor: pointer; padding: 8px 4px; }
.link-button img { width: 15px; height: 15px; }

.dashboard-shell {
  min-height: calc(100vh - 63px);
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  background: #fff;
}
.sidebar {
  min-width: 0;
  padding: 24px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.side-nav { position: sticky; top: 24px; display: grid; gap: 7px; }
.nav-item {
  width: 100%;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 15px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { color: var(--ink); background: #f2f5f7; }
.nav-item.is-active { color: var(--ink); border-left-color: transparent; background: var(--accent-soft); font-weight: 800; }
.nav-item:focus-visible { outline: 2px solid rgba(33, 150, 243, .32); outline-offset: 2px; }
.nav-item svg { width: 21px; height: 21px; flex: 0 0 21px; }
.content-shell { min-width: 0; width: 100%; padding: 34px 40px 48px; background: #fff; }
.view-panel[hidden] { display: none; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
h1 { margin: 0; font-size: 26px; line-height: 1.25; }
.updated { margin: 0; color: var(--muted); font-size: 12px; }

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.metric {
  min-width: 0;
  min-height: 134px;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(17, 24, 39, .06);
}
.metric span { display: block; margin-bottom: 8px; color: var(--muted); }
.metric strong { display: block; overflow-wrap: anywhere; font-size: 25px; line-height: 1.2; }
.metric.total strong { color: var(--accent); }

.trend-panel {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(17, 24, 39, .06);
}
.trend-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.trend-heading h2 { margin: 0; font-size: 17px; }
.trend-heading p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.trend-controls {
  flex: 0 0 auto;
  display: inline-flex;
  gap: 8px;
}
.trend-mode {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid #cfd6df;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
.trend-mode:hover { background: #f8fafc; }
.trend-mode.is-active { border-color: #2f7de1; background: #2f7de1; color: #fff; }
.trend-mode:focus-visible { outline: 2px solid rgba(47, 125, 225, .3); outline-offset: 2px; }
.trend-chart-wrap {
  position: relative;
  width: 100%;
  height: 360px;
  margin-top: 26px;
}
.trend-chart-wrap canvas { width: 100% !important; height: 100% !important; }

.data-section { margin-top: 0; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 10px; }
.section-heading h2 { margin: 0; font-size: 17px; }
.section-heading span { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 1px 2px rgba(17, 24, 39, .05); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); background: #fafafa; font-size: 12px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafafa; }
td small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.card-mark, .amount { font-weight: 700; }
.empty { padding: 32px; color: var(--muted); text-align: center; }
.status { display: inline-block; padding: 3px 7px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.status-ok { color: #1565c0; background: #e3f2fd; }
.status-warn { color: var(--warning); background: #fff4d6; }
.status-bad { color: var(--danger); background: #feeceb; }
.status-neutral { color: #4e5b67; background: #edf0f3; }
.pagination {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
}
.pagination-summary { color: var(--muted); font-size: 12px; }
.pagination-buttons { display: flex; align-items: center; gap: 6px; }
.pagination-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.pagination-button:hover:not(:disabled):not(.is-active) { border-color: #b8c0ca; background: #f8fafc; }
.pagination-button.is-active { border-color: var(--accent); background: var(--accent); color: #fff; }
.pagination-button:disabled { color: #aeb6c0; background: #f6f7f8; cursor: not-allowed; }
.pagination-button:focus-visible { outline: 2px solid rgba(33, 150, 243, .28); outline-offset: 2px; }
.pagination-arrow { font-size: 17px; }
.pagination-ellipsis { width: 24px; color: var(--muted); text-align: center; }

.alert { margin-bottom: 16px; padding: 11px 13px; border: 1px solid; border-radius: 4px; }
.alert-error { color: #8f1d15; border-color: #f2b8b5; background: #fff1f0; }
.alert-success { color: #155d32; border-color: #a7d7b8; background: #f0faf4; }

.open-card-workspace {
  display: grid;
  grid-template-columns: minmax(0, 620px) minmax(260px, 360px);
  gap: 20px;
  align-items: start;
}
.open-card-form,
.open-card-summary {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(17, 24, 39, .06);
}
.form-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.form-heading h2, .open-card-summary h2 { margin: 0; font-size: 17px; }
.form-heading span { color: var(--muted); font-size: 12px; font-weight: 700; }
.open-card-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 9px 16px; }
.open-card-fields label { color: var(--ink); font-size: 13px; font-weight: 700; }
.open-card-fields input {
  width: 100%;
  height: 48px;
  padding: 0 13px;
  border: 1px solid #d8e0e6;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
.open-card-fields input:focus { outline: 2px solid rgba(33, 150, 243, .18); border-color: var(--accent); }
.currency-input { position: relative; }
.currency-input span { position: absolute; top: 50%; left: 14px; transform: translateY(-50%); color: var(--muted); font-weight: 700; }
.currency-input input { padding-left: 30px; }
.open-card-total {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 22px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafafa;
}
.open-card-total span { color: var(--muted); }
.open-card-total strong { font-size: 18px; }
.primary-action {
  width: 100%;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.primary-action:hover { background: var(--accent-dark); }
.primary-action:disabled { background: #9fcdf3; cursor: wait; }
.primary-action:focus-visible { outline: 2px solid rgba(33, 150, 243, .35); outline-offset: 2px; }
.primary-action svg { width: 18px; height: 18px; }
.form-warning { margin: 12px 0 0; color: var(--danger); font-size: 12px; text-align: center; }
.open-card-summary dl { margin: 18px 0 0; }
.open-card-summary dl div { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.open-card-summary dl div:last-child { border-bottom: 0; }
.open-card-summary dt { color: var(--muted); }
.open-card-summary dd { margin: 0; font-weight: 800; }

.login-page { min-height: 100vh; background: var(--surface); }
.login-layout { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(520px, 1fr); }
.login-showcase {
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 56px clamp(34px, 4vw, 76px);
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: #fff;
}
.showcase-inner { width: min(760px, 100%); }
.preview-scene { position: relative; padding: 22px 0 82px 72px; }
.preview-desktop {
  width: 100%;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(17, 24, 39, .11);
}
.preview-phone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: clamp(116px, 20%, 148px);
  display: block;
  border: 5px solid #26343c;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 16px 32px rgba(17, 24, 39, .16);
}
.showcase-copy { margin-top: 26px; text-align: center; }
.showcase-copy h2 { margin: 0; font-size: 21px; }
.showcase-copy p { margin: 12px 0 0; color: var(--muted); }
.login-entry { min-width: 0; display: grid; place-items: start center; padding: 80px clamp(48px, 7vw, 120px) 56px; background: var(--surface); }
.login-panel { width: min(440px, 100%); }
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 68px; }
.login-logo { width: 46px; height: 46px; border-radius: 6px; object-fit: cover; }
.login-heading { margin-bottom: 32px; }
.login-panel h1 { margin: 0; font-size: 28px; line-height: 1.3; }
.login-heading p { margin: 10px 0 0; color: var(--muted); }
.login-panel .alert { margin-bottom: 20px; }
.login-form { display: grid; gap: 10px; }
.login-form label { margin-top: 5px; color: var(--ink); font-size: 13px; font-weight: 700; }
.login-form input {
  width: 100%;
  height: 50px;
  margin-bottom: 8px;
  border: 1px solid #d8e0e6;
  border-radius: 6px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
}
.login-form input::placeholder { color: #929da7; }
.login-form input:focus { outline: 2px solid rgba(33, 150, 243, .18); border-color: var(--accent); background: #fff; }
.password-field { position: relative; }
.password-field input { padding-right: 50px; }
.password-toggle {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.password-toggle:hover { color: var(--ink); background: #f3f4f6; }
.password-toggle:focus-visible { outline: 2px solid rgba(33, 150, 243, .28); }
.password-toggle svg { width: 19px; height: 19px; }
.password-toggle .eye-off { display: none; }
.password-toggle.is-visible .eye-open { display: none; }
.password-toggle.is-visible .eye-off { display: block; }
.login-form .login-submit {
  height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 18px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.login-submit img { width: 17px; height: 17px; filter: brightness(0) invert(1); }
.login-submit:hover { background: var(--accent-dark); }
.login-submit:focus-visible { outline: 2px solid rgba(33, 150, 243, .35); outline-offset: 2px; }

@media (max-width: 820px) {
  body.sidebar-open { overflow: hidden; }
  .topbar { position: sticky; top: 0; z-index: 30; }
  .menu-toggle {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
  }
  .menu-toggle:hover { background: #f8fafc; }
  .menu-toggle:focus-visible { outline: 2px solid rgba(33, 150, 243, .3); outline-offset: 2px; }
  .menu-toggle svg { width: 21px; height: 21px; }
  .dashboard-shell { display: block; }
  .sidebar-backdrop {
    position: fixed;
    z-index: 40;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    padding: 0;
    border: 0;
    background: rgba(17, 24, 39, .64);
  }
  .sidebar-backdrop[hidden] { display: none; }
  .sidebar {
    position: fixed;
    z-index: 50;
    inset: 0 auto 0 0;
    width: min(78vw, 340px);
    height: 100dvh;
    padding: 0 16px 24px;
    overflow-y: auto;
    border-right: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 18px 0 40px rgba(17, 24, 39, .16);
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform 180ms ease, visibility 180ms ease;
  }
  .sidebar.is-open { transform: translateX(0); visibility: visible; }
  .sidebar-header {
    min-height: 82px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--line);
  }
  .drawer-brand { font-size: 22px; font-weight: 800; }
  .drawer-brand small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; font-weight: 600; }
  .sidebar-close {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
  }
  .sidebar-close:hover { color: var(--ink); background: #f3f4f6; }
  .sidebar-close:focus-visible { outline: 2px solid rgba(33, 150, 243, .3); }
  .sidebar-close svg { width: 23px; height: 23px; }
  .side-nav { position: static; grid-template-columns: 1fr; gap: 8px; }
  .nav-item { height: 54px; justify-content: flex-start; padding: 0 15px; border-left: 3px solid transparent; font-size: 15px; }
  .nav-item.is-active { border-left-color: var(--accent); }
  .nav-item svg { width: 21px; height: 21px; flex-basis: 21px; }
  .content-shell { padding: 28px 24px 44px; }
  .open-card-workspace { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
  .login-layout { display: block; }
  .login-showcase { display: none; }
  .login-entry { min-height: 100vh; padding: 48px 28px; }
}

@media (max-width: 680px) {
  .topbar-inner { padding: 0 12px; }
  .account-name, .brand small { display: none; }
  .brand { font-size: 18px; }
  .content-shell { padding: 24px 12px 40px; }
  .page-heading { align-items: start; flex-direction: column; gap: 8px; }
  h1 { font-size: 22px; }
  .metrics { grid-template-columns: 1fr; }
  .metric, .metric:last-child { min-height: 0; padding: 17px 18px; border: 1px solid var(--line); }
  .metric strong { font-size: 22px; }
  .trend-panel { padding: 18px 14px; }
  .trend-heading { align-items: stretch; flex-direction: column; gap: 16px; }
  .trend-controls { width: 100%; }
  .trend-mode { min-width: 0; flex: 1; padding: 0 8px; }
  .trend-chart-wrap { height: 300px; margin-top: 22px; }
  .login-entry { place-items: start center; padding: 32px 20px; }
  .login-brand { margin-bottom: 52px; }
  .login-panel h1 { font-size: 24px; }
  .table-wrap { overflow: visible; border: 0; background: transparent; }
  table { min-width: 0; }
  thead { display: none; }
  tbody { display: grid; gap: 10px; }
  tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; box-shadow: 0 1px 2px rgba(17, 24, 39, .05); }
  tbody tr:hover { background: var(--surface); }
  tbody td { min-width: 0; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: normal; overflow-wrap: anywhere; }
  tbody td::before { content: attr(data-label); display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
  tbody td:nth-last-child(-n + 2) { border-bottom: 0; }
  tbody .empty { grid-column: 1 / -1; border-bottom: 0; }
  tbody .empty::before { display: none; }
  .pagination { align-items: flex-start; flex-direction: column; }
  .pagination-buttons { width: 100%; justify-content: flex-end; flex-wrap: wrap; }
  .open-card-form, .open-card-summary { padding: 18px 14px; }
  .open-card-fields { grid-template-columns: 1fr; }
}

@media (max-width: 390px) {
  .sidebar { width: min(80vw, 320px); }
}
