:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --text: #18212b;
  --muted: #697787;
  --line: rgba(137, 153, 172, 0.28);
  --soft-line: rgba(137, 153, 172, 0.16);
  --primary: #3a7ca5;
  --primary-dark: #245f82;
  --accent: #88b04b;
  --warn: #ffb000;
  --danger: #c94c4c;
  --positive: #2f8f6f;
  --negative: #c94c4c;
  --gain: #c94c4c;
  --loss: #2f8f6f;
  --serenity: #92a8d1;
  --coral: #ff6f61;
  --shadow: 0 18px 50px rgba(32, 43, 58, 0.1);
  --soft-shadow: 0 8px 24px rgba(32, 43, 58, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(244, 247, 251, 0.94)),
    var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "PingFang TC",
    "Microsoft JhengHei",
    sans-serif;
}

body.auth-pending,
body.auth-locked {
  background:
    linear-gradient(145deg, rgba(146, 168, 209, 0.24), rgba(136, 176, 75, 0.12)),
    #f7f8fb;
}

.auth-screen {
  display: none;
}

body.auth-pending .auth-screen,
body.auth-locked .auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

body.auth-pending .app-shell,
body.auth-locked .app-shell,
body.auth-unlocked .auth-screen {
  display: none;
}

.auth-panel {
  width: min(100%, 430px);
  padding: 34px 28px 26px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow:
    0 24px 70px rgba(38, 57, 77, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(20px) saturate(1.2);
}

.auth-panel h1 {
  margin-top: 0;
  font-size: 29px;
}

.auth-description,
.auth-message,
.auth-reset-hint {
  color: var(--muted);
  line-height: 1.6;
}

.auth-description {
  min-height: 50px;
  margin: 12px 0 20px;
}

.pin-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 18px;
}

.pin-input {
  height: 54px;
  padding: 0;
  text-align: center;
  font-size: 25px;
  font-weight: 800;
  border-radius: 8px;
  background:
    linear-gradient(180deg, #ffffff, #f7f9fb);
  border-color: rgba(89, 113, 139, 0.24);
  box-shadow: inset 0 1px 2px rgba(28, 38, 48, 0.04);
}

.pin-input:focus {
  border-color: rgba(58, 124, 165, 0.72);
}

.auth-remember {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
  margin: 4px 0 18px;
}

.auth-remember input {
  width: 18px;
  height: 18px;
  min-height: 18px;
  accent-color: var(--primary);
}

.auth-submit {
  width: 100%;
  min-height: 44px;
  border: 0;
  color: #ffffff;
  font-weight: 800;
  background: linear-gradient(180deg, #4f93bd, var(--primary-dark));
  box-shadow: 0 10px 24px rgba(36, 95, 130, 0.22);
}

.auth-submit:hover {
  background: linear-gradient(180deg, #4388b2, #1f5778);
}

.auth-submit:disabled {
  opacity: 0.68;
  cursor: wait;
}

.auth-message {
  min-height: 22px;
  margin: 14px 0 0;
  font-weight: 700;
}

.auth-message.error {
  color: var(--danger);
}

.auth-reset-hint {
  margin: 8px 0 0;
  font-size: 12px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--text);
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: rgba(58, 124, 165, 0.42);
  background: rgba(255, 255, 255, 0.96);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.2);
  outline-offset: 2px;
}

.app-shell {
  width: min(1480px, calc(100% - 36px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  padding: 8px 0 20px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #5b7288;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 32px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.35;
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.tabs {
  display: flex;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  margin-bottom: 18px;
  overflow-x: auto;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(18px);
}

.tab-button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  min-width: 84px;
}

.tab-button.active {
  color: #ffffff;
  background: linear-gradient(180deg, #4d91bb, var(--primary-dark));
  box-shadow: 0 8px 18px rgba(36, 95, 130, 0.18);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.year-filter {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(16px);
}

.year-filter span {
  color: var(--muted);
  font-size: 13px;
}

.year-filter select {
  min-width: 118px;
  min-height: 32px;
  border: 0;
  background: rgba(146, 168, 209, 0.16);
  color: var(--primary-dark);
  font-weight: 700;
  padding: 4px 28px 4px 10px;
}

.range-label {
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.metric-grid {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.metric-card {
  z-index: 1;
  min-height: 142px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  position: relative;
  border-color: rgba(255, 255, 255, 0.72);
}

.metric-card:hover,
.metric-card:focus-within {
  z-index: 40;
}

.metric-card span,
.panel-heading span,
.field span,
small,
.data-stats dt {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  font-size: 24px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.metric-info-wrap {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 24px;
}

.metric-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
}

.formula-label,
.metric-equation {
  color: #7a8895;
  font-size: 12px;
}

.metric-equation {
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.info-button {
  width: 23px;
  min-width: 23px;
  height: 23px;
  min-height: 23px;
  padding: 0;
  border-radius: 50%;
  border-color: rgba(89, 113, 139, 0.22);
  color: var(--primary-dark);
  background: rgba(146, 168, 209, 0.16);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.metric-tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 90;
  width: min(320px, calc(100vw - 48px));
  padding: 12px 14px;
  border: 1px solid rgba(137, 153, 172, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: #51606d;
  box-shadow: 0 18px 44px rgba(32, 43, 58, 0.14);
  font-size: 13px;
  line-height: 1.6;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
  white-space: normal;
}

.metric-card:nth-child(n + 5) .metric-tooltip {
  right: 0;
  left: auto;
}

.info-button:hover + .metric-tooltip,
.info-button:focus-visible + .metric-tooltip {
  opacity: 1;
  transform: translateY(0);
}

.dashboard-layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(390px, 0.8fr);
  gap: 16px;
}

.work-layout {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.data-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border-color: rgba(255, 255, 255, 0.72);
}

.panel-heading {
  min-height: 58px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--soft-line);
  background: rgba(255, 255, 255, 0.42);
}

.panel-heading span {
  text-align: right;
}

.form-panel {
  padding-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.field {
  display: grid;
  gap: 7px;
}

.compact-field {
  min-width: 128px;
}

.full-span {
  grid-column: 1 / -1;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  min-height: 40px;
  padding: 8px 10px;
}

.field-warning {
  color: var(--danger);
}

.field-loading {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--primary-dark);
}

.field-loading::before {
  content: "";
  width: 13px;
  height: 13px;
  flex: 0 0 13px;
  border: 2px solid rgba(58, 124, 165, 0.18);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.form-actions {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr);
  gap: 10px;
  padding: 0 18px;
}

.form-actions .primary-button {
  margin: 0;
  width: 100%;
}

.secondary-button {
  width: 100%;
  border-color: rgba(58, 124, 165, 0.24);
  color: var(--primary-dark);
  background: rgba(146, 168, 209, 0.14);
  font-weight: 700;
}

.secondary-button:hover {
  background: rgba(146, 168, 209, 0.22);
}

.primary-button {
  margin: 0 18px;
  width: calc(100% - 36px);
  background: linear-gradient(180deg, #4f93bd, var(--primary-dark));
  border-color: var(--primary);
  color: #ffffff;
  font-weight: 700;
}

.primary-button:hover {
  background: linear-gradient(180deg, #4388b2, #1f5778);
  border-color: var(--primary-dark);
}

.danger-button {
  border-color: rgba(201, 76, 76, 0.3);
  color: var(--danger);
  background: rgba(255, 246, 246, 0.82);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--soft-line);
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: rgba(247, 250, 252, 0.78);
}

td strong,
td small {
  display: block;
}

.action-cell {
  width: 52px;
  text-align: center;
}

.icon-button {
  min-width: 32px;
  min-height: 32px;
  width: 32px;
  height: 32px;
  padding: 0;
  line-height: 1;
  color: var(--danger);
}

.empty-cell {
  color: var(--muted);
  text-align: center;
  height: 116px;
}

.chart-panel {
  min-height: 400px;
}

.chart-wrap {
  padding: 16px 18px 6px;
}

#performance-chart {
  width: 100%;
  aspect-ratio: 19 / 7;
  min-height: 260px;
  display: block;
}

.chart-bg {
  fill: rgba(255, 255, 255, 0.56);
}

.grid-line {
  stroke: rgba(137, 153, 172, 0.22);
  stroke-width: 1;
}

.axis-label,
.empty-chart {
  fill: var(--muted);
  font-size: 13px;
}

.chart-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-line.value {
  stroke: var(--primary);
}

.chart-line.principal {
  stroke: var(--coral);
}

.chart-dot {
  fill: var(--accent);
  stroke: #ffffff;
  stroke-width: 2;
}

.legend {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 0 18px 18px;
  color: var(--muted);
  font-size: 13px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-line {
  width: 22px;
  height: 3px;
  border-radius: 3px;
  display: inline-block;
}

.value-line {
  background: var(--primary);
}

.principal-line {
  background: var(--coral);
}

.positive {
  color: var(--positive);
}

.negative {
  color: var(--negative);
}

.market-gain {
  color: var(--gain);
}

.market-loss {
  color: var(--loss);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 18px;
}

.hidden-file {
  display: none;
}

.data-stats {
  margin: 0;
  padding: 8px 18px 18px;
}

.data-stats div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0;
  border-bottom: 1px solid var(--soft-line);
}

.data-stats div:last-child {
  border-bottom: 0;
}

.data-stats dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  min-width: 180px;
  max-width: calc(100vw - 48px);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  background: rgba(31, 41, 51, 0.92);
  color: #ffffff;
  border-radius: 6px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard-layout,
  .work-layout,
  .data-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body.auth-pending .auth-screen,
  body.auth-locked .auth-screen {
    align-items: start;
    padding: 18px 14px;
  }

  .auth-panel {
    margin-top: 26px;
    padding: 28px 18px 22px;
  }

  .auth-panel h1 {
    font-size: 25px;
  }

  .auth-description {
    min-height: auto;
    margin-bottom: 18px;
  }

  .pin-grid {
    gap: 7px;
  }

  .pin-input {
    height: 48px;
    font-size: 22px;
  }

  .app-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 18px;
  }

  .app-header,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .range-label {
    text-align: left;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 124px;
  }

  .year-filter {
    width: 100%;
    justify-content: space-between;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-actions {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-heading span {
    text-align: left;
  }

  #performance-chart {
    min-height: 230px;
  }
}

@media (max-width: 390px) {
  body.auth-pending .auth-screen,
  body.auth-locked .auth-screen {
    padding-left: 10px;
    padding-right: 10px;
  }

  .pin-grid {
    gap: 5px;
  }

  .pin-input {
    height: 43px;
    font-size: 20px;
  }
}
