﻿:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #f8fafc;
  --ink: #142033;
  --muted: #64748b;
  --line: #d7dee9;
  --brand: #0f766e;
  --brand-strong: #0b5f59;
  --gain: #b42318;
  --gain-soft: #fff1f0;
  --loss: #027a48;
  --loss-soft: #ecfdf3;
  --flat: #475467;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 2px 16px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.45rem, 6vw, 2.2rem);
  line-height: 1.08;
}

h2 {
  font-size: 1rem;
}

.icon-button {
  display: inline-flex;
  width: 48px;
  height: 48px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 1.35rem;
}

.icon-button.spinning span {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.account-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.account-panel strong,
.account-panel span {
  display: block;
}

.account-panel strong {
  font-size: 0.95rem;
}

.account-panel span {
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.account-actions .secondary-button {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

.account-actions .secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.summary-band {
  margin-bottom: 14px;
}

.status-row {
  display: flex;
  min-height: 26px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

#countdownStatus {
  margin-left: auto;
  white-space: nowrap;
}

.status-error {
  color: #b42318;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.summary-card,
.position-card,
.editor-panel,
.settings-panel,
.holding-editor,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card {
  min-height: 112px;
  padding: 16px;
}

.summary-card span,
.metric span,
.price-block span,
label span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.summary-card strong {
  display: block;
  margin: 7px 0 4px;
  font-size: 1.65rem;
  line-height: 1.15;
}

.summary-card small,
.metric small,
.price-block small,
.holding-editor-header span {
  color: var(--muted);
  font-size: 0.82rem;
}

.gain strong,
.gain.metric strong {
  color: var(--gain);
}

.loss strong,
.loss.metric strong {
  color: var(--loss);
}

.flat strong,
.flat.metric strong {
  color: var(--flat);
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 -2px 14px;
  padding: 8px 2px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
}

.tab {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #ffffff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.positions-list,
.editor-list {
  display: grid;
  gap: 12px;
}

.position-card {
  overflow: hidden;
}

.position-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.position-card header > div {
  min-width: 0;
}

.position-card h2 {
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.position-card header p {
  color: var(--muted);
  font-size: 0.86rem;
  overflow-wrap: anywhere;
}

.position-card header .holding-meta {
  margin-top: 2px;
  color: var(--flat);
}

.price-block {
  min-width: 112px;
  text-align: right;
}

.price-block strong {
  display: block;
  margin-top: 2px;
  font-size: 1.12rem;
  white-space: nowrap;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.metric {
  min-height: 106px;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

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

.metric:last-child {
  grid-column: 1 / -1;
  border-right: 0;
  border-bottom: 0;
}

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

.empty-state {
  padding: 22px 18px;
}

.empty-state p {
  margin-top: 6px;
  color: var(--muted);
}

.editor-panel,
.settings-panel {
  margin-bottom: 14px;
  padding: 16px;
}

.settings-panel {
  display: grid;
  gap: 10px;
}

.field-hint,
.fee-preview,
.computed-field output {
  color: var(--muted);
  font-size: 0.82rem;
}

.fee-preview {
  align-self: end;
  min-height: 24px;
  font-weight: 700;
}

.computed-field output {
  display: flex;
  min-height: 46px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  font-weight: 800;
  padding: 10px 12px;
}

.tools-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-title-row,
.holding-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button {
  background: var(--brand);
  color: #ffffff;
}

.primary-button:active {
  background: var(--brand-strong);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.danger-button {
  background: #fff1f0;
  color: #b42318;
}

.input-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
}

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

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.holding-editor {
  padding: 16px;
}

.holding-editor-header {
  align-items: flex-start;
}

.holding-editor-header strong,
.holding-editor-header span {
  display: block;
}

.input-grid.compact {
  gap: 10px;
}

@media (min-width: 680px) {
  .app-shell {
    padding: 26px 24px 34px;
  }

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

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

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

  .input-grid label:nth-child(3) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .status-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  #countdownStatus {
    margin-left: 0;
  }

  .account-panel,
  .position-card header,
  .panel-title-row,
  .holding-editor-header {
    align-items: stretch;
    flex-direction: column;
  }

  .account-actions {
    justify-content: stretch;
  }

  .account-actions .secondary-button {
    flex: 1 1 auto;
  }

  .price-block {
    min-width: 0;
    text-align: left;
  }

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

  .metric {
    border-right: 0;
  }

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