:root {
  --ink: #111827;
  --muted: #6b7280;
  --line: #d1d5db;
  --soft: #f3f4f6;
  --paper: #ffffff;
  --input: #fff7cc;
  --adjust: #ffe4c7;
  --danger: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f4f6f9;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 20px auto 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 15px;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.panel-hint {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.role-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--soft);
}

.role-switch button {
  border: 0;
  padding: 9px 14px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.role-switch button.active {
  background: var(--ink);
  color: #fff;
}

.view {
  display: none;
  margin-top: 14px;
}

.view.active {
  display: block;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 12px;
  overflow: hidden;
}

.panel-title {
  min-height: 46px;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #f9fafb;
  border-bottom: 1px solid var(--line);
}

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

button {
  border: 1px solid var(--ink);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
}

.ghost-btn {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.form-grid,
.cost-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

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

label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-weight: 700;
}

input,
select {
  width: 100%;
  border: 1px solid #b8c0cc;
  border-radius: 6px;
  padding: 8px 9px;
  background: #fff;
  color: var(--ink);
}

input[type="number"],
input[type="month"],
.producer-input {
  background: var(--input);
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.25fr 1.25fr 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.metric {
  min-height: 72px;
  padding: 14px;
  display: grid;
  align-content: center;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.metric strong {
  font-size: 22px;
  line-height: 1.1;
}

.metric.primary strong {
  color: var(--danger);
}

.metric.primary {
  border-color: #f2b8b8;
  background: #fff7f7;
}

.table-wrap {
  overflow: auto;
}

.table-wrap.tall {
  max-height: 560px;
}

.table-wrap.small {
  max-height: 370px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--ink);
  color: #fff;
  padding: 8px;
  border: 1px solid var(--ink);
  text-align: center;
}

.data-table td {
  padding: 5px 8px;
  border: 1px solid var(--line);
  background: #fff;
  vertical-align: middle;
}

.data-table input,
.data-table select {
  border: 0;
  border-radius: 0;
  min-height: 32px;
  padding: 4px 6px;
  background: transparent;
}

.data-table td.editable {
  background: #fff9dc;
}

.name-cell input {
  font-weight: 700;
}

.data-table input:focus,
.data-table select:focus,
input:focus {
  outline: 2px solid #93c5fd;
  outline-offset: -1px;
  background: #ffffff;
}

.data-table td.adjust {
  background: var(--adjust);
}

.money,
.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.action-col {
  width: 72px;
}

.row-action {
  width: 100%;
  border-color: #e5e7eb;
  background: #fff;
  color: #991b1b;
  padding: 5px 8px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
  gap: 14px;
}

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

.project-list {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.project-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

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

@media (max-width: 860px) {
  .topbar,
  .project-item {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .cost-grid,
  .summary-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }
}
