:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-soft: #eef3ef;
  --ink: #17201b;
  --muted: #68736d;
  --line: #dce3de;
  --green: #1c7c54;
  --green-deep: #145b3f;
  --red: #b63d3d;
  --amber: #c28a20;
  --shadow: 0 18px 46px rgba(30, 45, 38, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(180deg, #e9f0ec 0%, var(--bg) 42%, #fbfcfb 100%);
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(rgba(244, 246, 243, 0.92), rgba(244, 246, 243, 0.92)),
    linear-gradient(180deg, #e9f0ec 0%, #fbfcfb 100%);
}

.lock-screen.is-unlocked {
  display: none;
}

.lock-panel {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.lock-panel h2 {
  margin: 0 0 10px;
  font-size: 24px;
}

.lock-panel p {
  color: var(--muted);
  line-height: 1.6;
}

.lock-note {
  margin: 14px 0 0;
  font-size: 12px;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 0 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green-deep);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.05;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.25;
}

.topbar-actions,
.section-heading,
.filters {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-button,
.danger-icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(30, 45, 38, 0.08);
}

.icon-button:hover {
  border-color: rgba(28, 124, 84, 0.35);
  color: var(--green-deep);
}

.danger-icon-button {
  color: var(--red);
}

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

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

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

.summary-card,
.trade-form,
.positions-panel,
.ledger-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.summary-card {
  padding: 18px;
}

.summary-card span,
.section-heading span,
.ledger-heading p {
  color: var(--muted);
  font-size: 13px;
}

.summary-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1;
}

.summary-card.accent {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--green-deep), var(--green));
}

.summary-card.accent span {
  color: rgba(255, 255, 255, 0.76);
}

.summary-card.negative strong,
.negative {
  color: var(--red);
}

.summary-card.positive strong,
.positive {
  color: var(--green);
}

.summary-card.accent.negative {
  background: linear-gradient(135deg, #842e2e, var(--red));
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(330px, 0.75fr);
  gap: 14px;
  align-items: start;
}

.trade-form,
.positions-panel,
.ledger-panel {
  padding: 18px;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 16px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea {
  margin-top: 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(28, 124, 84, 0.65);
  box-shadow: 0 0 0 3px rgba(28, 124, 84, 0.12);
}

.primary-button,
.small-button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  color: #fff;
  background: var(--green-deep);
}

.primary-button:hover {
  background: var(--green);
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  color: var(--green-deep);
  background: var(--surface-soft);
}

.ledger-panel {
  margin-top: 14px;
}

.ledger-heading {
  align-items: flex-start;
}

.ledger-heading p {
  margin: 6px 0 0;
  line-height: 1.6;
}

.filters {
  width: min(500px, 100%);
}

.filters input {
  min-width: 220px;
}

.filters select {
  width: 140px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-wrap.compact {
  max-height: 380px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: #fff;
}

.compact table {
  min-width: 420px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: #f8faf8;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.stock-name {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.side-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 26px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.side-badge.buy {
  color: var(--green-deep);
  background: rgba(28, 124, 84, 0.12);
}

.side-badge.sell {
  color: var(--red);
  background: rgba(182, 61, 61, 0.12);
}

.delete-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--red);
  background: rgba(182, 61, 61, 0.08);
}

.delete-button:hover {
  border-color: rgba(182, 61, 61, 0.28);
}

.empty-state {
  display: none;
  margin: 16px 0 0;
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: #fbfcfb;
}

.empty-state.show {
  display: block;
}

@media (max-width: 940px) {
  .summary-grid,
  .workspace,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .positions-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 14px;
  }

  .topbar,
  .ledger-heading,
  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

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

  .filters input,
  .filters select {
    min-width: 0;
    width: 100%;
  }

  .trade-form,
  .positions-panel,
  .ledger-panel {
    padding: 14px;
  }
}
