:root {
  --bg: #f2f5f9;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --line: #dfe6ef;
  --ink: #1c2733;
  --ink-2: #5c6b7c;
  --brand: #1c4e89;
  --brand-2: #2d74c4;
  --ok: #1a7f4e;
  --warn: #b45309;
  --err: #b91c1c;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}
button { font: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ---------- 登入 ---------- */
.login-shell {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #12355f 0%, #1c4e89 55%, #2d74c4 100%);
  padding: 24px;
}
.login-wrap {
  display: grid; grid-template-columns: 1.1fr 1fr;
  width: min(880px, 100%);
  background: var(--panel); border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.hero { background: #12355f; color: #fff; padding: 44px 38px; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.hero-logo-plate { background: #fff; border-radius: 12px; padding: 10px 14px; width: fit-content; box-shadow: 0 8px 22px rgba(2, 14, 30, .28); }
.hero-logo { width: 176px; height: auto; display: block; }
.hero-badge { font-size: 12px; letter-spacing: .12em; opacity: .75; border: 1px solid rgba(255,255,255,.3); border-radius: 999px; padding: 4px 12px; width: fit-content; }
.hero-title { font-size: 26px; margin: 10px 0 0; }
.hero-sub { margin: 0; color: #c9d9ec; line-height: 1.6; }
.hero-stats { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.hero-stats div { display: grid; grid-template-columns: 62px 1fr; gap: 12px; align-items: baseline; }
.hero-stats strong { font-size: 13px; letter-spacing: .12em; color: #fff; }
.hero-stats span { font-size: 13px; color: #a9c0d9; line-height: 1.55; }
.brand-mark { width: 42px; height: 42px; object-fit: contain; flex-shrink: 0; }
.brand-mark.sm { width: 32px; height: 32px; }
.login-card { padding: 40px 36px; display: flex; flex-direction: column; gap: 14px; }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand h1 { font-size: 17px; margin: 0; }
.login-brand p { margin: 2px 0 0; font-size: 12px; color: var(--ink-2); }
.logo-box {
  width: 44px; height: 44px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-weight: 700; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
}
.logo-box.sm { width: 34px; height: 34px; font-size: 16px; border-radius: 8px; }
.login-heading h2 { margin: 4px 0 2px; font-size: 20px; }
.login-heading p { margin: 0; color: var(--ink-2); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--ink-2); }
.field input {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--panel-2);
}
.field input:focus { outline: 2px solid var(--brand-2); border-color: var(--brand-2); }
.login-error { background: #fdecec; color: var(--err); border: 1px solid #f5c2c2; padding: 8px 10px; border-radius: 8px; font-size: 13px; }
.login-copy { color: #94a3b3; font-size: 12px; text-align: center; margin: 6px 0 0; }

/* ---------- 按鈕 ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 8px 14px;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #17406f; }
.btn.danger { color: var(--err); border-color: #f0bcbc; }
.btn.danger:hover { background: #fdf1f1; }
.btn.big { padding: 11px; font-size: 15px; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- 頂欄 / 佈局 ---------- */
.topbar {
  background: var(--panel); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { font-size: 15px; }
.brand-sub { display: block; font-size: 12px; color: var(--ink-2); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-meta strong { font-size: 13px; }
.user-meta span { font-size: 12px; color: var(--ink-2); }

.layout { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100vh - 55px); }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; }
.side-title { font-size: 12px; color: #8a97a5; margin: 0 8px 8px; letter-spacing: .08em; }
.side-link {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 9px 12px; border-radius: 8px; color: var(--ink); margin-bottom: 2px;
}
.side-link:hover { background: var(--panel-2); }
.side-link.active { background: #e8f0fa; color: var(--brand); font-weight: 600; }
.share-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left; background: none; border: none;
  padding: 9px 12px; border-radius: 8px; margin-bottom: 2px;
}
.share-link:hover { background: var(--panel-2); }
.share-link.active { background: #e8f0fa; color: var(--brand); font-weight: 600; }
.share-link .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode-badge { font-size: 11px; border-radius: 999px; padding: 2px 8px; flex-shrink: 0; }
.mode-badge.read { background: #fff4e2; color: var(--warn); }
.mode-badge.write { background: #e7f5ee; color: var(--ok); }
.content { padding: 20px 24px; }

/* ---------- 卡片 / 表格 ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; }
.crumbs button { background: none; border: none; color: var(--brand-2); padding: 2px 4px; border-radius: 6px; }
.crumbs button:hover { background: var(--panel-2); }
.crumbs .sep { color: #b3bdc9; }
.crumbs .cur { color: var(--ink); font-weight: 600; padding: 2px 4px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar .path-label { color: var(--ink-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.list th { color: #8a97a5; font-weight: 500; font-size: 12px; }
table.list tr:hover td { background: var(--panel-2); }
table.list .fname { display: flex; align-items: center; gap: 8px; cursor: pointer; max-width: 420px; }
table.list .fname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-ico { width: 26px; height: 26px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.file-ico.dir { background: #e8f0fa; color: var(--brand-2); }
.file-ico.file { background: #eef1f5; color: var(--ink-2); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.hint { color: var(--ink-2); font-size: 13px; }
.empty { text-align: center; color: var(--ink-2); padding: 40px 0; }

/* ---------- 表單 ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; align-items: end; }
.form-grid .field input, .form-grid .field select { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel-2); }
select.mode-sel { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: #fff; font-size: 13px; }
select.mode-sel:disabled { color: #b3bdc9; }
.tag-admin { background: #e8f0fa; color: var(--brand); font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.tag-super { background: #fdf0d9; color: #b26a00; font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.tag-off { background: #f1f3f6; color: #8a97a5; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.token-box { margin: 12px 0; padding: 12px 14px; background: #f7fbf7; border: 1px solid #cfe8cf; border-radius: 10px; font-size: 13px; }
.token-box code { display: block; margin-top: 8px; padding: 8px 10px; background: #fff; border: 1px solid #e2e8e2; border-radius: 8px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; user-select: all; }
.audit-time { color: #8a97a5; font-size: 12px; white-space: nowrap; }

/* ---------- toast / 彈窗 ---------- */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #223247; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13px; z-index: 99; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#toast.err { background: var(--err); }
#toast.ok { background: var(--ok); }
dialog { border: none; border-radius: var(--radius); padding: 22px; min-width: 340px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 30, 50, .45); }
dialog h3 { margin: 0 0 14px; font-size: 16px; }
dialog .dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

@media (max-width: 800px) {
  .login-wrap { grid-template-columns: 1fr; }
  .hero { display: none; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar .side-title { width: 100%; }
  .sidebar nav, .sidebar #adminNav, .sidebar #tenderNav { display: flex; flex-wrap: wrap; gap: 4px; }
  .content { padding: 14px; }
}

/* ===== 招投標管理 ===== */
.tender-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.tender-grid .span2 { grid-column: span 2; }
.parse-box { background: var(--navy-50, #f0f6fc); border: 1px dashed var(--line); border-radius: 10px; padding: 12px; margin-bottom: 14px; }
.parse-box .btn { margin-top: 8px; }
.parse-box .hint { margin-left: 10px; }

.st-badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.st-follow { background: #fff4d6; color: #8a6100; }
.st-submitted { background: #dbeafe; color: #1d4ed8; }
.st-won { background: #dcfce7; color: #15803d; }
.st-lost { background: #e5e7eb; color: #4b5563; }
.st-dropped { background: #fee2e2; color: #b91c1c; }

.dl-badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.dl-badge.ok { background: #e7f5ee; color: #1f7a4d; }
.dl-badge.soon { background: #fff4d6; color: #8a6100; }
.dl-badge.today { background: #fee2e2; color: #b91c1c; }
.dl-badge.over { background: #e5e7eb; color: #6b7280; }

.login-lan { margin: 10px 0 0; font-size: 13px; color: #1d4ed8; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px; padding: 8px 12px; text-align: center; }
