:root {
  color-scheme: dark;
  --bg: #0b0b09;
  --surface: #15140f;
  --surface-2: #1c1a13;
  --line: #343025;
  --line-soft: #28251c;
  --gold: #d8b55b;
  --gold-soft: #8c7236;
  --text: #f5f0e4;
  --muted: #a49d8e;
  --up: #ff625f;
  --down: #3ed184;
  --danger: #df5656;
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 720px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 85% 0%, rgba(216, 181, 91, 0.11), transparent 27rem),
    linear-gradient(145deg, #0d0d0a, var(--bg));
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar,
.sheet-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.eyebrow,
.sheet-kicker,
.dialog-kicker {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

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

h1 {
  margin-bottom: 7px;
  font-size: clamp(1.65rem, 3vw, 2.45rem);
  letter-spacing: 0.02em;
}

.subtitle {
  margin-bottom: 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-weight: 700;
  background: var(--surface-2);
}

.button:focus-visible,
.date-tab:focus-visible,
.cell-input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.button-secondary {
  border-color: var(--line);
}

.button-primary {
  border-color: #d8b55b;
  color: #17140b;
  background: linear-gradient(135deg, #e1c26d, #bb9140);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.button-secondary:hover {
  border-color: var(--gold-soft);
}

.button-danger {
  border-color: rgba(223, 86, 86, 0.4);
  color: #ffb2b2;
}

.file-button {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: 12px;
  margin: 25px 0 18px;
}

.summary-card {
  padding: 15px 18px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: linear-gradient(150deg, rgba(28, 26, 19, 0.95), rgba(19, 18, 14, 0.95));
}

.summary-card span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.76rem;
}

.summary-card strong {
  font-size: 1.14rem;
}

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

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

.date-tabs {
  display: flex;
  gap: 8px;
  padding: 2px 1px 13px;
  overflow-x: auto;
  scrollbar-color: var(--gold-soft) transparent;
}

.date-tab {
  flex: 0 0 auto;
  min-width: 82px;
  min-height: 50px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: #12110d;
}

.date-tab small,
.date-tab b {
  display: block;
}

.date-tab small {
  margin-top: 3px;
  font-size: 0.68rem;
  font-weight: 500;
}

.date-tab.active {
  border-color: var(--gold);
  color: #17140b;
  background: linear-gradient(135deg, #e1c26d, #bb9140);
  box-shadow: 0 6px 22px rgba(186, 144, 63, 0.2);
}

.sheet-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background: rgba(19, 18, 14, 0.95);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
}

.sheet-heading {
  padding: 20px 22px 17px;
}

.sheet-heading h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

.save-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.save-status.saved {
  color: var(--down);
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  table-layout: fixed;
}

th {
  height: 46px;
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: #d8ceb6;
  font-size: 0.78rem;
  text-align: right;
  background: #1d1b14;
}

th:first-child,
th:nth-child(2),
th:nth-child(3) {
  text-align: left;
}

td {
  height: 49px;
  padding: 0;
  border-right: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(21, 20, 15, 0.78);
}

tbody tr:hover td {
  background: #1a1812;
}

.col-index {
  width: 58px;
}

.col-code {
  width: 105px;
}

.col-market {
  width: 72px;
}

.col-name {
  width: 150px;
}

.col-change {
  width: 118px;
}

.row-index {
  padding-left: 17px;
  color: #746d5d;
  font-variant-numeric: tabular-nums;
}

.stock-code,
.stock-name,
.price-cell {
  padding: 0 12px;
}

.stock-code {
  color: var(--gold);
  font-weight: 800;
}

.stock-name {
  text-align: left;
}

.price-cell {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.market-badge {
  display: inline-flex;
  min-width: 38px;
  justify-content: center;
  margin-left: 10px;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 800;
}

.market-tw {
  color: #f1cc6d;
  background: rgba(216, 181, 91, 0.08);
}

.market-us {
  color: #8dbbff;
  background: rgba(91, 147, 216, 0.09);
}

.cell-input {
  width: 100%;
  height: 48px;
  padding: 0 11px;
  border: 0;
  border-radius: 0;
  color: var(--text);
  outline: 0;
  background: transparent;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.cell-input.code,
.cell-input.name {
  text-align: left;
}

.cell-input::placeholder {
  color: #585347;
}

.cell-input:focus {
  background: #252117;
  box-shadow: inset 0 0 0 1px var(--gold-soft);
}

.computed {
  padding: 0 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.value-up {
  color: var(--up);
  background: rgba(255, 98, 95, 0.045);
}

.value-down {
  color: var(--down);
  background: rgba(62, 209, 132, 0.045);
}

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

.table-note {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  padding: 15px 22px 18px;
  color: var(--muted);
  font-size: 0.76rem;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 50%;
}

.up-dot {
  background: var(--up);
}

.down-dot {
  background: var(--down);
}

dialog {
  max-width: 430px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  color: var(--text);
  background: #181711;
  box-shadow: 0 30px 100px #000;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(4px);
}

dialog form {
  padding: 27px;
}

.wide-dialog {
  width: min(760px, calc(100vw - 32px));
  max-width: 760px;
}

.stock-editor {
  display: grid;
  gap: 7px;
  max-height: 55vh;
  margin-top: 20px;
  overflow-y: auto;
}

.editor-row {
  display: grid;
  grid-template-columns: 34px 88px 150px 1fr;
  align-items: center;
  gap: 8px;
}

.editor-row > span {
  color: var(--muted);
  font-size: 0.75rem;
}

.editor-row input,
.editor-row select,
.dialog-input {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #100f0c;
}

.field-label {
  display: block;
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.8rem;
}

.field-label .dialog-input {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 1rem;
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 22px;
}

.sync-code-result {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px 12px;
  margin-top: 13px;
  padding: 14px;
  border: 1px solid var(--gold-soft);
  border-radius: 10px;
  background: rgba(216, 181, 91, 0.08);
}

.sync-code-result[hidden] {
  display: none;
}

.sync-code-result span {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.75rem;
}

.sync-code-result strong {
  color: var(--gold);
  font-size: 1.15rem;
  letter-spacing: 0.08em;
  user-select: all;
}

.sync-message {
  min-height: 1.25rem;
  margin: 10px 0 0;
  color: var(--down);
  font-size: 0.8rem;
}

.sync-message.error {
  color: var(--up);
}

.dialog-close {
  width: 100%;
  margin-top: 16px;
  border: 0;
  color: var(--muted);
  background: transparent;
}

.empty-tabs {
  margin: 13px 0 5px;
  color: var(--muted);
}

dialog h2 {
  margin-bottom: 8px;
}

dialog p:not(.dialog-kicker) {
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  padding: 12px 16px;
  border: 1px solid var(--gold-soft);
  border-radius: 10px;
  color: #18140b;
  background: var(--gold);
  font-weight: 800;
  opacity: 0;
  transform: translateY(15px);
  transition: 180ms ease;
  pointer-events: none;
}

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

@media (max-width: 900px) {
  .app-shell {
    padding: 20px 18px 36px;
  }

  .topbar {
    align-items: flex-start;
  }

  .summary-grid {
    grid-template-columns: repeat(4, minmax(135px, 1fr));
  }

  .summary-card {
    padding: 13px 14px;
  }

  .top-actions {
    max-width: 330px;
  }
}

@media (max-width: 760px) {
  body {
    min-width: 0;
  }

  .topbar {
    display: block;
  }

  .top-actions {
    justify-content: flex-start;
    max-width: none;
    margin-top: 18px;
  }

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

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

  .editor-row {
    grid-template-columns: 28px 72px 110px 1fr;
  }
}
