/* =========================================================
   PIXON eSCM 樣式表
   色調：深藍黑底 + 青色 / 靛紫光暈，營造科技感
   ========================================================= */

/* ---------- 1. 顏色變數（要換色只改這裡） ---------- */
:root {
  --bg: #070d1a;          /* 最底層背景 */
  --panel: #0e1729;       /* 卡片背景 */
  --panel-2: #14213b;     /* 卡片內較亮區塊 */
  --line: #1f2f4f;        /* 邊框線 */
  --text: #e6edf7;        /* 主要文字 */
  --muted: #8ea0bd;       /* 次要文字 */
  --accent: #22d3ee;      /* 主色：青色 */
  --accent-2: #818cf8;    /* 輔色：靛紫 */
  --ok: #34d399;          /* 綠＝正常 */
  --warn: #fbbf24;        /* 橙＝即將到期 */
  --bad: #f87171;         /* 紅＝逾期／不合格 */
  --radius: 14px;
}

/* ---------- 2. 基本設定 ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background:
    radial-gradient(circle at 15% 0%, rgba(34, 211, 238, 0.12), transparent 40%),
    radial-gradient(circle at 90% 10%, rgba(129, 140, 248, 0.12), transparent 40%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 3. 上方標題列 ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: rgba(7, 13, 26, 0.85);
  backdrop-filter: blur(10px);           /* 毛玻璃效果 */
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;                     /* 漸層文字 */
}
.logo span { font-weight: 400; }

.topbar-right { margin-left: auto; }

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

.menu-btn {
  display: none;                          /* 桌機隱藏，手機才顯示 */
  background: none;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 20px;
  border-radius: 8px;
  width: 40px; height: 40px;
  cursor: pointer;
}

/* ---------- 4. 左側選單 ---------- */
.sidebar {
  position: fixed;
  top: 60px; left: 0; bottom: 0;
  width: 220px;
  padding: 20px 12px;
  background: rgba(14, 23, 41, 0.9);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 20;
  transition: transform 0.25s;
}

.sidebar a {
  color: var(--muted);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 15px;
}
.sidebar a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.sidebar a.active {
  background: linear-gradient(90deg, rgba(34, 211, 238, 0.18), rgba(129, 140, 248, 0.08));
  color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);   /* 左側亮條 */
}

.sidebar-note { margin-top: auto; font-size: 12px; color: var(--muted); padding: 10px; }

.overlay { display: none; }

/* ---------- 5. 主要內容區 ---------- */
.main {
  margin-left: 220px;
  padding: 84px 28px 40px;
  max-width: 1400px;
}

.page-title { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.page-sub { color: var(--muted); margin-bottom: 20px; font-size: 14px; }

/* 卡片 */
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card h3 { font-size: 16px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }

/* 自動排列的格子：寬度不夠會自動換行，手機不會擠壓變形 */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

/* ---------- 6. KPI 卡片 ---------- */
.kpi {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.kpi:hover { transform: translateY(-2px); border-color: var(--accent); }
.kpi::after {                              /* 右上角光暈裝飾 */
  content: "";
  position: absolute;
  top: -40px; right: -40px;
  width: 100px; height: 100px;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.25), transparent 70%);
}
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 28px; font-weight: 700; margin: 4px 0; }
.kpi-value small { font-size: 14px; color: var(--muted); font-weight: 400; }
.kpi-trend { font-size: 13px; }
.up { color: var(--ok); }
.down { color: var(--bad); }

/* ---------- 7. 待辦與警示 ---------- */
.alert-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px dashed var(--line);
  flex-wrap: wrap;
}
.alert-row:last-child { border-bottom: none; }
.alert-text { flex: 1; min-width: 180px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot.bad { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.dot.warn { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

/* ---------- 8. 標籤（狀態顏色） ---------- */
.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
  border: 1px solid currentColor;
}
.tag.ok { color: var(--ok); background: rgba(52, 211, 153, 0.1); }
.tag.warn { color: var(--warn); background: rgba(251, 191, 36, 0.1); }
.tag.bad { color: var(--bad); background: rgba(248, 113, 113, 0.1); }
.tag.info { color: var(--accent); background: rgba(34, 211, 238, 0.1); }
.tag.gray { color: var(--muted); }

/* ---------- 9. 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 10px; border-bottom: 1px solid rgba(31, 47, 79, 0.6); vertical-align: top; }
tr:hover td { background: rgba(34, 211, 238, 0.04); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 10. 按鈕與表單 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #04101f;
  border: none;
  font-weight: 700;
}
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }

input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form .row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.required::after { content: " *"; color: var(--bad); }
.hint { font-size: 12px; color: var(--muted); }
.error { color: var(--bad); font-size: 13px; min-height: 18px; }

/* 評鑑題目 */
.q-item {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
  flex-wrap: wrap;
}
.q-item .q-text { flex: 1; min-width: 200px; color: var(--text); }
.q-options { display: flex; gap: 10px; }
.q-options label { display: flex; align-items: center; gap: 4px; color: var(--text); }
.score-box { font-size: 20px; font-weight: 700; color: var(--accent); }

/* 分頁籤 */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }
.tabs button {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 14px;
  cursor: pointer;
  font-family: inherit;
}
.tabs button.active { color: var(--accent); border-color: var(--accent); }

.info-grid { display: grid; gap: 8px 20px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); font-size: 14px; }
.info-grid b { color: var(--muted); font-weight: 400; margin-right: 6px; }

.demo-badge {
  display: inline-block;
  font-size: 12px;
  color: var(--warn);
  border: 1px dashed var(--warn);
  padding: 2px 8px;
  border-radius: 6px;
  margin-left: 8px;
  vertical-align: middle;
}

.chart-box { position: relative; height: 260px; }

/* ---------- 11. 對話框 ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 15, 0.7);
  z-index: 50;
  padding: 20px;
  overflow-y: auto;
}
.modal.show { display: flex; align-items: flex-start; justify-content: center; }
.modal-box {
  position: relative;
  width: 100%;
  max-width: 760px;
  margin-top: 40px;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 0 40px rgba(34, 211, 238, 0.2);
}
.modal-box h2 { font-size: 20px; margin-bottom: 14px; }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}

/* 提示訊息 */
.toast {
  position: fixed;
  right: 20px; bottom: 20px;
  background: var(--panel-2);
  border: 1px solid var(--accent);
  padding: 12px 18px;
  border-radius: 10px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  z-index: 60;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* 角色權限：沒權限的元素直接隱藏 */
body.role-user .maintainer-only,
body.role-user .admin-only,
body.role-maintainer .admin-only { display: none !important; }

/* 展示模式／正式模式各自才顯示的元素 */
body:not(.online) .online-only,
body.online .demo-only { display: none !important; }

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

/* 登入畫面 */
.login-card { max-width: 380px; margin: 60px auto; }
.login-card .page-title { margin-bottom: 16px; text-align: center; }

/* 按鈕送出中 */
.btn:disabled { opacity: 0.5; cursor: wait; }

/* =========================================================
   12. 手機版（螢幕寬度 820px 以下）
   ========================================================= */
@media (max-width: 820px) {
  .menu-btn { display: block; }
  .role-box > span { display: none; }
  .user-box { display: none; }

  /* 選單平常藏在左邊，按下 ☰ 才滑出來 */
  .sidebar { transform: translateX(-100%); width: 240px; }
  .sidebar.open { transform: translateX(0); }
  .overlay.show { display: block; position: fixed; inset: 60px 0 0 0; background: rgba(0, 0, 0, 0.5); z-index: 15; }

  .main { margin-left: 0; padding: 76px 16px 30px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-value { font-size: 22px; }

  /* 表格在手機改成「一列一張小卡片」，避免畫面被擠壓 */
  table.responsive thead { display: none; }
  table.responsive tr {
    display: block;
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 6px 10px;
  }
  table.responsive td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px dashed rgba(31, 47, 79, 0.6);
    padding: 6px 0;
    text-align: right;
  }
  table.responsive td:last-child { border-bottom: none; }
  table.responsive td::before {          /* 把欄位名稱顯示在左邊 */
    content: attr(data-label);
    color: var(--muted);
    text-align: left;
    flex-shrink: 0;
  }
  .modal { padding: 0; }
  .modal-box { margin-top: 0; min-height: 100vh; border-radius: 0; }
}
