/* Salvation Army HKM theme — primary red #B01C1C */
:root {
  --sa-red: #B01C1C;
  --sa-red-dark: #8E1616;
  --sa-navy: #132230;
  --sa-blue: #002056;
  --sa-grey: #989799;
  --sa-light: #EBEBEB;
  --sa-black: #000000;
  --bg: #f7f4f4;
  --card: #ffffff;
  --text: #1a1a1a;
  --radius: 12px;
  --shadow: 0 10px 28px rgba(19, 34, 48, 0.12);
  --font: "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(176, 28, 28, 0.18), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, rgba(0, 32, 86, 0.08), transparent 55%),
    linear-gradient(180deg, #fff5f5 0%, var(--bg) 40%, #f3f0f0 100%);
  min-height: 100%;
}

a { color: var(--sa-red); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 16px;
  background: var(--sa-red);
  color: #fff;
  box-shadow: 0 4px 16px rgba(176, 28, 28, 0.35);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: contain;
  object-position: center;
  /* White plate so red logo stays visible on the red header */
  background: #ffffff;
  padding: 3px;
  box-sizing: border-box;
  flex-shrink: 0;
  display: block;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  filter: none !important;
  opacity: 1 !important;
  mix-blend-mode: normal !important;
}
.brand-name { font-weight: 700; font-size: 0.95rem; line-height: 1.15; }
.brand-app { font-size: 0.78rem; opacity: 0.92; }

.top-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}
.top-nav a {
  color: #fff;
  font-size: 0.85rem;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
  text-decoration: none;
}
.top-nav a:hover { background: rgba(255,255,255,0.28); text-decoration: none; }
.top-nav .nav-logout { background: rgba(0,0,0,0.18); }

.user-chip {
  display: inline-flex;
  align-items: center;
  color: #fff;
  font-size: 0.78rem;
  opacity: 0.95;
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 14px 40px;
}
.main-centered {
  min-height: calc(100vh - 140px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.panel-wide { max-width: none; }

.panel, .hero-login {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 18px;
  border-top: 4px solid var(--sa-red);
  width: 100%;
}

.hero-login { text-align: center; max-width: 420px; }
.hero-login h1 { color: var(--sa-red); margin: 0 0 10px; font-size: 1.55rem; }

h1 { margin: 0 0 6px; font-size: 1.35rem; color: var(--sa-navy); }
h2 { margin: 0 0 12px; font-size: 1.1rem; color: var(--sa-navy); }
.lead { margin: 0 0 16px; color: #444; }
.hint, .hint-inline { color: var(--sa-grey); font-size: 0.85rem; }
.meta { font-size: 0.92rem; margin: 8px 0 0; }
.muted, .zh { color: var(--sa-grey); font-size: 0.82rem; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}
.panel-head-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
.panel-head-zh {
  font-size: 0.9rem;
  color: #555;
  text-align: right;
  line-height: 1.3;
}

.stack-form { display: grid; gap: 10px; }
.stack-form label { font-weight: 600; font-size: 0.9rem; color: var(--sa-navy); }
.stack-form input,
.stack-form select,
.stack-form textarea,
.filter-bar select,
.filter-bar input,
.inline-row input {
  width: 100%;
  padding: 12px 12px;
  border: 1px solid #d7d7d7;
  border-radius: 10px;
  font: inherit;
  background: #fff;
}
.stack-form input:focus,
.stack-form select:focus,
.stack-form textarea:focus {
  outline: 2px solid rgba(176, 28, 28, 0.35);
  border-color: var(--sa-red);
}

.form-grid {
  grid-template-columns: 1fr;
}
@media (min-width: 720px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .full { grid-column: 1 / -1; }
}

.tutors-form-panel .form-grid-spaced-after {
  margin-bottom: 1.1rem;
}
.tutors-form-panel .tutor-checkbox-field label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--sa-navy);
}
.tutors-form-panel .tutor-checkbox-row {
  margin-top: 6px;
  text-align: left;
}
.tutors-form-panel .tutor-checkbox-row input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn-primary { background: var(--sa-red); color: #fff; }
.btn-primary:hover { background: var(--sa-red-dark); color: #fff; }
.btn-secondary { background: var(--sa-navy); color: #fff; }
.btn-ghost { background: var(--sa-light); color: var(--sa-navy); }
.btn-danger { background: #B01C1C; color: #fff; }
.btn-lg { padding: 14px 22px; font-size: 1.05rem; }
.btn-sm { padding: 7px 10px; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.35); }
.btn-danger:disabled { background: #9a9a9a; color: #f2f2f2; }

.inline-row { display: flex; gap: 8px; align-items: stretch; }
.inline-row input { flex: 1; }

.empty-state, .empty-cell {
  text-align: center;
  padding: 28px 12px;
  color: #555;
  background: #fafafa;
  border-radius: 10px;
}

.flash-wrap { max-width: none; margin: 12px auto 0; padding: 0 16px; }
.flash {
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 8px;
  font-size: 0.92rem;
}
.flash-success { background: #e8f7ee; color: #146c2e; }
.flash-error { background: #fde8e8; color: #B01C1C; }

.mode-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 560px) {
  .mode-grid { grid-template-columns: 1fr 1fr; }
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 120px;
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 18px;
  cursor: pointer;
  font: inherit;
  color: #fff;
  box-shadow: var(--shadow);
}
.mode-in { background: var(--sa-red); }
.mode-out { background: var(--sa-navy); }
.mode-title { font-size: 1.15rem; font-weight: 700; }
.mode-zh { opacity: 0.9; font-size: 0.95rem; }

.scanner-section { margin-top: 8px; }
.scanner-container {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  border-radius: 14px;
  overflow: hidden;
  background: #111;
}
#reader { width: 100%; }
.scanner-controls { text-align: center; margin-top: 14px; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.scan-status {
  text-align: center;
  margin-top: 10px;
  min-height: 24px;
  font-weight: 600;
  color: var(--sa-red);
}
.manual-entry {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--sa-light);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(19, 34, 48, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal[hidden] { display: none !important; }
#confirmActions[hidden],
#closeModal[hidden] { display: none !important; }
.modal-card {
  background: #fff;
  width: min(440px, 100%);
  border-radius: 16px 16px 12px 12px;
  padding: 20px 18px;
  border-top: 5px solid var(--sa-red);
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow: auto;
}
@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 16px; }
}
.modal-message { font-weight: 600; color: var(--sa-navy); line-height: 1.45; white-space: pre-line; }
.modal-message--warn,
.modal-message--error { color: #B01C1C !important; }
.modal-message--ok { color: var(--sa-navy); }
#confirmActions { margin-bottom: 10px; }
.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px 10px;
  margin: 14px 0 18px;
}
.result-grid dt { font-size: 0.78rem; color: var(--sa-grey); margin-top: 8px; }
.result-grid dd { margin: 0; font-size: 1.05rem; font-weight: 600; color: var(--sa-navy); }

.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.filter-bar select, .filter-bar input[type="date"] { max-width: 220px; }
.filter-bar #tsa_id { max-width: 260px; }

/* Attendance: keep all filters on one compact row (desktop) */
.filter-bar.filter-bar-dates {
  gap: 6px;
  flex-wrap: nowrap;
  font-size: 0.82rem;
  margin-bottom: 10px;
}
.filter-bar.filter-bar-dates label {
  margin: 0;
  white-space: nowrap;
  font-weight: 600;
  color: var(--sa-navy);
  font-size: 0.78rem;
}
.filter-bar.filter-bar-dates select,
.filter-bar.filter-bar-dates input[type="date"] {
  width: auto;
  min-width: 0;
  max-width: 140px;
  padding: 5px 7px;
  border-radius: 6px;
  font-size: 0.8rem;
}
.filter-bar.filter-bar-dates #division_id { max-width: 130px; }
.filter-bar.filter-bar-dates #site_id { max-width: 130px; }
.filter-bar.filter-bar-dates #tsa_id { max-width: 150px; }
.filter-bar.filter-bar-dates input[type="date"] { max-width: 118px; }
.filter-bar.filter-bar-dates .btn-sm {
  padding: 5px 9px;
  font-size: 0.78rem;
  white-space: nowrap;
}
@media (max-width: 1100px) {
  .filter-bar.filter-bar-dates {
    flex-wrap: wrap;
  }
}
.payslip-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.voucher-actions-below-table {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 2px solid var(--sa-light);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}
.voucher-actions-below-table .btn-block-mobile {
  width: 100%;
  max-width: 420px;
}
.voucher-actions-hint {
  margin: 0;
  max-width: 520px;
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; border: 1px solid #eee; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
  background: #fff;
  font-size: 0.88rem;
}
.data-table th {
  background: var(--sa-red);
  color: #fff;
  text-align: left;
  padding: 10px 8px;
  white-space: nowrap;
}
.data-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}
.data-table tbody tr:nth-child(even) { background: #faf7f7; }
.attendance-table,
.tutors-table { min-width: 1080px; }
.attendance-table th,
.attendance-table td,
.tutors-table th,
.tutors-table td {
  padding: 6px 5px;
  white-space: nowrap;
  vertical-align: middle;
}
.attendance-table .col-site,
.attendance-table .col-course {
  max-width: 132px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attendance-table .dt-date,
.attendance-table .dt-time { display: inline; }
.attendance-table .dt-time::before { content: " "; }

/* Full-width staff data pages (Attendance, Tutors) */
.app-main.main-wide {
  max-width: none;
  width: 100%;
  padding: 12px 16px 32px;
}
.main-wide .panel-wide {
  padding: 14px 12px;
}
.main-wide .panel-wide + .panel-wide {
  margin-top: 14px;
}
.wide-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.wide-data-table {
  width: 100%;
  table-layout: fixed;
  font-size: 0.78rem;
}
.wide-data-table th,
.wide-data-table td {
  padding: 5px 4px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wide-data-table code {
  font-size: inherit;
  font-family: inherit;
}
.wide-data-table .cell-center {
  text-align: center;
}
.wide-data-table .actions-cell {
  white-space: nowrap;
  overflow: visible;
  text-overflow: unset;
}
.wide-data-table .btn-sm {
  padding: 3px 6px;
  font-size: 0.7rem;
}

/* Tutors table column widths */
.tutors-table col.col-unit { width: 12%; }
.tutors-table col.col-tutor-id { width: 10%; }
.tutors-table col.col-name { width: 12%; }
.tutors-table col.col-tsa { width: 8%; }
.tutors-table col.col-emp { width: 9%; }
.tutors-table col.col-resigned { width: 5%; }
.tutors-table col.col-last-emp { width: 9%; }
.tutors-table col.col-salary { width: 7%; }
.tutors-table col.col-actions { width: 16%; }

@media (min-width: 900px) {
  .wide-table-wrap { overflow-x: hidden; }
  .wide-data-table,
  .attendance-table,
  .tutors-table {
    min-width: 0;
  }
  .wide-data-table {
    font-size: 0.75rem;
  }
  .wide-data-table th,
  .wide-data-table td {
    padding: 5px 3px;
  }
  .attendance-table .col-site,
  .attendance-table .col-course {
    max-width: none;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .attendance-table .dt-date,
  .attendance-table .dt-time {
    display: block;
    white-space: nowrap;
  }
  .attendance-table .dt-time::before { content: none; }
}

@media (max-width: 899px) {
  .app-main.main-wide {
    padding: 12px 8px 28px;
  }
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0 4px;
}
.pager-meta { color: var(--sa-grey); font-size: 0.85rem; }
.pager-links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pager-num, .pager-current {
  min-width: 28px;
  text-align: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.85rem;
}
.pager-num { color: var(--sa-navy); text-decoration: none; border: 1px solid #eee; background: #fff; }
.pager-current { background: var(--sa-red); color: #fff; }
.actions-cell { white-space: nowrap; }
.actions-cell form { display: inline; }
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 12px;
}
.tab-btn {
  border: 1px solid #ddd;
  background: #fff;
  color: var(--sa-navy);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
}
.tab-btn.active {
  background: var(--sa-red);
  border-color: var(--sa-red);
  color: #fff;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.add-course {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--sa-light);
}

.app-footer {
  text-align: center;
  padding: 18px 12px 28px;
  color: var(--sa-grey);
  font-size: 0.78rem;
}

@media (max-width: 640px) {
  .top-nav {
    width: auto;
    margin-left: auto;
    flex-wrap: nowrap;
    gap: 6px;
  }
  .top-nav .nav-desktop-only {
    display: none;
  }
  .top-nav a {
    font-size: 0.8rem;
    padding: 6px 12px;
    white-space: nowrap;
  }
  .app-header {
    padding: 10px 12px;
  }
  .brand-name { font-size: 0.88rem; }
  .brand-app { font-size: 0.72rem; }
  .user-chip {
    font-size: 0.72rem;
    max-width: 140px;
  }
  .panel-head { flex-direction: column; }
}
