
:root {
  --bg-body: #eaf3fb; --bg-card: #ffffff;
  --text-main: #1e2a33; --text-sub: #546e7a;
  --border-color: #e0e0e0;
  --primary-color: #1565c0; --accent-color: #0d47a1;
  
  --th-bg: #f5faff; --th-text: #455a64;
  --input-bg: #ffffff; --input-border: #cfd8dc;
  
  --invig-label: #455a64; --invig-title: #1565c0; 
  --invigilator-bg: #f5faff; --invigilator-border: #bbdefb;

  --status-normal-bg: #e8f5e9;   --status-normal-text: #2e7d32; --bar-normal: #4caf50;
  --status-warning-bg: #fffde7;  --status-warning-text: #f57f17; --bar-warning: #fbc02d;
  --status-urgent-bg: #ffebee;   --status-urgent-text: #c62828; --bar-urgent: #d32f2f;
  --status-end-bg: #e3f2fd;      --status-end-text: #1565c0;    --bar-end: #1565c0;
  --status-idle-bg: #eceff1;     --status-idle-text: #78909c;   --bar-idle: #b0bec5;

  --clock-bg: linear-gradient(135deg, #ffffff 0%, #f9fcff 100%);
  --shadow-color: rgba(0,0,0,0.05);
  --btn-dark-mode-bg: #455a64; --btn-dark-mode-text: #ffffff;
}

[data-theme="dark"] {
  --bg-body: #121212; --bg-card: #1e1e1e;
  --text-main: #e0e0e0; --text-sub: #90a4ae;
  --border-color: #333333;
  --primary-color: #64b5f6; --accent-color: #ffffff;
  
  --th-bg: #252525; --th-text: #b0bec5;
  --input-bg: #2c2c2c; --input-border: #444444;

  --invig-label: #ffffff; --invig-title: #ffffff;
  --invigilator-bg: #252525; --invigilator-border: #444444;
  
  --status-normal-bg: #1e1e1e;   --status-normal-text: #81c784; --bar-normal: rgba(102, 187, 106, 0.6);
  --status-warning-bg: #1e1e1e;  --status-warning-text: #fff176; --bar-warning: rgba(255, 238, 88, 0.6);
  --status-urgent-bg: #1e1e1e;   --status-urgent-text: #e57373; --bar-urgent: rgba(239, 83, 80, 0.6);
  --status-end-bg: #1e1e1e;      --status-end-text: #64b5f6;    --bar-end: rgba(66, 165, 245, 0.6);
  --status-idle-bg: #1e1e1e;     --status-idle-text: #90a4ae;   --bar-idle: rgba(120, 144, 156, 0.4);

  --clock-bg: linear-gradient(135deg, #121212 0%, #1a1a1a 100%);
  --shadow-color: rgba(0,0,0,0.8);
  --btn-dark-mode-bg: #37474f; --btn-dark-mode-text: #90caf9; 
}

body { margin: 0; font-family: "Noto Sans TC","Microsoft JhengHei",sans-serif; background: var(--bg-body); color: var(--text-main); height: 100vh; overflow: hidden; display: flex; flex-direction: column; transition: background 0.3s, color 0.3s; }
header { background: var(--bg-card); padding: 24px 32px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 4px 12px var(--shadow-color); flex-shrink: 0; border-bottom: 1px solid var(--border-color); }
header h1 { display: flex; align-items: center; gap: 15px; font-size: 2.2rem; font-weight: 900; margin: 0; color: var(--text-main); }
header h1 span { background: #1565c0; color: white; border-radius: 999px; padding: 6px 20px; font-size: 1.6rem; }
#info { font-size: 1.1rem; color: var(--text-sub); text-align: right; line-height: 1.4; }
.sync-status { font-size: .85rem; margin-top: 2px; color: var(--text-sub); }
.sync-status.ok { color: #2e7d32; }
.sync-status.warn { color: #f57f17; }

main { flex: 1; display: grid; grid-template-columns: 40% 1fr; gap: 16px; padding: 16px; box-sizing: border-box; height: 100%; }
section { background: var(--bg-card); border-radius: 16px; padding: 20px; box-shadow: 0 4px 12px var(--shadow-color); display: flex; flex-direction: column; height: 100%; box-sizing: border-box; border: 1px solid var(--border-color); }

h2 { font-size: 1.6rem; margin: 0 0 15px; border-left: 5px solid var(--primary-color); padding-left: 10px; color: var(--text-main); }
.table-wrapper { flex: 1; overflow-y: auto; }

.dashboard-table { width: 100%; border-collapse: collapse; font-size: 1.6rem; table-layout: fixed; }
.dashboard-table th, .dashboard-table td { padding: 12px 8px; text-align: center; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.dashboard-table th { background: var(--th-bg); font-weight: bold; color: var(--th-text); }
.dashboard-table th:nth-child(1), .dashboard-table td:nth-child(1) { width: 10%; font-weight: bold; color: var(--text-sub); } 
.dashboard-table th:nth-child(2), .dashboard-table td:nth-child(2) { width: 50%; } 
.dashboard-table th:nth-child(3), .dashboard-table td:nth-child(3) { width: 40%; white-space: nowrap; font-family: "Roboto Mono", monospace; font-weight: bold; color: var(--text-main); font-size: 2rem; } 

.subject { font-weight: 900; color: var(--accent-color); font-size: 3.5rem; line-height: 1.1; padding: 10px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-container { margin-top: 5px; width: 100%; height: 14px; background: var(--border-color); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; transition: width 0.5s linear, background 0.5s linear; }

.invigilator-box { margin-top: auto; padding: 20px; background: var(--invigilator-bg); border-radius: 12px; border: 2px solid var(--invigilator-border); }
.invigilator-box h3 { margin: 0 0 15px; font-size: 2rem; color: var(--invig-title); font-weight: 800; }
.invigilator-row { display: flex; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.invigilator label { font-size: 2.2rem; font-weight: 900; color: var(--invig-label); margin-right: 12px; line-height: 1.2; white-space: nowrap; padding-top: 4px; }
.invigilator input { width: 120px; height: 60px; font-size: 2.2rem; text-align: center; border: 3px solid var(--input-border); border-radius: 10px; margin-right: 20px; background: var(--input-bg); color: var(--accent-color); font-weight: bold; }
.invigilator input:focus { border-color: var(--primary-color); outline: none; }

.absent-group { display: inline-flex; position: relative; margin-right: 12px; margin-bottom: 8px; }
.absent-group input { width: 90px; height: 60px; margin-right: 0; background: var(--input-bg); border: 3px solid var(--input-border); color: var(--accent-color); font-size: 2.2rem; border-radius: 10px; text-align: center; font-weight: bold; }
.remove-absent { position: absolute; top: -10px; right: -10px; width: 24px; height: 24px; background: #ff5252; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 1.2rem; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.2); z-index: 10; transition: transform 0.2s; }
.remove-absent:hover { background: #d32f2f; transform: scale(1.1); }

.add-btn { background: var(--primary-color); color: #fff; border:none; border-radius: 8px; padding: 8px 20px; font-size: 1.6rem; cursor:pointer; font-weight: bold; }
[data-theme="dark"] .add-btn { color: #000; background: var(--primary-color); }

.clock { justify-content: center; align-items: center; text-align: center; background: var(--clock-bg); }
.digital-time { font-size: 11vw; font-weight: 900; color: var(--accent-color); line-height: 1; font-variant-numeric: tabular-nums; text-shadow: 4px 4px 0px var(--shadow-color); margin-bottom: 10px; }
.date { font-size: 2.5rem; color: var(--text-sub); font-weight: bold; margin-bottom: 30px; }
.teacher-time-controls { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: -16px 0 24px; }
.time-adjust-current, .time-adjust-value { color: var(--text-sub); font-size: 1.1rem; font-weight: bold; }
.time-adjust-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.time-adjust-btn { background: var(--primary-color); color: #fff; border: none; border-radius: 8px; padding: 7px 12px; font-size: .95rem; cursor: pointer; font-weight: bold; }
[data-theme="dark"] .time-adjust-btn { color: #000; }

.status { font-size: 2.8rem; font-weight: 900; padding: 20px 40px; border-radius: 16px; width: 90%; box-shadow: 0 4px 15px var(--shadow-color); transition: background 0.5s, color 0.5s; background: var(--status-normal-bg); color: var(--status-normal-text); border: 1px solid var(--border-color); }
.status.normal { background: var(--status-normal-bg); color: var(--status-normal-text); }
.status.warning { background: var(--status-warning-bg); color: var(--status-warning-text); }
.status.urgent { background: var(--status-urgent-bg); color: var(--status-urgent-text); }
.status.end { background: var(--status-end-bg); color: var(--status-end-text); }
.status.idle { background: var(--status-idle-bg); color: var(--status-idle-text); }

#settingsBtn { display: none; position: fixed; right: 180px; bottom: 30px; z-index: 999; }
.btn-group { position: fixed; right: 30px; bottom: 30px; display: flex; gap: 15px; z-index: 900; }
.fab-btn { background: var(--btn-dark-mode-bg); color: var(--btn-dark-mode-text); border: none; border-radius: 999px; font-size: 1.1rem; padding: 12px 24px; cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,0.3); transition: opacity 0.5s, background 0.3s, transform 0.1s; display: flex; align-items: center; gap: 8px; }
.fab-btn:active { transform: scale(0.95); }
#fullscreenBtn { background: #2e7d32; color: white; }
#fullscreenBtn.exit-mode { background: #d32f2f; color: white; }
#fullscreenBtn.exit-mode:hover { background: #b71c1c; }

.settings-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; justify-content: center; align-items: center; z-index: 9999; backdrop-filter: blur(5px); }
.settings-panel { background: #ffffff; color: #333; border-radius: 12px; width: 800px; max-width: 95vw; max-height: 90vh; padding: 30px; box-shadow: 0 25px 50px rgba(0,0,0,0.5); display: flex; flex-direction: column; overflow-y: auto; }
.settings-title { margin: 0 0 20px 0; font-size: 1.5rem; font-weight: 800; color: #37474f; border-bottom: 2px solid #eceff1; padding-bottom: 12px; }
.settings-row { display: flex; align-items: center; gap: 12px; margin-bottom: 15px; font-size: 1rem; color: #333; }
.time-adjust-row { flex-wrap: wrap; }
.time-offset-display { min-width: 72px; text-align: center; font-weight: bold; color: #455a64; }
.settings-row label { min-width: 100px; font-weight: bold; text-align: right; }
.settings-input, .settings-select { padding: 8px 12px; border-radius: 6px; border: 1px solid #b0bec5; font-size: 1rem; flex: 1; height: 38px; box-sizing: border-box; background: #fff; color: #333; }
.settings-template-btn { padding: 8px 16px; border-radius: 6px; border: none; background: #607d8b; color: #fff; cursor: pointer; font-size: 0.95rem; }
.settings-table { width: 100%; border-collapse: collapse; margin-top: 10px; margin-bottom: 20px; font-size: 1rem; border: 1px solid #cfd8dc; }
.settings-table th { background: #eceff1; padding: 10px; font-weight: bold; border: 1px solid #cfd8dc; color: #455a64; }
.settings-table td { padding: 6px; border: 1px solid #cfd8dc; text-align: center; color: #333; }
.settings-table input { width: 90%; padding: 6px; border: 1px solid #ccc; border-radius: 4px; font-size: 1rem; text-align: center; background: #fff; color: #333; }
.settings-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 10px; border-top: 2px solid #eceff1; padding-top: 20px; }
.settings-btn-primary { background: #1565c0; color: white; border: none; padding: 10px 24px; border-radius: 6px; font-size: 1rem; cursor: pointer; font-weight: bold; }
.settings-btn-secondary { background: #eceff1; color: #455a64; border: none; padding: 10px 24px; border-radius: 6px; font-size: 1rem; cursor: pointer; }

.login-box { background: white; padding: 30px; border-radius: 12px; width: 320px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
.login-title { font-size: 1.4rem; color: #1565c0; margin-bottom: 20px; font-weight: bold; }
.login-input { width: 100%; padding: 10px; font-size: 1.1rem; text-align: center; border: 2px solid #ddd; border-radius: 6px; margin-bottom: 15px; box-sizing: border-box; height: 44px; color: #333; background: #fff; }
.login-btn { width: 100%; padding: 10px; background: #1565c0; color: white; font-size: 1.1rem; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; }

@media (max-width: 1024px) { 
  main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow-y: auto; }
  .digital-time { font-size: 15vw; }
  .status { font-size: 2rem; }
  body { overflow: auto; height: auto; } 
}
