:root {
  --primary: #b45309;          /* amber 700,深棕橘 */
  --primary-hover: #92400e;    /* amber 800 */
  --secondary: #78350f;        /* amber 900 */
  --bg: #fffbeb;
  --panel: #ffffff;
  --text: #1c1917;
  --muted: #6b7280;
  --border: #fcd34d;           /* amber 300 */
  --row-hover: #fef3c7;
  --danger: #dc2626;
  --shadow: 0 4px 12px rgba(120,53,15,0.12);
}
* { box-sizing: border-box; }
body { margin:0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* header */
header { background: var(--panel); border-bottom: 1px solid var(--border);
  padding: 12px 24px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; box-shadow: 0 4px 12px rgba(217,119,6,0.25); }
.title { font-size: 17px; font-weight: 600; }
.ver { font-size: 11px; font-weight: 500; color: var(--primary); background: #fde68a;
  border: 1px solid #fcd34d; padding: 1px 8px; border-radius: 10px; margin-left: 6px; vertical-align: middle; }
.subtitle { font-size: 12px; color: var(--muted); }
.user-info { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.btn-logout { background: white; border: 1px solid var(--border); color: var(--text);
  padding: 6px 12px; border-radius: 7px; font-size: 13px; cursor: pointer; font-family: inherit; }
.btn-logout:hover { background: var(--row-hover); color: var(--danger); border-color: var(--danger); }

/* main */
main { max-width: 1280px; margin: 0 auto; padding: 28px 24px; }
.tab { display: none; }
.tab.active { display: block; }

/* toolbar */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.toolbar h2 { margin: 0; font-size: 22px; }

/* filter row */
.filter-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: white; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 16px; }
.filter-row label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.filter-row select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: 13px; background: white; color: var(--text); }
.muted { color: var(--muted); }

/* table */
.table-wrap { background: white; border: 1px solid var(--border); border-radius: 12px; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #fef3c7; font-weight: 500; color: var(--secondary); font-size: 13px; }
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: none; }
.empty { text-align: center; color: #aaa; padding: 48px; font-size: 14px; }

/* btn */
.btn-primary { background: var(--primary); color: white; border: none;
  padding: 9px 16px; border-radius: 7px; cursor: pointer; font-size: 14px; font-family: inherit; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-ghost { background: white; border: 1px solid var(--border); color: var(--text);
  padding: 9px 16px; border-radius: 7px; cursor: pointer; font-size: 14px; font-family: inherit; }
.btn-ghost:hover { background: var(--row-hover); }
.btn-mini { background: white; border: 1px solid var(--border); color: var(--text);
  padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; font-family: inherit; margin-right: 4px; }
.btn-mini:hover { background: var(--primary); color: white; border-color: var(--primary); }
.btn-mini.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: white; }

/* modal */
.modal[hidden] { display: none !important; }
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-card { background: white; border-radius: 14px; box-shadow: var(--shadow);
  max-height: 92vh; display: flex; flex-direction: column; width: 540px; overflow: hidden; }
.modal-card.modal-large { width: 760px; max-width: 95vw; }
.modal-head { padding: 16px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; background: #fef3c7; }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-body { padding: 18px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px; }
.btn-close { background: transparent; border: none; font-size: 22px; cursor: pointer;
  color: var(--muted); padding: 0; width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center; }
.btn-close:hover { color: var(--text); }

/* form */
.sec-head { font-size: 14px; font-weight: 600; color: var(--secondary);
  background: #fde68a; padding: 6px 12px; margin: 16px 0 10px; border-radius: 6px;
  display: flex; align-items: center; }
.sec-head:first-child { margin-top: 0; }
.modal-body label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.modal-body label.span2 { grid-column: span 2; }
.modal-body input[type=text], .modal-body input[type=number], .modal-body input[type=time], .modal-body select {
  display: block; width: 100%; padding: 9px 12px; margin-top: 4px;
  border: 1px solid var(--border); border-radius: 7px;
  font-size: 14px; font-family: inherit; box-sizing: border-box; }
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(217,119,6,.18); }
.modal-body textarea { display: block; width: 100%; padding: 9px 12px; margin-top: 4px;
  border: 1px solid var(--border); border-radius: 7px;
  font-size: 14px; font-family: inherit; box-sizing: border-box; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-bottom: 8px; }

/* slot row(巡場 / 導覽 row)*/
.slot-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
  padding: 8px 10px; background: #f9fafb; border-radius: 8px; border: 1px solid var(--border); }
.slot-row .checkbox-label { display: flex; align-items: center; gap: 6px; min-width: 80px;
  margin: 0; font-size: 14px; color: var(--text); cursor: pointer; }
.slot-row input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.slot-row input[type=time], .slot-row input[type=number], .slot-row input[type=text] {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; font-family: inherit; background: white; }
.slot-row input.grow { flex: 1; min-width: 100px; }
.slot-row .slot-label { min-width: 60px; font-weight: 600; color: var(--secondary); }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: white; padding: 10px 18px;
  border-radius: 8px; font-size: 13px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }

/* nav tabs(主頁多 tab,manager 才看到月曆)*/
nav.tabs { display: flex; gap: 4px; }
.nav-btn { background: transparent; border: none; padding: 8px 16px;
  font-size: 14px; cursor: pointer; border-radius: 8px; color: var(--muted); font-family: inherit; }
.nav-btn:hover { background: var(--row-hover); color: var(--text); }
.nav-btn.active { background: var(--primary); color: white; }

/* slot-row 改兩列 layout — 異常情形 textarea 全寬可拖 */
.slot-row { padding: 10px 12px; }
.slot-row .slot-line1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.slot-row textarea.abnormal {
  width: 100%; min-height: 60px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit; background: white;
  resize: vertical; box-sizing: border-box;
}
.slot-row textarea.abnormal:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(180,83,9,.15); }

/* 月曆總覽 */
.cal-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: white; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; margin-bottom: 16px; }
.cal-toolbar .cal-month-display { font-size: 18px; font-weight: 600; color: var(--secondary); min-width: 130px; text-align: center; }
.cal-toolbar select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: 13px; background: white; }
.cal-toolbar .cal-nav { padding: 6px 14px; background: var(--primary); color: white;
  border: none; border-radius: 6px; cursor: pointer; font-family: inherit; font-size: 13px; }
.cal-toolbar .cal-nav:hover { background: var(--primary-hover); }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  background: white; border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.cal-head { font-size: 13px; font-weight: 600; color: var(--muted); text-align: center; padding: 8px 0; }
.cal-cell { aspect-ratio: 1; border: 1px solid #f3f4f6; border-radius: 8px;
  padding: 6px 8px; display: flex; flex-direction: column; cursor: pointer;
  background: #fafaf9; transition: all .15s; min-height: 70px; }
.cal-cell:hover { background: var(--row-hover); border-color: var(--primary); }
.cal-cell.empty { background: transparent; border: none; cursor: default; }
.cal-cell.empty:hover { background: transparent; }
.cal-cell.future { opacity: 0.4; }
.cal-cell .cal-date { font-size: 14px; font-weight: 600; color: var(--text); }
.cal-cell .cal-status { font-size: 11px; color: var(--muted); margin-top: auto; line-height: 1.3; }
.cal-cell.has-log { background: #ecfdf5; border-color: #86efac; }
.cal-cell.has-log .cal-status { color: #065f46; font-weight: 500; }
.cal-cell.no-log.workday { background: #fef2f2; border-color: #fecaca; }
.cal-cell.no-log.workday .cal-status { color: #991b1b; }

/* v1.1.1:日誌詳情 modal styling */
.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px 18px; margin: 6px 0 14px;
}
.detail-grid > div {
  display: flex; gap: 10px; align-items: baseline;
  padding: 8px 4px; border-bottom: 1px solid #f3f4f6;
}
.detail-label {
  min-width: 72px; color: var(--muted); font-size: 12px;
  font-weight: 500; letter-spacing: .3px;
}
.detail-table {
  width: 100%; border-collapse: collapse;
  margin: 6px 0 12px;
  background: white; border: 1px solid var(--border); border-radius: 8px;
  overflow: hidden;
}
.detail-table th, .detail-table td {
  padding: 9px 11px; text-align: left;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.detail-table th {
  background: var(--row-hover); color: var(--secondary);
  font-weight: 600; font-size: 12px;
}
.detail-table tbody tr:last-child td { border-bottom: none; }
.detail-text {
  background: #fafaf9; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  min-height: 36px; white-space: pre-wrap;
  line-height: 1.7; font-size: 14px; color: var(--text);
  margin-bottom: 4px;
}
.detail-block { margin-bottom: 12px; }

/* RWD 強化(駐館人員主要手機操作)*/
@media (max-width: 768px) {
  header { padding: 10px 14px; flex-wrap: wrap; gap: 8px; }
  main { padding: 14px 10px; }
  nav.tabs { width: 100%; order: 3; overflow-x: auto; flex-wrap: nowrap; }
  .nav-btn { flex: 0 0 auto; padding: 6px 12px; font-size: 13px; white-space: nowrap; }
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar h2 { font-size: 18px; }
  .filter-row { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; }
  .filter-row label { width: 100%; justify-content: space-between; }
  .filter-row select { flex: 1; }
  /* 表格手機 horizontal scroll */
  .table-wrap { overflow-x: auto; }
  th, td { padding: 8px 10px; font-size: 13px; }
  /* modal 全寬 */
  .modal { padding: 8px; }
  .modal-card.modal-large { width: 100%; max-width: 100%; max-height: calc(100vh - 16px); }
  .modal-head { padding: 12px 14px; }
  .modal-head h2 { font-size: 16px; }
  .modal-body { padding: 14px; }
  .grid-2 { grid-template-columns: 1fr; gap: 8px; }
  /* 16px 字避 iOS auto-zoom */
  .modal-body input, .modal-body select, .modal-body textarea,
  .filter-row select, .slot-row input, .slot-row textarea { font-size: 16px; }
  /* slot-row 在手機:第一行 wrap、textarea 仍全寬 */
  .slot-row .slot-line1 { gap: 6px; }
  .slot-row .slot-line1 .checkbox-label { min-width: 60px; }
  .slot-row .slot-line1 input[type=time] { width: auto; flex: 1; min-width: 100px; }
  .slot-row .slot-line1 input[type=number] { width: 90px; }
  /* 詳情 grid 改單列 + table 字級縮 */
  .detail-grid { grid-template-columns: 1fr; gap: 0; }
  .detail-table th, .detail-table td { padding: 7px 8px; font-size: 12px; }
  .detail-text { padding: 10px 12px; font-size: 13px; }
  /* 月曆手機緊湊 */
  .cal-toolbar { padding: 10px; gap: 8px; }
  .cal-toolbar .cal-month-display { font-size: 16px; min-width: 100px; }
  .cal-grid { padding: 8px; gap: 2px; }
  .cal-head { font-size: 11px; padding: 4px 0; }
  .cal-cell { min-height: 52px; padding: 4px; }
  .cal-cell .cal-date { font-size: 12px; }
  .cal-cell .cal-status { font-size: 9px; }
  /* 觸控目標 */
  .btn-primary { min-height: 38px; }
  .btn-mini { min-height: 32px; padding: 6px 10px; }
}

@media (max-width: 480px) {
  .cal-cell { min-height: 44px; }
  .cal-cell .cal-date { font-size: 11px; }
  .cal-cell .cal-status { display: none; }  /* 極窄只看顏色 */
}
