/* ================================================================
   課表管理系統 v2 — style.css
   ================================================================ */

/* ========== 色彩系統 ========== */
:root {
  /* 主色 */
  --primary:        #9AA7F2;
  --primary-hover:  #8694E8;
  --primary-light:  #C1D0EE;
  --primary-ring:   rgba(154, 167, 242, 0.25);

  /* 背景 */
  --bg-page:        #FAF6F1;
  --bg-card:        #FEFEFE;

  /* 文字 */
  --text-primary:   #575C66;
  --text-secondary: #7A7F88;
  --text-hint:      #A0A4AB;

  /* 邊框 / 輸入框 */
  --border:         #EAE3D9;
  --border-light:   #F0EBE3;

  /* 互動淺底（hover 用） */
  --hover-light:    #F5F1EC;

  /* 語意色 */
  --danger:         #EF4444;
  --danger-light:   #FEF2F2;
  --warning:        #F59E0B;
  --warning-light:  #FEF3C7;
  --success:        #10B981;
  --success-light:  #ECFDF5;

  /* 圓角 */
  --radius-sm:      8px;
  --radius-md:      12px;
  --radius-lg:      16px;
  --radius-pill:    9999px;

  /* 陰影（暖色調） */
  --shadow-xs:      0 1px 2px rgba(87, 72, 56, 0.04);
  --shadow-sm:      0 1px 3px rgba(87, 72, 56, 0.06), 0 1px 2px rgba(87, 72, 56, 0.03);
  --shadow-md:      0 4px 12px rgba(87, 72, 56, 0.07);
  --shadow-lg:      0 8px 24px rgba(87, 72, 56, 0.12);

  /* 動畫 */
  --transition:     0.2s cubic-bezier(0.4, 0, 0.2, 1);

  /* 尺寸 */
  --header-h:       60px;
  --tab-bar-h:      52px;
  --top-fixed-h:    calc(var(--header-h) + var(--tab-bar-h));
}


/* ========== Reset ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

html, body {
  width: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', 'Noto Sans TC', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

button {
  font-family: inherit;
  cursor: pointer;
}


/* ========== 動畫 ========== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes modalIn {
  from { transform: scale(0.95) translateY(10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}


/* ========== 頂部固定區 ========== */
.top-fixed {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}


/* ========== Header ========== */
.app-header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border-light);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-brand h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.header-school {
  display: flex;
  align-items: center;
  gap: 8px;
}

.school-label {
  font-size: 13px;
  color: var(--text-hint);
}

.school-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: var(--border);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-pill);
}


/* ========== Tab Bar ========== */
.tab-bar {
  height: var(--tab-bar-h);
  border-bottom: 1px solid var(--border);
}

.tab-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  height: 100%;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tab-bar-inner::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

.tab-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.tab-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(154, 167, 242, 0.35);
}

.tab-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}


/* ========== 主內容區 ========== */
.content {
  min-height: calc(100vh - var(--top-fixed-h));
}

.content-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 28px 40px;
}

.tab-content {
  display: none;
  animation: fadeIn 0.25s ease;
}

.tab-content.active {
  display: block;
}


/* ========== Card ========== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  transition: box-shadow var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-count {
  font-size: 12px;
  font-weight: 500;
  color: #92400E;
  background: #FEF3C7;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
}

.placeholder-text {
  color: var(--text-hint);
  font-size: 14px;
}


/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-ring);
}
.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--primary-ring);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  padding: 6px 10px;
}
.btn-danger:hover {
  background: var(--danger-light);
}

.btn-edit {
  background: transparent;
  color: var(--primary);
  padding: 6px 10px;
}
.btn-edit:hover {
  background: var(--primary-light);
}

.btn-ghost {
  background: transparent;
  color: #78350F;
  border: 1.5px dashed #D4A574;
  width: 100%;
  justify-content: center;
  padding: 12px;
  border-radius: var(--radius-sm);
}
.btn-ghost:hover {
  border-color: #92400E;
  color: #92400E;
  background: #FEF3C7;
}

.btn-export {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px var(--primary-ring);
}
.btn-export:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-import {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-import:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

/* Small buttons (popover 等) */
.btn-sm {
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-sm.btn-primary { background: var(--primary); color: #fff; }
.btn-sm.btn-primary:hover { background: var(--primary-hover); }
.btn-sm.btn-secondary { background: var(--bg-page); color: var(--text-primary); border: 1px solid var(--border); }
.btn-sm.btn-secondary:hover { background: var(--primary-light); }
.btn-sm.btn-danger { background: transparent; color: var(--danger); border: 1px solid #fecaca; }
.btn-sm.btn-danger:hover { background: var(--danger-light); }


/* ========== Form ========== */
.form-row {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

.school-name { flex: 2; min-width: 0; }
.school-year { flex: 1; min-width: 0; }
.school-semester { flex: 1; min-width: 0; }

.form-group input,
.form-group select {
  padding: 9px 14px;
  border: 1.5px solid #EAE3D9;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-primary);
  background: #fff;
  transition: all var(--transition);
  width: 100%;
}

.form-group select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237A7F88' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.form-group input:hover,
.form-group select:hover {
  border-color: var(--primary-light);
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.form-group input::placeholder {
  color: var(--text-hint);
}


/* ========== Item List ========== */
.item-list {
  list-style: none;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  border: 1px solid transparent;
  gap: 8px;
}

.item-row:hover {
  background: var(--hover-light);
  border-color: var(--border-light);
}

.item-row .item-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.item-info > div {
  min-width: 0;
}

.item-badge {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}

.item-name {
  font-weight: 500;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-sub {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}

.item-row:hover .item-actions {
  opacity: 1;
}

.item-row.clickable {
  cursor: pointer;
}

.btn-icon-action {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-hint);
  line-height: 1;
  border-radius: 6px;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon-action:hover {
  color: #78350F;
  background: #FEF3C7;
}

.btn-del-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-hint);
  font-size: 16px;
  line-height: 1;
  border-radius: 6px;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-del-icon:hover {
  color: var(--danger);
  background: var(--danger-light);
}


/* ========== Batch Select ========== */
.batch-cb {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--primary);
  margin-right: 4px;
}

.batch-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  background: var(--warning-light);
  border: 1px solid var(--warning);
  animation: fadeIn 0.2s ease;
}

.batch-bar span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.batch-bar .batch-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-batch-del {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-batch-del:hover {
  background: #DC2626;
}

.btn-batch-cancel {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.btn-batch-cancel:hover {
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.05);
}


/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-hint);
  font-size: 14px;
}


/* ========== Modal / Confirm ========== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  justify-content: center;
  align-items: center;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 90%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.25s ease;
}

.modal h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--primary);
}

.modal .form-group {
  margin-bottom: 14px;
}

.modal .form-group input,
.modal .form-group select {
  width: 100%;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}


/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 22px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  transform: translateY(80px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 200;
  pointer-events: none;
  max-width: calc(100vw - 48px);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}


/* ========== Sub-tabs（設定頁內） ========== */
.sub-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border-light);
}

.sub-tab {
  padding: 10px 24px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.sub-tab:hover {
  color: var(--primary);
}

.sub-tab.active {
  color: var(--primary);
  font-weight: 600;
  border-bottom-color: var(--primary);
}

.sub-tab-content {
  display: none;
  animation: fadeIn 0.25s ease;
}

.sub-tab-content.active {
  display: block;
}


/* ========== Settings Grid ========== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.settings-full {
  grid-column: 1 / -1;
}


/* ========== Period Grid ========== */
.period-grid {
  display: grid;
  grid-template-columns: 50px auto 1fr 1fr 36px;
  gap: 6px;
  align-items: center;
}

.period-grid .pg-label {
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  color: var(--text-primary);
}

.period-grid .pg-header {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  text-align: center;
}

.period-grid input {
  padding: 7px 8px;
  border: 1.5px solid #EAE3D9;
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: center;
  transition: all var(--transition);
  width: 100%;
  background: #fff;
}

.period-grid input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.period-del {
  background: none;
  border: none;
  color: var(--text-hint);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  border-radius: 6px;
  transition: all var(--transition);
}

.period-del:hover {
  color: var(--danger);
  background: var(--danger-light);
}

.period-type-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
  border: 1px solid;
  white-space: nowrap;
  text-align: center;
}

.period-type-tag:hover {
  opacity: 0.75;
}

.pg-label-dim {
  opacity: 0.45;
}

.period-visibility-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}
.period-vis-row {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}
.period-vis-group {
  flex: 1;
  min-width: 0;
}
.period-vis-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.period-vis-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.period-vis-tag {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-page);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.period-vis-tag:hover {
  border-color: var(--primary);
}
.period-vis-tag.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}


/* ========== Type Popover ========== */
.type-popover {
  position: fixed;
  z-index: 70;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  max-width: 300px;
  animation: fadeIn 0.15s ease;
}

.type-popover-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.type-option {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-page);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.type-option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.type-option.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.type-popover-custom input {
  width: 100%;
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-primary);
  background: #fff;
  transition: all var(--transition);
}

.type-popover-custom input::placeholder {
  color: var(--text-hint);
}

.type-popover-custom input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}


/* ========== Period Timeline ========== */
.period-timeline {
  margin: 16px 0 4px;
}

.timeline-track {
  position: relative;
  height: 32px;
  background: var(--border-light);
}

.timeline-block {
  position: absolute;
  top: 0;
  height: 100%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: default;
}

.timeline-gap {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px dashed var(--text-hint);
  cursor: default;
}

.timeline-gap-label {
  font-size: 10px;
  color: var(--text-hint);
  font-weight: 500;
  white-space: nowrap;
}

.timeline-axis {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  padding: 0 2px;
}

.timeline-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.timeline-block[data-tip]::after,
.timeline-gap[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 400;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 10;
}

.timeline-block:hover[data-tip]::after,
.timeline-gap:hover[data-tip]::after {
  opacity: 1;
}


/* ========== Day Selector ========== */
.day-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.day-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.day-toggle.active {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--bg-card);
  font-weight: 600;
}

.day-toggle.locked {
  opacity: 0.6;
  cursor: default;
}


/* ========== Subject Tags ========== */
.subject-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.subject-tag {
  font-size: 11px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: #FEF3C7;
  color: #92400E;
  font-weight: 500;
}


/* ========== Category Tag / Built-in Badge ========== */
.category-tag {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  background: var(--border);
  color: var(--text-secondary);
  border: 1px solid transparent;
  font-weight: 500;
  vertical-align: middle;
}

.cat-color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
}

.builtin-badge {
  font-size: 10px;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  margin-left: 6px;
}


/* ========== Checkbox Grid ========== */
.checkbox-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition);
  border: none;
  background: transparent;
}

.checkbox-grid label:hover {
  background: #FAF6F1;
}

.checkbox-grid input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: #78350F;
  cursor: pointer;
}

.checkbox-grid span {
  line-height: 1.4;
}

.checkbox-grid input:checked + span {
  color: #78350F;
  font-weight: 600;
}

.sort-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px;
  width: 24px;
  height: 24px;
  transition: all var(--transition);
  margin-left: 8px;
  vertical-align: middle;
}

.sort-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.sort-toggle.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.sort-toggle.active:hover {
  background: var(--primary-hover);
}


/* ========== Teacher Filter Trigger Button ========== */
.btn-filter-trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-filter-trigger:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-filter-trigger.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-filter-trigger.active:hover {
  background: var(--primary-hover);
}

/* ========== Teacher Filter Bar (summary tags) ========== */
.teacher-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.teacher-filter-bar:empty {
  display: none;
}

.active-filter-tags {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.active-filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--primary-light);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-pill);
}

.active-filter-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: all var(--transition);
}

.active-filter-remove:hover {
  background: rgba(0, 0, 0, 0.1);
  color: var(--danger);
}

.filter-count {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-left: auto;
}

/* ========== Teacher Filter Modal ========== */
.teacher-filter-modal {
  max-width: 520px;
}

.filter-section {
  margin-bottom: 18px;
}

.filter-section:last-child {
  margin-bottom: 0;
}

.filter-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.filter-tags-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-page);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.filter-tag:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.filter-tag.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.teacher-filter-actions {
  justify-content: space-between;
}


/* ========== Backup Row ========== */
.backup-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}


/* ========== Demo Banner ========== */
.demo-banner {
  background: var(--border);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.demo-banner p {
  font-size: 14px;
  color: var(--text-primary);
}


/* ========== Editor Layout ========== */
.editor-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.editor-sidebar {
  width: 200px;
  flex-shrink: 0;
  position: sticky;
  top: calc(var(--top-fixed-h) + 24px);
}

.class-selector {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.class-selector .grade-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 8px 2px;
  letter-spacing: 0.04em;
}

.class-selector-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
}

.cs-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
}

.cs-count.count-full {
  color: var(--success, #2e7d32);
  font-weight: 600;
}

.class-selector-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.class-selector-item.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.editor-grid-wrap {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.editor-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 520px;
  table-layout: fixed;
}

.editor-table th {
  background: var(--border-light);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 4px;
  border: 1px solid var(--border);
  text-align: center;
}

.editor-table th:first-child {
  width: 54px;
}

.editor-cell {
  border: 1px solid var(--border);
  padding: 0;
  text-align: center;
  vertical-align: middle;
  height: 56px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
  font-size: 13px;
}

.editor-cell:hover {
  background: var(--primary-light);
}

.editor-cell .cell-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2px 4px;
  gap: 1px;
}

.editor-cell .cell-subject {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.3;
}

.editor-cell .cell-teacher {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.3;
}

.editor-cell.empty .cell-content::after {
  content: '+';
  font-size: 18px;
  color: var(--text-hint);
  opacity: 0;
  transition: opacity var(--transition);
}

.editor-cell.empty:hover .cell-content::after {
  opacity: 1;
}

.editor-cell.conflict {
  background: var(--warning-light);
}

.editor-cell.conflict .cell-conflict-mark {
  position: absolute;
  top: 2px;
  right: 4px;
  color: var(--danger);
  font-weight: 700;
  font-size: 12px;
}

.editor-fill-count {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
  text-align: right;
}


/* ========== Cell Popover ========== */
.cell-popover {
  display: none;
  position: fixed;
  z-index: 60;
}

.cell-popover.open {
  display: block;
  animation: fadeIn 0.15s ease;
}

.cell-popover-inner {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 18px;
  width: 280px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.cell-popover-inner .form-group {
  margin-bottom: 12px;
}

.cell-popover-inner .form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
  display: block;
}

.cell-popover-inner select {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid #EAE3D9;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  background: #fff;
  transition: all var(--transition);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237A7F88' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.cell-popover-inner select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.popover-conflict-warn {
  font-size: 12px;
  color: var(--danger);
  font-weight: 500;
  padding: 8px 10px;
  background: var(--danger-light);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  display: none;
  line-height: 1.5;
}

.popover-conflict-warn.show {
  display: block;
}

.popover-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}


/* ========== Schedule Table（各班課表檢視） ========== */
.schedule-table {
  border-collapse: collapse;
  font-family: 'Microsoft JhengHei', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.schedule-table th,
.schedule-table td {
  border: 1px solid var(--text-primary);
  text-align: center;
  padding: 4px 6px;
  font-size: 14px;
}

.schedule-table th {
  background: var(--border-light);
}

.cv-title-row td {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.1em;
  padding: 8px 12px;
  background: var(--bg-card);
}

/* Class view toolbar */
.cv-toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.cv-toolbar .form-group {
  min-width: 180px;
}

.cv-table-wrap {
  overflow-x: auto;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}

.cv-table-wrap .schedule-table {
  table-layout: fixed;
  width: 100%;
}

.schedule-table .cv-subj-cell {
  min-width: 60px;
  padding: 6px 4px;
  vertical-align: middle;
  text-align: center;
}

.schedule-table .cv-subject {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.schedule-table .cv-tchr-cell {
  padding: 2px 6px;
  vertical-align: middle;
}

.schedule-table .cv-teacher {
  font-size: 17px;
  color: var(--text-secondary);
}

.schedule-table .cv-time-cell {
  white-space: nowrap;
  font-size: 14px;
  padding: 4px 4px;
  vertical-align: middle;
  color: var(--text-secondary);
  line-height: 1.3;
}

.schedule-table .cv-num-cell {
  font-weight: 700;
  font-size: 20px;
  color: var(--text-primary);
  vertical-align: middle;
}

.schedule-table .cv-subject-en {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.2;
  margin-top: 2px;
}

.schedule-table .cv-subject-en-only {
  font-size: 14px;
}

.schedule-table .cv-teacher-en {
  font-size: 11px;
  color: var(--text-secondary);
}

.schedule-table .cv-merged-type-cell {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--border-light);
  vertical-align: middle;
  text-align: center;
  letter-spacing: 0.5em;
}



/* ========== Summary Tables（班級/教師總課表） ========== */
.summary-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.summary-table-wrap {
  overflow-x: auto;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}

.summary-table {
  border-collapse: collapse;
  font-size: 14px;
  white-space: nowrap;
}

.summary-table th,
.summary-table td {
  border: 1px solid var(--border);
  text-align: center;
  padding: 4px 6px;
  min-width: 58px;
}

.summary-table th {
  background: var(--border-light);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 14px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.summary-table .st-day-header {
  background: var(--text-primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.summary-table .st-period-header {
  background: var(--border-light);
  width: 32px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
}

.summary-table .st-row-label {
  background: var(--bg-page);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 13px;
}

.summary-table .st-total-row td {
  background: var(--bg-page);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.summary-table td.st-cell {
  font-size: 13px;
  line-height: 1.3;
  padding: 3px 4px;
}

.st-cell-v {
  display: inline-flex;
  flex-direction: row-reverse;
  gap: 0;
  justify-content: center;
}

.st-cell-v span {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
}

.st-cell-v .st-v-class {
  color: var(--text-secondary);
}

.st-cell-v .st-v-subj {
  font-weight: 500;
}


/* ================================================================
   Footer
   ================================================================ */
.site-footer {
  text-align: center;
  padding: 24px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

/* ================================================================
   RWD
   ================================================================ */

/* -- Tablet (768 ~ 1023px) -- */
@media (max-width: 1023px) {
  .header-inner {
    padding: 0 20px;
  }

  .tab-bar-inner {
    padding: 0 20px;
  }

  .content-inner {
    padding: 20px 20px 32px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .settings-full {
    grid-column: auto;
  }
}


/* -- Mobile (< 768px) -- */
@media (max-width: 767px) {
  :root {
    --header-h: 52px;
    --tab-bar-h: 46px;
  }

  /* Header */
  .header-inner {
    padding: 0 16px;
  }

  .header-brand h1 {
    font-size: 16px;
  }

  .brand-icon {
    width: 32px;
    height: 32px;
  }

  .brand-icon svg {
    width: 18px;
    height: 18px;
  }

  .header-school {
    display: none;
  }

  /* Tab bar */
  .tab-bar-inner {
    padding: 0 12px;
    gap: 4px;
  }

  .tab-btn {
    padding: 6px 14px;
    font-size: 13px;
  }

  .tab-icon {
    width: 14px;
    height: 14px;
  }

  /* Content */
  .content-inner {
    padding: 16px 12px 28px;
  }

  .card {
    padding: 20px 16px;
    border-radius: var(--radius-md);
  }

  /* Form */
  .form-row {
    flex-direction: column;
    gap: 10px;
  }

  .form-group,
  .school-name,
  .school-year,
  .school-semester {
    flex: none !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Item list */
  .item-row {
    padding: 10px 8px;
  }

  .item-actions {
    opacity: 1;
  }

  /* Sub-tabs */
  .sub-tab {
    padding: 8px 16px;
    font-size: 13px;
  }

  /* Period grid */
  .period-grid {
    grid-template-columns: 40px auto 1fr 1fr 30px;
    gap: 4px;
  }

  .period-grid input {
    padding: 6px 4px;
    font-size: 12px;
  }

  /* Backup */
  .backup-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .backup-row .btn {
    justify-content: center;
    width: 100%;
  }

  /* Demo banner */
  .demo-banner {
    flex-direction: column;
    text-align: center;
    padding: 14px;
  }

  /* Modal */
  .modal {
    width: calc(100% - 32px);
    padding: 20px;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* Summary toolbar */
  .summary-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-toolbar .btn {
    width: 100%;
    justify-content: center;
  }

  /* Class view toolbar */
  .cv-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .cv-toolbar .form-group {
    min-width: 0;
    width: 100%;
  }

  .cv-toolbar .btn {
    width: 100%;
    justify-content: center;
  }

  /* Teacher filter modal */
  .teacher-filter-modal {
    max-width: none;
    width: calc(100% - 32px);
  }

  .filter-tag {
    padding: 8px 16px;
    font-size: 14px;
  }

  .teacher-filter-actions {
    flex-direction: row;
  }

  .teacher-filter-actions .btn {
    width: auto;
  }

  .filter-count {
    width: 100%;
    margin-left: 0;
    text-align: right;
  }

  /* Editor */
  .editor-layout {
    flex-direction: column;
    gap: 12px;
  }

  .editor-sidebar {
    width: 100%;
    position: static;
  }

  .class-selector {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .class-selector .grade-label {
    width: 100%;
    padding: 4px 4px 0;
  }

  .class-selector-item {
    width: auto;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    font-size: 13px;
  }

  .editor-cell {
    min-height: 48px;
  }

  /* Popover */
  .cell-popover-inner {
    width: calc(100vw - 48px);
  }
}


/* -- Small mobile (< 380px) -- */
@media (max-width: 379px) {
  .tab-btn {
    padding: 6px 10px;
    font-size: 12px;
    gap: 4px;
  }

  .tab-icon {
    display: none;
  }
}


/* ================================================================
   列印
   ================================================================ */
@media print {
  .top-fixed {
    position: static;
    box-shadow: none;
  }

  .tab-bar,
  .toast,
  .no-print {
    display: none !important;
  }

  .tab-content {
    display: none !important;
  }

  .tab-content.print-target {
    display: block !important;
    padding: 0;
  }

  body {
    background: #fff;
  }

  .content {
    min-height: auto;
  }

  .cv-table-wrap,
  .summary-table-wrap {
    box-shadow: none;
    border: none;
    padding: 0;
  }

  .schedule-table {
    width: 100%;
  }

  .summary-table th {
    position: static;
  }
}
