:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --blue: #1769e0;
  --blue-strong: #0f4fb8;
  --green: #11845b;
  --amber: #b76e00;
  --red: #c2413a;
  --shadow: 0 16px 38px rgba(28, 39, 66, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
  padding: 24px 18px;
  background: #101828;
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--blue);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 17px;
}

.brand span {
  margin-top: 3px;
  color: #aab4c5;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 12px;
  color: #e2e8f0;
  font-weight: 650;
}

.nav-group-label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-icon {
  display: inline-grid;
  place-items: center;
  width: 20px;
  color: #8fb8ff;
  font-size: 15px;
}

.nav-chevron {
  color: #8e9aaf;
  font-size: 20px;
  line-height: 1;
  transition: transform 160ms ease;
}

.nav-group.expanded .nav-chevron {
  transform: rotate(90deg);
}

.nav-group-items {
  display: none;
  gap: 3px;
  padding: 2px 0 6px 30px;
}

.nav-group.expanded .nav-group-items {
  display: grid;
}

.nav .nav-item {
  position: relative;
  padding: 9px 12px 9px 16px;
  color: #aeb9ca;
  font-size: 14px;
}

.nav .nav-item::before {
  position: absolute;
  top: 50%;
  left: 3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #526079;
  content: "";
  transform: translateY(-50%);
}

.nav .nav-group-toggle:hover,
.nav .nav-item.active,
.nav .nav-item:hover {
  background: #243147;
  color: #ffffff;
}

.nav .nav-item.active::before {
  background: #5ba2ff;
  box-shadow: 0 0 0 3px rgba(91, 162, 255, 0.18);
}

.side-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid #344054;
  border-radius: 8px;
  background: #182235;
}

.finance-coming-soon {
  padding: 24px;
}

.finance-coming-soon h3 {
  margin: 0 0 8px;
}

.finance-coming-soon p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.side-note span,
.side-note strong {
  display: block;
}

.side-note span {
  color: #aab4c5;
  font-size: 12px;
}

.side-note strong {
  margin-top: 5px;
  font-size: 14px;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar,
.section-head,
.panel-head,
.filters,
.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 6px;
  font-size: 20px;
}

.section-head {
  margin-bottom: 16px;
}

.section-head p,
.panel-head span {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.toolbar {
  display: flex;
  gap: 10px;
}

.primary,
.ghost,
.danger,
.icon-btn {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 14px;
  font-weight: 700;
}

.primary {
  background: var(--blue);
  color: #ffffff;
}

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

.ghost {
  border-color: var(--line);
  background: #ffffff;
  color: var(--text);
}

.danger {
  border-color: #f2c8c5;
  background: #fff6f5;
  color: var(--red);
}

.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 13px;
  background: #ffffff;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.icon-btn {
  width: 38px;
  padding: 0;
  font-size: 24px;
  background: #f1f5f9;
  color: #334155;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.dashboard-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.dashboard-controls label {
  display: grid;
  gap: 6px;
  min-width: 180px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dashboard-controls input,
.dashboard-controls select {
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

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

.metric {
  padding: 18px;
}

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

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.receivable-summary,
.supply-summary,
.quality-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.receivable-summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.receivable-summary-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.receivable-summary-head strong {
  font-size: 18px;
}

.receivable-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.receivable-summary-grid div {
  min-width: 0;
  border: 1px solid #e6edf5;
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.receivable-summary-grid span,
.receivable-summary-card p {
  color: var(--muted);
  font-size: 12px;
}

.receivable-summary-grid strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  font-size: 18px;
}

.receivable-summary-card p {
  margin: 12px 0 0;
}

.split {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
}

.panel {
  overflow: hidden;
}

.panel-head,
.filters {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.table-panel {
  min-height: 480px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 800px;
  border-collapse: collapse;
}

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

th {
  color: #475467;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

tr:hover td {
  background: #fbfdff;
}

.filters {
  justify-content: flex-start;
}

input,
select,
textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: #ffffff;
  color: var(--text);
}

input[type="search"] {
  width: 320px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 800;
}

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

.tag.blue {
  background: #e9f1ff;
  color: var(--blue);
}

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

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

.row-actions {
  display: flex;
  gap: 8px;
}

.row-actions button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.alert-list {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.alert-item {
  border: 1px solid #ffd8a8;
  border-radius: 8px;
  padding: 12px;
  background: #fff8eb;
}

.alert-item strong,
.alert-item span {
  display: block;
}

.finance-controls {
  align-items: end;
}

.finance-controls label {
  min-width: 150px;
}

.finance-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.85fr);
  gap: 16px;
  margin-top: 16px;
}

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

.finance-trend-panel .panel-head strong {
  color: var(--primary);
  font-size: 20px;
}

.finance-chart {
  min-height: 280px;
  padding: 8px 18px 18px;
}

.finance-chart-legend {
  display: flex;
  justify-content: flex-end;
  gap: 18px;
  padding: 8px 20px 0;
  color: var(--muted);
  font-size: 12px;
}

.finance-chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.finance-chart-legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.finance-chart-legend i.income { background: #14b8a6; }
.finance-chart-legend i.expense { background: #2563eb; }

.finance-chart svg {
  width: 100%;
  height: 260px;
  overflow: visible;
}

.finance-month-bar {
  cursor: pointer;
}

.finance-month-bar rect {
  fill: #dbeafe;
  transition: fill 0.18s ease;
}

.finance-month-bar rect.income-bar { fill: #99f6e4; }
.finance-month-bar rect.expense-bar { fill: #bfdbfe; }

.finance-month-bar:hover rect.income-bar,
.finance-month-bar.is-active rect.income-bar { fill: #14b8a6; }

.finance-month-bar:hover rect.expense-bar,
.finance-month-bar.is-active rect.expense-bar { fill: #2563eb; }

.finance-month-bar:hover rect,
.finance-month-bar.is-active rect {
  fill: var(--primary);
}

.finance-month-bar text {
  fill: var(--muted);
  font-size: 11px;
  text-anchor: middle;
}

.finance-month-bar .amount-label {
  fill: #344054;
  font-size: 10px;
}

.finance-category-chart {
  display: grid;
  grid-template-columns: 160px 1fr;
  align-items: center;
  gap: 18px;
  padding: 20px;
}

.finance-donut {
  width: 160px;
  height: 160px;
  transform: rotate(-90deg);
}

.finance-donut-bg {
  fill: none;
  stroke: #eef2f6;
  stroke-width: 18;
}

.finance-donut-segment {
  fill: none;
  stroke-width: 18;
}

.finance-legend,
.finance-ranking,
.finance-reconcile {
  display: grid;
  gap: 11px;
  padding: 16px;
}

.finance-legend-item,
.finance-rank-item,
.finance-reconcile-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.finance-legend-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.finance-legend-label i {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--legend-color, #2563eb);
}

.finance-legend-label i[data-finance-color="0"] { --legend-color: #2563eb; }
.finance-legend-label i[data-finance-color="1"] { --legend-color: #14b8a6; }
.finance-legend-label i[data-finance-color="2"] { --legend-color: #f59e0b; }
.finance-legend-label i[data-finance-color="3"] { --legend-color: #8b5cf6; }
.finance-legend-label i[data-finance-color="4"] { --legend-color: #ef4444; }
.finance-legend-label i[data-finance-color="5"] { --legend-color: #06b6d4; }
.finance-legend-label i[data-finance-color="6"] { --legend-color: #84cc16; }
.finance-legend-label i[data-finance-color="7"] { --legend-color: #f97316; }
.finance-legend-label i[data-finance-color="8"] { --legend-color: #64748b; }

.finance-legend-item strong,
.finance-rank-item strong,
.finance-reconcile-item strong {
  font-size: 13px;
}

.finance-legend-item span,
.finance-rank-item span,
.finance-reconcile-item span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.finance-rank-track {
  grid-column: 1 / -1;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2f6;
}

.finance-rank-track b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #60a5fa);
}

.finance-rank-item progress {
  grid-column: 1 / -1;
  width: 100%;
  height: 7px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #eef2f6;
}

.finance-rank-item progress::-webkit-progress-bar {
  border-radius: 999px;
  background: #eef2f6;
}

.finance-rank-item progress::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #60a5fa);
}

.finance-rank-item progress::-moz-progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #60a5fa);
}

.finance-reconcile-item small {
  grid-column: 1 / -1;
  color: var(--muted);
}

.finance-reconcile-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8fafc;
}

.alert-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.roadmap-card {
  padding: 18px;
}

.roadmap-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.roadmap-card ul {
  margin: 0;
  padding-left: 18px;
  color: #475467;
}

.roadmap-card li + li {
  margin-top: 7px;
}

dialog {
  width: min(760px, calc(100vw - 48px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.44);
}

.dialog-card {
  padding: 20px;
}

.dialog-head {
  margin-bottom: 16px;
}

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

.field {
  display: grid;
  gap: 7px;
}

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

.field label {
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.dialog-actions {
  margin: 20px 0 0;
  padding: 16px 0 0;
  border-top: 1px solid var(--line);
}

.empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #101828, #1f3b63);
}

.login-screen.hidden {
  display: none;
}

.login-card {
  width: 390px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 26px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.login-brand {
  margin-bottom: 22px;
  color: var(--text);
}

.login-card h2 {
  margin-bottom: 18px;
}

.login-card .field {
  margin-bottom: 14px;
}

.login-card .primary {
  width: 100%;
  margin-top: 4px;
}

.login-error {
  min-height: 20px;
  margin: 0 0 10px;
  color: var(--red);
  font-size: 13px;
}

.login-hint {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.is-readonly [data-open-form],
.is-readonly [data-edit],
.is-readonly [data-delete],
.is-readonly #resetBtn,
.is-readonly #importBtn {
  display: none;
}

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .metric-grid,
  .split,
  .finance-grid,
  .roadmap,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .section-head,
  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  input[type="search"] {
    width: 100%;
  }

  .finance-category-chart {
    grid-template-columns: 1fr;
    justify-items: center;
  }
}
