* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e3e8ef;
  --text: #1a2233;
  --muted: #6b7688;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a; --green-bg: #dcfce7;
  --yellow: #ca8a04; --yellow-bg: #fef9c3;
  --red: #dc2626; --red-bg: #fee2e2;
  --gray: #64748b; --gray-bg: #f1f5f9;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --radius: 10px;
}
body {
  font-family: -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; background: none; font-size: 14px; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------- Login ---------- */
#login {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--card); padding: 40px 36px; border-radius: 16px; box-shadow: var(--shadow);
  width: 100%; max-width: 380px; text-align: center;
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p { color: var(--muted); margin-bottom: 28px; font-size: 13px; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px;
}
.login-card input:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.login-card button {
  width: 100%; padding: 12px; background: var(--primary); color: #fff; border-radius: 8px; font-weight: 600;
}
.login-card button:hover { background: var(--primary-dark); }
.login-err { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- App shell ---------- */
header {
  background: var(--card); border-bottom: 1px solid var(--border); padding: 0 24px;
  height: 60px; display: flex; align-items: center; gap: 20px; position: sticky; top: 0; z-index: 50;
}
header .logo { font-weight: 700; font-size: 17px; white-space: nowrap; }
header .logo span { color: var(--primary); }
.search-wrap { flex: 1; max-width: 460px; position: relative; }
.search-wrap input {
  width: 100%; padding: 9px 14px 9px 38px; border: 1px solid var(--border); border-radius: 20px; background: var(--bg);
}
.search-wrap input:focus { outline: none; border-color: var(--primary); background: #fff; }
.search-wrap::before { content: "🔍"; position: absolute; left: 13px; top: 8px; font-size: 14px; opacity: .5; }
header .spacer { flex: 1; }
.btn {
  padding: 8px 16px; border-radius: 8px; font-weight: 600; white-space: nowrap;
  background: var(--gray-bg); color: var(--text); border: 1px solid var(--border);
}
.btn:hover { background: #e9eef5; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { filter: brightness(.92); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--gray-bg); }

main { max-width: 1240px; margin: 0 auto; padding: 20px 24px 60px; }

/* ---------- Stat pills ---------- */
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; min-width: 96px; cursor: pointer; transition: .12s; box-shadow: var(--shadow);
}
.stat:hover { transform: translateY(-1px); border-color: var(--primary); }
.stat.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.18); }
.stat .num { font-size: 22px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.toolbar .spacer { flex: 1; }
.result-info { color: var(--muted); font-size: 13px; }

/* ---------- Table ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
th { background: #fafbfc; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--primary); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7f9fc; }
tbody tr:last-child td { border-bottom: none; }
td.id { color: var(--muted); font-variant-numeric: tabular-nums; }
td.name { font-weight: 600; }
.cancelled-row td { opacity: .5; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.b-green { background: var(--green-bg); color: var(--green); } .b-green .dot { background: var(--green); }
.b-yellow { background: var(--yellow-bg); color: var(--yellow); } .b-yellow .dot { background: var(--yellow); }
.b-red { background: var(--red-bg); color: var(--red); } .b-red .dot { background: var(--red); }
.b-gray { background: var(--gray-bg); color: var(--gray); } .b-gray .dot { background: var(--gray); }
.doc-tag { background: #eef2ff; color: #4f46e5; padding: 2px 8px; border-radius: 6px; font-size: 12px; }
.empty { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- Pagination ---------- */
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 18px; }
.pager button { padding: 7px 13px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager .cur { color: var(--muted); font-size: 13px; }

/* ---------- Drawer / detail ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100; display: flex; justify-content: flex-end;
}
.drawer {
  background: var(--bg); width: 560px; max-width: 100%; height: 100%; overflow-y: auto;
  animation: slidein .18s ease; display: flex; flex-direction: column;
}
@keyframes slidein { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head {
  background: var(--card); padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 2;
}
.drawer-head h2 { font-size: 18px; flex: 1; }
.drawer-head .cid { color: var(--muted); font-weight: 400; font-size: 14px; }
.drawer-body { padding: 20px 22px; }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field .val { padding: 4px 0; min-height: 22px; word-break: break-all; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 64px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.section-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 22px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.section-title:first-child { margin-top: 0; }
.drawer-foot {
  margin-top: auto; background: var(--card); padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; position: sticky; bottom: 0;
}
.drawer-foot .spacer { flex: 1; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1a2233; color: #fff; padding: 12px 22px; border-radius: 10px; z-index: 200;
  opacity: 0; transition: .2s; pointer-events: none; box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
#toast.err { background: var(--red); }

.loading { padding: 50px; text-align: center; color: var(--muted); }

@media (max-width: 640px) {
  header { padding: 0 14px; gap: 10px; }
  header .logo { font-size: 15px; }
  main { padding: 14px; }
  .hide-sm { display: none; }
  .drawer { width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
}
