:root {
  --bg: #fcfdfe;
  --bg-2: #f7f9fb;
  --panel: #ffffff;
  --panel-2: #fafbfd;
  --line: #e9edf3;
  --line-soft: #f1f4f8;
  --text: #1b2029;
  --muted: #6a7383;
  --muted-2: #98a1b0;
  --accent: #2f6bed;
  --accent-soft: rgba(47, 107, 237, .09);
  --up: #d8332c;
  --down: #0f8a63;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,30,50,.04), 0 4px 14px rgba(20,30,50,.045);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 20% -10%, #f3f6fc 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font: 14px/1.55 "Noto Sans TC", "PingFang TC",
        "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.hidden { display: none !important; }

/* 數字統一等寬，避免跳動 */
.num, .meta, .quote, .panel-stat, .broker-sum {
  font-variant-numeric: tabular-nums;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #dbe0e9;
  border: 2px solid transparent;
  background-clip: content-box;
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover { background: #c4cbd8; background-clip: content-box; }

/* ---------------- top bar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  height: 52px;
  padding: 0 18px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .3px;
  background: linear-gradient(92deg, #2f6bed, #7b4ddb);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topnav { flex: 1; display: flex; gap: 4px; }

.topnav a {
  padding: 6px 12px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13.5px;
  transition: background .15s, color .15s;
}

.topnav a:hover { background: var(--panel-2); color: var(--text); }

.user {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.logout {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  transition: border-color .15s, color .15s;
}

.logout:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------- layout ---------------- */

main.center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 52px);
  padding: 24px;
}

main.chips {
  display: flex;
  align-items: stretch;
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 52px);
}

/* ---------------- login ---------------- */

.login-card {
  width: 340px;
  padding: 34px 30px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  text-align: center;
  background: linear-gradient(92deg, #2f6bed, #7b4ddb);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.login-card .sub {
  margin: 0 0 24px;
  text-align: center;
  color: var(--muted-2);
  font-size: 12.5px;
  letter-spacing: 1px;
}

.login-card label {
  display: block;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 12.5px;
}

.login-card input {
  width: 100%;
  margin-top: 7px;
  padding: 11px 12px;
  background: #fcfdff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}

.login-card input:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #fff;
}

.login-card button {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  background: linear-gradient(180deg, #3f78f0, #2a60dd);
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s;
}

.login-card button:hover { filter: brightness(1.06); }

.error {
  margin: 0 0 16px;
  padding: 9px 11px;
  background: #fdeceb;
  border: 1px solid #f5c2bf;
  border-radius: 8px;
  color: #b02620;
  font-size: 13px;
}

/* ---------------- functions ---------------- */

.functions h1 { margin: 0 0 22px; font-size: 21px; }

.func-grid { display: flex; gap: 16px; flex-wrap: wrap; }

.func-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 236px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}

.func-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.func-title { font-size: 16.5px; font-weight: 600; }
.func-desc { color: var(--muted); font-size: 13px; }

/* ---------------- sidebar ---------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  width: 200px;
  flex: 0 0 200px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.tabs { display: flex; padding: 6px; gap: 6px; background: var(--panel-2); }

.tab {
  flex: 1;
  padding: 8px 4px;
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.tab:hover { color: var(--text); }

.tab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.side-block { padding: 11px; border-top: 1px solid var(--line-soft); }

.side-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted-2);
  font-size: 11.5px;
  letter-spacing: .5px;
}

#code-input {
  width: 100%;
  padding: 8px 10px;
  background: #fcfdff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  transition: border-color .15s, box-shadow .15s;
}

#code-input:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: #fff;
}

.btn-file {
  width: 100%;
  padding: 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.btn-file:hover { border-color: var(--accent); background: #eef3fe; }

.hint { margin: 7px 0 0; color: var(--muted-2); font-size: 11px; }

.list-head {
  padding: 9px 12px 6px;
  color: var(--muted-2);
  font-size: 11.5px;
  letter-spacing: .5px;
  border-top: 1px solid var(--line-soft);
}

.stock-list {
  flex: 1;
  margin: 0;
  padding: 0 6px 6px;
  list-style: none;
  overflow-y: auto;
}

.stock-list li {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  transition: background .12s;
}

.stock-list li:hover { background: var(--panel-2); }

.stock-list li.active {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}

.stock-list li.empty,
.stock-list li.missing {
  color: var(--muted-2);
  cursor: default;
  font-size: 12px;
}

.stock-list li.empty:hover,
.stock-list li.missing:hover { background: transparent; }

.stock-list .sid {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
}

.stock-list li.active .sid { color: var(--accent); }

/* ---------------- content ---------------- */

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.content-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 2px 4px 12px;
}

.content-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: .2px;
}

.quote {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-size: 15px;
}

.quote .price { font-size: 20px; font-weight: 600; }
.quote.up .price, .quote.up .chg { color: var(--up); }
.quote.down .price, .quote.down .chg { color: var(--down); }
.quote .chg { font-size: 13.5px; }

.meta { color: var(--muted); font-size: 12.5px; }

.meta .dot { color: var(--muted-2); margin: 0 7px; }

.notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 4px 12px;
  padding: 10px 12px;
  background: #fff8e8;
  border: 1px solid #f0dcae;
  border-left: 3px solid #d9a520;
  border-radius: 8px;
  color: #8a6414;
  font-size: 12.5px;
}

/* ---------------- panels ---------------- */

.panel-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding-bottom: 4px;
}

@media (max-width: 1500px) {
  .panel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 950px) {
  .panel-grid { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}

.panel:hover { border-color: #d5dde9; }

.panel-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}

.badge {
  padding: 2px 8px;
  background: var(--accent-soft);
  border: 1px solid rgba(47,107,237,.24);
  border-radius: 20px;
  color: #2559c9;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .3px;
}

.panel-title { font-size: 12.5px; color: var(--muted); }

.panel-stat {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted-2);
}

.chart { height: 230px; position: relative; }

/* 圖上左上角的 MA 圖例 */
.legend {
  position: absolute;
  top: 7px;
  left: 10px;
  z-index: 3;
  display: flex;
  gap: 11px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 2px;
  margin-right: 4px;
  vertical-align: middle;
  border-radius: 2px;
}

.panel-foot {
  padding: 9px 12px;
  border-top: 1px solid var(--line-soft);
  font-size: 11.5px;
  line-height: 1.75;
}

.pending {
  display: inline-block;
  color: var(--muted-2);
}

.pending::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: #d6dbe4;
  vertical-align: 1px;
}

/* ---------------- broker ---------------- */

.broker-split { display: flex; }

.broker-col {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-right: 1px solid var(--line-soft);
}

.broker-col:last-child { border-right: 0; }

.broker-title {
  margin-bottom: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

.broker-col:first-child .broker-title { color: #c0332c; }
.broker-col:last-child .broker-title { color: #0d7a58; }

.broker-body {
  min-height: 148px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-2);
  font-size: 12px;
}

.broker-sum {
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--muted);
}

/* ---------------- message / register ---------------- */

.login-card .msg {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.8;
}

.login-card .alt {
  margin: 18px 0 0;
  text-align: center;
  color: var(--muted-2);
  font-size: 12.5px;
}

.login-card .alt a { color: var(--accent); }

.login-card .req {
  float: right;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 400;
}

.btn-link {
  display: block;
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-align: center;
  transition: border-color .15s;
}

.btn-link:hover { border-color: var(--accent); }

/* ---------------- badges ---------------- */

.dot-badge {
  display: inline-block;
  min-width: 18px;
  margin-left: 6px;
  padding: 1px 6px;
  background: var(--up);
  border-radius: 20px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  vertical-align: 1px;
}

/* ---------------- admin ---------------- */

main.admin { padding: 20px; }

.admin-wrap { max-width: 1280px; margin: 0 auto; }

.admin-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.admin-head h1 { margin: 0; font-size: 20px; }

.pill {
  padding: 3px 10px;
  background: #fdeceb;
  border: 1px solid #f5c2bf;
  border-radius: 20px;
  color: #b02620;
  font-size: 12px;
}

.filters { display: flex; gap: 6px; margin-bottom: 14px; }

.filter {
  padding: 6px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  font-size: 13px;
  transition: border-color .15s, color .15s;
}

.filter:hover { color: var(--text); }

.filter.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #2559c9;
}

.empty-box {
  padding: 40px;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted-2);
  text-align: center;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.admin-table th {
  padding: 11px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.admin-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover { background: #fbfcfe; }

.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted-2); }

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  white-space: nowrap;
}

.tag-admin    { background: #f0eaff; color: #6b3fc4; }
.tag-pending  { background: #fff4de; color: #96650f; }
.tag-approved { background: #e4f6ef; color: #0d7a58; }
.tag-rejected { background: #fdeceb; color: #b02620; }
.tag-disabled { background: #eef0f4; color: #6a7383; }

.reason { margin-top: 4px; color: var(--muted-2); font-size: 11.5px; }

.actions { white-space: nowrap; }
.actions .inline { display: inline-flex; gap: 5px; margin-right: 6px; }

.actions input {
  width: 110px;
  padding: 5px 8px;
  background: #fcfdff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
}

.btn {
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.btn.ok:hover     { border-color: var(--down); color: var(--down); }
.btn.danger:hover { border-color: var(--up);   color: var(--up); }

/* ---------------- 面板日期區間 ---------------- */

.panel-range {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.panel-range input[type="date"] {
  width: 118px;
  padding: 3px 6px;
  background: #fcfdff;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.panel-range input[type="date"]:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.panel-range .tilde { color: var(--muted-2); font-size: 11px; }

.btn-reset {
  padding: 2px 7px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.btn-reset:hover { border-color: var(--accent); color: var(--accent); }

@media (max-width: 1500px) {
  .panel-range input[type="date"] { width: 108px; }
}


/* ---------------- 圖表懸停資訊 ---------------- */

.chart-tip {
  position: absolute;
  z-index: 5;
  min-width: 130px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, .97);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 2px 10px rgba(20,30,50,.12);
  font-size: 11.5px;
  line-height: 1.6;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.chart-tip .tip-date {
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 11px;
}

.chart-tip .tip-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.chart-tip .tip-row span { color: var(--muted-2); }
.chart-tip .tip-row b { font-weight: 600; }
.chart-tip .tip-row.up b   { color: var(--up); }
.chart-tip .tip-row.down b { color: var(--down); }


/* 標題列緊湊化 —— 避免徽章與日期框擠成多行 */

.panel-head {
  flex-wrap: nowrap;
  gap: 8px;
  padding: 8px 10px;
}

.badge {
  white-space: nowrap;
  flex: 0 0 auto;
}

.panel-range {
  flex: 1 1 auto;
  justify-content: flex-end;
  min-width: 0;
  gap: 3px;
}

.panel-range input[type="date"] {
  width: 112px;
  min-width: 0;
  flex: 0 1 auto;
  padding: 3px 4px;
}

.btn-reset { flex: 0 0 auto; }

@media (max-width: 1500px) {
  .panel-range input[type="date"] { width: 104px; font-size: 10.5px; }
}


/* 圖例獨立列 —— 不再浮在圖面上，避免與 K 棒重疊 */

.legend {
  position: static;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 6px 12px 0;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 18px;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 2px;
  margin-right: 4px;
  vertical-align: middle;
  border-radius: 2px;
}

.chart { height: 214px; }


/* 功能權限勾選 */

.perm-cell { min-width: 150px; }

.perm-form {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.perm-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
}

.perm-item input { margin: 0; cursor: pointer; }

.perm-save {
  margin-top: 2px;
  padding: 3px 10px;
  font-size: 11.5px;
}

.perm-save:hover { border-color: var(--accent); color: var(--accent); }


/* 管理者工具 */

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  flex: 1 1 140px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat.warn { border-color: #f0dcae; background: #fffdf7; }

.stat-num {
  display: block;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat.warn .stat-num { color: #96650f; }

.stat-label {
  display: block;
  margin-top: 2px;
  color: var(--muted-2);
  font-size: 12px;
}

.admin-tools { margin-bottom: 8px; }

.sub-head {
  margin: 24px 0 10px;
  font-size: 15px;
  font-weight: 600;
}

.tip-box {
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}

.tip-box code, .ep-list code {
  padding: 1px 6px;
  background: #eef2f9;
  border-radius: 4px;
  font-size: 12px;
}

.ep-list { display: flex; flex-wrap: wrap; gap: 6px; }

.in-xs, .in-sm, .in-md {
  padding: 5px 8px;
  background: #fcfdff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
}

.in-xs { width: 56px; }
.in-sm { width: 118px; }
.in-md { width: 190px; }

.in-xs:focus, .in-sm:focus, .in-md:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.mono { font-variant-numeric: tabular-nums; }
td.center { text-align: center; }

.ep-bad {
  margin-top: 3px;
  color: var(--up);
  font-size: 11px;
}

.new-row { background: #fbfcfe; }
.new-row input { border-style: dashed; }

.msg-cell { max-width: 260px; font-size: 12px; }
