:root {
  --bg: #f4f6fa; --card: #fff; --ink: #1f2937; --muted: #6b7280;
  --line: #e5e7eb; --brand: #2563eb; --brand-d: #1d4ed8;
  --ok: #16a34a; --ok-bg: #d7f0d7; --warn: #d97706; --danger: #dc2626;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; }
.loading { padding: 80px; text-align: center; color: var(--muted); }
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.side { width: 210px; background: #111827; color: #cbd5e1; flex-shrink: 0; display: flex; flex-direction: column; }
.side .brand { padding: 18px 16px; font-weight: 700; color: #fff; font-size: 15px; line-height: 1.4; border-bottom: 1px solid #1f2937; }
.side nav { padding: 8px; flex: 1; }
.side nav a { display: block; padding: 10px 14px; color: #cbd5e1; border-radius: 8px; margin-bottom: 2px; }
.side nav a:hover { background: #1f2937; color: #fff; }
.side nav a.active { background: var(--brand); color: #fff; }
.side .who { padding: 12px 16px; border-top: 1px solid #1f2937; font-size: 12px; color: #94a3b8; }
.side .who button { margin-top: 8px; width: 100%; background: #1f2937; color: #cbd5e1; border: none; padding: 8px; border-radius: 8px; }
.main { flex: 1; padding: 22px 28px; overflow: auto; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 22px 0 10px; }

/* Cards / tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f0f4fb; font-weight: 600; white-space: nowrap; }
tr:hover td { background: #fafbff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.lowest { background: var(--ok-bg) !important; font-weight: 600; }

/* Forms */
input, select, textarea { font-family: inherit; font-size: 14px; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); }
input.cell { padding: 5px 6px; border-radius: 5px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 140px; }

/* Buttons */
.btn { background: var(--brand); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; font-size: 14px; }
.btn:hover { background: var(--brand-d); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f3f4f6; }
.btn.danger { background: var(--danger); }
.btn.ok { background: var(--ok); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.b-draft { background: #e5e7eb; color: #374151; }
.b-open { background: #dbeafe; color: #1d4ed8; }
.b-closed { background: #fef3c7; color: #b45309; }
.b-done { background: #d7f0d7; color: #166534; }
.tag-urgent { background: #fee2e2; color: #b91c1c; }
.muted { color: var(--muted); }
.right { text-align: right; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }
.spacer { flex: 1; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg,#1e3a8a,#2563eb); }
.login-box { background: #fff; padding: 34px; border-radius: 14px; width: 340px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-box h1 { text-align: center; font-size: 18px; }
.login-box .sub { text-align: center; color: var(--muted); margin-bottom: 20px; font-size: 13px; }

/* Toast */
#toast { position: fixed; top: 18px; right: 18px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #111827; color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: 0 6px 18px rgba(0,0,0,.2); animation: slide .2s; }
.toast.ok { background: var(--ok); } .toast.err { background: var(--danger); }
@keyframes slide { from { transform: translateX(20px); opacity: 0; } }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 500; }
.modal { background: #fff; border-radius: 12px; padding: 22px; width: 560px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal h2 { margin-top: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.chk-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 320px; overflow: auto; }
.chk-list label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; margin: 0; color: var(--ink); font-size: 13px; }
.chk-list input { width: auto; }
