/* === ColorClock PWA — Styles === */
/* Adapted from popup.css. Key change: removed 400px body width, full-viewport layout. */

:root {
  --primary: #4361ee;
  --primary-hover: #3a56d4;
  --secondary: #f72585;
  --secondary-hover: #e01f77;
  --accent: #4cc9f0;
  --accent-hover: #3ab8dd;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #212529;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --error: #dc3545;
  --success: #198754;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  /* Safe area for iPhone notch / home indicator */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Center content on large screens, full-width on mobile */
#app {
  max-width: 480px;
  min-width: 300px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  background: var(--bg);
}

/* === Views === */
.view { display: none; padding: 20px; min-height: 100vh; }
.view.active { display: flex; flex-direction: column; }

/* Student clock fills the popup window exactly — no scroll, clock expands to fill */
#view-student-clock.active {
  height: 100vh;
  min-height: 0;
  padding: 12px;
  overflow: hidden;
  box-sizing: border-box;
}
#view-student-clock .clock-container {
  flex: 1;
  min-height: 0;
  padding: 4px;
}
#view-student-clock .view-header {
  margin-bottom: 8px;
  flex-shrink: 0;
}
#view-student-clock .clock-session-info {
  margin-top: 4px;
  flex-shrink: 0;
}
#view-student-clock .clock-block-title {
  font-size: clamp(13px, 4vw, 22px);
  padding: 2px 8px 0;
}
#view-student-clock .clock-session-time {
  font-size: clamp(11px, 3vw, 14px);
}

/* === Brand === */
.brand {
  text-align: center;
  padding: 80px 0 48px;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.brand-title {
  font-size: 36px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-subtitle {
  font-size: 16px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  padding: 10px 20px;
  min-height: 44px;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: var(--secondary-hover); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-text { background: none; color: var(--text-muted); padding: 6px 12px; }
.btn-text:hover { color: var(--text); background: rgba(0,0,0,0.05); }
.btn-large { padding: 16px 32px; font-size: 18px; border-radius: var(--radius); min-height: 56px; }
.btn-small { padding: 6px 14px; font-size: 13px; min-height: 36px; }
.btn-full { width: 100%; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #c82333; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.role-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 48px;
}

/* === View Header === */
.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.view-header h2 { flex: 1; font-size: 20px; font-weight: 700; }
.btn-back {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-back:hover { background: rgba(0,0,0,0.05); color: var(--text); }

/* === Forms === */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  font-family: inherit;
  transition: border-color var(--transition);
  outline: none;
  background: var(--surface);
  min-height: 48px;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}
.input-large { font-size: 22px !important; text-align: center; letter-spacing: 2px; }
.char-count { font-size: 11px; color: var(--text-muted); text-align: right; }

.form-footer {
  text-align: center;
  margin-top: 16px;
  color: var(--text-muted);
  font-size: 14px;
}
.form-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }
.form-footer a:hover { text-decoration: underline; }

/* === Error/Success Messages === */
.error-message {
  background: #fff5f5;
  color: var(--error);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border: 1px solid #fecdd3;
}
.hidden { display: none !important; }

/* === Dashboard === */
.dashboard-welcome {
  background: var(--surface);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  font-size: 15px;
}
.dashboard-welcome span { font-weight: 700; color: var(--primary); }

.passphrase-section {
  background: var(--surface);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.passphrase-display {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.passphrase-display .passphrase-text {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--secondary);
  flex: 1;
  min-width: 160px;
  cursor: pointer;
}
.passphrase-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

/* === Blocks Section === */
.blocks-section { flex: 1; margin-bottom: 16px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-header h3 { font-size: 16px; font-weight: 700; }

.blocks-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}
.blocks-list::-webkit-scrollbar { width: 4px; }
.blocks-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 16px;
  font-size: 14px;
}

.block-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all var(--transition);
}
.block-item:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.block-color { width: 14px; height: 40px; border-radius: 4px; flex-shrink: 0; }
.block-info { flex: 1; min-width: 0; }
.block-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.block-time { font-size: 12px; color: var(--text-muted); }
.block-actions { display: flex; gap: 4px; }

.dashboard-actions { margin-top: auto; padding-top: 12px; }

/* === Student Join === */
.student-join-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}
.student-join-content p { margin-bottom: 20px; color: var(--text-muted); font-size: 15px; }

/* === Clock Block Title === */
.clock-block-title {
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  min-height: 28px;
  padding: 4px 16px 0;
  letter-spacing: -0.3px;
}

/* === Clock === */
.clock-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 10px;
}
.clock-canvas { max-width: 100%; height: auto; }
.clock-session-info { text-align: center; margin-top: 12px; }
.clock-session-title { font-size: 20px; font-weight: 800; }
.clock-session-time { font-size: 14px; color: var(--text-muted); margin-top: 2px; }
.clock-passphrase {
  text-align: center;
  margin-top: 16px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--secondary);
}
/* End-time message overlay */
.end-time-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.10);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: pointer;
}
.end-time-dialog {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  pointer-events: none; /* clicks pass through to overlay */
}
.end-time-message-text {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 16px;
  line-height: 1.3;
}
.end-time-dismiss-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

/* Preview block row with scheduled-time input */
.preview-block-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
  flex-wrap: wrap;
}
.sched-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.sched-time-input {
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  width: 90px;
}

/* === Color Picker === */
.color-picker-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}
.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  min-width: 36px;
  min-height: 36px;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--text); box-shadow: var(--shadow); }

/* === Time Inputs === */
.time-inputs { display: flex; align-items: center; gap: 8px; }
.time-inputs input[type="time"] {
  flex: 1;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  background: var(--surface);
  min-height: 48px;
}
.time-inputs input[type="time"]:focus { border-color: var(--primary); }

/* Custom H / M / AM-PM time picker */
.tp-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tp-sep {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 0 1px;
}
.tp-select {
  appearance: none;
  -webkit-appearance: none;
  padding: 10px 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  text-align: center;
  cursor: pointer;
  outline: none;
  min-height: 48px;
}
.tp-select:focus { border-color: var(--primary); }
.tp-select.tp-min { width: 68px; }
/* Smaller variant for preview summary rows */
.tp-select-sm {
  font-size: 13px;
  padding: 4px 6px;
  min-height: 30px;
  font-weight: 500;
}
.tp-select-sm.tp-min { width: 52px; }
.tp-row-inline { display: inline-flex; }
.form-hint { font-size: 12px; color: var(--text-muted); margin: -8px 0 8px; }

/* Duration scroll picker */
.duration-picker-wrapper { position: relative; }
.duration-input-row { display: flex; align-items: stretch; }
.duration-text-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  color: var(--text);
  outline: none;
  min-height: 48px;
  transition: border-color var(--transition);
}
.duration-text-input:focus { border-color: var(--primary); }
.duration-picker-wrapper.open .duration-text-input { border-bottom-left-radius: 0; }
.btn-duration-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 20px;
  min-width: 80px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.btn-duration-picker:hover { background: var(--bg); color: var(--primary); }
.duration-picker-wrapper.open .btn-duration-picker {
  border-bottom-right-radius: 0;
  color: var(--primary);
}
.scroll-picker-panel {
  border: 2px solid var(--primary);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  position: absolute;
  left: 0;
  right: 0;
  z-index: 50;
}
.scroll-picker-track {
  position: relative;
  height: 200px;
  overflow: hidden;
}
.scroll-picker-items {
  position: relative;
  z-index: 1;
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scroll-picker-items::-webkit-scrollbar { display: none; }
.scroll-picker-items::before,
.scroll-picker-items::after {
  content: '';
  display: block;
  height: 80px;
}
.scroll-picker-item {
  height: 40px;
  scroll-snap-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: color 0.1s;
}
.scroll-picker-item.selected { color: var(--text); font-weight: 600; }
.scroll-picker-highlight {
  position: absolute;
  top: 50%;
  left: 12px;
  right: 12px;
  height: 40px;
  transform: translateY(-50%);
  background: var(--bg);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

/* === Preview === */
#view-preview {
  min-height: unset;
  overflow-y: auto;
}
#view-preview .clock-container {
  flex: 0 0 auto;
  padding: 4px 10px;
}
.preview-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.preview-header h2 { flex: 1; font-size: 20px; font-weight: 700; }

/* === Confirmation Dialog === */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.confirm-dialog {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.confirm-dialog h3 { margin-bottom: 8px; }
.confirm-dialog p { color: var(--text-muted); margin-bottom: 16px; font-size: 14px; }
.confirm-dialog .btn-group { display: flex; gap: 8px; }
.confirm-dialog .btn-group .btn { flex: 1; }

/* === Toast === */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  transition: transform 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* === Connection Status === */
.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

/* === Recurring / Checkbox / Day Picker === */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: auto;
  accent-color: var(--primary);
}
.day-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.day-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
}
.day-chip input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: auto;
  accent-color: var(--primary);
}

/* === History === */
.history-section { margin-top: 8px; }
.history-search-input {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  width: 130px;
  min-height: auto;
}
.history-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}
.history-item-meta { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.history-item-blocks { display: flex; flex-direction: column; gap: 3px; }
.history-block-row { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.history-block-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.history-block-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-block-dur { color: var(--text-muted); font-size: 12px; flex-shrink: 0; }
.history-more { font-size: 12px; color: var(--text-muted); padding-left: 15px; }
.history-item-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 2px; }
.history-date { font-size: 12px; color: var(--text-muted); }
.history-name { font-size: 14px; font-weight: 600; }

/* === Recurring Badge === */
.recurring-badge {
  font-size: 11px;
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

/* === Loading Spinner === */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 16px;
  color: var(--text-muted);
  font-size: 15px;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Responsive === */
@media (max-width: 400px) {
  .view { padding: 16px; }
  .brand-title { font-size: 28px; }
  .brand { padding: 60px 0 36px; }
  .btn-large { padding: 14px 28px; font-size: 17px; }
  .color-picker-grid { grid-template-columns: repeat(4, 1fr); gap: 10px; }
  .clock-passphrase { font-size: 22px; }
  .view-header h2 { font-size: 18px; }
  .clock-block-title { font-size: 18px; }
}

@media (max-width: 340px) {
  .view { padding: 12px; }
  .brand-title { font-size: 24px; }
  .clock-passphrase { font-size: 18px; }
  .clock-block-title { font-size: 15px; }
  .clock-session-time { font-size: 12px; }
  .view-header h2 { font-size: 16px; }
  .btn { font-size: 13px; min-height: 40px; }
}

@media (max-width: 300px) {
  .view { padding: 8px; }
  .clock-block-title { font-size: 13px; padding: 2px 8px 0; }
  .clock-session-time { font-size: 11px; }
  .view-header { margin-bottom: 8px; }
  .connection-status span { display: none; }
}
