:root {
  --ink: #152436;
  --muted: #64748b;
  --line: #d8e0e7;
  --paper: #f7f4ee;
  --surface: #ffffff;
  --navy: #12324a;
  --teal: #287f78;
  --mint: #e6f3ef;
  --amber: #c9892b;
  --amber-soft: #fff4db;
  --green: #347b45;
  --green-soft: #e6f4ea;
  --red: #b83a35;
  --red-soft: #fde8e6;
  --blue-soft: #e8f1fb;
  --shadow: 0 12px 28px rgba(18, 50, 74, 0.08);
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    linear-gradient(180deg, #f4efe5 0, #f8f7f3 260px, #f6f7f8 100%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding-bottom: calc(78px + var(--safe-bottom));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 12px;
  background: rgba(247, 244, 238, 0.94);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(216, 224, 231, 0.8);
}

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  box-shadow: 0 5px 16px rgba(18, 50, 74, 0.16);
}

.brand-name {
  font-weight: 760;
  font-size: 17px;
  line-height: 1.2;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.month-select,
.field select,
.field input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.month-select {
  flex: 0 0 116px;
  height: 38px;
  padding: 0 10px;
  color: var(--navy);
  font-weight: 650;
}

.app-main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 14px 14px 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  gap: 12px;
  margin: 2px 0 12px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 760;
  line-height: 1.2;
}

.panel,
.status-panel,
.entry-form {
  background: var(--surface);
  border: 1px solid rgba(216, 224, 231, 0.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
  margin: 12px 0;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 15px;
  font-weight: 760;
}

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

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

.kpi {
  min-height: 96px;
  padding: 13px;
  background: var(--surface);
  border: 1px solid rgba(216, 224, 231, 0.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.kpi-value {
  margin-top: 8px;
  font-size: clamp(21px, 7vw, 28px);
  font-weight: 780;
  line-height: 1.04;
  overflow-wrap: anywhere;
}

.kpi-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.warning {
  color: #8a5a00;
}

.status-panel {
  margin: 12px 0;
  padding: 14px;
  display: grid;
  gap: 10px;
  background: linear-gradient(135deg, #12324a 0%, #1b5e66 100%);
  color: #fff;
}

.status-panel .status-title {
  font-size: 15px;
  font-weight: 760;
}

.status-panel .status-text {
  font-size: 20px;
  font-weight: 760;
  line-height: 1.28;
}

.status-panel .status-detail {
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  line-height: 1.45;
}

.split-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

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

.bar-row {
  display: grid;
  grid-template-columns: minmax(74px, 1fr) minmax(0, 2.1fr) auto;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.bar-track {
  height: 10px;
  background: #edf2f6;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 3px;
  border-radius: 999px;
  background: var(--teal);
}

.bar-value {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 54px;
}

.metric-stack {
  display: grid;
  gap: 10px;
}

.metric-line {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.metric-line:last-child {
  border-bottom: 0;
}

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

.metric-value {
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.sku-list {
  display: grid;
  gap: 10px;
}

.sku-card {
  padding: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sku-card-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.sku-name {
  font-weight: 760;
  line-height: 1.25;
}

.sku-id {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 720;
  white-space: nowrap;
}

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

.pill.watch {
  color: #7a540c;
  background: var(--amber-soft);
}

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

.pill.neutral {
  color: var(--navy);
  background: var(--blue-soft);
}

.sku-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.small-metric {
  padding: 9px;
  background: #f8fafb;
  border-radius: 7px;
}

.small-label {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.small-value {
  margin-top: 5px;
  font-weight: 760;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.sku-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(42px, 1fr));
  align-items: end;
  min-height: 170px;
  gap: 8px;
  padding-top: 10px;
}

.trend-col {
  display: grid;
  align-items: end;
  gap: 5px;
  min-width: 0;
}

.trend-bars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 3px;
  height: 112px;
}

.trend-bar {
  border-radius: 6px 6px 2px 2px;
  min-height: 2px;
  background: var(--teal);
}

.trend-bar.profit {
  background: var(--amber);
}

.trend-label {
  color: var(--muted);
  font-size: 10px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry-form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.entry-form.collapsed {
  display: none;
}

.entry-form:not(.collapsed) {
  display: grid;
}

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

.quick-chip {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafb;
  color: var(--ink);
  font-weight: 680;
  font-size: 13px;
}

.quick-chip.active {
  border-color: var(--teal);
  background: var(--mint);
  color: var(--teal);
}

.field,
.field-row {
  min-width: 0;
}

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

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.field input,
.field select {
  width: 100%;
  height: 46px;
  padding: 0 12px;
}

.field input:focus,
.field select:focus,
.month-select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(40, 127, 120, 0.12);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button-row,
.button-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

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

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button,
.file-button {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 13px;
  font-weight: 720;
  text-decoration: none;
}

.primary-button {
  background: var(--navy);
  color: #fff;
}

.secondary-button {
  background: var(--mint);
  color: var(--teal);
  border-color: #bddbd3;
}

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

.danger-button {
  background: var(--red-soft);
  color: var(--red);
  border-color: #f0c5c1;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: var(--navy);
  color: #fff;
}

.full-width {
  width: 100%;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.transaction-list {
  display: grid;
  gap: 8px;
}

.transaction-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.transaction-row:last-child {
  border-bottom: 0;
}

.transaction-title {
  font-weight: 720;
  line-height: 1.25;
}

.transaction-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.transaction-amount {
  font-weight: 760;
  text-align: right;
  white-space: nowrap;
}

.mini-delete {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--red);
  background: #fff;
}

.cash-table {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.cash-table table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 13px;
}

.cash-table th,
.cash-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cash-table th:first-child,
.cash-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface);
}

.cash-table th {
  background: var(--navy);
  color: #fff;
  font-weight: 720;
}

.cash-table th:first-child {
  background: var(--navy);
}

.calc-results {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.calc-result-main {
  padding: 15px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #1b5e66, #12324a);
  color: #fff;
  box-shadow: var(--shadow);
}

.calc-result-main .label {
  color: rgba(255, 255, 255, 0.76);
  font-size: 12px;
}

.calc-result-main .value {
  margin-top: 8px;
  font-size: 28px;
  font-weight: 780;
}

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

.version-line {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
  padding: 7px 6px calc(7px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid rgba(216, 224, 231, 0.9);
  backdrop-filter: blur(16px);
}

.nav-button {
  min-width: 0;
  min-height: 55px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  gap: 2px;
}

.nav-button span {
  font-size: 19px;
  line-height: 1;
}

.nav-button b {
  font-size: 11px;
  font-weight: 700;
}

.nav-button.active {
  color: var(--teal);
  background: var(--mint);
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(88px + var(--safe-bottom));
  z-index: 40;
  display: none;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 14px;
}

.toast.show {
  display: block;
}

@media (min-width: 720px) {
  .app-header {
    padding-left: 24px;
    padding-right: 24px;
  }

  .app-main {
    padding-left: 24px;
    padding-right: 24px;
  }

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

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

  .split-layout {
    grid-template-columns: 1.25fr 0.75fr;
    gap: 12px;
  }

  .quick-actions {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

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

  .sku-list.compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .entry-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
  }

  .entry-form .quick-actions,
  .entry-form .full-width,
  .entry-form .panel-title,
  .entry-form .button-row,
  .entry-form > .field:not(.field-row):last-child {
    grid-column: 1 / -1;
  }

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

  .bottom-nav {
    width: min(720px, calc(100% - 40px));
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    bottom: 16px;
    border: 1px solid rgba(216, 224, 231, 0.9);
    border-radius: 18px;
    box-shadow: 0 16px 36px rgba(18, 50, 74, 0.12);
    padding: 7px;
  }

  .toast {
    left: 50%;
    right: auto;
    width: min(520px, calc(100% - 32px));
    transform: translateX(-50%);
  }
}

@media (max-width: 380px) {
  .brand-subtitle {
    display: none;
  }

  .month-select {
    flex-basis: 106px;
  }

  .field-row {
    grid-template-columns: 1fr;
  }

  .button-grid {
    grid-template-columns: 1fr;
  }

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

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