* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f5dede;
  --bg-light: #fdf0f0;
  --bg-white: #fff;
  --header-bg: #7b3b5a;
  --header-text: #fff;
  --row-even: #fce8e8;
  --row-odd: #fdf0f0;
  --row-hover: #f0c8c8;
  --border: #d4a0a0;
  --border-light: #e8c0c0;
  --text: #333;
  --text-muted: #888;
  --title-red: #9b2d3f;
  --accent: #c4446a;
  --accent-hover: #a03355;
  --link: #7b3b5a;
  --cell-booked: #ffe0f0;
  --cell-booked-hover: #ffd0e8;
  --cell-lunch: #d8d8d8;
  --cell-empty: #fff;
  --cell-block: #c0c0c0;
  --cell-holiday: #c00;
  --btn-pink: #e87ca0;
  --btn-pink-hover: #d06888;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Noto Sans TC", Arial, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Page title — large red Chinese text like original */
.page-title {
  font-size: 28px;
  font-weight: bold;
  color: var(--title-red);
  padding: 6px 16px 0;
}

/* Icon nav bar — horizontal strip matching original top menu */
.icon-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 16px;
  background: var(--bg);
  flex-wrap: wrap;
}

.icon-bar a {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 11px;
  border-radius: 3px;
  transition: background 0.15s;
  min-width: 40px;
}

.icon-bar a .icon { font-size: 28px; line-height: 1; }
.icon-bar a:hover { background: rgba(123, 59, 90, 0.1); }
.icon-bar a.active { background: var(--header-bg); color: var(--header-text); }
.icon-bar .divider { color: #ccc; font-size: 16px; margin: 0 4px; }
.icon-bar .spacer { flex: 1; }
.icon-bar .lang-link { font-size: 12px; color: var(--link); text-decoration: underline; }

/* Sub-nav tabs — colored buttons like original */
.sub-tabs {
  display: flex;
  gap: 2px;
  padding: 4px 16px;
  flex-wrap: wrap;
}

.sub-tabs a {
  display: inline-block;
  padding: 4px 14px;
  font-size: 12px;
  font-weight: bold;
  color: var(--header-text);
  background: var(--btn-pink);
  text-decoration: none;
  border-radius: 2px;
}

.sub-tabs a:hover { background: var(--btn-pink-hover); }
.sub-tabs a.active { background: var(--header-bg); }
.sub-tabs a.blue { background: #6ca0dc; }
.sub-tabs a.blue:hover { background: #5888c0; }

/* Section header — maroon bar */
.section-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 6px 16px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
}

/* Command bar — date/branch controls */
.command-bar {
  background: var(--bg-light);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  font-size: 13px;
}

.command-bar label { font-weight: bold; color: var(--title-red); }

.command-bar input, .command-bar select {
  font-size: 13px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg-white);
}

.command-bar select { min-width: 100px; }

.command-bar .nav-btn {
  background: var(--btn-pink);
  color: var(--header-text);
  border: none;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  border-radius: 2px;
}

.command-bar .nav-btn:hover { background: var(--btn-pink-hover); }
.command-bar .spacer { flex: 1; }
.command-bar .status { font-size: 12px; color: var(--text-muted); }

/* Booking grid */
.grid-wrap { overflow-x: auto; }

.grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  table-layout: auto;
}

.grid-table th {
  background: var(--row-even);
  border: 1px solid var(--border);
  padding: 2px 3px;
  font-weight: bold;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 2;
  font-size: 10px;
  white-space: nowrap;
  line-height: 1.2;
}

.grid-table th.holiday { color: var(--cell-holiday); }

.grid-table td {
  border: 1px solid var(--border-light);
  padding: 1px 2px;
  vertical-align: top;
  min-width: 65px;
  height: 18px;
  font-size: 9px;
  overflow: hidden;
}

.grid-table .time-col {
  background: var(--row-even);
  font-weight: bold;
  text-align: left;
  min-width: 40px;
  max-width: 44px;
  white-space: nowrap;
  font-size: 10px;
  padding: 1px 3px;
}

.grid-table .cell-booked {
  background: var(--cell-booked);
  cursor: pointer;
  line-height: 1.3;
}

.grid-table .cell-booked:hover { background: var(--cell-booked-hover); }

.grid-table .cell-lunch {
  background: var(--cell-lunch);
  text-align: center;
  color: #666;
  font-style: italic;
}

.grid-table .cell-empty { background: var(--row-even); }

.grid-table .cell-empty.cell-drag-preview {
  background: #dff3ff;
  box-shadow: inset 0 0 0 1px #42a5f5;
}

.grid-table .cell-block {
  background: var(--cell-block);
  text-align: center;
  color: #666;
  font-weight: bold;
}

/* Booking cell content */
.booking-id { font-weight: bold; color: var(--title-red); font-size: 10px; }
.booking-customer { font-size: 10px; }
.booking-detail { font-size: 9px; color: var(--text-muted); }
.booking-treatment { font-size: 9px; color: #c06; font-weight: bold; }
.booking-selected-member-badge {
  display: inline-block;
  background: #f7efe8;
  border: 1px solid #e3d2c3;
  border-radius: 999px;
  padding: 2px 8px;
}

/* Q7 (Done Aug-8): safety-critical member prefs/remark on the booking surface */
.booking-member-prefs-alert {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 10px;
  background: #fff3cd;
  border: 1px solid #f0c36d;
  border-radius: 4px;
  color: #8a5a00;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
  max-width: 60vw;
  vertical-align: middle;
}

.booking-treat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  margin: 0 6px 6px 0;
  background: #eef7ee;
  border: 1px solid #b8d8b8;
  border-radius: 999px;
  font-size: 11px;
  color: #245b24;
}

.booking-treat-chip button {
  border: none;
  background: transparent;
  color: #245b24;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
  padding: 0;
}

.booking-owned-row {
  cursor: pointer;
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
  font-size: 12px;
  line-height: 1.35;
}

.booking-owned-row:hover {
  background: #fff7fb;
}

.booking-search-collapsed {
  font-size: 11px;
  color: #666;
  padding: 8px;
  background: #fafafa;
}

/* Footer action bar */
.footer-bar {
  background: var(--bg-light);
  padding: 4px 16px;
  font-size: 11px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.footer-bar a {
  color: var(--link);
  text-decoration: underline;
  font-size: 11px;
}

.footer-bar .sep { color: #ccc; }
.footer-bar .spacer { flex: 1; }
.footer-bar .close-link { color: var(--title-red); font-weight: bold; }

/* Data tables (members, staff, etc) */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 5px 10px;
  text-align: left;
  font-size: 12px;
  white-space: nowrap;
}

.data-table td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
}

.data-table tr:nth-child(even) { background: var(--row-even); }
.data-table tr:nth-child(odd) { background: var(--row-odd); }
.data-table tr:hover { background: var(--row-hover); }

/* Search form bar */
.search-bar {
  background: var(--bg-light);
  padding: 8px 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.search-bar label { font-weight: bold; font-size: 12px; }

.search-bar input {
  font-size: 13px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 2px;
  width: 280px;
}

/* Buttons */
.btn {
  background: var(--btn-pink);
  color: var(--header-text);
  border: none;
  padding: 4px 14px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 12px;
  font-weight: bold;
}

.btn:hover { background: var(--btn-pink-hover); }
.btn-grey { background: #999; }
.btn-grey:hover { background: #777; }
.btn-orange { background: #e8a040; }
.btn-orange:hover { background: #d09030; }

/* Pagination */
.pagination {
  padding: 8px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.pagination .page-info { font-size: 12px; color: var(--text-muted); }

/* Finance layout */
.finance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.finance-section { border: 1px solid var(--border); }

.finance-section h3 {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 5px 12px;
  font-size: 13px;
  text-align: center;
}

.finance-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 12px;
  border-bottom: 1px solid #eee;
  font-size: 12px;
}

.finance-row:nth-child(even) { background: var(--row-even); }
.finance-row .label { flex: 1; }
.finance-row .value { text-align: right; font-weight: bold; min-width: 110px; }

.finance-total {
  font-size: 14px;
  font-weight: bold;
  padding: 5px 12px;
  background: var(--row-even);
  display: flex;
  justify-content: space-between;
  border-top: 2px solid var(--border);
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 12px;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-white);
  border: 2px solid var(--header-bg);
  border-radius: 4px;
  padding: 16px;
  min-width: 340px;
  max-width: 90vw;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  margin: auto 0;
  max-width: 500px;
}

.modal-overlay.wide .modal { max-width: min(800px, 95vw); }

/* Y6b (Done Aug-15, MK): wider default on large screens so the deduction
   table shows fully, plus an explicit maximize state (95vw/95vh) toggled by
   the ⛶ button on the dialog header. */
@media (min-width: 1280px) {
  .modal-overlay.wide.deduction-movable .modal { max-width: min(1100px, 95vw); }
}
.modal-overlay.deduction-maximized .modal {
  width: 95vw;
  max-width: 95vw;
  height: calc(100vh - 48px);
  max-height: calc(100vh - 48px);
  transform: none !important;
}

/* Done Aug-10 R5: movable deduction dialog — backdrop stops dimming so the
   booking grid behind stays readable while deducting. The backdrop still
   absorbs clicks (no accidental tile-click replacing the dialog) but no
   longer closes the dialog — see the guard in bookings-deduction-drag.js. */
.modal-overlay.deduction-movable {
  background: transparent;
}
.modal-overlay.deduction-movable .modal {
  box-shadow: 0 10px 40px rgba(0,0,0,0.35);
}
.deduction-drag-handle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  margin: -16px -16px 10px;
  padding: 10px 16px;
  background: var(--row-even);
  border-bottom: 1px solid var(--border);
  border-radius: 4px 4px 0 0;
}
.deduction-drag-hint {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

.modal h3 { color: var(--header-bg); margin-bottom: 10px; font-size: 14px; }

.modal .detail-row {
  display: flex;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
}

.modal .detail-row .label {
  font-weight: bold;
  min-width: 70px;
  color: var(--accent);
}

.modal .close-btn { margin-top: 12px; display: block; width: 100%; }

/* Login page */
.login-layout {
  display: flex;
  min-height: 100vh;
  background: var(--bg);
}

.login-sidebar {
  width: 280px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-sidebar a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 18px;
  font-weight: bold;
}

.login-sidebar a .icon { font-size: 24px; order: 1; }
.login-sidebar a:hover { color: var(--accent); }

.login-main {
  flex: 1;
  padding: 30px 60px 30px 40px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.login-main .title {
  color: var(--title-red);
  font-size: 20px;
  font-style: italic;
  text-align: right;
  margin-bottom: 4px;
}

.login-main .subtitle {
  color: var(--text);
  font-size: 14px;
  text-align: right;
  margin-bottom: 2px;
}

.login-main .user-line {
  color: var(--text);
  font-size: 14px;
  font-weight: bold;
  text-align: right;
  margin-bottom: 16px;
}

.login-links {
  text-align: right;
  margin-top: 8px;
  line-height: 1.9;
}

.login-links a {
  display: block;
  color: var(--link);
  text-decoration: none;
  font-size: 13px;
}

.login-links a:hover { text-decoration: underline; }
.login-links .logout { color: var(--title-red); font-weight: bold; }

.login-form {
  margin-top: 20px;
  background: var(--bg-light);
  border: 1px solid var(--border);
  padding: 24px;
  border-radius: 4px;
  width: 320px;
}

.login-form input {
  display: block;
  width: 100%;
  padding: 6px 10px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 13px;
}

.login-form button { width: 100%; padding: 8px; font-size: 14px; }

.notice-box {
  margin-top: 20px;
  width: 500px;
  align-self: flex-start;
}

.notice-box .notice-header {
  color: var(--title-red);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 2px;
  text-decoration: underline;
}

.notice-box .notice-body {
  border: 1px solid var(--border);
  min-height: 120px;
  padding: 8px;
  background: var(--bg-white);
  font-size: 12px;
  color: var(--text-muted);
}

/* Dev note callout — floating bottom-right */
.dev-note {
  position: fixed; bottom: 12px; right: 12px; z-index: 999;
  width: 360px; max-height: 70vh; overflow-y: auto;
  background: #1a1a2e; color: #ccc; border: 1px solid #0f3460;
  border-radius: 6px; font-size: 11px; line-height: 1.5;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.dev-note-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; background: #0f3460; color: #e94560;
  font-weight: bold; font-size: 11px; border-radius: 6px 6px 0 0;
}
.dev-note-close { cursor: pointer; color: #888; font-size: 14px; }
.dev-note-close:hover { color: #fff; }
.dev-note-body { padding: 8px 10px; }
.dev-note-body h4 { color: #e94560; font-size: 11px; margin: 6px 0 2px; }
.dev-note-body h4:first-child { margin-top: 0; }
.dev-note-body p { margin: 0 0 2px; color: #aaa; }
.dev-note-body .done { color: #52b788; }
.dev-note-body .next { color: #ffd000; }
.dev-note-body .critical { color: #ff6b6b; font-weight: bold; }

.dev-note-stories-wrap { margin-top: 8px; border-top: 1px solid #2a3f5f; padding-top: 6px; }
.dev-note-stories-summary {
  cursor: pointer; color: #ffd000; font-weight: 600; font-size: 11px;
  list-style: none; user-select: none;
}
.dev-note-stories-summary::-webkit-details-marker { display: none; }
.dev-note-stories-hint {
  font-size: 9px; color: #64748b; margin: 4px 0 0; line-height: 1.35;
}
.dev-note-story-digest {
  font-size: 9px; color: #94a3b8; margin: 0 0 8px; line-height: 1.4; font-style: italic;
}
.dev-note-stories-scroll {
  max-height: min(38vh, 260px); overflow-y: auto; margin-top: 6px;
  display: flex; flex-direction: column; gap: 6px;
}
.dev-note-story-tags {
  display: flex; flex-wrap: wrap; gap: 3px; margin: 2px 0 4px;
}
.dev-note-story-tags span {
  font-size: 8px; padding: 1px 5px; border-radius: 3px; background: #0f3460; color: #cbd5e1;
}
.dev-note-story-card {
  background: #16213e; border: 1px solid #0f3460; border-radius: 4px; padding: 6px 8px;
}
.dev-note-story-meta { font-size: 9px; color: #94a3b8; display: block; margin-bottom: 4px; }
.dev-note-story-text { font-size: 10px; color: #e2e8f0; line-height: 1.45; margin: 0; }
.dev-note-story-empty { font-size: 10px; color: #888; margin: 4px 0 0; }

.status-preparing { background: #0277bd; color: #fff; }
.status-reconfirmed { background: #7b1fa2; color: #fff; }

.grid-table th.doctor-duty-col { background: #e3f2fd; color: #1565c0; }

/* Toast notifications */
.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%) translateY(-60px);
  padding: 8px 20px; border-radius: 4px; font-size: 13px; font-weight: 600;
  z-index: 10000; opacity: 0; transition: all .3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: #e6f4ea; color: #1a7a3a; border: 1px solid #a3d9a5; }
.toast-error { background: #fde8e8; color: #c00; border: 1px solid #f5a5a5; }

/* Form elements inside modals */
.form-grid { display: grid; grid-template-columns: 100px 1fr; gap: 6px 10px; align-items: center; margin: 10px 0; }
.form-grid label { font-size: 12px; font-weight: 600; color: var(--header-bg); text-align: right; }
.form-grid input, .form-grid select, .form-grid textarea {
  font-size: 12px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 3px;
  font-family: inherit;
}
.form-grid textarea { resize: vertical; min-height: 50px; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
  outline: none; border-color: var(--header-bg); box-shadow: 0 0 0 2px rgba(123,59,90,.15);
}
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.btn-primary { background: var(--header-bg); color: #fff; border: none; padding: 6px 16px; font-size: 12px; font-weight: 600; border-radius: 3px; cursor: pointer; }
.btn-primary:hover { background: #5a2040; }
.btn-danger { background: #c44; color: #fff; border: none; padding: 6px 16px; font-size: 12px; font-weight: 600; border-radius: 3px; cursor: pointer; }
.btn-danger:hover { background: #a33; }
.btn-secondary { background: #eee; color: #333; border: 1px solid var(--border); padding: 6px 16px; font-size: 12px; font-weight: 600; border-radius: 3px; cursor: pointer; }

/* Utilities */
.container { padding: 0; }
.scroll-x { overflow-x: auto; }
.mt-8 { margin-top: 8px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none; }
.loading { text-align: center; padding: 40px; color: var(--text-muted); font-size: 13px; }

/* L16 (Done 21/7): 搜尋 不要 — remove the top-nav booking-search entry.
   Page stays reachable by URL; only the nav icon is hidden. */
.icon-bar a[href="search.html"] { display: none !important; }
