/* ========== 全域樣式 ========== */
:root { 
  scroll-behavior: smooth;
  --primary-color: #06c;
  --border-color: #ddd;
  --bg-light: #fafafa;
  --text-color: #333;
  /* 固定欄位寬度變數 */
  --w-col1: 40px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: #fff;
  color: var(--text-color);
  line-height: 1.6;
}

img, video, canvas, svg { 
  max-width: 100%; 
  height: auto; 
}

a {
  color: var(--primary-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ========== Logo 頁首區域 ========== */
.site-header {
  background: #fff;
  border-bottom: 1px solid #f2f2f2;
  padding: 1rem 0;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.logo-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

.company-logo {
  max-width: 200px;
  height: auto;
  display: inline-block;
}

/* ========== 主要內容區域 ========== */
.main-content {
  min-height: calc(100vh - 200px);
  padding: 24px;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
}

h2, h3 {
  color: var(--text-color);
  margin-top: 0;
}

/* ========== 頁尾 ========== */
.site-footer {
  background: #f8f8f8;
  border-top: 1px solid #eee;
  padding: 1.5rem;
  text-align: center;
  color: #666;
  font-size: 0.9rem;
  margin-top: 2rem;
}

.site-footer p {
  margin: 0;
}

/* ========== 卡片樣式 ========== */
.card {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  margin: 16px 0;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.card h3 {
  margin-top: 0;
  color: var(--text-color);
  font-size: 1.3rem;
}

/* ========== 網格佈局 ========== */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.kpi {
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 12px;
  background: var(--bg-light);
  text-align: center;
}

.kpi div {
  color: #666;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.kpi h3 {
  margin: 8px 0 0 0;
  font-size: 1.5rem;
  color: var(--primary-color);
  font-weight: 600;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

/* ========== 按鈕 ========== */
.btn, button[type="submit"], button {
  display: inline-block;
  padding: 10px 16px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #fff;
  margin: 4px 8px 4px 0;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
  text-decoration: none;
  color: var(--text-color);
}

.btn:hover, button[type="submit"]:hover, button:hover {
  background: #f5f5f5;
  text-decoration: none;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

button[type="submit"] {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  margin-top: 8px;
  font-weight: 500;
}

button[type="submit"]:hover {
  background: #0056b3;
  border-color: #0056b3;
}

/* ========== 表單 ========== */
input, select, textarea {
  width: 100%;
  padding: 10px;
  margin: 8px 0;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(0, 102, 204, 0.1);
}

label {
  display: block;
  margin-top: 12px;
  margin-bottom: 4px;
  font-weight: 500;
  color: #555;
}

form {
  max-width: 480px;
}

.auth-form {
  max-width: 480px;
  margin: 0 auto;
}

.form-control {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 1rem;
}

/* ========== 表格基礎樣式 ========== */
table, .table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}

th, td {
  border-bottom: 1px solid #eee;
  padding: 12px 8px;
  text-align: left;
}

thead th {
  background: #f8f8f8;
  font-weight: 600;
  color: #555;
  border-bottom: 2px solid #ddd;
}

tbody tr:hover {
  background: #f9f9f9;
}

/* ========== 表格響應式容器（全站單行 + 左右滑動）========== */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* 讓表格欄寬可以依內容伸展 */
.table-responsive > .table,
.table-responsive > table {
  table-layout: auto !important;
  width: auto !important;
  min-width: 1400px !important; /* 視欄位多寡調整 1200/1400/1600 */
}

/* 所有儲存格單行顯示，不裁切、不顯示省略號 */
.table-responsive > .table th,
.table-responsive > .table td,
.table-responsive > table th,
.table-responsive > table td {
  white-space: nowrap !important;
  overflow: visible !important;
  text-overflow: clip !important;
  word-break: normal !important;
}

/* 儲存格內任何子元素也跟著不換行 */
.table-responsive > .table th *,
.table-responsive > .table td *,
.table-responsive > table th *,
.table-responsive > table td * {
  white-space: inherit !important;
  word-break: inherit !important;
}

/* 覆蓋任何特定欄位的換行規則 */
.table-responsive > .table td:nth-child(n),
.table-responsive > .table th:nth-child(n),
.table-responsive > table td:nth-child(n),
.table-responsive > table th:nth-child(n) {
  white-space: nowrap !important;
  word-break: normal !important;
}

/* 可選：需要更寬時加在 <table> 上的工具類 */
.table-wide-1200 { min-width: 1200px !important; }
.table-wide-1400 { min-width: 1400px !important; }
.table-wide-1600 { min-width: 1600px !important; }

/* ========== 固定左側欄位（可選功能）========== */
.table-sticky-2 th:nth-child(1),
.table-sticky-2 td:nth-child(1) {
  min-width: var(--w-col1);
  width: var(--w-col1);
}

.table-sticky-2 th:nth-child(1),
.table-sticky-2 td:nth-child(1) {
  position: sticky;
  left: -5px;
  z-index: 2;
  background: #fff;
  box-shadow: 1px 0 0 rgba(0,0,0,.06);
}

.table-sticky-2 thead th:nth-child(1) {
  z-index: 3;
}

/* ========== 訊息提示 ========== */
.msg, .error, .info {
  padding: 12px;
  border-radius: 8px;
  margin: 12px 0;
}

.msg {
  background: #f7fff7;
  border: 1px solid #cfe8cf;
  color: #2d5016;
}

.error {
  background: #fff5f5;
  border: 1px solid #ffcccc;
  color: #b00;
}

.info {
  background: #f7f7ff;
  border: 1px solid #dfe3ff;
  color: #333;
}

/* ========== 工具樣式 ========== */
.code {
  font-family: 'Courier New', monospace;
  background: #f7f7ff;
  border: 1px dashed #cbd5ff;
  padding: 6px 8px;
  border-radius: 6px;
  display: inline-block;
  word-break: break-all;
  font-size: 0.9rem;
}

.text-break { 
  word-break: break-word; 
}

pre, code { 
  white-space: pre-wrap; 
  word-break: break-word; 
}

small {
  color: #666;
  font-size: 0.85rem;
}

.level-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #ddd;
  background: #f8f8f8;
  font-size: 0.85rem;
  font-weight: 500;
}

.sum-row {
  background: #fcfcff;
  font-weight: 600;
}

/* ========== 響應式設計 ========== */
@media (max-width: 992px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .main-content {
    padding: 16px;
  }
  
  .grid, .kpis {
    grid-template-columns: 1fr;
  }
  
  .kpi {
    padding: 14px;
  }
  
  .company-logo {
    max-width: 150px;
  }
  
  /* 手機上的表單內元素 */
  .table-responsive input,
  .table-responsive select,
  .table-responsive textarea {
    width: 100% !important;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  
  /* 按鈕在手機上 */
  .btn {
    display: inline-block;
    margin: 8px 8px 8px 0;
  }
  
  /* 表單在手機上更寬鬆 */
  form {
    max-width: 100%;
  }
  
  h2 {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .site-header {
    padding: 0.75rem 0;
  }
  
  .company-logo {
    max-width: 120px;
  }
  
  h2 {
    font-size: 1.3rem;
  }
  
  .kpi h3 {
    font-size: 1.2rem;
  }
  
  .btn {
    display: block;
    width: 100%;
    margin: 8px 0;
    text-align: center;
  }
}

/* ========== 列印樣式 ========== */
@media print {
  .site-header,
  .site-footer,
  .btn,
  button {
    display: none;
  }
  
  .main-content {
    padding: 0;
  }
}

/* === 固定左側第 1 欄（ID）在左右滑動時仍可見 === */
/* 可調整固定欄寬（若你的 ID 欄較窄可設 60~90px） */
.table-sticky-1 { --w-col1: 80px; }

/* Sticky 在 collapse 下較不穩，對「有 sticky 的表」改成 separate */
.table-responsive .table.table-sticky-1 {
  border-collapse: separate !important;
  border-spacing: 0 !important;             /* 視覺仍貼齊 */
}

/* 強化選擇器 & 優先權，避免被其他規則覆蓋 */
.table-responsive .table.table-sticky-1 th:nth-child(1),
.table-responsive .table.table-sticky-1 td:nth-child(1) {
  position: sticky !important;
  left: 0 !important;
  min-width: var(--w-col1) !important;
  width: var(--w-col1) !important;
  z-index: 5 !important;                     /* 疊在其他欄上 */
  background: #fff !important;               /* 視你的底色調整 */
  box-shadow: 1px 0 0 rgba(0,0,0,.06);       /* 分隔線，可移除 */
}

/* 表頭層級再高一些，避免被資料列遮住 */
.table-responsive .table.table-sticky-1 thead th:nth-child(1) {
  z-index: 6 !important;
}

/* 保險起見：外層一定要能水平捲動（你檔案已有，這裡再強化一次） */
.table-responsive {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
}

/* 你已經在檔案中設定了：不換行 + 表格可依內容撐寬 + min-width
   這些會讓內容太寬時出現水平捲軸，維持單行。
   若某張表欄位更多，可在 <table> 加下列工具類，使表更寬： */
.table-wide-1200 { min-width: 1200px !important; }
.table-wide-1400 { min-width: 1400px !important; }
.table-wide-1600 { min-width: 1600px !important; }

/* === Table Search (sitewide) === */
.table-search-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: .5rem 0 .75rem;
}
.table-search-bar .form-control {
  max-width: 320px;
}
.table-search-count {
  font-size: .875rem;
  color: #6c757d;
}
@media (max-width: 576px) {
  .table-search-bar .form-control { max-width: 100%; }
  .table-search-bar { flex-wrap: wrap; }
}

/* ===== Table Search + Pagination (Sitewide) ===== */
.table-tools {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: .5rem 0 .75rem;
  flex-wrap: wrap;
}
.table-tools .form-control,
.table-tools .form-select {
  height: 32px;
  padding: .25rem .5rem;
  font-size: .9rem;
}
.table-tools .table-count {
  font-size: .875rem;
  color: #6c757d;
}

.table-pagination {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin: .5rem 0;
  flex-wrap: wrap;
}
.table-pagination .page-btn {
  border: 1px solid #dee2e6;
  background: #fff;
  padding: .25rem .5rem;
  border-radius: .375rem;
  cursor: pointer;
  user-select: none;
}
.table-pagination .page-btn[disabled] {
  opacity: .5;
  cursor: not-allowed;
}
.table-pagination .page-btn.active {
  background: #0d6efd;
  color: #fff;
  border-color: #0d6efd;
}

.table-tools-spacer {
  flex: 1 1 auto;
  min-width: 12px;
}
