* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: #f4f6fb;
  color: #1a1a2e;
}

/* ── 登入頁 ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.08);
  padding: 40px 36px;
  width: 320px;
}
.login-card h1 { font-size: 20px; margin: 0 0 24px; }
.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 12px;
}
.login-card button {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: #1a56db;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.login-error { color: #dc2626; font-size: 13px; margin-bottom: 12px; min-height: 16px; }

/* ── 共用版面 ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
}
.topbar h1 { font-size: 17px; margin: 0; }
.topbar a.logout { color: #6b7280; font-size: 13px; text-decoration: none; }
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-right { display: flex; align-items: center; gap: 20px; }
.admin-nav { display: flex; gap: 4px; }
.admin-nav .nav-link { padding: 6px 12px; border-radius: 999px; font-size: 13px; color: #374151; text-decoration: none; }
.admin-nav .nav-link:hover { background: #f4f6fb; }
.admin-nav .nav-link.active { background: #1a56db; color: #fff; }
.container { max-width: 1320px; margin: 0 auto; padding: 24px; }

/* ── 案件列表 ── */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 6px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #e5e7eb;
  font-size: 13px;
  cursor: pointer;
  color: #374151;
}
.tab.active { background: #1a56db; color: #fff; border-color: #1a56db; }

/* ── 建案資料庫 ── */
.projects-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 0; }
.projects-toolbar .tabs { margin-bottom: 16px; }
.search-input {
  padding: 7px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 13px;
  width: 260px;
  margin-bottom: 16px;
}
.project-links { display: flex; gap: 10px; margin-top: 16px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: #1a56db; }
th.sortable.sorted { color: #1a56db; }

/* 表格本身可以比容器窄（欄位都是短內容），但太窄會逼儲存格內文字換行、
   一行案件要占兩三行高度，可讀性很差——外面包一層可以水平捲動的容器，
   表格內文字一律不換行，欄寬由內容自然撐開。 */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
th, td { text-align: left; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid #f0f1f5; white-space: nowrap; }
th { background: #f9fafb; color: #6b7280; font-weight: 600; }
tr.case-row { cursor: pointer; }
tr.case-row:hover { background: #f8faff; }
.empty-state { padding: 40px; text-align: center; color: #9ca3af; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; font-size: 13px; color: #6b7280; }
.pagination button {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  font-size: 13px;
  cursor: pointer;
}
.pagination button:disabled { opacity: 0.4; cursor: default; }

.status-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-新案件 { background: #dbeafe; color: #1e40af; }
.status-派工中 { background: #fef3c7; color: #92400e; }
.status-已處理 { background: #d1fae5; color: #065f46; }
.status-已結案 { background: #e5e7eb; color: #374151; }
.status-已取消 { background: #fee2e2; color: #991b1b; }

/* ── 案件詳細 ── */
/* 左欄（報修內容／附件／變更狀態／狀態歷史）7 份寬，右欄（對話紀錄）3 份寬
   （約 30%）。右欄高度鎖死等於瀏覽器可視高度扣掉上面 topbar 的高度（不是
   內容多高就長多高），overflow: hidden 把超出的部分擋住，逼對話紀錄卡片
   自己（.conversation-list）內部捲動——這樣整個網頁的捲動長度只由左欄
   決定，不會因為對話很長被拉成一個超長的頁面。
   --topbar-h 由 case.js 在載入時量測 topbar 實際渲染高度寫入（不同瀏覽器
   字型 metrics 不同，量的比猜的準）；sticky 元素還沒被捲動「黏住」之前
   是照正常文件流排版，所以扣除值還要再加上 .container 的 padding-top
   （24px）跟底部留白（16px），不然對話紀錄底部會超出瀏覽器可視範圍。
   窄螢幕（手機）改回上下堆疊，高度鎖定也一併取消，不然會卡住畫面。 */
.detail-grid { display: grid; grid-template-columns: 7fr 3fr; gap: 16px; align-items: start; }
.detail-side { position: sticky; top: 16px; height: calc(100vh - var(--topbar-h, 73px) - 40px); overflow: hidden; }
.detail-side .card { display: flex; flex-direction: column; height: 100%; min-height: 0; width: 100%; margin-bottom: 0; }
.detail-side .conversation-list { flex: 1; min-height: 0; max-height: none; }
@media (max-width: 860px) {
  .detail-grid { display: block; }
  .detail-side { position: static; height: auto; overflow: visible; margin-top: 16px; }
}

.draft-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 13px;
  line-height: 1.6;
}
.status-對話中 { background: #ede9fe; color: #5b21b6; }
.back-link { display: inline-block; color: #1a56db; text-decoration: none; font-size: 13px; white-space: nowrap; }
.card { background: #fff; border-radius: 10px; padding: 20px 24px; margin-bottom: 16px; box-shadow: 0 1px 4px rgba(0,0,0,0.04); }
.card h2 { font-size: 15px; margin: 0 0 14px; }
.field-grid { display: grid; grid-template-columns: 160px 1fr; row-gap: 10px; column-gap: 12px; font-size: 14px; }
.field-grid dt { color: #6b7280; }
.field-grid dd { margin: 0; }

.attachments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.attachment-item {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  background: #f9fafb;
}
.attachment-item img, .attachment-item video {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
  background: #000;
}
.attachment-item .attachment-meta {
  padding: 6px 8px;
  font-size: 11px;
  color: #6b7280;
}
.attachment-item a { color: inherit; text-decoration: none; }

.status-form { display: flex; flex-direction: column; gap: 10px; }
.status-form select, .status-form textarea {
  padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; font-family: inherit;
}
.status-form textarea { resize: vertical; min-height: 60px; }
.status-form button {
  align-self: flex-start;
  padding: 8px 18px; border: none; border-radius: 8px;
  background: #1a56db; color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
}
.status-form button.secondary { background: #fff; color: #1a56db; border: 1px solid #1a56db; }
.form-msg { font-size: 13px; min-height: 16px; }
.form-msg.ok { color: #065f46; }
.form-msg.err { color: #dc2626; }

.history-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.history-list li { padding: 8px 0; border-bottom: 1px solid #f0f1f5; }
.history-list li:last-child { border-bottom: none; }
.history-time { color: #9ca3af; margin-right: 8px; }

.conversation-list { display: flex; flex-direction: column; gap: 10px; max-height: 480px; overflow-y: auto; }
.conv-msg { display: flex; flex-direction: column; max-width: 78%; }
.conv-msg.conv-assistant { align-self: flex-start; }
.conv-msg.conv-user { align-self: flex-end; align-items: flex-end; }
.conv-meta { font-size: 11px; color: #9ca3af; margin-bottom: 3px; }
.conv-bubble { padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.conv-assistant .conv-bubble { background: #f3f4f6; color: #1a1a2e; border-bottom-left-radius: 4px; }
.conv-user .conv-bubble { background: #1a56db; color: #fff; border-bottom-right-radius: 4px; }

.docx-btn {
  display: inline-block; padding: 8px 16px; border-radius: 8px;
  background: #fff; border: 1px solid #d1d5db; color: #1a1a2e;
  font-size: 13px; text-decoration: none;
}
