:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --surface: #fffdfa;
  --text: #181716;
  --muted: #79736b;
  --line: #ded8ce;
  --accent: #1d6f61;
  --accent-dark: #11483f;
  --danger: #9a2c3b;
  --up: #0d7a50;
  --down: #b83245;
  --shadow: 0 18px 45px rgba(57, 48, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(29, 111, 97, 0.08), transparent 32%),
    linear-gradient(315deg, rgba(145, 76, 52, 0.08), transparent 36%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 42px;
}

.topbar,
.summary,
.watchlist {
  background: rgba(255, 253, 250, 0.86);
  border: 1px solid rgba(222, 216, 206, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

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

.brand {
  min-width: 220px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
}

.icon-button,
.delete-button,
.nav-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    background 160ms ease;
}

.icon-button:hover,
.delete-button:hover,
.nav-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  color: var(--accent-dark);
}

.icon-button svg,
.delete-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.nav-button {
  width: auto;
  min-width: 74px;
  padding: 0 12px;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.controls {
  display: flex;
  align-items: stretch;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 12px;
  min-width: 280px;
}

.add-form {
  display: flex;
  width: 100%;
  max-width: 560px;
  gap: 10px;
  margin: 0 auto;
}

.add-form input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.holding-input input,
.category,
.note {
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  outline: none;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.add-form input {
  height: 42px;
  padding: 0 13px;
  text-transform: uppercase;
}

.add-form input:focus,
.holding-input input:focus,
.category:focus,
.note:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(29, 111, 97, 0.13);
}

.holding-input input:hover,
.category:hover,
.note:hover {
  border-color: rgba(222, 216, 206, 0.85);
  background: rgba(255, 255, 255, 0.58);
}

.holding-input input::placeholder,
.category::placeholder,
.note::placeholder {
  color: rgba(121, 115, 107, 0.5);
}

.add-form button {
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.status {
  margin: 0 auto;
  color: var(--muted);
  font-size: 0.92rem;
  width: 100%;
  max-width: 560px;
  text-align: left;
  white-space: nowrap;
}

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

.metric {
  min-width: 0;
  padding: 18px 24px;
  background: rgba(255, 253, 250, 0.9);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 7px;
  overflow-wrap: anywhere;
  font-size: 1.38rem;
  line-height: 1.1;
}

.cash-metric input {
  display: block;
  width: 100%;
  min-width: 0;
  margin-top: 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 1.38rem;
  font-weight: 700;
  line-height: 1.1;
  outline: none;
  padding: 0;
}

.cash-metric input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(29, 111, 97, 0.13);
  padding: 2px 6px;
}

.watchlist {
  overflow-x: auto;
  border-top: 0;
  border-radius: 0 0 8px 8px;
}

.is-reordering .watchlist {
  overflow-x: hidden;
}

.list-head,
.stock-row {
  display: grid;
  grid-template-columns:
    minmax(92px, 0.86fr)
    minmax(180px, 1.42fr)
    minmax(92px, 0.86fr)
    minmax(92px, 0.86fr)
    minmax(92px, 0.86fr)
    minmax(92px, 0.86fr)
    minmax(72px, 0.62fr)
    minmax(64px, 0.54fr)
    minmax(152px, 1.32fr)
    48px;
  align-items: center;
  gap: 14px;
  min-width: 1230px;
}

.list-head {
  padding: 13px 24px;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.sort-button {
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  text-align: center;
  text-transform: inherit;
}

.sort-button:hover,
.sort-button.active {
  color: var(--accent-dark);
}

.sort-button.active::after {
  content: " ↑";
}

.sort-button.active[data-direction="desc"]::after {
  content: " ↓";
}

.stock-row {
  min-height: 74px;
  padding: 14px 24px;
  border-bottom: 1px solid rgba(222, 216, 206, 0.7);
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  transition:
    background 160ms ease,
    opacity 160ms ease;
}

.stock-row:active {
  cursor: grabbing;
}

.stock-row.dragging {
  opacity: 0.48;
}

.is-reordering,
.is-reordering .stock-row {
  cursor: grabbing;
}

.stock-row.drop-before {
  box-shadow: inset 0 2px 0 var(--accent);
}

.stock-row.drop-after {
  box-shadow: inset 0 -2px 0 var(--accent);
}

.stock-row:last-child {
  border-bottom: 0;
}

.identity {
  min-width: 0;
  text-align: center;
}

.category,
.price,
.market-value,
.profit,
.return-rate,
.holding-input input {
  text-align: center;
}

.note {
  text-align: left;
}

.symbol {
  display: block;
  font-size: 1.05rem;
}

.price,
.market-value {
  font-weight: 750;
}

.profit,
.return-rate {
  font-weight: 700;
}

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

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

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

.holding-input input,
.note {
  height: 38px;
  padding: 0 12px;
}

.delete-button {
  border-color: transparent;
  background: transparent;
  color: rgba(121, 115, 107, 0.48);
  justify-self: end;
  outline: none;
}

.delete-button:hover,
.delete-button:focus,
.delete-button:focus-visible,
.delete-button:active {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--danger);
}

.empty {
  padding: 34px 24px;
  color: var(--muted);
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  padding: 0;
  white-space: nowrap;
}

.confirm-overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(24, 23, 22, 0.38);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.confirm-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.confirm-dialog {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  width: min(420px, 100%);
  border: 1px solid rgba(222, 216, 206, 0.96);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.96);
  box-shadow: 0 24px 65px rgba(57, 48, 36, 0.24);
  padding: 22px;
  transform: translateY(8px) scale(0.98);
  transition: transform 160ms ease;
}

.confirm-overlay.open .confirm-dialog {
  transform: translateY(0) scale(1);
}

.confirm-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: rgba(154, 44, 59, 0.08);
  color: var(--danger);
}

.confirm-icon svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.add-icon {
  background: rgba(29, 111, 97, 0.1);
  color: var(--accent);
}

.confirm-copy {
  min-width: 0;
}

.confirm-copy h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.confirm-copy p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  grid-column: 1 / -1;
  margin-top: 4px;
}

.confirm-actions button {
  min-width: 70px;
  height: 34px;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 0.88rem;
  cursor: pointer;
}

.holding-dialog-form {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.holding-dialog-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-wide {
  grid-column: 1 / -1;
}

.holding-dialog-fields label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.holding-dialog-fields input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  padding: 0 12px;
}

.holding-dialog-fields input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(29, 111, 97, 0.13);
}

.dialog-error {
  min-height: 1.2em;
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 700;
}

.confirm-cancel {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
}

.confirm-delete,
.confirm-save {
  border: 0;
  color: #fff;
  font-weight: 700;
}

.confirm-delete {
  background: var(--danger);
}

.confirm-save {
  background: var(--accent);
}

.confirm-cancel:hover,
.confirm-cancel:focus-visible {
  border-color: var(--accent);
  color: var(--accent-dark);
  outline: none;
}

.confirm-delete:hover,
.confirm-delete:focus-visible {
  background: #7f2230;
  outline: none;
}

.confirm-save:hover,
.confirm-save:focus-visible {
  background: var(--accent-dark);
  outline: none;
}

@media (max-width: 860px) {
  .shell {
    width: min(100% - 20px, 680px);
    padding: 12px 0 20px;
  }

  .topbar,
  .metric {
    padding: 18px;
  }

  .topbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .brand {
    flex: 1 1 220px;
    min-width: 0;
  }

  .controls {
    flex: 1 1 100%;
    order: 3;
    min-width: 0;
  }

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

  .status {
    white-space: normal;
  }

  .list-head {
    display: none;
  }

  .stock-row {
    grid-template-columns: 1fr auto;
    gap: 10px 14px;
    min-width: 0;
    padding: 18px;
  }

  .identity,
  .category-wrap,
  .price,
  .holding-input,
  .market-value,
  .profit,
  .return-rate,
  .note-wrap {
    grid-column: 1 / 2;
  }

  .price,
  .market-value,
  .profit,
  .return-rate,
  .category,
  .holding-input input {
    font-size: 0.96rem;
  }

  .category,
  .holding-input input,
  .identity,
  .note {
    text-align: left;
  }

  .delete-button {
    grid-column: 2 / 3;
    grid-row: 1 / 3;
  }

  .holding-dialog-fields {
    grid-template-columns: 1fr;
  }

  .note-wrap {
    width: 100%;
  }
}

@media (max-width: 460px) {
  .topbar {
    align-items: flex-start;
  }

  .add-form {
    flex-direction: column;
  }

  .add-form button {
    width: 100%;
  }

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