/**
 * 護養安老院管理系統 - 樣式表
 */

:root {
  --bg: #f8faf9;
  --bg-card: #ffffff;
  --primary: #0d6b5c;
  --primary-light: #e8f5f3;
  --accent: #c4a35a;
  --ink: #1a1a1a;
  --ink-muted: #5c5c5c;
  --border: #e2e8e6;
  --danger: #c53030;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --sidebar-w: 260px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Noto Sans TC', 'Noto Sans', 'Microsoft JhengHei', sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
}

/* 頂部 */
.site-header {
  background: var(--bg-card);
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 0 24px;
  padding-top: var(--safe-top);
}
.site-header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.site-logo {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--primary);
}
.site-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}
.site-nav a, .site-nav button {
  padding: 8px 14px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 8px;
  font-size: 0.95rem;
}
.site-nav a:hover, .site-nav button:hover { background: var(--primary-light); color: var(--primary); }
.lang-btn { font-size: 0.85rem; color: var(--ink-muted); }
.btn-primary {
  background: var(--primary);
  color: #fff !important;
  padding: 8px 18px;
}
.btn-primary:hover { background: #0a5548; }

/* 登入頁 Hero */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, #0a5548 100%);
  color: #fff;
  padding: 60px 24px 80px;
  text-align: center;
}
.hero h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); margin-bottom: 12px; }
.hero p { font-size: 1.1rem; opacity: 0.95; max-width: 560px; margin: 0 auto 24px; }

/* 區塊、卡片 */
.section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 48px 24px;
}
.section h2 {
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 24px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-light);
}
.card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
}

/* 後台版面 */
.dashboard-layout {
  display: flex;
  min-height: calc(100vh - 64px);
}
.dashboard-sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  flex-shrink: 0;
}
.dashboard-sidebar a {
  display: block;
  padding: 12px 24px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
  border-left: 3px solid transparent;
}
.dashboard-sidebar a:hover { background: var(--primary-light); color: var(--primary); }
.dashboard-sidebar a.active { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); }
.dashboard-main {
  flex: 1;
  padding: 24px;
  overflow-x: auto;
}
.panel { display: none; }
.panel.active { display: block; }
.panel h2 { margin-bottom: 20px; font-size: 1.35rem; }

.dashboard-top {
  background: var(--bg-card);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.dashboard-top .user-role { font-size: 0.9rem; color: var(--ink-muted); }
.dashboard-top button { padding: 6px 14px; border: none; background: var(--border); border-radius: 8px; cursor: pointer; font-size: 0.9rem; }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--bg-card); border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { background: var(--primary-light); font-weight: 600; color: var(--primary); }
tr:hover { background: #fafafa; }
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; }
.badge-success { background: #c6f6d5; color: #276749; }
.badge-warning { background: #feebc8; color: #c05621; }
.badge-danger { background: #fed7d7; color: #c53030; }
tr.staff-row-fulltime { background: #f0fff4; }
tr.staff-row-parttime { background: #a2d2e2; }
.td-parttime { background: #a2d2e2 !important; }
.understaffed { color: #c53030; font-weight: 600; }

/* 表單 */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  max-width: 400px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
textarea { min-height: 80px; resize: vertical; }

/* 排班日曆（含邊框） */
.shift-calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0; margin-top: 16px; border: 2px solid #0d6b5c; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.shift-calendar .day-head { padding: 10px; text-align: center; font-weight: 600; background: var(--primary-light); color: var(--primary); font-size: 0.9rem; border: 1px solid #0d6b5c; }
.shift-calendar .day-cell { min-height: 80px; padding: 8px; background: var(--bg); font-size: 0.85rem; border: 1px solid #b0c4c0; }
.shift-calendar .roster-slot { border-bottom: 1px solid #b0c4c0; padding: 2px 0; }
.shift-calendar .roster-slot:last-child { border-bottom: none; }
.shift-calendar .shift-tag { display: block; padding: 4px 6px; margin-bottom: 4px; border-radius: 4px; }
.shift-calendar .shift-tag.evening { background: #feebc8; color: #c05621; }
.shift-calendar .shift-tag.night { background: #e9d8fd; color: #553c9a; }
/* 全職／兼職顏色 */
.roster-tag.fulltime { background: #c6f6d5; color: #276749; }
.roster-tag.parttime { background: #a2d2e2; color: #1a365d; }
.roster-pool .roster-pool-tag.fulltime { background: #c6f6d5; color: #276749; }
.roster-pool .roster-pool-tag.parttime { background: #a2d2e2; color: #1a365d; }
.shift-subtitle { font-size: 1.1rem; color: var(--primary); margin: 24px 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.roster-pool-label { margin: 12px 0 6px; font-weight: 500; }
.roster-pool { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.roster-pool .roster-pool-tag { cursor: grab; display: inline-block; }
.roster-pool .roster-pool-tag:active { cursor: grabbing; }
.roster-editable .roster-slot { min-height: 22px; }
.slot-label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 6px;
  margin-bottom: 6px;
  font-size: 0.75rem;
  line-height: 1.3;
}
.slot-label-text { color: var(--ink-muted); font-weight: 600; }
.roster-editable .slot-time {
  color: #c53030 !important;
  font-weight: 700;
  font-size: 0.75rem;
}
.roster-editable .roster-tag { cursor: grab; display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.roster-editable .roster-tag:active { cursor: grabbing; }
.roster-remove-btn {
  width: 16px; height: 16px; min-width: 16px; min-height: 16px; padding: 0; margin: 0 0 0 4px;
  border: none; border-radius: 50%; background: #c53030; color: #fff; font-size: 11px; line-height: 1;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-weight: bold;
  flex-shrink: 0; outline: none; box-shadow: none; vertical-align: middle;
}
.roster-remove-btn:hover { background: #9b2c2c; color: #fff; }
.roster-remove-btn:focus { outline: none; }
.roster-remove-btn:focus-visible { outline: 2px solid #c53030; outline-offset: 1px; }
.roster-tag.parttime .roster-remove-btn { background: #c53030; color: #fff; }
.roster-add-select { font-size: 0.75rem; padding: 2px 4px; margin-top: 4px; max-width: 100%; }
.slot-label-row .understaffed { margin-left: 4px; }
.help-tip { color: var(--ink-muted); font-size: 0.9rem; margin-bottom: 8px; }
.roster-editable .roster-cell .roster-slot.shift-cell.drag-over {
  background-color: #fff3cd !important;
  border: 2px dashed #ffc107;
  border-radius: 4px;
  transition: background 0.2s, border 0.2s;
}
.roster-editable .employee.dragging {
  opacity: 0.45;
  transform: scale(1.02);
}
.roster-container { margin-bottom: 24px; }
.conflict-bar {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  line-height: 1.45;
}
.conflict-bar--ok {
  background: #e6fffa;
  border: 1px solid #81e6d9;
  color: #234e52;
}
.conflict-bar--warn {
  background: #feebc8;
  border: 1px solid #ed8936;
  color: #7b341e;
}
.conflict-bar__title { font-weight: 700; margin-right: 8px; }
.conflict-bar__list { margin: 8px 0 0 18px; padding: 0; }
.conflict-bar__ok { font-weight: 500; }
.roster-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.roster-action-inline { display: inline; margin: 0; }
.add-employee,
.roster-add-select.add-employee {
  min-height: 36px;
  font-size: 0.85rem;
  padding: 6px 10px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
}
.available-employees.roster-pool {
  min-height: 48px;
  font-size: 1.05rem;
  padding: 12px;
  background: #f8f9fa;
  border: 2px dashed #6c757d;
  border-radius: 6px;
}
.btn-warning { background: #c05621 !important; }
.btn-warning:hover { background: #9c4221 !important; }
.btn-info { background: #2b6cb0 !important; }
.btn-info:hover { background: #2c5282 !important; }
.btn-success { background: #276749 !important; }
.btn-success:hover { background: #1e4538 !important; }
/* 列印時只顯示編更表（不印整個網頁） */
@media print {
  body, body * { visibility: hidden !important; }
  #roster-print-area, #roster-print-area * { visibility: visible !important; }
  #roster-print-area {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    padding: 16px !important;
    margin: 0 !important;
    background: #fff !important;
    z-index: 99999 !important;
    overflow: visible !important;
  }
  #roster-print-area .roster-print-title { font-size: 1.25rem; margin-bottom: 12px; font-weight: 700; }
}

/* 圖表 */
.chart-container { max-width: 500px; height: 280px; margin: 20px 0; }

/* 警報／提示 */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 12px; }
.alert-warning { background: #feebc8; color: #c05621; border: 1px solid #ed8936; }
.alert-danger { background: #fed7d7; color: #c53030; }
.alert-success { background: #c6f6d5; color: #276749; border: 1px solid #38a169; }
.alert-info { background: #bee3f8; color: #2b6cb0; }

/* 響應式 */
@media (max-width: 768px) {
  .dashboard-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .dashboard-layout { flex-direction: column; }
  .dashboard-sidebar { display: flex; flex-wrap: wrap; gap: 4px; padding: 12px; }
  .dashboard-sidebar a { padding: 8px 12px; border-radius: 8px; border-left: none; border-bottom: 2px solid transparent; }
  .dashboard-sidebar a.active { border-bottom-color: var(--primary); }
}
