/* doc500 — mobile-first */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", Roboto, sans-serif; background: #f4f6f9; color: #222; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea, button { font-size: 16px; }   /* 16px 避 iOS 自動 zoom */
.hidden { display: none !important; }
.view { min-height: 100vh; }

/* ====== 登入 ====== */
#loginView { display: flex; align-items: center; justify-content: center; padding: 20px; min-height: 100vh; background: linear-gradient(135deg,#0b5394 0%, #1f6fbf 100%); }
.login-card { background: #fff; padding: 32px 24px; border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,0.18); width: 100%; max-width: 360px; }
.login-card h1 { margin: 0 0 4px; color: #0b5394; }
.login-card .subtitle { margin: 0 0 20px; color: #666; font-size: 14px; }
.login-card label { display: block; margin: 12px 0; font-size: 13px; color: #555; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid #cdd6dd; border-radius: 6px; margin-top: 4px; }
.login-card .hint { font-size: 12px; color: #888; margin-top: 16px; text-align: center; }
.login-card .version { font-size: 11px; color: #aaa; text-align: center; margin: 12px 0 0; }
.err { color: #c0392b; font-size: 13px; min-height: 1.2em; margin: 8px 0 0; }

/* ====== 主框架 ====== */
.topbar { background: #0b5394; color: #fff; padding: 10px 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; box-shadow: 0 2px 6px rgba(0,0,0,0.1); position: sticky; top: 0; z-index: 50; }
.topbar .brand { font-weight: 700; font-size: 18px; }
.topbar .tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar .tab { background: transparent; color: #cde4ff; border: 1px solid transparent; padding: 6px 12px; border-radius: 6px; }
.topbar .tab.active { background: #fff; color: #0b5394; font-weight: 600; }
.topbar .user-box { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.topbar .user-box #userBadge { color: #cde4ff; }

.tab-panel { padding: 14px; max-width: 1100px; margin: 0 auto; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input, .toolbar select { padding: 8px 10px; border: 1px solid #cdd6dd; border-radius: 6px; background: #fff; }
.toolbar #qInput { flex: 1; min-width: 200px; }

/* ====== 按鈕 ====== */
.btn { display: inline-block; padding: 8px 16px; border-radius: 6px; border: 1px solid transparent; background: #e9ecef; color: #222; }
.btn.primary { background: #0b5394; color: #fff; }
.btn.primary:hover { background: #094078; }
.btn.danger { background: #c0392b; color: #fff; }
.btn.ghost { background: transparent; border-color: #cdd6dd; color: #444; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 12px; font-size: 16px; }

/* ====== 卡片列表 ====== */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card { background: #fff; border-radius: 10px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); cursor: pointer; transition: transform 0.1s, box-shadow 0.1s; border-left: 4px solid #cdd6dd; }
.card:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.card.dir-in { border-left-color: #2980b9; }
.card.dir-out { border-left-color: #27ae60; }
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: #666; margin-bottom: 6px; flex-wrap: wrap; }
.card .row .badges { display: flex; gap: 4px; }
.card .subject { font-weight: 600; font-size: 15px; margin: 4px 0 6px; color: #222; }
.card .meta { font-size: 12px; color: #888; }
.card .thumb { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; margin-top: 8px; background: #f0f2f5; }

/* badge */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge.dir-in { background: #d6e9f7; color: #0b5394; }
.badge.dir-out { background: #d4efdf; color: #186a3b; }
.badge.status-pending { background: #fceec0; color: #7d6608; }
.badge.status-processing { background: #d6e0f7; color: #21618c; }
.badge.status-archived { background: #d5d8dc; color: #424949; }
.badge.ocr-none { background: #eee; color: #555; }
.badge.ocr-queued, .badge.ocr-running { background: #fdebd0; color: #a04000; }
.badge.ocr-done { background: #d4efdf; color: #186a3b; }
.badge.ocr-error { background: #f5b7b1; color: #922b21; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }

/* ====== 表單 ====== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 760px; }
.form-grid label { display: flex; flex-direction: column; font-size: 13px; color: #555; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { padding: 9px 10px; border: 1px solid #cdd6dd; border-radius: 6px; margin-top: 4px; font-family: inherit; }
.form-grid textarea { resize: vertical; }
.form-grid .actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.status-msg { color: #555; font-size: 13px; }
.photo-pick { background: #f7f9fb; padding: 12px; border-radius: 8px; border: 1px dashed #cdd6dd; }
.photo-pick.photo-cover { border-color: #0b5394; background: #f0f6fc; }
.photo-pick small { display: block; color: #888; font-size: 12px; margin-top: 4px; }
.photo-pick input[type=file] { padding: 8px 0; }
.photo-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.photo-preview img { width: 100px; height: 100px; object-fit: cover; border-radius: 6px; border: 1px solid #ddd; }
/* 詳情頁 cover badge */
.badge.kind-cover { background: #d6e9f7; color: #0b5394; }
.badge.kind-content { background: #eef1f4; color: #555; }
.img-wrap .kind-tag { position: absolute; left: 4px; top: 4px; background: rgba(11,83,148,0.92); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 600; }
.img-wrap .rotation-tag { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,0.6); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 4px; }

/* ====== modal ====== */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-bg { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-card { position: relative; background: #fff; border-radius: 10px; max-width: 720px; width: 100%; max-height: 90vh; overflow: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-close { position: absolute; top: 10px; right: 12px; background: transparent; border: none; font-size: 22px; cursor: pointer; color: #888; }
.modal-card h2 { margin-top: 0; }

/* ====== 詳情頁:每張附件一張卡 ====== */
.att-list { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 12px 0; }
@media (min-width: 720px) { .att-list { grid-template-columns: 1fr 1fr; } }
.att-card { border: 1px solid #e6ebf0; border-radius: 8px; padding: 10px; background: #fff; }
.att-card .img-wrap { position: relative; }
.att-card img { width: 100%; max-height: 300px; object-fit: contain; border-radius: 6px; cursor: zoom-in; background: #f7f9fb; }
.att-card .rm { position: absolute; top: 4px; right: 4px; background: rgba(255,255,255,0.9); border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 12px; cursor: pointer; }
.att-ocr { margin-top: 8px; }
.att-ocr-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.att-ocr-text { white-space: pre-wrap; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; background: #f7f9fb; border: 1px solid #e6ebf0; border-radius: 6px; padding: 8px; font-size: 12px; max-height: 200px; overflow: auto; margin: 0; }
.ocr-text { white-space: pre-wrap; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; background: #f7f9fb; border: 1px solid #e6ebf0; border-radius: 6px; padding: 10px; font-size: 13px; max-height: 280px; overflow: auto; }

/* ====== 表格 ====== */
table.simple { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
table.simple th, table.simple td { padding: 8px 10px; text-align: left; font-size: 14px; border-bottom: 1px solid #eef1f4; }
table.simple th { background: #f7f9fb; color: #555; font-weight: 600; }
table.simple tr:last-child td { border-bottom: none; }

/* ====== 響應式 ====== */
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar { padding: 8px 10px; }
  .topbar .brand { font-size: 16px; }
  .topbar .user-box #userBadge { display: none; }
  .tab-panel { padding: 10px; }
  .toolbar input, .toolbar select { flex: 1 1 calc(50% - 4px); }
}
