:root {
  --bg: #0b1020;
  --card: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f4f7ff;
  --muted: #c2cbe1;
  --primary: #5f7cff;
  --primary-dark: #4f6af0;
  --warn: #f3af2f;
  --danger: #ff6b7b;
  --success: #2acc83;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #1b2450 0%, #0f1634 42%, #090d1d 100%);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 19px;
}

.app-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 14px 26px;
}

.top-bar {
  padding: 4px 6px 14px;
}

.top-bar h1 {
  margin: 0;
  font-size: 36px;
}

.top-bar p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 21px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 38px rgba(5, 8, 20, 0.45);
  padding: 16px;
  margin-bottom: 12px;
}

.panel h2,
.panel h3 {
  margin: 0 0 12px;
  font-size: 28px;
}

.compact {
  padding-top: 12px;
  padding-bottom: 12px;
}

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

.toolbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.toolbar h2 {
  margin: 0;
  font-size: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-panel {
  padding: 10px;
}

.menu-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.menu-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 999px;
  min-height: 46px;
  padding: 0 16px;
  font-size: 18px;
  cursor: pointer;
}

.menu-btn.active {
  background: linear-gradient(90deg, #5f7cff, #7f5bff);
  border-color: transparent;
}

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

.summary-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.summary-title {
  color: var(--muted);
  font-size: 17px;
}

.summary-value {
  margin-top: 6px;
  font-size: 34px;
  font-weight: 700;
}

.adjust-grid {
  margin-top: 12px;
}

.compact-entry-grid label {
  font-size: 16px;
}

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

.grid.compact-entry-grid .wide {
  grid-column: span 2;
}

.entry-card {
  background: linear-gradient(180deg, rgba(95, 124, 255, 0.1), rgba(127, 91, 255, 0.06));
  border: 1px solid rgba(124, 151, 255, 0.34);
  border-radius: 16px;
  padding: 12px;
}

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

.entry-card-head h3 {
  margin: 0;
}

.entry-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: #dbe5ff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
}

.entry-field {
  display: grid;
  gap: 6px;
  min-width: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}

.compact-entry-grid input,
.compact-entry-grid select,
.compact-entry-grid textarea,
.compact-entry-grid .btn {
  min-height: 38px;
  font-size: 15px;
}

.compact-entry-grid input,
.compact-entry-grid select,
.compact-entry-grid textarea {
  width: 100%;
  box-sizing: border-box;
}

.compact-entry-input {
  padding: 6px 8px;
}

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

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

.inline-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.inline-stat {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 13px;
  line-height: 1.4;
}

.inline-stat.ok {
  background: rgba(42, 204, 131, 0.2);
  color: #84ebba;
}

.inline-stat.bad {
  background: rgba(255, 107, 123, 0.2);
  color: #ffb5bf;
}

.date-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.date-switch input[type="date"] {
  min-height: 44px;
  min-width: 170px;
  padding: 8px 10px;
  font-size: 18px;
}

.date-today-btn {
  min-height: 38px;
  padding: 0 10px;
  font-size: 14px;
  border: 1px solid rgba(95, 124, 255, 0.55);
  border-radius: 999px;
  background: rgba(95, 124, 255, 0.22);
  color: #dce4ff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  writing-mode: horizontal-tb;
}

.config-grid {
  display: grid;
  gap: 12px;
}

.config-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.04);
  min-width: 0;
}

.config-panel h4 {
  margin: 0 0 10px;
  font-size: 22px;
}

.action-btn {
  min-height: 40px;
  font-size: 16px;
  padding: 0 10px;
  margin-right: 6px;
  margin-bottom: 6px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  padding: 12px;
}

.modal-card {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #152240;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.modal-card h4 {
  margin: 0 0 10px;
  font-size: 24px;
}

.modal-text {
  margin: 0 0 14px;
  color: var(--muted);
}

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

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 20px;
}

input,
select {
  width: 100%;
  min-height: 50px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 20px;
  color: #f8fbff;
  background: rgba(7, 10, 20, 0.38);
}

textarea {
  width: 100%;
  min-height: 50px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 20px;
  color: #f8fbff;
  background: rgba(7, 10, 20, 0.38);
  resize: vertical;
}

input::placeholder {
  color: #bcc6de;
}

option {
  color: #102040;
  background: #f3f7ff;
}

.btn {
  border: none;
  border-radius: 10px;
  min-height: 50px;
  font-size: 20px;
  padding: 0 16px;
  cursor: pointer;
  max-width: 100%;
}

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

.btn.primary:hover {
  background: var(--primary-dark);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.14);
  color: #f3f7ff;
}

.btn.warn {
  background: rgba(243, 175, 47, 0.2);
  color: #ffd78e;
}

.btn.danger {
  background: rgba(255, 107, 123, 0.2);
  color: var(--danger);
}

.hidden {
  display: none;
}

.hint {
  margin-top: 10px;
  color: var(--muted);
}

.alert {
  margin-bottom: 10px;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 18px;
}

.alert.error {
  background: rgba(255, 107, 123, 0.16);
  color: #ffb5bf;
}

.alert.success {
  background: rgba(42, 204, 131, 0.18);
  color: var(--success);
}

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

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

th,
td {
  border-bottom: 1px solid var(--line);
  text-align: center;
  padding: 10px;
  font-size: 18px;
}

th {
  background: rgba(131, 146, 194, 0.2);
  position: sticky;
  top: 0;
}

.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 16px;
}

.tag.pending {
  background: rgba(243, 175, 47, 0.2);
  color: #ffd48b;
}

.tag.done {
  background: rgba(42, 204, 131, 0.2);
  color: #84ebba;
}

.empty {
  color: var(--muted);
  padding: 14px;
}

.action-wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  max-width: 100%;
}

.inventory-table {
  min-width: 100%;
  table-layout: fixed;
}

.inventory-table th,
.inventory-table td {
  padding: 6px 8px;
  font-size: 14px;
  line-height: 1.2;
}

.inventory-table .product-col {
  width: 140px;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inventory-table .qty-col {
  width: 88px;
  white-space: nowrap;
}

.product-config-table {
  min-width: 0;
  table-layout: fixed;
}

.product-config-table th,
.product-config-table td {
  padding: 6px 8px;
  font-size: 14px;
}

.product-config-table .col-name {
  width: 120px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-config-table .col-price {
  width: 86px;
  white-space: nowrap;
}

.product-config-table .col-wholesale {
  width: 96px;
  white-space: nowrap;
}

.product-config-table .col-charger {
  width: 108px;
  white-space: nowrap;
}

.product-config-table .col-actions {
  width: auto;
}

.party-config-table {
  min-width: 100%;
  table-layout: auto;
}

.party-config-table th,
.party-config-table td {
  white-space: normal;
}

.detail-table {
  width: 100%;
  min-width: 760px;
  table-layout: auto;
}

.detail-table th,
.detail-table td {
  padding: 4px 6px;
  font-size: 13px;
  vertical-align: middle;
  white-space: nowrap;
}

.detail-box {
  overflow-x: auto;
}

.entry-half {
  min-width: 0;
}

.detail-table .col-pay,
.detail-table .col-actions {
  white-space: normal;
}

.detail-table .col-pay .mini-action,
.detail-table .col-actions .mini-action {
  min-height: 24px;
  font-size: 12px;
  padding: 0 6px;
  width: 100%;
}

.note-mini {
  margin-left: 3px;
  border: 1px solid rgba(255, 184, 77, 0.7);
  border-radius: 999px;
  padding: 0 4px;
  min-height: 0;
  font-size: 10px;
  line-height: 1.1;
  color: #ffe6bf;
  background: rgba(255, 184, 77, 0.22);
}

.note-mini.has-note {
  box-shadow: 0 0 0 1px rgba(255, 184, 77, 0.16) inset;
}

.pay-mini {
  display: inline-block;
  margin-left: 3px;
  border-radius: 999px;
  padding: 0 4px;
  font-size: 10px;
  line-height: 1.1;
}

.pay-mini.pending {
  color: #ffb5bf;
  background: rgba(255, 107, 123, 0.22);
}

.pay-mini.done {
  color: #84ebba;
  background: rgba(42, 204, 131, 0.2);
}

.unpaid-table .col-date {
  white-space: nowrap;
}

@media (max-width: 560px) {
  body {
    font-size: 14px;
  }

  .app-shell {
    padding: 8px 6px 10px;
  }

  .top-bar h1 {
    font-size: 24px;
  }

  .panel {
    padding: 10px;
    margin-bottom: 8px;
  }

  .panel h2,
  .panel h3 {
    font-size: 20px;
    margin-bottom: 8px;
  }

  .toolbar h2 {
    font-size: 14px;
  }

  .menu-btn {
    min-height: 34px;
    padding: 0 10px;
    font-size: 14px;
  }

  .inventory-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .inline-stat {
    font-size: 12px;
    padding: 2px 6px;
  }

  .summary-grid {
    gap: 6px;
    margin-bottom: 8px;
  }

  .summary-card {
    padding: 8px;
  }

  .summary-title {
    font-size: 12px;
  }

  .summary-value {
    margin-top: 2px;
    font-size: 20px;
  }

  label {
    font-size: 15px;
  }

  input,
  select,
  .btn {
    min-height: 38px;
    font-size: 15px;
    padding: 6px 8px;
  }

  .action-btn {
    min-height: 28px;
    font-size: 11px;
    padding: 0 5px;
    margin-right: 0;
    margin-bottom: 0;
  }

  table {
    min-width: 460px;
  }

  th,
  td {
    padding: 5px;
    font-size: 12px;
  }

  .tag {
    padding: 0 3px;
    font-size: 9px;
    line-height: 1.1;
  }

  .detail-table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
  }

  .detail-table thead {
    display: table-header-group;
  }

  .detail-table td {
    white-space: normal;
    font-size: 11px;
    padding: 3px 4px;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .detail-table .col-pay,
  .detail-table .col-actions {
    white-space: normal;
  }

  .detail-table .col-pay .mini-action,
  .detail-table .col-actions .mini-action {
    min-height: 22px;
    font-size: 11px;
    padding: 0 4px;
    width: 100%;
  }

  .pay-mini,
  .note-mini {
    margin-left: 1px;
    padding: 0 2px;
    font-size: 8px;
  }

  .detail-table .col-type {
    width: 9%;
  }

  .unpaid-table .col-date {
    width: 15%;
  }

  .detail-table .col-warehouse {
    width: 12%;
  }

  .detail-table .col-product {
    width: 24%;
  }

  .detail-table .col-qty {
    width: 8%;
  }

  .detail-table .col-party {
    width: 16%;
  }

  .detail-table .col-pay {
    width: 9%;
  }

  .detail-table .col-user {
    width: 12%;
  }

  .detail-table .col-actions {
    width: 10%;
  }

  .date-today-btn {
    min-height: 32px;
    font-size: 12px;
    padding: 0 8px;
  }

  .date-switch input[type="date"] {
    min-width: 136px;
    font-size: 14px;
    padding: 6px 8px;
  }

  .entry-card {
    padding: 8px;
  }

  .entry-card-head {
    margin-bottom: 6px;
  }

  .entry-card-head h3 {
    font-size: 17px;
  }

  .entry-badge {
    font-size: 11px;
    padding: 1px 7px;
  }

  .compact-entry-grid {
    gap: 8px;
  }

  .entry-half {
    width: 100%;
  }

  .entry-field {
    padding: 4px;
    gap: 4px;
    font-size: 13px;
  }

  .compact-entry-grid input,
  .compact-entry-grid select,
  .compact-entry-grid textarea {
    min-height: 30px;
    font-size: 12px;
    padding: 4px 5px;
  }

  .compact-entry-grid .btn {
    min-height: 32px;
    font-size: 13px;
    padding: 4px 6px;
  }

  #outbound-form .btn,
  #inbound-form .btn {
    font-size: 13px;
    padding: 6px;
    white-space: normal;
    line-height: 1.2;
  }
}

@media (min-width: 760px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .adjust-grid {
    grid-template-columns: 1fr 1fr 1fr auto;
    align-items: end;
  }

  .adjust-grid .wide {
    grid-column: span 1;
    white-space: nowrap;
  }

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

  .config-grid .config-panel:last-child {
    grid-column: span 2;
  }

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

  .party-grid .config-panel:last-child {
    grid-column: span 1;
  }
}
