/* =========================================================
   校園設備借用管理系統 - 前台/後台全新樣式
   Scope: 僅作用於 .sem-hub / .sem-wrap / .sem-admin
   Author: YenSam x GPT-5 Thinking
   ========================================================= */

/* ---------- 主題色系（藍黃校風） ---------- */
:root{
  --sem-primary:       #2f5adf;
  --sem-primary-600:   #274fc5;
  --sem-primary-700:   #1e409f;
  --sem-accent:        #ffd400;
  --sem-ink:           #101521;
  --sem-muted:         #6b7280;
  --sem-card:          #ffffff;
  --sem-bg:            #f4f7ff;
  --sem-border:        #e6e9f3;
  --sem-shadow:        0 10px 24px rgba(30,64,159,.16);
}

/* =========================================================
   A) 外掛頁限定：隱藏主題自己的頁面標題（B 方案）
   ========================================================= */
.sem-app-page .entry-title,
.sem-app-page .post-title,
.sem-app-page .page-title{
  display:none !important;
}

/* =========================================================
   B) 外掛容器：重置與基礎排版（B 方案）
   ========================================================= */
.sem-hub, .sem-wrap{
  font-family: system-ui, Segoe UI, Arial, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--sem-ink);
}
.sem-hub h1, .sem-wrap h1,
.sem-hub .sem-title, .sem-wrap .sem-title{
  font-weight: 800;
  font-size: 24px;
  line-height: 1.35;
  margin: 8px 0 12px;
  letter-spacing: .2px;
  color: var(--sem-ink);
  text-align: left;
  float: none;
  background: none;
  border: 0;
  text-shadow: none;
  box-shadow: none;
}
.sem-hub h2, .sem-wrap h2{
  font-weight: 700;
  font-size: 18px;
  margin: 16px 0 10px;
  line-height: 1.4;
}
.sem-hub a.sem-title, .sem-wrap a.sem-title{ display:inline; float:none; }

/* =========================================================
   C) 前台基礎結構
   ========================================================= */
.sem-hub{
  background: var(--sem-bg);
  padding: 10px;
  border-radius: 16px;
}
.sem-wrap{ margin: 10px 0; }
.sem-wrap, .sem-item, .sem-rules{
  background: var(--sem-card);
  border: 1px solid var(--sem-border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--sem-shadow);
}

/* Brand bar */
.sem-brandbar{
  display:flex; align-items:center; gap:14px;
  padding:16px 18px; margin:0 0 14px;
  background: linear-gradient(135deg, var(--sem-primary), var(--sem-primary-700));
  color:#fff; border-radius:18px; box-shadow: var(--sem-shadow);
}
.sem-brand-logo{ width:44px; height:44px; object-fit:contain; filter: drop-shadow(0 2px 4px rgba(0,0,0,.25)); }
.sem-brand-title{ font-size:18px; font-weight:800; letter-spacing:.5px; }
.sem-brand-sub{ font-size:12px; opacity:.9; }

/* 工具列 */
.sem-toolbar{ display:flex; gap:12px; align-items:center; margin:10px 0; }
.sem-toolbar.hub{ justify-content: space-between; }
.sem-search, .sem-select,
.sem-authform input[type="email"],
.sem-authform input[type="password"],
.sem-authform input[type="text"],
.sem-authform textarea, .sem-authform select{
  padding:10px 12px;
  border:1px solid var(--sem-border);
  border-radius:12px;
  background:#fff;
  font:14px/1.4 inherit;
  width:auto;
  box-shadow: var(--sem-shadow);
}
.sem-select{ min-width: 180px; }

/* 放大工具列字距（好點按） */
.sem-toolbar.hub .sem-search,
.sem-toolbar.hub .sem-select{
  font-size: 18px;
  line-height: 1.3;
  padding: 14px 16px;
  height: 48px;
}
.sem-toolbar.hub .sem-search::placeholder{ font-size: 18px; opacity:.75; }

/* 按鈕 */
.sem-btn{
  appearance: none;
  border: 0;
  background: var(--sem-primary);
  color: #fff;
  padding: 9px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(47,90,223,.25);
  transition: transform .05s ease, filter .15s ease;
}
.sem-btn:hover{ filter:brightness(1.03); }
.sem-btn:active{ transform: translateY(1px); }
.sem-btn.ghost{
  background:#eef2ff;
  color:#2a3360;
  box-shadow:none;
}
.sem-btn.ghost:hover{ background:#e3e7ff; }

/* 分頁籤 */
.sem-tabs{ display:flex; gap:8px; margin:12px 0; flex-wrap:wrap; }
.sem-tab{
  border:1px solid var(--sem-border);
  background:#fff; color:var(--sem-ink);
  padding:8px 14px; border-radius:999px; cursor:pointer;
  font-weight:700; box-shadow: var(--sem-shadow);
  transition: all .2s ease;
}
.sem-tab.is-active{ background: var(--sem-primary); color:#fff; border-color: transparent; }
.sem-tab:hover{ transform: translateY(-1px); }

/* 表格（卡片化列、滑鼠 hover） */
.sem-table{
  width:100%;
  border-collapse: separate;
  border-spacing: 0 12px;       /* 每列像卡片 */
  table-layout: auto;
}
.sem-table thead th{
  background: #f3f6ff;
  color: var(--sem-ink);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .4px;
  white-space: nowrap;
  padding: 14px 16px;
  border-bottom: 2px solid var(--sem-border);
  text-align: left;
}
.sem-table tbody tr{
  background:#fff;
  border:1px solid var(--sem-border);
  border-radius:12px;
  box-shadow: var(--sem-shadow);
}
.sem-table tbody td{
  padding: 14px 16px;
  border-bottom: 1px solid #f5f6fb;
  font-size: 16px;
  line-height: 1.55;
}
.sem-table tbody tr td:first-child{ border-top-left-radius:12px; border-bottom-left-radius:12px; }
.sem-table tbody tr td:last-child { border-top-right-radius:12px; border-bottom-right-radius:12px; }
.sem-table tbody tr:hover{ outline: 2px solid rgba(47,90,223,.08); }

/* 單品/標註 */
.sem-item h3{ margin:0 0 6px; font-weight:800; }
.sem-code-badge{
  display:inline-block; margin-left:8px; padding:2px 8px;
  border-radius:999px; border:1px solid rgba(0,0,0,.1);
  background:#f7f7f7; font-size:.85em; font-weight:600; vertical-align:middle;
}
.sem-note{
  background:#fff8e1; border:1px solid #f2c94c;
  border-radius:12px; padding:10px 12px; margin:10px 0;
}
.sem-res{ margin:6px 0 0 18px; }

/* 彈窗 */
.sem-modal{ position:fixed; inset:0; background:rgba(0,0,20,.55); display:flex; align-items:center; justify-content:center; padding:20px; z-index: 9999; }
.sem-modal[hidden]{ display:none; }
.sem-modal-card{
  width:min(920px,96vw);
  background:#fff; border-radius:16px; padding:22px;
  box-shadow: 0 24px 60px rgba(20,23,38,.35); position:relative;
}
.sem-close{
  position:absolute; right:10px; top:6px;
  border:0; background:transparent; font-size:24px; line-height:1; cursor:pointer; color:#6b7280;
}

/* 登入/註冊/忘記密碼 */
.sem-authbar{
  background:#f8fafc; border:1px solid var(--sem-border);
  border-radius:12px; padding:12px; margin-bottom:12px;
}
.sem-authform{ display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.sem-hello{ display:flex; gap:12px; align-items:center; }
.sem-login-tip{
  margin: 8px 0 12px;
  padding: 10px 12px;
  border: 1px solid #f2c94c;
  background: #fff8e1;
  border-radius: 8px;
  font-weight: 700;
}

/* Footer（開發者標示） */
.sem-footer{
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px dashed #e5e7eb;
  display: flex;
  justify-content: flex-end;
}
.sem-footer small{
  display: inline-flex; align-items:center; gap:8px;
  padding: 8px 12px; font-size: 12px; color:#1e409f;
  background: linear-gradient(135deg,#f7f9ff,#eef2ff);
  border: 1px solid #e3e8ff; border-radius: 999px;
  box-shadow: 0 6px 16px rgba(53,90,203,.10);
  transition: transform .15s ease, box-shadow .15s ease, background .2s ease;
}
.sem-footer small::before{ content:"🛠️"; font-size:14px; line-height:1; opacity:.95; }
.sem-footer a{ color:#1e409f; font-weight:700; text-decoration:none; }
.sem-footer a:hover{ text-decoration: underline; }
.sem-footer small:hover{ transform: translateY(-1px); box-shadow: 0 10px 24px rgba(53,90,203,.16); }

/* =========================================================
   D) 手機版優化（前台）
   ========================================================= */
@media (max-width: 640px){
  /* 表格改卡片：以 ::before 顯示欄名 */
  .sem-table thead{ display:none; }
  .sem-table tbody tr{ display:block; margin-bottom:12px; }
  .sem-table tbody td{
    display:flex; justify-content:space-between; gap:12px;
    padding:12px 14px; border-bottom:0;
  }
  .sem-table tbody td::before{
    content: attr(data-label);
    font-weight:700; color:var(--sem-muted);
    margin-right:10px; flex:0 0 auto;
  }
  /* 若沒 data-label，就用位置對應（你的清單：編號/器材/分類/地點/狀態/操作） */
  #sem-table tbody tr td:nth-child(1)::before{ content: "編號"; }
  #sem-table tbody tr td:nth-child(2)::before{ content: "器材"; }
  #sem-table tbody tr td:nth-child(3)::before{ content: "分類"; }
  #sem-table tbody tr td:nth-child(4)::before{ content: "地點"; }
  #sem-table tbody tr td:nth-child(5)::before{ content: "狀態"; }
  #sem-table tbody tr td:nth-child(6)::before{ content: "操作"; }

  /* 操作按鈕拉滿寬、可換行 */
  #sem-table tbody tr td:last-child .sem-btn{
    width:100%;
    margin:6px 0;
  }

  /* 表單/彈窗/分頁籤更友善拇指 */
  .sem-authform input,
  .sem-authform select,
  .sem-authform textarea,
  .sem-authform .sem-btn{ width:100%; }
  .sem-modal-card{ width:96vw; padding:14px; }
  .sem-tabs{ flex-wrap:wrap; }
  .sem-tab{ flex:1 1 auto; text-align:center; }
  .sem-brandbar{ padding:12px 14px; gap:10px; border-radius:14px; }
  .sem-brand-title{ font-size:16px; }
  .sem-brand-sub{ font-size:11px; }
}

/* =========================================================
   E) 深色模式微調
   ========================================================= */
@media (prefers-color-scheme: dark){
  :root{
    --sem-bg:     #141923;
    --sem-card:   #1b2230;
    --sem-border: #2a3447;
    --sem-ink:    #d8def0;
  }
  .sem-hub{ background: var(--sem-bg); }
  .sem-wrap, .sem-item, .sem-rules{
    background: var(--sem-card);
    border-color: var(--sem-border);
    box-shadow: 0 10px 24px rgba(0,0,0,.35);
  }
  .sem-table thead th{ background:#202a3d; color:#d8def0; border-bottom-color:#33415e; }
  .sem-table tbody tr{ background:#1e2636; border-color:#2a3447; }
  .sem-table tbody tr:hover{ outline-color: rgba(88,131,255,.25); }
  .sem-btn.ghost{ background:#253352; color:#d8def0; }
  .sem-authbar{ background:#1b2230; border-color:#2a3447; }
  .sem-login-tip{ background:#2d2630; border-color:#775aa1; color:#e7dcff; }
  .sem-footer{ border-top-color: rgba(255,255,255,.12); }
  .sem-footer small{
    color:#cbd5ff;
    background: linear-gradient(135deg,#1f2a44,#19223a);
    border-color: rgba(203,213,255,.18);
    box-shadow: 0 8px 20px rgba(0,0,0,.35);
  }
  .sem-footer a{ color:#cbd5ff; }
}

/* =========================================================
   F) 後台（.sem-admin + .wp-admin）美化與 RWD
   ========================================================= */
.sem-admin h1{ font-weight:800; letter-spacing:.2px; }

/* 主要按鈕校色 */
.sem-admin .button.button-primary,
.sem-admin .page-title-action,
.wp-admin .wrap .button.button-primary,
.wp-admin .wrap .page-title-action{
  background: var(--sem-primary);
  border-color: var(--sem-primary-600);
  color:#fff;
  font-weight:700;
  border-radius:10px;
  box-shadow: var(--sem-shadow);
}
.sem-admin .button.button-primary:hover,
.sem-admin .page-title-action:hover,
.wp-admin .wrap .button.button-primary:hover,
.wp-admin .wrap .page-title-action:hover{ filter: brightness(1.05); }

/* 表格卡片化 */
.sem-admin table.widefat,
.wp-admin .wrap table.widefat{
  border-collapse: separate;
  border-spacing: 0 10px;
  background: transparent;
}
.sem-admin table.widefat thead th,
.wp-admin .wrap table.widefat thead th{
  background:#f3f6ff;
  color:var(--sem-ink);
  font-size:14px;
  font-weight:800;
  border:0;
  border-bottom:2px solid var(--sem-border);
}
.sem-admin table.widefat td, .sem-admin table.widefat th,
.wp-admin .wrap table.widefat td, .wp-admin .wrap table.widefat th{
  padding:12px 14px;
}
.sem-admin table.widefat tbody tr,
.wp-admin .wrap table.widefat tbody tr{
  background:#fff;
  border:1px solid var(--sem-border);
  border-radius:12px;
  box-shadow: var(--sem-shadow);
}
.sem-admin table.widefat tbody tr td:first-child,
.wp-admin .wrap table.widefat tbody tr td:first-child{ border-top-left-radius:12px; border-bottom-left-radius:12px; }
.sem-admin table.widefat tbody tr td:last-child,
.wp-admin .wrap table.widefat tbody tr td:last-child{ border-top-right-radius:12px; border-bottom-right-radius:12px; }

/* 後台工具列與搜尋區塊對齊 */
.wp-admin .wrap p.search-box,
.wp-admin .wrap .tablenav.top,
.wp-admin .wrap .tablenav.bottom{
  display:flex; gap:10px; align-items:center;
}

/* 後台表單 */
.sem-admin .form-table th{ width:160px; font-weight:700; }
.sem-admin .form-table input[type="text"],
.sem-admin .form-table input[type="email"],
.sem-admin .form-table input[type="date"],
.sem-admin .form-table input[type="number"],
.sem-admin .form-table textarea,
.sem-admin .form-table select{
  border:1px solid var(--sem-border);
  border-radius:10px;
  padding:10px 12px;
  box-shadow: var(--sem-shadow);
  max-width:520px;
}

/* 通知圓角 */
.sem-admin .notice, .sem-admin .updated, .sem-admin .error{ border-radius:12px; }

/* 後台 RWD（橫向滑動） */
@media (max-width: 900px){
  .sem-admin table.widefat,
  .wp-admin .wrap table.widefat{
    display:block; overflow-x:auto; -webkit-overflow-scrolling:touch;
    white-space:nowrap; border-spacing:0;
  }
  .sem-admin table.widefat thead th,
  .wp-admin .wrap table.widefat thead th{
    position:sticky; top:0; z-index:1;
  }
}
/* ===== 放大表格字級 + 操作按鈕 ===== */
.sem-table thead th{
  font-size: 20px;         /* 原本 18px */
  padding: 16px 18px;
}

.sem-table tbody td{
  font-size: 20px;         /* 原本 18px */
  line-height: 1.75;
  padding: 16px 18px;
}

/* 只放大「操作」欄位裡的按鈕文字 */
#sem-table tbody td:last-child .sem-btn{
  font-size: 18px;         /* 原本未指定，通常約 14–16px */
  padding: 12px 16px;      /* 配合字級加大一點內距 */
  border-radius: 12px;
}

/* 手機版略縮，避免擠爆 */
@media (max-width: 640px){
  .sem-table tbody td{ font-size: 18px; }
  #sem-table tbody td:last-child .sem-btn{
    font-size: 17px;
    padding: 12px 14px;
  }
}
/* 表頭圓角 */
.sem-table thead th:first-child{ border-top-left-radius: 14px; }
.sem-table thead th:last-child { border-top-right-radius: 14px; }

/* 避免直線把圓角切掉（有些主題會加左右邊線） */
.sem-table thead th{
  border-left: 0 !important;
  border-right: 0 !important;
  background:#f3f6ff;
}
/* === Mobile 改善（<=768px）=== */
@media (max-width: 768px){
  .sem-hub{ padding:10px; }

  /* Brand bar 縮排、字小一點 */
  .sem-brandbar{ padding:12px 14px; gap:10px; border-radius:14px; }
  .sem-brand-title{ font-size:16px; }
  .sem-brand-sub{ font-size:11px; }

  /* 搜尋 + 分類下拉改為直排滿版 */
  .sem-toolbar.hub{ flex-direction: column; align-items: stretch; gap:10px; }
  .sem-toolbar.hub .sem-search,
  .sem-toolbar.hub .sem-select{
    width:100%; font-size:16px; line-height:1.35; padding:12px 14px; height:auto;
  }

  /* Tabs 可換行、好點按 */
  .sem-tabs{ flex-wrap: wrap; gap:8px; }
  .sem-tab{ flex:1 1 calc(50% - 8px); text-align:center; padding:10px 12px; font-size:16px; }

  /* Modal 滿版 */
  .sem-modal-card{ width:96vw; padding:14px; }

  /* 表單與按鈕滿版、加大 */
  .sem-authform{ gap:10px; }
  .sem-authform input,
  .sem-authform select,
  .sem-authform textarea,
  .sem-authform .sem-btn{ width:100%; font-size:16px; padding:12px 14px; }

  .sem-btn{ padding:12px 14px; border-radius:12px; font-size:16px; }
  .sem-btn.ghost{ background:#f3f6ff; }

  /* 表格 → 卡片：隱藏表頭、每列變區塊 */
  .sem-table{ border-spacing:0; }
  .sem-table thead{ display:none; }
  .sem-table tbody tr{
    display:block;
    margin:12px 0;
    border:1px solid var(--sem-border);
    border-radius:12px;
    background:#fff;
    box-shadow:var(--sem-shadow);
  }
  .sem-table tbody td{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:12px;
    padding:12px 14px;
    border:0;
    border-bottom:1px solid #eef0f4;
    font-size:16px;
  }
  .sem-table tbody tr td:last-child{ border-bottom:0; }

  /* data-label 標籤（有就用它） */
  .sem-table tbody td::before{
    content: attr(data-label);
    font-weight:700;
    color: var(--sem-muted);
    flex:0 0 42%;
    max-width:42%;
  }

  /* 操作欄：按鈕拉滿寬、直排 */
  .sem-table tbody td[data-label="操作"]{ display:block; }
  .sem-table tbody td[data-label="操作"] .sem-btn{
    width:100%; margin:6px 0;
  }

  /* Fallback：清單表（#sem-table）在沒 data-label 時自動補標籤 */
  #sem-table tbody tr td:nth-child(1)::before{ content:"編號"; }
  #sem-table tbody tr td:nth-child(2)::before{ content:"器材"; }
  #sem-table tbody tr td:nth-child(3)::before{ content:"分類"; }
  #sem-table tbody tr td:nth-child(4)::before{ content:"地點"; }
  #sem-table tbody tr td:nth-child(5)::before{ content:"狀態"; }
  #sem-table tbody tr td:nth-child(6)::before{ content:"操作"; }

  /* 我的借用表（加了 .sem-table--my 後就會套用） */
  .sem-table--my tbody tr td:nth-child(1)::before{ content:"器材"; }
  .sem-table--my tbody tr td:nth-child(2)::before{ content:"狀態"; }
  .sem-table--my tbody tr td:nth-child(3)::before{ content:"借出"; }
  .sem-table--my tbody tr td:nth-child(4)::before{ content:"到期"; }
  .sem-table--my tbody tr td:nth-child(5)::before{ content:"操作"; }
}
add_action('wp_enqueue_scripts', function () {
    if (!function_exists('sem_is_plugin_front_page') || !sem_is_plugin_front_page()) return;

    $css = <<<CSS
/* 手機優先：聯絡管理員區塊 */
.sem-contact{
  margin:16px 0;
  padding:12px 14px;
  border:1px solid #e6e7ef;
  border-radius:12px;
  background:#fff;
}
.sem-contact__title{
  margin:0 0 6px;
  font-size:16px;
  font-weight:800;
}
.sem-contact__text{
  margin:0 0 12px;
  font-size:14px;
  line-height:1.6;
  word-break: break-word;
}
.sem-contact__actions{
  display:grid;
  grid-template-columns: 1fr;   /* 手機：單欄滿寬 */
  gap:8px;
}
.sem-contact__btn{
  display:flex;
  align-items:center;
  justify-content:center;
  width:100%;
  min-height:44px;              /* 觸控友善 */
  text-align:center;
  border-radius:10px;
}

/* >=480px 變兩欄 */
@media (min-width:480px){
  .sem-contact__actions{ grid-template-columns: 1fr 1fr; }
}

/* iOS 瀏海安全區 */
@supports (padding: env(safe-area-inset-bottom)){
  .sem-contact{
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}
CSS;
    wp_add_inline_style('sem-frontend', $css);
}, 30);
