:root {
  --bg: #f7f7f8;
  --card: #ffffff;
  --ink: #1c1c1e;
  --muted: #8e8e93;
  --line: #edeef2;
  --brand: #f07885;
  --brand-ink: #d95f6d;
  --brand-tint: #fdeaec;
  --np: #2f8f5f;         /* NP 初診：文字色（薄荷底） */
  --np-bg: #d8f3dc;
  --rtc: #a1660a;         /* RTC 回診：文字色（奶油黃底） */
  --rtc-bg: #ffe6a3;
  --nursing: #3f6fb8;     /* 護理組：文字色（淺藍底） */
  --nursing-bg: #dbe8ff;
  --nutrition: #c15a72;   /* 營養組：文字色（淺粉底） */
  --nutrition-bg: #ffd9e0;
  --danger: #e0554f;
  --shadow: 0 1px 2px rgba(30, 30, 40, .03), 0 10px 28px rgba(30, 30, 40, .06);
  --shadow-sm: 0 1px 2px rgba(30, 30, 40, .04), 0 4px 12px rgba(30, 30, 40, .05);
  --radius: 20px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Nunito", -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: .1px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }

/* 登入 */
.login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
}
.login-card {
  background: var(--card); border-radius: 24px; box-shadow: var(--shadow);
  padding: 36px 28px; width: 100%; max-width: 340px; text-align: center;
}
.login-card h1 { font-family: "Quicksand", inherit; font-size: 21px; margin: 0 0 4px; font-weight: 700; }
.login-card input {
  width: 100%; padding: 13px 14px; margin: 18px 0 10px; border: 1px solid var(--line);
  border-radius: 999px; font-size: 16px; text-align: center; background: var(--bg);
}
.login-card button {
  width: 100%; padding: 13px; border: 0; border-radius: 999px; background: var(--brand);
  color: #fff; font-size: 16px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow-sm);
}
.login-card button:hover { background: var(--brand-ink); }

/* 版面 */
.topbar {
  position: sticky; top: 0; z-index: 10; background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 14px 20px; flex-wrap: wrap;
}
.brand { font-family: "Quicksand", inherit; font-weight: 700; font-size: 17px; }
.tabs { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.tab {
  border: 0; background: transparent; color: var(--muted); padding: 9px 16px;
  border-radius: 999px; font-size: 15px; cursor: pointer; font-weight: 700;
  transition: background .15s ease, color .15s ease;
}
.tab:hover { background: var(--brand-tint); color: var(--brand-ink); }
.tab.active { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.link-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; }
.link-btn:hover { color: var(--danger); }
.view { max-width: 1100px; margin: 0 auto; padding: 24px 20px 70px; }

/* 卡片 & 通用 */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 20px;
}
.card h2 { margin: 0 0 4px; font-size: 18px; font-weight: 800; }
.card .sub { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

textarea, input[type=text], input[type=date], input[type=search], select {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 15px;
  font-family: inherit; background: var(--bg); color: var(--ink); width: 100%;
}
textarea:focus, input:focus, select:focus {
  outline: none; border-color: var(--brand); background: #fff;
}
textarea { min-height: 180px; resize: vertical; line-height: 1.55; }

button.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; font-size: 15px; font-weight: 700;
  cursor: pointer; background: var(--brand); color: #fff; box-shadow: var(--shadow-sm);
  transition: background .15s ease, transform .1s ease;
}
button.btn:hover { background: var(--brand-ink); }
button.btn:active { transform: scale(.97); }
button.btn.secondary { background: var(--brand-tint); color: var(--brand-ink); box-shadow: none; }
button.btn.secondary:hover { background: #fbdadd; }
button.btn.ghost { background: transparent; color: var(--brand); padding: 6px 10px; box-shadow: none; }
button.btn:disabled { opacity: .5; cursor: default; }
button.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 15px; padding: 5px 8px; border-radius: 999px;
}
button.icon-btn:hover { background: var(--brand-tint); color: var(--danger); }

/* 表格 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; min-width: 640px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 700; font-size: 13px; white-space: nowrap; }
tbody tr:hover { background: #fbfbfc; }
tbody tr:last-child td { border-bottom: 0; }
td input, td select { padding: 7px 9px; font-size: 14px; background: transparent; border-color: transparent; }
td input:hover, td select:hover { border-color: var(--line); }
td.narrow { width: 1%; white-space: nowrap; }

/* 標籤 */
.pill { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.pill.np { background: var(--np-bg); color: var(--np); }
.pill.rtc { background: var(--rtc-bg); color: var(--rtc); }
.pill.nursing { background: var(--nursing-bg); color: var(--nursing); }
.pill.nutrition { background: var(--nutrition-bg); color: var(--nutrition); }
.pill.unassigned { background: #eef0f4; color: var(--muted); }

/* 統計 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat-tile { background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; }
.stat-tile .n { font-family: "Quicksand", inherit; font-size: 30px; font-weight: 700; letter-spacing: -.5px; color: var(--ink); }
.stat-tile .k { color: var(--muted); font-size: 13px; margin-top: 2px; }
.team-head { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 10px; }
.team-head h3 { margin: 0; font-size: 16px; font-weight: 800; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #1c1c1e; color: #fff; padding: 11px 20px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 50; font-size: 14px; max-width: 90vw; font-weight: 600;
}
.toast.err { background: var(--danger); }

.empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .brand { width: 100%; }
  .view { padding: 16px 12px 70px; }
  .card { padding: 18px 16px; border-radius: 18px; }
}
