:root {
  --bg: #f5f5f7;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --soft: #86868b;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.14);
  --buy: #12805c;
  --sell: #c7362f;
  --hold: #6e6e73;
  --accent: #0066cc;
  --accent-soft: rgba(0, 102, 204, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 34px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.42;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 14px max(18px, calc((100vw - 1180px) / 2 + 18px)) 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 245, 247, 0.82);
  backdrop-filter: saturate(180%) blur(18px);
  position: sticky;
  top: 0;
  z-index: 3;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 17px;
  line-height: 1.2;
  font-weight: 650;
}

h2 {
  font-size: 13px;
  line-height: 1.2;
  font-weight: 650;
}

.meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.submeta {
  color: var(--soft);
  font-size: 11px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px max(18px, calc((100vw - 1180px) / 2 + 18px));
  border-bottom: 1px solid var(--line);
  background: rgba(245, 245, 247, 0.86);
  backdrop-filter: saturate(180%) blur(18px);
  position: sticky;
  top: 86px;
  z-index: 2;
  overflow-x: auto;
}

.tab {
  min-width: 80px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  color: var(--ink);
  background: var(--panel-solid);
  border-color: var(--line);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.03);
  font-weight: 650;
}

button,
input,
select {
  font: inherit;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  height: 30px;
  border-radius: 8px;
  outline: none;
}

button {
  padding: 0 10px;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

button:hover {
  border-color: var(--line-strong);
  background: #fff;
}

button:active {
  background: #f0f0f2;
}

input,
select {
  padding: 0 9px;
}

#passwordInput {
  width: 132px;
}

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 18px 28px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(118px, 1fr));
  background: transparent;
}

.summary.compact {
  grid-template-columns: repeat(4, minmax(118px, 1fr));
  border: 0;
  border-radius: 0;
  box-shadow: none;
  margin-bottom: 0;
}

.metric {
  padding: 12px 14px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric span {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
  font-size: 11px;
}

.metric strong {
  display: block;
  min-height: 22px;
  font-size: 17px;
  line-height: 1.3;
  font-weight: 650;
  white-space: nowrap;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.54);
}

#actionCount {
  color: var(--muted);
  font-size: 12px;
}

#portfolioView .panel,
#historyView .panel,
#systemView .panel {
  min-height: 620px;
}

.compact-panel {
  box-shadow: none;
}

.table-wrap {
  overflow: auto;
}

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

.table-wrap.holdings {
  max-height: 545px;
}

.compact-table {
  max-height: 360px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

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

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  background: rgba(248, 248, 250, 0.96);
  position: sticky;
  top: 0;
  z-index: 1;
}

.compact-table th,
.compact-table td {
  padding: 5px 10px;
}

.compact-table table {
  font-size: 12px;
}

tbody tr {
  transition: background 0.12s ease;
}

tbody tr:hover {
  background: rgba(0, 0, 0, 0.025);
}

td br + .hold {
  font-size: 11px;
}

.code-cell {
  color: var(--muted);
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
}

.buy,
.sell {
  font-weight: 650;
}

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

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

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

.field {
  display: grid;
  grid-template-columns: 64px minmax(180px, 280px);
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
}

.portfolio-totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 0;
  border-bottom: 1px solid var(--line);
}

.portfolio-field {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-right: 1px solid var(--line);
}

.portfolio-field:last-child {
  border-right: 0;
}

.portfolio-field span {
  color: var(--muted);
  font-size: 11px;
}

.portfolio-field input {
  width: 100%;
  max-width: 220px;
}

.portfolio-field strong {
  min-height: 30px;
  display: flex;
  align-items: center;
  color: var(--ink);
  font-size: 15px;
  font-weight: 650;
}

.portfolio-field.readonly {
  background: rgba(0, 0, 0, 0.015);
}

.system-panel .section-head span {
  color: var(--muted);
  font-size: 12px;
}

.system-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
}

.system-card {
  min-height: 136px;
  padding: 18px;
  background: rgba(255, 255, 255, 0.72);
}

.system-card.lead,
.system-card.caution {
  grid-column: 1 / -1;
  min-height: auto;
}

.system-card span {
  display: block;
  margin-bottom: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.system-card p {
  max-width: 860px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.system-card ul {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.system-card li + li {
  margin-top: 2px;
}

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

.share-input,
.cost-input {
  width: 104px;
  height: 28px;
  font-size: 12px;
}

#cashInput {
  height: 30px;
}

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  min-width: 200px;
  max-width: 420px;
  padding: 10px 12px;
  background: rgba(29, 29, 31, 0.92);
  color: #fff;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  font-size: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

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

@media (max-width: 760px) {
  .topbar {
    display: block;
    padding: 12px 14px;
  }

  .toolbar {
    justify-content: flex-start;
    margin-top: 10px;
  }

  .tabs {
    top: 138px;
    padding: 8px 14px;
  }

  .layout {
    padding: 12px 12px 24px;
  }

  .summary,
  .summary.compact,
  .portfolio-totals,
  .system-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric:nth-child(2n) {
    border-right: 0;
  }

  .portfolio-field:nth-child(2n) {
    border-right: 0;
  }

  .system-card,
  .system-card.lead,
  .system-card.caution {
    grid-column: 1 / -1;
  }

  .metric {
    padding: 10px 12px;
  }

  .metric strong {
    font-size: 15px;
  }

  th,
  td {
    padding: 7px 9px;
  }
}
