:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #617080;
  --line: #dbe2ea;
  --accent: #0f766e;
  --accent-soft: #d8f3ef;
  --danger: #b42318;
  --cell: 96px;
  --gap: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 22px 28px 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

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

main {
  padding: 20px 28px 32px;
}

.actions {
  display: flex;
  gap: 8px;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.actions button {
  width: 40px;
  font-size: 20px;
}

button[type="submit"] {
  width: fit-content;
  padding: 0 16px;
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.settings {
  margin-bottom: 18px;
  padding: 18px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
  align-items: end;
}

label,
fieldset {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.checkbox {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 40px;
}

input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
  font: inherit;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px 12px;
}

legend {
  color: var(--text);
}

#accounts {
  display: grid;
  gap: 6px;
}

#accounts label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

#accounts input {
  width: auto;
  min-height: auto;
}

.grid {
  position: relative;
  min-height: 520px;
  background-image:
    linear-gradient(to right, rgba(23, 32, 42, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(23, 32, 42, 0.06) 1px, transparent 1px);
  background-size: calc((100% - 11 * var(--gap)) / 12 + var(--gap)) calc(var(--cell) + var(--gap));
}

.panel {
  position: absolute;
  display: grid;
  align-content: space-between;
  padding: 16px 42px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(22, 34, 51, 0.06);
  overflow: hidden;
  touch-action: pan-y;
}

.panel.dragging {
  opacity: 0.82;
  z-index: 10;
}

.panel-title {
  color: var(--muted);
  font-size: 14px;
}

.panel-value {
  margin-top: 10px;
  font-size: 32px;
  line-height: 1.05;
  font-weight: 700;
}

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

.progress-note {
  margin-top: 8px;
}

.panel-details {
  display: grid;
  gap: 2px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
}

.progress-goal {
  padding-bottom: 3px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.progress-track {
  width: 100%;
  height: 18px;
  border-radius: 999px;
  background: var(--accent-soft);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  min-width: 3px;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.trend-chart {
  width: 100%;
  height: 100%;
  min-height: 86px;
  max-height: 120px;
}

.trend-area {
  fill: rgba(15, 118, 110, 0.14);
}

.trend-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trade-table-wrap {
  min-height: 0;
  overflow: auto;
}

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

.trade-table th,
.trade-table td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.trade-table th {
  color: var(--muted);
  font-weight: 600;
}

.trade-sort-button {
  display: inline-flex;
  width: 100%;
  min-height: auto;
  justify-content: space-between;
  gap: 6px;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
}

.trade-sort-button.numeric {
  justify-content: flex-end;
}

.sort-indicator {
  display: inline-block;
  width: 10px;
  color: var(--text);
  text-align: right;
}

.trade-table .numeric {
  text-align: right;
  white-space: nowrap;
}

.ticker-cell {
  font-weight: 700;
}

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

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

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

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.drag-handle {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  cursor: grab;
  touch-action: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-handle::before {
  content: "";
  position: absolute;
  inset: 10px 12px;
  background-image: radial-gradient(#9aa7b4 1.4px, transparent 1.4px);
  background-size: 5px 5px;
}

.resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 26px;
  height: 26px;
  cursor: nwse-resize;
  touch-action: none;
}

.resize::after {
  content: "";
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 10px;
  height: 10px;
  border-right: 2px solid #9aa7b4;
  border-bottom: 2px solid #9aa7b4;
}

.warning {
  color: var(--danger);
}

@media (max-width: 760px) {
  :root {
    --cell: 88px;
  }

  .topbar {
    padding: 18px 16px 14px;
  }

  main {
    padding: 16px;
  }

  .grid {
    background-size: calc((100% - 3 * var(--gap)) / 4 + var(--gap)) calc(var(--cell) + var(--gap));
  }
}
