:root {
  --bg: #eef3f9;
  --bg-2: #f9fbff;
  --panel: rgba(255, 255, 255, 0.85);
  --panel-solid: #ffffff;
  --ink: #10233f;
  --muted: #5f718a;
  --line: #d8e2f0;
  --line-strong: #c4d3e7;
  --accent: #0b7fd4;
  --accent-2: #18a37a;
  --danger: #c24141;
  --warn: #a86a00;
  --chip: #edf6ff;
  --pos: #198754;
  --neg: #d94141;
  --shadow-soft: 0 18px 60px rgba(16, 35, 63, 0.08);
  --shadow-card: 0 8px 28px rgba(16, 35, 63, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 580px at 5% -10%, rgba(24, 163, 122, 0.13), transparent 65%),
    radial-gradient(1200px 640px at 98% -12%, rgba(11, 127, 212, 0.14), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  min-height: 100vh;
  overflow-x: hidden;
}

body.locked,
body.modal-open {
  overflow: hidden;
}

.app-shell {
  width: min(1360px, 94vw);
  margin: 20px auto 30px;
  display: grid;
  gap: 14px;
  min-width: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(8px);
  min-width: 0;
}

.topbar {
  padding: 20px 22px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  animation: rise-in 0.5s ease;
}

.topbar > div {
  min-width: 0;
}

.topbar h1 {
  margin: 2px 0 8px;
  font-family: "Space Grotesk", "Plus Jakarta Sans", sans-serif;
  letter-spacing: 0.01em;
  font-size: clamp(28px, 3.5vw, 40px);
}

.topbar p {
  margin: 0;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  color: #3f5472;
  font-weight: 700;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  max-width: 640px;
}

.mobile-actions {
  display: none;
}

.action-btn,
.warn-btn,
.ghost-btn,
button {
  border-radius: 14px;
  border: 1px solid transparent;
  min-height: 42px;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

button,
.action-btn {
  background: linear-gradient(135deg, var(--accent), #0e95ed);
  color: #fff;
  box-shadow: 0 8px 20px rgba(11, 127, 212, 0.28);
}

.warn-btn {
  background: linear-gradient(135deg, #b37500, #d58f00);
  color: #fff;
  box-shadow: 0 8px 20px rgba(168, 106, 0, 0.24);
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.9);
  color: #1d3658;
  border-color: var(--line-strong);
}

button:hover,
.action-btn:hover,
.warn-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
  opacity: 0.96;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 14px;
  align-items: start;
  min-width: 0;
}

.side-panel {
  padding: 18px;
  position: sticky;
  top: 10px;
}

h2 {
  margin: 0 0 12px;
  font-size: 20px;
  letter-spacing: 0.01em;
}

h3 {
  margin: 0 0 8px;
}

.muted {
  color: var(--muted);
}

.focus-row {
  display: grid;
  gap: 8px;
}

label {
  font-size: 12px;
  font-weight: 700;
}

.person-add-form {
  margin-top: 12px;
}

.inline-form,
.grid-form {
  display: grid;
  gap: 10px;
}

.inline-form {
  grid-template-columns: 1fr auto;
}

.grid-form {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
}

.price-grid {
  grid-template-columns: minmax(160px, 1fr) minmax(220px, 1fr) minmax(320px, 2fr) minmax(200px, 1fr);
  align-items: start;
}

.search-selected {
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  background: #f8fbff;
  min-height: 44px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
}

.search-results {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-solid);
  min-height: 44px;
  padding: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.search-opt {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #f6f9ff;
  color: #1d3658;
  box-shadow: none;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12px;
}

.search-opt.active {
  background: linear-gradient(135deg, #158bdf, #18a37a);
  color: #fff;
  border-color: transparent;
}

input,
select {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: var(--panel-solid);
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  font-size: 14px;
  outline: none;
}

input:focus,
select:focus {
  border-color: #53a7e8;
  box-shadow: 0 0 0 4px rgba(11, 127, 212, 0.14);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.chip {
  border: 1px solid var(--line-strong);
  background: var(--chip);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
}

.chip.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #158bdf, #18a37a);
}

.chip button {
  min-height: auto;
  padding: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  color: inherit;
  font-size: 12px;
}

.chip [data-delete-person] {
  color: var(--danger);
  font-weight: 700;
}

.main-grid {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.main-grid .card {
  padding: 18px;
  animation: rise-in 0.55s ease;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 6px;
}

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

.sync-status {
  margin: 8px 0 10px;
  min-height: 18px;
  font-size: 13px;
}

.tip {
  margin: 8px 0 0;
  font-size: 13px;
}

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

.kpi {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-solid);
  padding: 14px;
  position: relative;
  overflow: hidden;
}

.kpi::after {
  content: "";
  position: absolute;
  inset: auto -10% -60% auto;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(11, 127, 212, 0.12), transparent 70%);
}

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

.kpi .value {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-width: 100%;
  overscroll-behavior-x: contain;
}

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

.mobile-item {
  border: 1px solid var(--line);
  background: var(--panel-solid);
  border-radius: 14px;
  padding: 12px;
}

.mobile-item .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0;
  font-size: 13px;
}

.mobile-item .key {
  color: var(--muted);
}

.mobile-item .val {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
}

.mobile-item .title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
}

.mobile-item .actions {
  margin-top: 8px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: #486184;
  font-weight: 700;
  position: sticky;
  top: 0;
  background: #f4f8ff;
  z-index: 1;
}

tbody tr:hover {
  background: #f7fbff;
}

tr.selected {
  background: #e8f5ff;
}

.num {
  text-align: right;
}

.pos {
  color: var(--pos);
}

.neg {
  color: var(--neg);
}

.small-btn {
  min-height: 30px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 10px;
  box-shadow: none;
}

.danger-btn,
.small-btn.danger-btn {
  background: #e95555;
  color: #fff;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(13, 25, 45, 0.45);
  padding: 16px;
}

.sheet.hidden {
  display: none;
}

.sheet-inner {
  width: min(1260px, 100%);
  margin: 0 auto;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  animation: sheet-in 0.25s ease;
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.sheet .table-wrap {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.auth-page {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(12, 26, 47, 0.58);
  display: grid;
  place-items: center;
  padding: 14px;
}

.auth-page.hidden {
  display: none;
}

.auth-card {
  width: min(460px, 100%);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 22px;
  box-shadow: var(--shadow-soft);
}

.auth-card h2 {
  font-family: "Space Grotesk", "Plus Jakarta Sans", sans-serif;
  margin: 6px 0 8px;
  font-size: 28px;
}

#auth-msg {
  margin-top: 10px;
  min-height: 18px;
  font-size: 13px;
}

.hidden {
  display: none;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

  .side-panel {
    position: static;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .grid-form,
  .price-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 780px) {
  .app-shell {
    width: 95vw;
    margin-top: 10px;
  }

  .topbar {
    padding: 16px;
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    display: none;
  }

  .mobile-actions {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
    margin-top: 2px;
    margin-bottom: 4px;
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: var(--shadow-card);
  }

  .mobile-actions button {
    width: 100%;
    min-height: 42px;
    font-size: 14px;
    white-space: nowrap;
    padding-inline: 10px;
  }

  #m-open-cash-page,
  #m-open-trade-page {
    grid-column: span 3;
  }

  #m-open-audit,
  #m-export-json,
  #m-export-csv {
    grid-column: span 2;
  }

  .main-grid .card,
  .side-panel {
    padding: 14px;
    border-radius: 18px;
  }

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

  .grid-form,
  .price-grid,
  .inline-form {
    grid-template-columns: 1fr;
  }

  input,
  select,
  button,
  .action-btn,
  .ghost-btn,
  .warn-btn {
    min-height: 46px;
    font-size: 15px;
  }

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

  .sheet {
    padding: 8px;
  }

  .sheet-inner {
    height: calc(100vh - 16px);
    padding: 12px;
    border-radius: 18px;
  }
}
