.sync-status {
  font-size: 12px;
  color: #667085;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  align-self: center;
  transition: color 0.2s, background 0.2s;
}
.sync-status[data-state="saving"] {
  color: #2563eb;
  background: #eff6ff;
}
.sync-status[data-state="saved"] {
  color: #0f8f64;
  background: #e9f8f2;
}
.sync-status[data-state="error"] {
  color: #c83f3f;
  background: #fff0f0;
}
.sync-status[data-state="offline"] {
  color: #c77808;
  background: #fff5df;
}

:root {
  color-scheme: light;
  --bg: #f7f7f5;
  --panel: #ffffff;
  --panel-soft: #fafafa;
  --text: #1f2937;
  --muted: #667085;
  --line: #e5e7eb;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --green: #0f8f64;
  --green-soft: #e9f8f2;
  --red: #c83f3f;
  --red-soft: #fff0f0;
  --amber: #c77808;
  --amber-soft: #fff5df;
  --magenta: #c53d8d;
  --cyan: #168999;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 10px 30px rgba(16, 24, 40, 0.05);
  --radius: 8px;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: #fbfbfa;
  overflow-y: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(229, 231, 235, 0.75);
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb 0%, #14b8a6 100%);
  color: #fff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
}

.brand-mark svg {
  width: 30px;
  height: 30px;
}

.brand-mark path:first-child {
  fill: rgba(255, 255, 255, 0.16);
  stroke: rgba(255, 255, 255, 0.95);
  stroke-width: 2.6;
}

.brand-mark path:not(:first-child) {
  fill: none;
  stroke: #ffffff;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  letter-spacing: 0;
}

.brand p,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
}

.side-section {
  margin-top: 22px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.company-list,
.nav-list {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.company-item,
.nav-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.company-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 9px 8px 9px 11px;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.company-item:hover,
.nav-item:hover {
  background: #f2f4f7;
}

.company-name {
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  overflow: hidden;
  font-weight: 700;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.company-actions {
  display: flex;
  gap: 4px;
  opacity: 1;
}

.icon-action,
.icon-button {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 0;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.icon-action svg,
.icon-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-action:hover,
.icon-button:hover {
  border-color: var(--line);
  background: #ffffff;
  color: var(--text);
}

.company-actions .icon-action {
  background: rgba(255, 255, 255, 0.72);
}

.icon-action.danger:hover {
  border-color: #fecaca;
  background: var(--red-soft);
  color: var(--red);
}

.icon-action.muted:hover {
  color: #475467;
}

.company-item.active,
.nav-item.active {
  border-color: transparent;
  background: #eceff3;
  color: #111827;
}

.nav-list {
  margin-top: 28px;
}

.nav-item {
  padding: 11px 13px;
  color: #344054;
  font-weight: 650;
  transition: background 0.16s ease, color 0.16s ease;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  padding: 20px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 247, 245, 0.92);
  backdrop-filter: blur(8px);
}

.topbar h2 {
  margin-top: 4px;
  font-size: 24px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
}

.segmented {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.segmented button {
  min-width: 58px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
}

.segmented button.active {
  background: #111827;
  color: #fff;
}

.date-input {
  display: flex;
  gap: 6px;
  align-items: center;
  height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.date-input input {
  width: 132px;
  border: 0;
  color: var(--text);
  outline: 0;
}

.primary-button,
.ghost-button,
.danger-button {
  min-height: 42px;
  border-radius: 10px;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  border: 1px solid #111827;
  background: #111827;
  color: #fff;
}

.ghost-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.primary-button:hover {
  background: #0f172a;
}

.ghost-button:hover {
  background: #f9fafb;
}

.danger-button {
  border: 1px solid #f1b6b6;
  background: var(--red-soft);
  color: var(--red);
}

.danger-button.soft {
  background: #fff;
}

.content {
  padding: 24px 28px 38px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.toolbar-left,
.toolbar-right,
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.search-input,
.select-input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0 12px;
  outline: 0;
}

.search-input:focus,
.select-input:focus,
label input:focus,
label select:focus,
label textarea:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

.metric-card,
.panel-card,
.table-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 17px;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.metric-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 34px rgba(16, 24, 40, 0.07);
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-value {
  margin-top: 10px;
  font-size: 30px;
  font-weight: 800;
}

.metric-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.metric-card.income .metric-value {
  color: var(--green);
}

.metric-card.expense .metric-value {
  color: var(--red);
}

.metric-card.profit .metric-value {
  color: var(--blue);
}

.metric-card.advance .metric-value {
  color: var(--amber);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(520px, 0.58fr) minmax(520px, 0.42fr);
  gap: 16px;
  margin-top: 16px;
}

.dashboard-main-grid {
  grid-template-columns: 1fr;
}

.panel-card {
  min-width: 0;
  padding: 18px;
}

.panel-head {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-head h3 {
  margin: 0;
  font-size: 17px;
}

.panel-note {
  color: var(--muted);
  font-size: 12px;
}

.panel-desc {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.chart-wrap {
  position: relative;
  height: 320px;
}

.chart-wrap.small {
  height: 300px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.split-charts {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 16px;
}

.profit-chart {
  grid-column: auto;
  height: 300px;
}

.daily-summary-grid,
.daily-block-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.daily-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.monthly-week-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 4px 12px 0;
  scroll-snap-type: x proximity;
}

.week-block-button {
  flex: 0 0 260px;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  scroll-snap-align: start;
}

.week-block-button .daily-block {
  height: 100%;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.week-block-button:hover .daily-block,
.week-block-button.active .daily-block {
  border-color: #b8d5ff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.1);
  transform: translateY(-1px);
}

.week-days-panel {
  margin-top: 12px;
  border-top: 1px solid #eef2f7;
  padding-top: 12px;
}

.week-days-head {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 10px;
}

.week-days-head strong {
  color: var(--text);
  font-size: 15px;
}

.week-days-head span {
  color: var(--muted);
  font-size: 12px;
}

.week-day-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 2px 4px;
  scroll-snap-type: x proximity;
}

.week-day-strip .daily-block {
  flex: 0 0 200px;
  min-height: 138px;
  scroll-snap-align: start;
}

.daily-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.day-drilldown {
  min-width: 0;
}

.day-drilldown summary {
  display: block;
  cursor: pointer;
  list-style: none;
}

.day-drilldown summary::-webkit-details-marker {
  display: none;
}

.day-drilldown[open] {
  grid-column: 1 / -1;
}

.day-drilldown[open] summary {
  max-width: 240px;
  margin-bottom: 12px;
}

.day-drilldown[open] .daily-focus-card {
  margin-top: 0;
}

.daily-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 4px 12px 0;
  scroll-snap-type: x proximity;
}

.daily-strip .daily-block {
  flex: 0 0 238px;
  scroll-snap-align: start;
}

.daily-strip .day-drilldown {
  flex: 0 0 238px;
  scroll-snap-align: start;
}

.daily-strip .day-drilldown[open] {
  flex-basis: 100%;
}

.daily-strip-detail {
  margin-top: 12px;
}

.daily-strip-detail .daily-block {
  flex-basis: 190px;
}

.daily-detail-toggle {
  margin-top: 14px;
  border-top: 1px solid #eef2f7;
  padding-top: 12px;
}

.daily-detail-toggle summary {
  display: flex;
  width: fit-content;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  border: 1px solid #d7e2f0;
  border-radius: 999px;
  background: #ffffff;
  padding: 7px 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  list-style: none;
}

.daily-detail-toggle summary::before {
  content: "›";
  display: inline-grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 16px;
  line-height: 1;
  transition: transform 0.16s ease;
}

.daily-detail-toggle[open] summary::before {
  transform: rotate(90deg);
}

.daily-detail-toggle summary::-webkit-details-marker {
  display: none;
}

.daily-detail-toggle summary span {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 500;
}

.daily-block-grid {
  padding-right: 4px;
}

.daily-block {
  min-height: 168px;
  border: 1px solid #edf0f4;
  border-radius: 12px;
  background: #fbfcfe;
  padding: 15px;
}

.daily-block.compact {
  min-height: 138px;
  padding: 12px;
}

.daily-block.has-data {
  border-color: #d7e2f0;
  background: #ffffff;
}

.daily-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.daily-block-head small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.daily-block-head strong {
  font-size: 18px;
}

.daily-block-head span {
  color: var(--muted);
  font-size: 12px;
}

.daily-bar-row {
  display: grid;
  grid-template-columns: 36px minmax(90px, 1fr) 58px;
  gap: 9px;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.daily-bar-row b {
  color: var(--text);
  font-size: 12px;
  text-align: right;
}

.daily-bar-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2f7;
}

.daily-bar-track i {
  display: block;
  height: 100%;
  min-width: 0;
  border-radius: inherit;
}

.daily-focus-card {
  width: 100%;
  min-height: 250px;
  border: 1px solid #d7e2f0;
  border-radius: 12px;
  background: #ffffff;
  padding: 20px;
}

.daily-focus-card.compact {
  min-height: 220px;
  padding: 18px;
}

.daily-focus-head {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}

.daily-focus-head strong {
  display: block;
  color: var(--text);
  font-size: 28px;
}

.daily-focus-head span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.daily-focus-head b {
  font-size: 26px;
  white-space: nowrap;
}

.daily-focus-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.daily-focus-metrics div {
  border: 1px solid #edf0f4;
  border-radius: 10px;
  background: #fbfcfe;
  padding: 12px;
}

.daily-focus-metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.daily-focus-metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

.daily-focus-bars .daily-bar-row {
  grid-template-columns: 42px minmax(120px, 1fr) 76px;
  margin-top: 14px;
  font-size: 13px;
}

.daily-focus-bars .daily-bar-track {
  height: 12px;
}

.income-fill {
  background: var(--green);
}

.expense-fill {
  background: var(--red);
}

.profit-fill-positive {
  background: var(--blue);
}

.profit-fill-negative {
  background: var(--red);
}

.profit-text-positive {
  color: var(--blue) !important;
}

.profit-text-negative {
  color: var(--red) !important;
}

.maintenance-panel {
  margin-top: 16px;
}

.maintenance-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.table-card {
  margin-top: 16px;
  overflow: auto;
}

.table-card .panel-head {
  padding: 18px 18px 0;
  margin-bottom: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid #eef0f3;
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.action-table th:last-child,
.action-table td:last-child {
  position: sticky;
  right: 0;
  z-index: 1;
  background: #ffffff;
  box-shadow: -10px 0 18px rgba(255, 255, 255, 0.88);
}

.action-table th:last-child {
  z-index: 2;
  background: var(--panel-soft);
}

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

tbody tr {
  transition: background 0.14s ease;
}

tbody tr:hover {
  background: #fafafa;
}

td {
  font-size: 14px;
}

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

.amount-income {
  color: var(--green);
  font-weight: 800;
}

.amount-expense {
  color: var(--red);
  font-weight: 800;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 650;
}

.advance-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 150px;
  max-width: 260px;
}

.advance-note-pill {
  max-width: 100%;
  background: #fff7ed;
  color: #9a5b13;
  line-height: 1.4;
  white-space: normal;
}

.tag.green {
  background: var(--green-soft);
  color: var(--green);
}

.tag.red {
  background: var(--red-soft);
  color: var(--red);
}

.tag.amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.row-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 700;
}

.table-action {
  width: 32px;
  height: 32px;
}

.restore-button {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  gap: 6px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--blue);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.restore-button:hover {
  border-color: #93c5fd;
  background: #dbeafe;
  transform: translateY(-1px);
}

.restore-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.trash-panel {
  overflow: auto;
}

td .icon-action {
  color: #667085;
}

.empty-state {
  display: grid;
  min-height: 240px;
  place-items: center;
  border: 1px dashed #c9d3e1;
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  text-align: center;
}

.empty-state.compact {
  min-height: 220px;
}

.modal {
  width: min(720px, calc(100vw - 28px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(18, 27, 43, 0.22);
}

.modal.small {
  width: min(440px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(17, 24, 39, 0.42);
}

.modal-panel {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.modal-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
}

.modal-head h3 {
  margin: 4px 0 0;
  font-size: 20px;
}

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

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

label input,
label select,
label textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
  outline: 0;
}

label textarea {
  resize: vertical;
}

.wide-field {
  grid-column: 1 / -1;
}

.custom-category-field,
.advance-only {
  display: none;
}

.custom-category-field.show,
.advance-only.show {
  display: grid;
}

.export-date-grid {
  align-items: end;
}

[data-export-field][hidden] {
  display: none;
}

.export-range-hint {
  margin: -4px 0 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.export-hint {
  margin: 0;
  border: 1px solid #b8d5ff;
  border-radius: var(--radius);
  background: var(--blue-soft);
  color: #285f9d;
  padding: 10px 12px;
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: 360px;
  transform: translateY(18px);
  border: 1px solid #b8d5ff;
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  padding: 13px 15px;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

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

  .metric-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .dashboard-grid,
  .split-charts {
    grid-template-columns: 1fr;
  }

  .dashboard-main-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-main-grid .split-charts {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
  }
}

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

  .sidebar {
    position: relative;
    height: auto;
  }

  .topbar {
    position: relative;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .toolbar,
  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }

  .segmented,
  .primary-button,
  .ghost-button,
  .danger-button,
  .date-input,
  .search-input,
  .select-input {
    width: 100%;
  }

  .segmented button {
    flex: 1;
    min-width: 0;
  }

  .metric-grid,
  .form-grid,
  .dashboard-main-grid .split-charts {
    grid-template-columns: 1fr;
  }

  .table-card {
    overflow-x: auto;
  }

  table {
    min-width: 760px;
  }
}
