/* =====================
   LegendStock — Clean Dark UI (refined)
   ===================== */

/* ---- design tokens ---- */
:root{
  /* colors */
  --bg:#0b1220;
  --panel:#0f1729;
  --card:#0f1729cc;
  --text:#e6ecff;
  --muted:#8aa0c6;
  --border:#1e2a46;
  --border-strong:#3d5282;

  /* accents */
  --brand:#78a5ff;
  --brand-2:#43c7ff;
  --accent:#6fe3ff;
  --danger:#ff6b6b;
  --ok:#2dd4bf;

  /* effects */
  --shadow-lg:0 10px 30px rgba(5,12,28,.35);
  --radius:16px;
  --blur:10px;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
:root{ color-scheme: dark; }

/* ---- page / header ---- */
body.page{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Noto Sans TC", sans-serif;
  color:var(--text);
  background:
    radial-gradient(1000px 400px at 10% -10%, rgba(67,199,255,.20), transparent 60%),
    radial-gradient(800px 300px at 100% 0%, rgba(120,165,255,.18), transparent 60%),
    var(--bg);
}
.container{ max-width:1200px; margin:24px auto; padding:0 16px; }

.bar{
  position:sticky; top:0; z-index:10;
  display:flex; align-items:center; justify-content:space-between; gap:12px;
  padding:12px 16px;
  background:linear-gradient(180deg, rgba(255,255,255,.02), transparent);
  border-bottom:1px solid var(--border);
  backdrop-filter: blur(var(--blur));
}
.brand{ display:flex; align-items:center; gap:10px; font-weight:800; letter-spacing:.5px; }
.brand .logo{
  width:28px; height:28px; border-radius:10px;
  background: conic-gradient(from 180deg, var(--brand-2), var(--brand), var(--brand-2));
  box-shadow: inset 0 0 14px rgba(255,255,255,.2);
}

/* ---- cards / blocks ---- */
.card{
  background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(0,0,0,.08)), var(--card);
  border:1px solid var(--border-strong);
  border-radius: calc(var(--radius) + 2px);
  padding:18px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(var(--blur));
}
.card h3{
  margin:0 0 10px;
  padding:8px 0 14px;
  font-size:1.05rem; letter-spacing:.03em;
  border-bottom:1px dashed var(--border);
}

/* ---- buttons ---- */
.btn{
  appearance:none; cursor:pointer;
  padding:10px 16px; border-radius:14px; font-weight:700; color:#fff;
  border:1px solid var(--border-strong);
  background: linear-gradient(180deg, #83b0ff, #638cff);
  box-shadow: 0 6px 16px rgba(38,76,140,.35), 0 1px 0 rgba(255,255,255,.12) inset;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover{ transform: translateY(-1px); box-shadow: 0 10px 24px rgba(38,76,140,.38); }
.btn:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; }
.btn.light{
  background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(255,255,255,.04));
  color:var(--text); border-color: var(--border);
}
.btn.danger{
  background: linear-gradient(180deg, #ff8a8a, var(--danger));
  border-color: rgba(255,107,107,.6);
}

/* ---- inputs (global baseline) ---- */
input{
  width:100%; padding:12px 14px;
  color:var(--text); background:#0b1220;
  border:1px solid var(--border); border-radius:12px;
}

/* ---- tabs ---- */
.tabs{ display:flex; flex-wrap:wrap; gap:10px; margin:10px 0 12px; }
.tab{
  appearance:none; cursor:pointer;
  padding:8px 14px; border-radius:9999px; font-weight:600; letter-spacing:.02em; color:var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(0,0,0,.08));
  border:1px solid var(--border);
  transition: all .18s ease; box-shadow: 0 2px 0 rgba(0,0,0,.25) inset;
}
.tab:hover{ border-color:#a9c4ff; box-shadow: 0 0 0 2px rgba(120,165,255,.15) inset, 0 6px 16px rgba(14,25,45,.25); transform: translateY(-1px); }
.tab.active{
  background: radial-gradient(120% 140% at 30% 20%, rgba(120,165,255,.22), rgba(120,165,255,.06));
  border-color: var(--brand); color:#fff; box-shadow: 0 0 0 2px rgba(120,165,255,.25) inset;
}
.tab.disabled{ opacity:.45; filter:grayscale(.25); cursor:not-allowed; }

.subtabs{ display:flex; gap:8px; flex-wrap:wrap; margin:12px 0 8px; }
.subtab{
  appearance:none; cursor:pointer;
  padding:6px 12px; border-radius:9999px; font-weight:600; color:var(--text);
  background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(0,0,0,.08));
  border:1px solid var(--border); transition:all .18s ease;
}
.subtab:hover{ border-color:#a9c4ff; box-shadow: 0 0 0 2px rgba(120,165,255,.14) inset; transform: translateY(-1px); }
.subtab.active{
  background: linear-gradient(180deg, rgba(120,165,255,.22), rgba(120,165,255,.06));
  border-color: var(--brand); color:#fff;
}

/* ---- content header / badge ---- */
.content{ border:1px solid var(--border); border-radius:20px; background: linear-gradient(180deg, rgba(255,255,255,.015), rgba(0,0,0,.06)); }
.content h2{ margin:0 0 10px; font-weight:800; letter-spacing:.3px; display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.content h2 small{ opacity:.7; font-weight:600; }
.badge{
  --bdg-bg: rgba(16,23,41,.75);
  --bdg-grad: linear-gradient(135deg, var(--brand-2), var(--brand));
  display:inline-flex; align-items:center; gap:6px;
  padding:6px 12px; border-radius:9999px; font-weight:700; letter-spacing:.03em; color:#eaf1ff;
  background: linear-gradient(var(--bdg-bg), var(--bdg-bg)) padding-box, var(--bdg-grad) border-box;
  border:1px solid transparent;
  box-shadow: 0 8px 22px rgba(67,199,255,.18), inset 0 1px 0 rgba(255,255,255,.12);
  position:relative; isolation:isolate;
}
.badge::before{
  content:""; position:absolute; inset:-2px; border-radius:inherit;
  background: conic-gradient(from 180deg, transparent 30%, rgba(111,227,255,.5), transparent 60%);
  filter: blur(12px); opacity:.45; z-index:-1; pointer-events:none;
}
.badge:hover{
  box-shadow: 0 10px 26px rgba(67,199,255,.24), inset 0 1px 0 rgba(255,255,255,.16);
  transform: translateY(-1px); transition: all .18s ease;
}
.content h2 .badge{ padding:4px 10px; font-size:.9rem; }

/* ---- data grids ---- */
.grid2{ display:grid; grid-template-columns:1fr 1fr; gap:14px 18px; }
.grid2 .full{ grid-column:1 / -1; }
.grid3{ display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:14px 18px; }

.label{ font-size:.78rem; color:var(--muted); text-transform:uppercase; letter-spacing:.08em; margin-bottom:6px; }
.val{ font-size:1.05rem; font-weight:650; color:var(--text); }

.metric{
  background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(0,0,0,.06));
  border:1px solid var(--border); border-radius:14px; padding:12px 14px;
}
.metric .k{ font-size:.78rem; color:var(--muted); text-transform:uppercase; letter-spacing:.08em; margin-bottom:6px; }
.metric .v{ font-size:1.4rem; font-weight:750; line-height:1.15; color:#f2f6ff; }

/* ---- utility ---- */
.center{ max-width:480px; margin:12vh auto; }
.title{ margin:0 0 12px; font-weight:800; }
.muted{ color:var(--muted); }
.msg{ margin-top:8px; font-size:.95em; }
.msg.ok{ color:var(--ok); } .msg.error{ color:var(--danger); }

/* ---- skeleton ---- */
.skeleton{ position:relative; overflow:hidden; min-height:120px; }
.skeleton::after{
  content:""; position:absolute; inset:0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.12), transparent);
  transform: translateX(-100%); animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 100%{ transform: translateX(100%);} }

/* ---- busy overlay (+ progress) ---- */
#busy{
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(8,12,20,.45); backdrop-filter: blur(3px); z-index: 9999;
}
#busy.show{ display:flex; }
#busy .box{
  display:inline-flex; align-items:center; gap:12px;
  padding:14px 16px; border-radius:14px;
  background: var(--card); border:1px solid var(--border); box-shadow: var(--shadow-lg);
}
#busy .spin{
  width:18px; height:18px; border-radius:50%;
  border:2px solid transparent; border-top-color:var(--brand-2); border-right-color:var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin{ to{ transform: rotate(360deg); } }

#busy .progress{
  width:320px; height:10px; border-radius:999px; overflow:hidden;
  border:1px solid var(--border); background:#0b1224; margin-top:8px;
}
#busy .progress .bar{
  height:100%; width:0%;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width .25s ease;
}
#busy .subtext{ margin-top:6px; font-size:.9em; color:var(--muted); }

body.busy{ cursor: progress; }
.tab[data-disabled="1"], .subtab[data-disabled="1"], .btn[data-disabled="1"]{
  pointer-events:none; opacity:.55; filter:saturate(.4); cursor:not-allowed;
}

/* ---- content spacing helpers ---- */
.content > section.card { margin-top: 16px; }
.content h2 { margin-bottom: 16px; }
@media (min-width: 768px){
  .content > section.card { margin-top: 20px; }
  .content h2 { margin-bottom: 18px; }
}

/* ======================================================
   Login Overrides (login.html 專用強化樣式)
   ====================================================== */

/* 卡片尺寸與留白 */
.page .center.card{
  padding:22px;             /* 內距 */
  max-width:560px;          /* 寬度 */
}

/* 表單間距 */
.page .center.card form{ display:grid; gap:12px; margin-top:6px; }
.page .center.card form label{ display:grid; gap:6px; font-weight:600; }

/* 玻璃底 */
.glass{
  background: linear-gradient(180deg, rgba(255,255,255,.02), rgba(0,0,0,.08)), var(--card);
  backdrop-filter: blur(var(--blur));
}

/* 標題/品牌列與表單距離（logo + 標題同行時使用） */
.brandline{
  display:flex; align-items:center; gap:10px;
  margin-bottom:24px; /* ← 標題與輸入框距離 */
}

/* 雷電 Logo */
.logo-bolt{
  width:36px; height:36px; border-radius:6px;
  background: linear-gradient(135deg, #60a5fa, #a78bfa);
  clip-path: polygon(45% 0, 100% 0, 60% 50%, 80% 50%, 35% 100%, 35% 60%, 15% 60%);
  box-shadow: 0 4px 12px rgba(96,165,250,.4);
}

/* 標題（與下方表單距離若沒用 brandline） */
/* .title{ margin:0 0 24px; } */

/* 輸入框：字體、顏色、邊框、背景（#serial / #admin_pwd） */
#serial, #admin_pwd{
  font-size:18px;
  color:#f8fafc;
  border:2px solid #334155;              /* 預設明顯邊框 */
  border-radius:10px;
  background: rgba(255,255,255,0.03);    /* 與背景拉開 */
  height:44px; padding:0 14px;
  transition: box-shadow .15s ease, border-color .15s ease, background .15s ease;
}

/* placeholder 提亮 */
#serial::placeholder, #admin_pwd::placeholder{
  color:#cbd5e1; font-size:18px; font-weight:500; opacity:1;
}

/* 聚焦狀態：亮藍框＋發光 */
#serial:focus, #admin_pwd:focus{
  border-color:#60a5fa;
  box-shadow:0 0 0 4px rgba(96,165,250,.35);
  background: rgba(255,255,255,0.06);
  outline:none;
}

/* 登入按鈕滿版且高度一致 */
.page .center.card .btn{ height:44px; width:100%; }

/* 訊息區預留高度避免跳動 */
.page .center.card .msg,
.page .center.card #msg,
.page .center.card #msg-admin{ min-height:1.35em; margin-top:6px; }

/* 對話框（管理員登入） */
dialog.modal{
  width:min(420px,92vw);
  border:1px solid var(--border);
  border-radius:14px;
  padding:18px;
  box-shadow:0 24px 60px rgba(2,6,23,.25);
  animation: pop .18s ease-out;
}
dialog::backdrop,
dialog.modal::backdrop{
  background:rgba(15,23,42,.45);
  backdrop-filter:blur(2px);
}
@keyframes pop{
  from{ transform:translateY(8px) scale(.98); opacity:0; }
  to{ transform:translateY(0) scale(1); opacity:1; }
}
.modal-header{ display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; }
.modal-title{ font-size:18px; font-weight:700; letter-spacing:.02em; }
.modal-actions{ display:flex; gap:8px; margin-top:10px; }
.btn.full{ width:100%; height:44px; }
@media (max-width: 768px){
  .grid2, .grid3 { grid-template-columns: 1fr !important; }
  .container { padding: 0 12px; }
  .content > section.card { margin-top: 14px; }
}

/* 讓 top tabs 與 subtabs 可左右滑動；隱藏醜捲軸 */
.tabs, .subtabs{
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar, .subtabs::-webkit-scrollbar{ display: none; }

/* 行動裝置：加大可點面積與字距 */
@media (max-width: 768px){
  .tab, .subtab{
    padding: 10px 14px;
    font-size: .95rem;
    flex: 0 0 auto; /* 保持 pill 寬度，避免被壓縮 */
  }
}

@media (max-width: 768px){
  .content { padding: 12px; border-radius: 14px; }
  .content h2 { line-height: 1.25; word-break: break-word; }
}

/* 觸控裝置：加大按鈕高度 */
@media (pointer: coarse){
  .btn{ min-height: 44px; }
}

/* 清楚的鍵盤焦點（整站通用增強） */
:where(.btn, .tab, .subtab):focus-visible{
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* 減少動作偏好：關閉非必要動畫 */
@media (prefers-reduced-motion: reduce){
  *{ animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* 讓標籤與數值在單欄時更易讀 */
.metric .k { font-size: .8rem; }
.metric .v { font-size: 1.2rem; }
.val { word-break: break-word; }

.tab:hover{
  border-color:#a9c4ff;
  /* 內圈高亮 + 外部浮起感（不位移） */
  box-shadow:
    0 0 0 2px rgba(120,165,255,.15) inset,
    0 6px 16px rgba(14,25,45,.25);
  /* ← 刪掉 transform: translateY(-1px); */
}

.tab:active{
  transform: translateY(0);       /* 或改成  translateY(1px) */
  box-shadow:
    0 0 0 2px rgba(120,165,255,.12) inset,
    0 2px 10px rgba(14,25,45,.22);
}

.tab{ transform: translateZ(0); will-change: box-shadow; }

/* --- Tabs hover fix (no jump, no notch) --- */
.tab{
  position: relative;
  transform: none;                 /* 先確保起始不會有殘留 transform */
  will-change: box-shadow;
}

/* 1) 取消 hover 位移（確保覆蓋舊規則） */
.tab:hover{
  transform: none !important;      /* ← 關鍵：把舊的 translateY(-1px) 壓掉 */
  border-color: #a9c4ff;
  box-shadow: none;                /* 不用陰影來畫內圈，避免視覺缺口 */
}

/* 2) 用偽元素畫「內發光環」，不會造成位移或缺口 */
.tab::after{
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 9999px;           /* 膠囊對齊 */
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease;
  /* 以 outline 的方式畫一圈亮邊（不影響佈局、不會抬升或露縫） */
  box-shadow: 0 0 0 2px rgba(120,165,255,.15) inset;
}

.tab:hover::after{
  opacity: 1;                      /* hover 才顯示高亮環 */
}

/* 3) 真的需要點按壓感，就在 active 時做「向下 1px」，不是 hover */
.tab:active{
  transform: translateY(1px);      /* 只在按下時短暫位移，不會看到缺口 */
  box-shadow: none;
}

/* 保險：任何狀態一律不要在 hover 做位移 */
.tab:hover { transform: none !important; }
.subtab:hover{
  border-color:#a9c4ff;
  box-shadow: 0 0 0 2px rgba(120,165,255,.14) inset;
  transform: translateY(-1px);     /* ← 問題根源 */
}

/* --- Subtabs hover fix --- */
.subtab{
  position: relative;
  transform: none;
  will-change: box-shadow;
}

/* 1) 移除 hover 位移與陰影造成的跳動 */
.subtab:hover{
  transform: none !important;          /* ← 關鍵：壓掉 translateY(-1px) */
  border-color: #a9c4ff;
  box-shadow: none;                     /* 不用陰影畫環，避免視覺缺口 */
}

/* 2) 用偽元素畫高亮環，不會擠動版面 */
.subtab::after{
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease;
  box-shadow: 0 0 0 2px rgba(120,165,255,.15) inset;
}
.subtab:hover::after{ opacity: 1; }

/* 3) 按下時才做輕微壓下感（不會露縫） */
.subtab:active{
  transform: translateY(1px);
  box-shadow: none;
}

/* 按鈕本身更醒目，且下方間距減少 */
#btn-login{
  font-size: 16px;      /* 想更大用 17~18px */
  font-weight: 700;
  height: 48px; 
  padding: 0 20px;
  margin-bottom: 6px;   /* ↓ 按鈕 → 訊息 的距離縮小 */
  letter-spacing: .02em;
}

/* 輸入框 → 按鈕：距離拉大 */
#serial{ 
  margin-bottom: 18px;  /* 想更大改 20~24px */
}

/* 只影響登入頁：讓卡片垂直置中 */
body.page.login{
  min-height: 100svh;     /* 滿版高度（行動裝置更準） */
  display: grid;
  place-items: center;     /* 水平＋垂直置中 */
  padding-top: 56px;       /* 頂部預留給固定的 topbar */
}

/* 取消共用樣式裡對登入卡片的額外位移 */
body.page.login .center.card{
  margin: 0;
}

/* 只影響登入頁的卡片寬度 */
body.page.login .center.card{
  width: min(92vw, 600px);  /* 讓卡片更寬：上限 720px，可視窗 92% */
  max-width: 600px;         /* 想更寬改 760/800 皆可 */
  padding: 28px 32px;       /* 視覺上更舒適的內距（可調） */
}

/* 小螢幕維持舒適邊距 */
@media (max-width: 480px){
  body.page.login .center.card{
    width: 94vw;
    padding: 20px 16px;
  }
}

/* 只影響 INDEX 頁的小字體，最低放大到「基礎資料」(≈1.05rem) */
body.page.index{ --min-txt: 1.05rem; }

/* 常見比 1.05rem 還小的元素，統一提升到最小值 */
body.page.index .label,
body.page.index .metric .k,
body.page.index .tab,
body.page.index .subtab,
body.page.index .msg,
body.page.index .muted,
body.page.index input,
body.page.index button.btn{
  font-size: var(--min-txt);
}
