:root {
  --bg: #071020;
  --panel: #0d1a33;
  --panel2: #102444;
  --line: #244264;
  --text: #e9f4ff;
  --muted: #8fb0d0;
  --accent: #1de9ff;
  --accent2: #7c4dff;
  --ok: #29f084;
  --warn: #ffce3a;
  --bad: #ff5570;
  --shadow: 0 20px 60px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 15% 10%, #143b66 0, #071020 35%, #050914 100%);
  color: var(--text);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; }
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-box { width: 100%; max-width: 420px; padding: 35px; background: rgba(13, 26, 51, 0.9); border: 1px solid rgba(29, 233, 255, 0.25); border-radius: 24px; box-shadow: var(--shadow); }
.app-shell { display: flex; min-height: 100vh; }

/* 側邊欄與導覽 - 桌面版 */
.sidebar { 
  width: 285px; 
  padding: 22px; 
  background: rgba(4, 12, 28, 0.92); 
  border-right: 1px solid rgba(29, 233, 255, 0.18); 
  backdrop-filter: blur(14px); 
  position: sticky; 
  top: 0; 
  height: 100vh; 
  display: flex; 
  flex-direction: column; 
  z-index: 100; 
  transition: transform 0.3s ease; 
  overflow-y: auto; 
  overflow-x: hidden;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(29,233,255,0.3); border-radius: 4px; }

.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; flex-shrink: 0; }
.brand-icon { width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent2)); font-weight: 900; color: #061022; box-shadow: 0 0 30px rgba(29, 233, 255, 0.45); }
h1, h2, h3, p { margin: 0; }
.brand h1 { font-size: 18px; }
.brand p, .muted, small { color: var(--muted); }

.nav { 
  display: flex; 
  flex-direction: column; 
  gap: 6px; 
  flex: 1; 
  min-height: min-content;
  padding-bottom: 10px;
}
.nav button { 
  border: 1px solid transparent; 
  color: var(--muted); 
  background: transparent; 
  text-align: left; 
  padding: 13px 14px; 
  border-radius: 14px; 
  cursor: pointer; 
  width: 100%; 
  font-size: 14px; 
  flex-shrink: 0;
}
.nav button.active, .nav button:hover { 
  color: var(--text); 
  border-color: rgba(29, 233, 255, 0.35); 
  background: linear-gradient(90deg, rgba(29, 233, 255, 0.12), rgba(124, 77, 255, 0.08)); 
  box-shadow: inset 0 0 18px rgba(29, 233, 255, 0.08); 
}

.sidebar > div:last-child { 
  margin-top: auto; 
  padding-top: 16px; 
  flex-shrink: 0; 
}

/* 主工作區 */
.main { flex: 1; padding: 22px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; }
.mobile-topbar { display: none; }

/* 組件與元件 */
.btn { border: 1px solid rgba(29, 233, 255, 0.35); background: rgba(29, 233, 255, 0.1); color: var(--text); border-radius: 14px; padding: 11px 14px; cursor: pointer; transition: all 0.2s; display: inline-block; font-size: 14px; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #061022; font-weight: 800; border: none; }
.btn.ghost { background: rgba(255, 255, 255, 0.04); }
.btn.danger { background: rgba(255, 85, 112, 0.15); border-color: var(--bad); color: var(--bad); }
.btn.danger:hover { background: rgba(255, 85, 112, 0.25); }
.panel { border: 1px solid rgba(29, 233, 255, 0.2); background: linear-gradient(180deg, rgba(13,26,51,.92), rgba(8,18,38,.88)); border-radius: 24px; padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel h3 { margin-bottom: 14px; }
.tabs { display: flex; gap: 10px; margin-bottom: 18px; overflow-x: auto; padding-bottom: 5px; white-space: nowrap; }

/* 表單與欄位自適應 */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.field { display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
label { color: #b8d5f0; font-size: 14px; }
input, select, textarea { width: 100%; border: 1px solid rgba(143, 176, 208, 0.28); background: rgba(2,8,20,.55); color: var(--text); border-radius: 14px; padding: 12px; outline: none; }

/* 表格捲動與標籤 - 手機優化 */
.table-wrap { overflow-x: auto; margin-top: 14px; width: 100%; border-radius: 14px; border: 1px solid rgba(255,255,255,.05); -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
th, td { border-bottom: 1px solid rgba(255,255,255,.08); padding: 10px 8px; text-align: left; vertical-align: middle; }
th { color: #b8d5f0; background: rgba(29,233,255,.06); font-weight: 600; white-space: nowrap; }
td { word-break: break-word; }
.badge { border-radius: 99px; padding: 4px 10px; font-size: 12px; display: inline-block; text-align: center; }
.badge.ok { background: rgba(41,240,132,.15); color: var(--ok); }
.badge.warn { background: rgba(255,206,58,.15); color: var(--warn); }
.badge.bad { background: rgba(255,85,112,.15); color: var(--bad); }
.summary-bar { background: rgba(29, 233, 255, 0.05); border: 1px dashed var(--accent); padding: 14px; border-radius: 14px; margin-bottom: 14px; font-size: 16px; font-weight: bold; }
.search-box { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.alert-pulse { display: inline-flex; align-items: center; gap: 6px; color: var(--bad); font-weight: bold; animation: blink 1.5s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* 📱 手機與平板 RWD 自適應核心樣式設定 */
@media(max-width: 900px) {
  .app-shell { display: block; padding-top: 60px; }
  .mobile-topbar { 
    display: flex; 
    align-items: center; 
    gap: 14px; 
    background: rgba(7, 16, 32, 0.9); 
    border-bottom: 1px solid rgba(29, 233, 255, 0.18); 
    padding: 10px 16px; 
    position: fixed; 
    top: 0; 
    left: 0; 
    right: 0; 
    height: 60px; 
    z-index: 200; 
    backdrop-filter: blur(10px); 
  }
  .hamburger { 
    background: transparent; 
    border: 1px solid rgba(29,233,255,0.3); 
    color: var(--text); 
    font-size: 20px; 
    padding: 6px 12px; 
    border-radius: 8px; 
    cursor: pointer; 
  }
  
  /* ===== 手機版側邊欄 - 強制可滾動（適用 Safari） ===== */
  .sidebar { 
    position: fixed; 
    left: 0; 
    top: 60px; 
    bottom: 0;                    /* 改用 bottom:0 取代 height 計算，避免 Safari 計算錯誤 */
    width: 280px; 
    transform: translateX(-100%); 
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    overflow-y: auto !important; 
    overflow-x: hidden;
    padding: 16px 16px 30px;
    -webkit-overflow-scrolling: touch;
    background: rgba(4, 12, 28, 0.92); /* 確保背景色，避免透出 */
    backdrop-filter: blur(14px);
    transition: transform 0.3s ease;
    z-index: 100;
  }
  .sidebar::-webkit-scrollbar { width: 3px; }
  .sidebar::-webkit-scrollbar-thumb { background: rgba(29,233,255,0.25); border-radius: 3px; }
  
  .sidebar.open { transform: translateX(0); }
  
  .topbar { display: none; }
  .main { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .search-box { flex-direction: column; }
  
  .table-wrap { overflow-x: auto; }
  table { min-width: 500px; font-size: 13px; }
  th, td { padding: 8px 5px; }
  .btn { padding: 8px 12px; font-size: 13px; }
  .btn.danger { min-width: 50px; text-align: center; }
  td .btn { margin: 2px 0; display: inline-block; }
  td .btn + .btn { margin-left: 5px; }
  td img { max-width: 50px !important; max-height: 50px !important; }
}

/* 針對更小螢幕（iPhone SE 等） */
@media(max-width: 420px) {
  .panel { padding: 12px; }
  table { font-size: 12px; min-width: 400px; }
  th, td { padding: 6px 4px; }
  .btn { padding: 6px 10px; font-size: 12px; }
  .sidebar { width: 260px; }
}