/* 共用元件：按鈕、表單、跳出視窗、表格、標籤、月曆、提示、登入頁 */
:root {
  --accent: #7760d6; --accent-ink: #fff; --light: #f1edfc; --ink: #252333; --muted: #8b8999; --line: #ecebf1; --bg: #f7f7fb; --card: #fff;
  --green: #2f9e6b; --orange: #d98a1c; --red: #c94c5e; --radius: 12px;
  --font: system-ui, -apple-system, 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.55 var(--font); }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; letter-spacing: .5px; }
[hidden] { display: none !important; }

button, .btn { font: inherit; display: inline-block; text-decoration: none; cursor: pointer; border: 1px solid #e3e1eb; background: #fff; color: #555263; padding: 9px 15px; border-radius: 9px; transition: .15s; }
button:hover:not(:disabled), .btn:hover { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled), .btn.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
button.danger { color: var(--red); }
button.danger-fill { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
button.small, .btn.small { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
button.link { border: 0; background: none; color: var(--accent); padding: 6px 0; }
button.block { width: 100%; }
.icon-btn { border: 0; background: none; padding: 6px 9px; font-size: 16px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }

input, select, textarea { font: inherit; color: var(--ink); width: 100%; padding: 9px 11px; border: 1px solid #dddbe6; border-radius: 9px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
textarea { resize: vertical; }
input[type=checkbox] { width: auto; }
.form .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label, .field legend { font-size: 12.5px; font-weight: 600; color: #4a4759; }
.field i { color: var(--red); font-style: normal; }
.field small { color: var(--muted); font-size: 11.5px; }
fieldset.field { border: 0; padding: 0; margin: 0; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.form-error { color: var(--red); min-height: 1.2em; margin: 12px 0 0; font-size: 13px; }
.note { background: var(--light); color: #4d4570; border-radius: 9px; padding: 10px 12px; margin-bottom: 14px; font-size: 13px; }

.overlay { position: fixed; inset: 0; background: rgba(30, 26, 45, .45); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .12s; }
.dialog { background: #fff; border-radius: 16px; width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(30, 20, 60, .25); }
.dialog.wide { width: min(860px, 100%); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 17px; }
.dialog-body { padding: 18px 20px; overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.confirm-text { margin: 0; font-size: 15px; white-space: pre-line; }
.code-box dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; background: var(--light); padding: 14px 16px; border-radius: 10px; }
.code-box dt { color: var(--muted); }
.code-box dd { margin: 0; font-weight: 700; }
.code-box .big { font-size: 22px; color: var(--accent); }
@keyframes fade { from { opacity: 0; } }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }
.badge { display: inline-block; font-size: 11.5px; padding: 2px 9px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.badge.green { background: #e3f5ec; color: var(--green); }
.badge.gray { background: #efeef3; color: #77748a; }
.badge.orange { background: #fdf0dc; color: #b86f0c; }
.badge.red { background: #fbe5e8; color: var(--red); }
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--light); display: inline-grid; place-items: center; color: var(--accent); font-weight: 700; flex: none; }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 30px); background: #2b2838; color: #fff; padding: 11px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 200; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--red); }

.cal-week, .cal-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-week span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.day { min-height: 64px; padding: 6px; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; border-radius: 9px; background: #fff; border: 1px solid var(--line); text-align: left; overflow: hidden; }
.day span { font-size: 13px; font-weight: 600; }
.day.other { opacity: .45; }
.day.today span { color: #fff; background: var(--accent); border-radius: 99px; padding: 0 7px; }
.day.sel { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--light); }
.day:disabled { opacity: .3; }
.day .dot { font-size: 10.5px; line-height: 1.3; padding: 1px 5px; border-radius: 5px; background: var(--light); color: var(--accent); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day .dot.orange { background: #fdf0dc; color: #b86f0c; }

.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 20% 10%, var(--light), transparent 55%), var(--bg); }
.login-card { width: min(400px, 100%); background: #fff; padding: 30px 26px; border-radius: 20px; box-shadow: 0 12px 40px rgba(60, 40, 120, .1); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0 0 6px; font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #4a4759; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.brandmark { width: 42px; height: 42px; border-radius: 13px 4px 13px 4px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 20px; flex: none; overflow: hidden; }
.brandmark img { width: 100%; height: 100%; object-fit: cover; background: #fff; }
.brandname strong { display: block; font-size: 15px; }
.brandname small { color: var(--muted); font-size: 11px; }

@media (max-width: 640px) {
  .form .grid, .checks { grid-template-columns: 1fr; }
  .dialog { border-radius: 16px 16px 0 0; max-height: 92dvh; }
  .overlay { place-items: end center; padding: 0; }
}
