/* base.css — 報工系統 mobile-first 樣式 */
* { box-sizing: border-box; margin: 0; padding: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none; }
html, body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  color: #222;
  background: #f5f6f8;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;       /* iOS 旋轉時不自動放大字 */
  overscroll-behavior-y: contain;       /* 阻擋 iOS over-scroll bounce */
}
a { color: #2563eb; text-decoration: none; }
img { max-width: 100%; height: auto; }  /* 防破版 */

/* ---- Layout ---- */
.app { max-width: 800px; margin: 0 auto; padding: 0 12px 80px; }

:root { --topbar-h: 52px; }    /* 給 nav.tabs 對齊用 */

header.topbar {
  background: #1e40af; color: #fff;
  padding: 12px 16px;
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 17px; font-weight: 500;
  min-height: var(--topbar-h);
  padding-top: calc(12px + env(safe-area-inset-top));  /* 瀏海手機 */
}
header.topbar .who { font-size: 13px; opacity: 0.9; }
header.topbar button { background: rgba(255,255,255,.18); color: #fff; border: 0;
  padding: 8px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
  min-height: 36px;          /* 觸控目標 */
}

nav.tabs {
  background: #fff;
  display: flex; overflow-x: auto;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  z-index: 9;
  -webkit-overflow-scrolling: touch;
  /* 讓使用者明顯看到「還能往右滑」的暗示 */
  scrollbar-width: thin;
}
nav.tabs button {
  flex: 0 0 auto; padding: 12px 16px;
  background: transparent; border: 0; border-bottom: 3px solid transparent;
  cursor: pointer; font-size: 14px; color: #555;
  white-space: nowrap;
  min-height: 44px;     /* iOS Apple HIG 觸控目標下限 */
}
nav.tabs button.active { color: #1e40af; border-bottom-color: #1e40af; font-weight: 600; }

section.panel { display: none; padding: 16px 0; }
section.panel.active { display: block; }

/* ---- Card ---- */
.card {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 14px; margin-bottom: 12px;
}
.card h3 { font-size: 15px; margin-bottom: 8px; color: #111;
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 8px;             /* h3 內含「新增」按鈕時不擠不浮動 */
}
.card h3 button { float: none !important; } /* 蓋掉舊 inline float:right */
.card .meta { font-size: 13px; color: #666; margin-bottom: 6px; }
.card .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.card .row .k { color: #666; }
.card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---- Form ---- */
label { display: block; font-size: 13px; color: #444; margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid #cbd5e1; border-radius: 6px; background: #fff;
}
textarea { min-height: 60px; resize: vertical; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
/* 斷點 align HRM 系統(768px) */
@media (max-width: 768px) {
  .row-2, .row-3 { grid-template-columns: 1fr; }
}

/* ---- Button ---- */
button.btn {
  padding: 11px 16px; font-size: 15px; border: 0; border-radius: 6px;
  cursor: pointer; font-weight: 500;
}
button.btn.primary { background: #1e40af; color: #fff; }
button.btn.primary:hover { background: #1e3a8a; }
button.btn.danger  { background: #dc2626; color: #fff; }
button.btn.ghost   { background: transparent; color: #1e40af; border: 1px solid #1e40af; }
button.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Status badge ---- */
.badge {
  display: inline-block; padding: 2px 8px; font-size: 12px; border-radius: 4px;
}
.badge.draft       { background: #e5e7eb; color: #374151; }
.badge.submitted   { background: #fef3c7; color: #92400e; }
.badge.foreman_approved { background: #dbeafe; color: #1e40af; }
.badge.manager_approved { background: #d1fae5; color: #065f46; }
.badge.rejected    { background: #fee2e2; color: #991b1b; }

/* ---- Sub-tabs(用在 master / 其他多區段 panel)---- */
nav.subtabs {
  display: flex; overflow-x: auto;
  background: #f3f4f6; border-radius: 6px; padding: 4px;
  margin-bottom: 14px;
}
nav.subtabs button {
  flex: 0 0 auto; padding: 8px 14px;
  background: transparent; border: 0; border-radius: 4px;
  cursor: pointer; font-size: 14px; color: #555;
  white-space: nowrap;
}
nav.subtabs button.active { background: #fff; color: #1e40af; font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,.08); }

section.subpanel { display: none; }
section.subpanel.active { display: block; }

/* ---- List item row(主檔 / 歷史共用)---- */
.list-item {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 6px;
  padding: 12px; margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
  flex-wrap: wrap;                      /* 窄螢幕讓 ops 換行 */
}
.list-item .info { flex: 1 1 60%; min-width: 0; word-break: break-word; }
.list-item .info .title { font-weight: 500; font-size: 14px; }
.list-item .info .sub { color: #666; font-size: 12px; margin-top: 2px; }
.list-item .ops { display: flex; gap: 6px; flex-shrink: 0; }
.list-item .ops button { padding: 8px 12px; font-size: 13px; border-radius: 4px; border: 0; cursor: pointer; min-height: 36px; }
.list-item .ops button.edit { background: #dbeafe; color: #1e40af; }
.list-item .ops button.del  { background: #fee2e2; color: #991b1b; }

/* ---- Drawer(桌機:右側滑出 / 手機:全螢幕,學 HRM modal 模式)---- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 90; display: none;
}
.drawer-mask.show { display: block; }
.drawer {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: 100%; max-width: 480px;
  background: #fff; z-index: 100;
  padding: 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom)); /* iPhone 底部安全區 */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;                          /* iOS 慣性滾動 */
  transform: translateX(100%); transition: transform .2s;
  box-shadow: -4px 0 20px rgba(0,0,0,.15);
}
@media (max-width: 768px) {
  /* 手機:drawer 不滑出,直接全螢幕(避免 transform 動畫卡頓 + 內容被擠) */
  .drawer {
    max-width: 100%;
    box-shadow: none;
    transform: translateY(100%);   /* 從下方滑上來 */
    transition: transform .25s;
  }
  .drawer.show { transform: translateY(0); }
}
.drawer.show { transform: translateX(0); }
.drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid #eee; padding-bottom: 10px; margin-bottom: 14px;
}
.drawer-header h3 { font-size: 17px; color: #111; margin: 0; }
.drawer-header .close { background: transparent; border: 0; font-size: 22px;
  cursor: pointer; color: #888; padding: 0 6px; }
.drawer .footer { margin-top: 18px; display: flex; gap: 8px; }

/* ---- Detail drawer report card ---- */
.detail-entry {
  border-left: 3px solid #1e40af; padding: 8px 12px; margin: 10px 0;
  background: #f8fafc;
}
.detail-entry .title { font-weight: 500; }
.detail-entry .meta  { color: #666; font-size: 12px; margin-top: 2px; }
.photo-thumb-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.photo-thumb-row img {
  width: 60px; height: 60px; object-fit: cover; border-radius: 4px;
  border: 1px solid #e5e7eb;
}

/* ---- Login page ---- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
}
.login-box {
  background: #fff; padding: 28px; border-radius: 12px; max-width: 360px; width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.login-box h1 { font-size: 22px; margin-bottom: 6px; color: #1e40af; }
.login-box .subtitle { font-size: 13px; color: #666; margin-bottom: 20px; }
.login-box button { width: 100%; margin-top: 18px; }
.login-box .err { color: #dc2626; font-size: 13px; margin-top: 10px; min-height: 1em; }

/* ---- Loading / empty ---- */
.empty { text-align: center; color: #888; padding: 40px 0; font-size: 14px; }
.loading { text-align: center; color: #888; padding: 20px 0; }

/* ---- Desktop ---- */
@media (min-width: 768px) {
  .app { padding: 0 24px 80px; }
}

/* ---- Mobile 整體壓縮(學 HRM 768px 斷點)---- */
@media (max-width: 768px) {
  .app { padding: 0 8px 80px; }
  .card { padding: 12px; margin-bottom: 10px; }
  .card h3 { font-size: 14px; }
  header.topbar { padding: 10px 12px; font-size: 15px; }
  header.topbar .who { font-size: 11px; }
  header.topbar button { padding: 5px 10px; font-size: 12px; min-height: 32px; }
  nav.tabs button { padding: 10px 12px; font-size: 13px; }
  nav.subtabs button { padding: 7px 10px; font-size: 12px; }
  /* form 元素更緊湊但仍 ≥16px 字避免 iOS 自動 zoom */
  input, select, textarea { font-size: 16px; padding: 9px 10px; }
  label { font-size: 12px; margin: 8px 0 3px; }
  button.btn { padding: 10px 14px; font-size: 14px; }
}
