﻿:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #6b778b;
  --line: #dbe3ec;
  --blue: #1769e0;
  --blue-dark: #0f55b8;
  --green: #0f9d6a;
  --soft: #e7f0fd;
  --shadow: 0 10px 30px rgba(23, 32, 51, .08);
  --radius: 12px;
}
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html, body {
  width: 100%;
  max-width: 100vw;
  height: 100%;
  margin: 0;
  overflow-x: hidden;
}
body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei UI", sans-serif;
}
button, input { font: inherit; }
button { touch-action: manipulation; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.topbar {
  position: relative;
  width: 100%;
  min-width: 0;
  max-width: 100vw;
  z-index: 20;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: linear-gradient(135deg, #1769e0, #0f55b8);
  color: #fff;
  box-shadow: 0 3px 16px rgba(15, 55, 110, .22);
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--blue);
  font-size: 20px;
  font-weight: 800;
}
.brand-title { font-size: 16px; font-weight: 800; line-height: 1.1; }
.brand-sub { display: none; font-size: 11px; opacity: .78; margin-top: 2px; }
.top-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.badge {
  border-radius: 999px;
  padding: 5px 8px;
  background: rgba(255,255,255,.17);
  font-size: 11px;
  white-space: nowrap;
}
.icon-btn, .secondary-btn, .sync-btn, .primary-btn, .view-btn, .market-tab {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 11px;
  cursor: pointer;
}
.topbar .icon-btn {
  min-height: 34px;
  background: rgba(255,255,255,.14);
  color: #fff;
  border-color: rgba(255,255,255,.3);
}
.primary-btn {
  width: 100%;
  min-height: 46px;
  background: var(--blue);
  color: #fff;
  border: 0;
  font-weight: 700;
}
.sync-btn, .secondary-btn { font-weight: 700; }
.sync-btn { background: var(--blue); color: #fff; border-color: var(--blue); }
.secondary-btn { background: var(--soft); color: var(--blue-dark); border-color: #cfe0f8; }
.banner {
  flex: 0 0 auto;
  background: #fff5d7;
  color: #7b5700;
  padding: 8px 12px;
  font-size: 12px;
  text-align: center;
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(238, 243, 248, .82);
  backdrop-filter: blur(4px);
  font-weight: 700;
}
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #b9cce6;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 120;
  transform: translate(-50%, 16px);
  max-width: calc(100vw - 32px);
  border-radius: 10px;
  padding: 10px 14px;
  background: #172033;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.pairing {
  width: calc(100% - 28px);
  max-width: 560px;
  margin: 14px auto;
  padding: 20px;
  overflow: auto;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.pairing h1 { margin: 0 0 8px; font-size: 23px; }
.pairing p { color: var(--muted); line-height: 1.65; }
.pairing label { display: block; margin: 13px 0 6px; font-weight: 600; }
.pairing input[type=password] {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f9fbfd;
  font-size: 16px;
}
.check { display: flex !important; align-items: center; gap: 8px; font-weight: 400 !important; }
.pairing code { word-break: break-all; }

.main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  max-width: min(1800px, 100vw);
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  overflow: hidden;
}
.market-tabs {
  flex: 0 0 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #dfe8f3;
}
.market-tab {
  min-height: 40px;
  border: 0;
  background: transparent;
  color: #526076;
  font-size: 15px;
  font-weight: 800;
}
.market-tab.active {
  background: var(--panel);
  color: var(--blue-dark);
  box-shadow: 0 2px 8px rgba(23, 32, 51, .1);
}
.toolbar {
  flex: 0 0 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
}
.search {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font-size: 16px;
}
.sync-btn { min-width: 74px; min-height: 42px; padding: 8px 12px; }

.dashboard {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  min-height: 0;
}
.stock-panel, .detail-panel { min-width: 0; min-height: 0; }
.stock-panel {
  flex: 0 0 auto;
  padding: 0;
  overflow: hidden;
  background: transparent;
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 5px;
  font-size: 12px;
  font-weight: 800;
  color: #536177;
}
.count {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--blue-dark);
  font-size: 11px;
}
.stock-list {
  display: flex;
  flex-direction: row;
  gap: 6px;
  padding: 0 0 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.stock-list::-webkit-scrollbar { display: none; }
.stock-item {
  flex: 0 0 auto;
  min-width: 64px;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
  white-space: nowrap;
  scroll-snap-align: start;
}
.stock-item.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  box-shadow: 0 3px 10px rgba(23, 105, 224, .25);
}
.stock-list .empty-state { min-height: 38px !important; width: 100%; }

.detail-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  background: transparent;
}
.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  color: var(--muted);
  text-align: center;
}
#stockDetail:not(.hidden) {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.stock-heading {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.stock-heading h1 { margin: 0; font-size: 19px; line-height: 1.15; }
#stockMeta { margin-top: 3px; font-size: 11px; }
#stockSyncBtn {
  min-height: 38px;
  padding: 7px 10px;
  white-space: nowrap;
  font-size: 12px;
}

.table-tabs {
  flex: 0 0 auto;
  min-width: 0;
  max-width: 100%;
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  padding: 0 0 2px;
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.table-tabs::-webkit-scrollbar { display: none; }
.table-tab {
  flex: 0 0 auto;
  min-width: 52px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  scroll-snap-align: center;
}
.table-tab.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  box-shadow: 0 3px 10px rgba(23, 105, 224, .22);
}
.table-tab.missing, .table-tab:disabled {
  color: #a1aab8;
  background: #eef2f7;
  border-color: #e3e9f0;
  font-weight: 500;
  text-decoration: line-through;
}

.viewbar {
  flex: 0 0 auto;
  min-width: 0;
  max-width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: 0 0 6px;
}
.view-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  border-radius: 10px;
  background: #dfe8f3;
}
.view-btn {
  min-height: 34px;
  padding: 6px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #536177;
  font-size: 12px;
  font-weight: 700;
}
.view-btn.active {
  background: var(--panel);
  color: var(--blue-dark);
  box-shadow: 0 2px 7px rgba(23, 32, 51, .1);
}
.view-btn:disabled { opacity: .45; }
.zoom-group { display: flex; align-items: center; gap: 5px; font-size: 11px; }
.zoom-group .icon-btn {
  min-width: 38px;
  min-height: 34px;
  padding: 4px 7px;
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
}
#tableMeta { flex: 1 1 100%; font-size: 10px; line-height: 1.2; }

.table-viewport {
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  position: relative;
  min-height: 220px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.table-viewport > .empty-state { height: 100%; min-height: 0; }
.table-wrap {
  width: 100%;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.data-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}
.data-table th, .data-table td {
  min-width: 58px;
  padding: 7px 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  text-align: left;
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #e9f0f8;
  font-weight: 800;
}
.data-table th.row-head, .data-table td.row-head {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 40px;
  padding: 6px;
  background: #f3f6fa;
  color: var(--muted);
  text-align: right;
}
.data-table th.row-head { z-index: 4; }
.data-table td.row-head {
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.data-table td.row-head:active { background: #d7e7ff; }
.data-table tr.selected-row td {
  box-shadow: inset 0 1px 0 #1769e0, inset 0 -1px 0 #1769e0, inset 0 0 9999px rgba(23, 105, 224, .10);
}
.data-table tr.selected-row td.row-head {
  background: #1769e0 !important;
  color: #fff;
  box-shadow: none;
}
.data-table tbody tr:nth-child(even) td:not(.row-head) { background: #fbfcfe; }

.chart-wrap {
  width: 100%;
  height: 100%;
  padding: 7px;
  overflow: auto;
  background: #fff;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.chart-wrap img { display: block; max-width: none; height: auto; background: #fff; }

@media (min-width: 760px) {
  .brand-sub { display: block; }
  .main { gap: 10px; padding: 12px; }
  .dashboard { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 10px; align-items: stretch; }
  .stock-panel, .detail-panel {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
  }
  .stock-panel { display: flex; flex-direction: column; }
  .stock-list { flex: 1 1 auto; flex-direction: column; overflow-x: hidden; overflow-y: auto; }
  .stock-item { width: 100%; min-width: 0; text-align: left; }
  .detail-panel { padding: 12px; }
  .table-tabs { flex-wrap: wrap; overflow: visible; }
  .table-tab { min-width: 62px; }
  #tableMeta { flex-basis: auto; margin-left: auto; font-size: 11px; }
  .table-viewport { min-height: 320px; }
  .data-table th, .data-table td { padding: 6px 8px; }
}

@media (orientation: landscape) and (max-height: 560px) {
.topbar{min-height:36px;padding:calc(2px + env(safe-area-inset-top)) 8px 2px}.brand{gap:6px}.brand-mark{width:26px;height:26px;border-radius:8px;font-size:15px}.brand-title{font-size:13px}.brand-sub{display:none}.top-actions{gap:4px}.topbar .icon-btn{min-height:26px;padding:3px 7px;font-size:11px}.badge{padding:3px 6px;font-size:9px}
.main{display:grid;grid-template-columns:clamp(74px,13vw,104px) minmax(0,1fr);grid-template-rows:30px minmax(0,1fr);gap:4px;padding:4px max(4px,env(safe-area-inset-right)) max(4px,env(safe-area-inset-bottom)) max(4px,env(safe-area-inset-left))}
.market-tabs{grid-column:1;grid-row:1;padding:2px;border-radius:7px}.market-tab{min-height:24px;padding:2px;font-size:12px}.toolbar{grid-column:2;grid-row:1;gap:4px}.search{min-height:30px;height:30px;padding:4px 8px;border-radius:7px;font-size:13px}.sync-btn{min-width:54px;min-height:30px;height:30px;padding:3px 7px;font-size:12px}
.dashboard{grid-column:1/-1;grid-row:2;display:grid;grid-template-columns:clamp(74px,13vw,104px) minmax(0,1fr);grid-template-rows:minmax(0,1fr);gap:4px;min-height:0}
.stock-panel{display:flex;flex-direction:column;min-height:0;padding:4px;border:1px solid var(--line);border-radius:7px;background:var(--panel)}.panel-title{display:none}.stock-list{flex:1 1 auto;flex-direction:column;gap:2px;padding:0;overflow-x:hidden;overflow-y:auto}.stock-item{width:100%;min-width:0;min-height:24px;padding:3px 4px;border-radius:6px;text-align:center;font-size:11px}
.detail-panel{display:flex;flex-direction:column;min-height:0;padding:4px;border:1px solid var(--line);border-radius:7px;overflow:hidden;background:var(--panel)}
#stockDetail:not(.hidden){display:grid;grid-template-columns:minmax(0,1fr) auto;grid-template-rows:24px 25px minmax(0,1fr);column-gap:4px;row-gap:1px;min-height:0}
.stock-heading{grid-column:1/-1;grid-row:1;flex:0 0 auto;gap:4px;margin:0}.stock-heading h1{font-size:14px;line-height:1.1}#stockMeta{display:none}#stockSyncBtn{min-height:24px;padding:2px 7px;font-size:10px}
.table-tabs{grid-column:1;grid-row:2;align-self:center;min-width:0;flex:0 0 auto;flex-wrap:nowrap;gap:3px;margin:0;overflow-x:auto;overflow-y:hidden}.table-tab{min-height:24px;padding:2px 7px;border-radius:6px;font-size:10px}
.viewbar{grid-column:2;grid-row:2;align-self:center;justify-content:flex-end;flex:0 0 auto;flex-wrap:nowrap;gap:0 4px;margin:0}.view-switch{gap:1px;padding:1px;border-radius:6px}.view-btn{min-height:24px;padding:2px 7px;font-size:10px}.zoom-group{gap:3px;font-size:9px}.zoom-group .icon-btn{min-width:24px;min-height:24px;padding:1px 4px;font-size:13px}#tableMeta{display:none}
.table-viewport{grid-column:1/-1;grid-row:3;flex:1 1 auto;height:auto;min-height:0;border-radius:7px}.table-viewport>.empty-state{min-height:0}.data-table th,.data-table td{min-width:48px;padding:3px 5px;font-size:11px}.chart-wrap{padding:3px}.toast{bottom:calc(6px + env(safe-area-inset-bottom))}
}
