/* =============================================================================
   CSS VARIABLES
   ============================================================================= */
:root {
  --bg:          #f1f5f9;
  --surface:     #ffffff;
  --header-bg:   #1e293b;
  --header-text: #f8fafc;
  --text:        #1e293b;
  --text-muted:  #64748b;
  --border:      #e2e8f0;
  --primary:        #3b82f6;
  --primary-hover:  #2563eb;
  --danger:         #ef4444;
  --danger-hover:   #dc2626;
  --radius:    10px;
  --radius-sm:  6px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 8px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 12px 28px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);
  --t: 150ms ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* =============================================================================
   HEADER
   ============================================================================= */
.site-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top, 10px));
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  z-index: 100;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -.03em;
  flex: 1;
  color: var(--primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* (show-completed removed) */

/* =============================================================================
   BUTTONS
   ============================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: background var(--t), transform var(--t);
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-sm { padding: 5px 10px; font-size: .78rem; }

/* Large icon button in header (settings gear) */
.btn.btn-icon {
  padding: 8px;
  background: transparent;
  color: #94a3b8;
  border-radius: var(--radius-sm);
  transition: background var(--t), color var(--t);
}
.btn.btn-icon--lg { padding: 9px; color: #cbd5e1; }
.btn.btn-icon:hover,
.btn.btn-icon--lg:hover { background: rgba(255,255,255,.12); color: #fff; }

/* Undo / Redo */
.undo-redo-group {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,.07);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.btn-icon-header {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  background: transparent;
  color: #94a3b8;
  font-family: inherit;
  transition: background var(--t), color var(--t);
}
.btn-icon-header:hover:not(:disabled) { background: rgba(255,255,255,.12); color: #fff; }
.btn-icon-header:disabled { opacity: .28; cursor: not-allowed; }

/* =============================================================================
   APP LAYOUT — split view
   ============================================================================= */
.app-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 340px;
  overflow: hidden;
}
.app-body:has(.summary-panel--collapsed) {
  grid-template-columns: 1fr 16px;
}

/* ---- MAIN PANEL (left) ---- */
.main-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* Tab bar */
.tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab-list {
  display: flex;
  align-items: flex-end;
  padding: 0 16px;
  gap: 2px;
}

.tab {
  padding: 10px 16px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: color var(--t), border-color var(--t);
  white-space: nowrap;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab--active { color: var(--primary); border-bottom-color: var(--primary); }

.tab--add {
  font-size: 1.1rem;
  padding: 8px 12px;
  color: var(--text-muted);
}
.tab--add:hover { color: var(--primary); }

/* Tab content scrolls */
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 48px;
  display: flex;
  flex-direction: column;
}
#classes-container { flex: 1; }
#empty-state:not(.hidden) { flex: 1; }

/* ---- SUMMARY PANEL (right) ---- */
.summary-panel {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  overflow: hidden;
  background: var(--surface);
  transition: none;
}

/* Drag handle — always-visible left strip */
.summary-drag-handle {
  width: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: col-resize;
  background: var(--bg);
  border-right: 1px solid var(--border);
  transition: background var(--t);
  user-select: none;
}
.summary-drag-handle:hover { background: color-mix(in srgb, var(--bg) 60%, var(--border)); }

.summary-drag-chevron { display: none; }

/* Pill — vertical on desktop, horizontal on mobile */
.summary-drag-pill {
  display: block;
  width: 4px;
  height: 32px;
  border-radius: 2px;
  background: var(--primary);
  opacity: 0.45;
  transition: opacity 120ms, height 120ms;
  pointer-events: none;
}
.summary-drag-handle:hover .summary-drag-pill { opacity: 0.85; }
.summary-drag-handle:active .summary-drag-pill { opacity: 1; height: 40px; }

/* Panel content fills remaining space */
.summary-drag-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Collapsed state — content hidden, chevron flips */
.summary-panel--collapsed .summary-drag-content {
  display: none;
}
.summary-panel--collapsed .summary-drag-chevron {
  transform: rotate(180deg);
}

.summary-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.summary-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  flex: 1;
}
.summary-count {
  background: var(--primary);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 99px;
}

#summary-list { flex: 1; overflow-y: auto; }

.summary-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 9px 14px 9px 0;
  border-bottom: 1px solid var(--border);
  transition: background var(--t);
}
.summary-item:last-child { border-bottom: none; }
.summary-item:hover { background: var(--bg); }

.summary-color-bar {
  width: 3px;
  min-height: 28px;
  align-self: stretch;
  background: var(--color, #94a3b8);
  border-radius: 2px;
  flex-shrink: 0;
  margin-left: 14px;
}

.summary-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  justify-content: center;
}
.summary-desc {
  font-size: .82rem;
  font-weight: 500;
  word-break: break-word;
  overflow-wrap: break-word;
}
.summary-meta {
  font-size: .72rem;
  color: var(--text-muted);
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Right-side column: deadline badge + action buttons stacked */
.summary-aside {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  flex-shrink: 0;
}
/* Badge stretches to match the buttons row width */
.summary-aside .deadline-badge {
  text-align: center;
  width: 100%;
}

.summary-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

.summary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: .7rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t);
  white-space: nowrap;
}
.summary-btn:hover { background: var(--bg); border-color: var(--text-muted); }

.summary-btn--edit { color: var(--primary); border-color: var(--primary); }
.summary-btn--edit:hover { background: #eff6ff; }

.summary-btn--done { color: #16a34a; border-color: #22c55e; }
.summary-btn--done:hover { background: #f0fdf4; }

/* No Due Date collapsible section in summary panel */
.summary-nodate-section { border-top: 1px solid var(--border); }
.summary-nodate-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 14px 16px 12px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-family: inherit;
  transition: background var(--t);
}
.summary-nodate-toggle:hover { background: var(--bg); }
.summary-nodate-label { flex: 1; text-align: left; }
.summary-nodate-ct {
  background: var(--primary);
  color: #fff;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 700;
}
.summary-nodate-chevron { font-size: .75rem; }
.summary-nodate-section--collapsed .summary-nodate-toggle { border-bottom: none; }
.summary-nodate-section--collapsed .summary-nodate-items { display: none; }

.summary-empty {
  padding: 32px 16px;
  text-align: center;
  font-size: .83rem;
  color: var(--text-muted);
}

/* =============================================================================
   CLASS ROWS
   ============================================================================= */
.class-row {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
  border-left: 5px solid var(--color, #94a3b8);
  transition: box-shadow var(--t);
}
.class-row:hover { box-shadow: var(--shadow-md); }

.class-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--color, #94a3b8) 9%, white);
  cursor: pointer;
  user-select: none;
}

.class-toggle-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  font-size: .9rem;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
  transition: color var(--t);
  pointer-events: none;
}
.class-header:hover .class-toggle-btn { color: var(--text); }

.class-drag-handle {
  color: var(--border);
  cursor: grab;
  font-size: 1rem;
  user-select: none;
  flex-shrink: 0;
  line-height: 1;
  opacity: 0;
  transition: color var(--t), opacity var(--t);
  touch-action: none;
}
.class-header:hover .class-drag-handle { opacity: 1; color: var(--text-muted); }
@media (pointer: coarse) { .class-drag-handle { opacity: .45; } }
.class-row.class-dragging  { opacity: .35; }
.class-row.class-drag-over { outline: 2px solid var(--primary); outline-offset: -2px; }
/* Assignment being dragged over a group → drop it into that group */
.class-row.group-drop-target { outline: 2px dashed var(--primary); outline-offset: -2px; }

/* Unified drag: floating clone + drop cursor + space-bar drop target */
body.is-dragging { cursor: grabbing !important; user-select: none; }
.hw-drag-clone    { background: var(--surface); border: 1px solid var(--border); }
.class-drag-clone { background: var(--surface); }
.tab.tab--drop {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  border-radius: 6px 6px 0 0;
}

/* =============================================================================
   CONTEXT MENU (right-click / long-press)
   ============================================================================= */
.context-menu {
  position: fixed;
  z-index: 10000;
  min-width: 190px;
  max-width: 280px;
  max-height: 70vh;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0,0,0,.22);
  animation: ctx-in .1s ease-out;
}
@keyframes ctx-in { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: scale(1); } }
.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: .88rem;
  text-align: left;
  cursor: pointer;
  transition: background var(--t), color var(--t);
}
.ctx-item:hover:not(:disabled) { background: color-mix(in srgb, var(--primary) 12%, transparent); }
.ctx-item:disabled { cursor: default; }
.ctx-icon  { width: 18px; text-align: center; flex-shrink: 0; font-size: .95rem; }
.ctx-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-arrow { color: var(--text-muted); font-size: 1rem; flex-shrink: 0; }
.ctx-item--danger        { color: var(--danger); }
.ctx-item--danger:hover  { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.ctx-item--muted         { color: var(--text-muted); font-size: .8rem; }
.ctx-divider { height: 1px; margin: 5px 6px; background: var(--border); }
.ctx-heading {
  padding: 6px 10px 4px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.ctx-item--indent .ctx-icon { margin-left: 14px; }

.class-row--collapsed .class-header { border-bottom: none; }
.class-row--collapsed .hw-list { display: none; }

.class-meta { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.class-name-text    { font-size: 1rem; font-weight: 700; }
.class-details-text { font-size: .78rem; color: var(--text-muted); }
.class-badge-area   { flex-shrink: 0; }
.class-header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* =============================================================================
   BADGES
   ============================================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.badge--pending { background: #fef3c7; color: #92400e; }
.badge--done    { background: #dcfce7; color: #166534; }

/* =============================================================================
   HOMEWORK LIST
   ============================================================================= */
.hw-list { padding: 2px 0; }

.hw-empty {
  padding: 14px 16px;
  font-size: .85rem;
  color: var(--text-muted);
  font-style: italic;
}

/* =============================================================================
   FOLDERS — a mini-group inside a group. Indented and boxed so it reads as one
   thing that happens to contain assignments, rather than as a nested group.
   ============================================================================= */
.folder {
  margin: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--color, #94a3b8) 5%, var(--surface));
  overflow: hidden;
}
.folder + .folder { margin-top: 8px; }

.folder-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  user-select: none;
  background: color-mix(in srgb, var(--color, #94a3b8) 8%, var(--surface));
  border-bottom: 1px solid var(--border);
}
.folder--collapsed .folder-header { border-bottom: none; }
.folder--collapsed .folder-items  { display: none; }

.folder-drag-handle {
  color: var(--border);
  cursor: grab;
  font-size: .95rem;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0;
  transition: color var(--t), opacity var(--t);
  touch-action: none;
}
.folder-header:hover .folder-drag-handle { opacity: 1; color: var(--text-muted); }
@media (pointer: coarse) { .folder-drag-handle { opacity: .45; } }

.folder-toggle-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  font-size: .8rem;
  color: var(--text-muted);
  font-family: inherit;
  line-height: 1;
  pointer-events: none;
}
.folder-icon  { flex-shrink: 0; font-size: .9rem; line-height: 1; }
.folder-name  { font-size: .87rem; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count {
  flex-shrink: 0;
  min-width: 20px;
  text-align: center;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 700;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--text-muted) 16%, transparent);
}
.folder-add-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  font-family: inherit;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--t), color var(--t), border-color var(--t);
}
.folder-header:hover .folder-add-btn { opacity: 1; }
.folder-add-btn:hover { color: var(--primary); border-color: var(--primary); }
@media (pointer: coarse) { .folder-add-btn { opacity: 1; } }

.folder-items .hw-item { padding-left: 22px; }
.folder-items .hw-item:last-child { border-bottom: none; }
.folder-empty {
  padding: 10px 14px 10px 22px;
  font-size: .78rem;
  color: var(--text-muted);
  font-style: italic;
}

.folder.folder-dragging { opacity: .35; }
/* An assignment dragged over a folder drops inside it */
.folder.folder-drop-target { outline: 2px dashed var(--primary); outline-offset: -2px; }
.folder.hw-drag-over { border-top: 2px solid var(--primary); }

.hw-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  transition: background var(--t);
}
.hw-item:last-child { border-bottom: none; }
.hw-item:hover { background: #f8fafc; }
.hw-item.hw-dragging  { opacity: .35; }
.hw-item.hw-drag-over { border-top: 2px solid var(--primary); }
.hw-item[draggable="true"] { cursor: default; }

.hw-drag-handle {
  color: var(--border);
  cursor: grab;
  font-size: 1rem;
  user-select: none;
  flex-shrink: 0;
  padding: 0 2px;
  line-height: 1;
  opacity: 0;
  transition: color var(--t), opacity var(--t);
  touch-action: none;
}
.hw-item:hover .hw-drag-handle { opacity: 1; color: var(--text-muted); }

@media (pointer: coarse) {
  .hw-drag-handle { opacity: .4; }
}

.hw-item--done { opacity: .65; background: #f8fafc; }
.hw-item--done .hw-desc { text-decoration: line-through; color: var(--text-muted); }

/* Collapsible hw-items */
.hw-item--collapsible { cursor: pointer; align-items: flex-start; }
.hw-item--collapsible .hw-check-label { align-self: center; }
.hw-item--collapsible .hw-right { align-self: center; }
.hw-item--collapsible .hw-drag-handle { align-self: center; }
.hw-item--collapsible .hw-desc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hw-item--collapsible .hw-notes { display: none; }
.hw-item--collapsible .hw-notes--always { display: block; }

.hw-expand-hint {
  font-size: .7rem;
  color: var(--text-muted);
  letter-spacing: .02em;
  margin-top: 1px;
}

/* Expanded state */
.hw-item--expanded .hw-desc {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.hw-item--expanded .hw-notes { display: block; }

/* Custom checkbox (uses the class color) */
.hw-check-label {
  position: relative;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  cursor: pointer;
}
.hw-check {
  opacity: 0;
  position: absolute;
  inset: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  margin: 0;
}
.custom-check {
  position: absolute;
  inset: 0;
  border: 2px solid #cbd5e1;
  border-radius: 4px;
  pointer-events: none;
  transition: border-color var(--t), background var(--t);
}
.hw-check:checked ~ .custom-check {
  background: var(--color, var(--primary));
  border-color: var(--color, var(--primary));
}
.hw-check:checked ~ .custom-check::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 5px; height: 9px;
  border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(45deg);
}
.hw-check:focus-visible ~ .custom-check {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.hw-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hw-desc  { font-size: .9rem; font-weight: 500; }
.hw-notes { font-size: .78rem; color: var(--text-muted); white-space: pre-wrap; }

.hw-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Deadline badges (shared by hw-items and summary) */
.deadline-badge {
  font-size: .72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}
.deadline--overdue { background: #fee2e2; color: #b91c1c; }
.deadline--today   { background: #ffedd5; color: #c2410c; }
.deadline--soon    { background: #fef3c7; color: #92400e; }
.deadline--ok      { background: #f1f5f9; color: #475569; }

/* Per-class quick-add button (in class header) */
.class-add-hw-btn {
  padding: 4px 11px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--header-bg);
  border: none;
  color: #fff;
  border-radius: 99px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background var(--t);
  flex-shrink: 0;
}
.class-add-hw-btn:hover { background: #334155; }

.add-topic-wrap {
  display: flex;
  justify-content: center;
  padding: 20px 0 8px;
}
.add-topic-btn {
  font-size: .82rem;
  padding: 7px 22px;
  opacity: .75;
  transition: opacity var(--t), background var(--t);
}
.add-topic-btn:hover { opacity: 1; }

/* Edit / Delete buttons on homework items (visible on row hover) */
.btn-icon-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 6px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  opacity: 0;
  transition: opacity var(--t), background var(--t), color var(--t);
}
.hw-item:hover .btn-icon-sm { opacity: 1; }
.btn-icon-sm:hover          { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.btn-icon-sm.hw-edit-btn:hover { background: color-mix(in srgb, var(--primary) 15%, transparent); color: var(--primary); }

/* =============================================================================
   EMPTY STATE
   ============================================================================= */
.empty-state {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 280px;
  color: var(--text-muted);
}
.empty-state-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateY(-50px);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 16px; }
.empty-state h2 { font-size: 1.2rem; color: var(--text); margin-bottom: 8px; }
.empty-state p  { margin-bottom: 20px; }
.empty-state-actions { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.btn-link { background: none; border: none; padding: 0; color: var(--primary); cursor: pointer; font-size: inherit; text-decoration: underline; }
.btn-link:hover { color: var(--primary-hover); }

/* =============================================================================
   MODALS
   ============================================================================= */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal--open { display: flex; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(3px);
}

.modal-box {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  animation: modal-in 200ms ease;
}
.modal-box--wide {
  max-width: 720px;
  height: 620px;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(-12px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 0;
  margin-bottom: 16px;
}
.modal-header h2 { font-size: 1.05rem; font-weight: 700; }

.close-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 4px;
  transition: background var(--t), color var(--t);
}
.close-btn:hover { background: var(--bg); color: var(--text); }

/* =============================================================================
   FORMS
   ============================================================================= */
#hw-form    { padding: 0 20px 20px; }
#tab-form   { padding: 0; }
.modal-form-body { padding: 0 20px 20px; }
.modal-box--narrow { max-width: 420px; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 13px;
}
.form-group--grow { flex: 1; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 110px; }

label {
  font-size: .74rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.required { color: var(--danger); }
.optional  { font-weight: 400; text-transform: none; letter-spacing: 0; font-size: .8rem; color: var(--text-muted); }

input[type="text"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--t), box-shadow var(--t);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
textarea { min-height: 68px; resize: vertical; }

.deadline-row { display: flex; gap: 8px; align-items: center; }
#hw-deadline { flex: 1; min-width: 0; padding: 11px 12px; font-size: 1rem; cursor: pointer; box-sizing: border-box; height: 47px; -webkit-appearance: none; appearance: none; }
#hw-deadline::-webkit-calendar-picker-indicator { cursor: pointer; opacity: 1; }
.time-picker { display: flex; gap: 2px; }
.time-picker input,
.time-picker select { padding: 0 8px; font-size: 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); font-family: inherit; cursor: pointer; box-sizing: border-box; height: 47px; }
#hw-hour   { width: 58px; }
#hw-minute { width: 58px; }
#hw-ampm   { width: 68px; }

.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* =============================================================================
   COLOR PICKER
   ============================================================================= */
.color-picker { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 2px; }
.color-swatches { display: flex; gap: 6px; flex-wrap: wrap; }

.color-swatch {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform var(--t), box-shadow var(--t);
  outline: none;
}
.color-swatch:hover { transform: scale(1.2); }
.color-swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px currentColor;
}

input[type="color"] {
  width: 32px; height: 32px;
  padding: 2px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: none;
}

/* =============================================================================
   SETTINGS MODAL
   ============================================================================= */
.settings-section {
  padding: 0 20px 8px;
  margin-bottom: 4px;
}
.settings-section--form { padding-bottom: 20px; }
.settings-section-label {
  font-size: .74rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 10px;
}

.divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* Tabs section */
.settings-tabs-list-inner { margin-bottom: 10px; }

.settings-tab-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.settings-tab-item:last-child { border-bottom: none; }
.settings-tab-item[draggable="true"] { cursor: default; }
.settings-tab-item.dragging  { opacity: .35; }
.settings-tab-item.drag-over { border-top: 2px solid var(--primary); }
.settings-tab-item:hover .drag-handle { color: var(--text-muted); }
.settings-tab-name    { flex: 1; min-width: 0; font-size: .9rem; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.settings-tab-default { font-size: .75rem; color: var(--text-muted); font-style: italic; }

/* Inline add-tab form */
.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.inline-form input { flex: 1; }

/* Groups-in section */
.settings-tab-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.settings-tab-header .settings-section-label { margin-bottom: 0; }
.settings-tab-header select {
  width: auto;
  max-width: 180px;
  min-width: 0;
  padding: 5px 10px;
  font-size: .82rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-empty { font-size: .875rem; color: var(--text-muted); padding: 4px 0 8px; }

.settings-class-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.settings-class-item:last-child { border-bottom: none; }
.settings-class-item[draggable="true"] { cursor: default; }
.settings-class-item.dragging  { opacity: .35; }
.settings-class-item.drag-over { border-top: 2px solid var(--primary); }

/* Drag handle (left of each settings row) */
.drag-handle {
  color: var(--border);
  cursor: grab;
  font-size: 1rem;
  user-select: none;
  flex-shrink: 0;
  padding: 0 2px;
  transition: color var(--t);
  line-height: 1;
}
.settings-class-item:hover .drag-handle { color: var(--text-muted); }

.settings-class-dot   { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.settings-class-info  { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; overflow: hidden; }
.settings-class-name  { font-weight: 600; font-size: .88rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.settings-class-details { font-size: .76rem; color: var(--text-muted); }
.settings-class-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Settings modal sidebar layout */
.settings-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid var(--border);
}

.settings-sidebar {
  width: 172px;
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg);
  overflow-y: auto;
}

.settings-nav-item {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: .82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background var(--t), color var(--t);
}
.settings-nav-item:hover:not(.settings-nav--active) { background: var(--border); color: var(--text); }
.settings-nav--active { background: var(--primary); color: #fff; }

.settings-content {
  flex: 1;
  overflow-y: auto;
  min-width: 0;
  padding-top: 12px;
}

.settings-page { display: block; }

/* Tab actions (edit + delete buttons) */
.settings-tab-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* =============================================================================
   HELP SECTION
   ============================================================================= */
.help-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.help-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-decoration: none;
  transition: background var(--t);
}
.help-item:hover { background: var(--border); }

.help-item-icon { font-size: 1.15rem; flex-shrink: 0; }
.help-item-body { flex: 1; display: flex; flex-direction: column; gap: 1px; text-align: left; }
.help-item-title { font-size: .88rem; font-weight: 600; }
.help-item-desc  { font-size: .75rem; color: var(--text-muted); }
.help-item-arrow { font-size: 1.2rem; color: var(--text-muted); flex-shrink: 0; }

/* =============================================================================
   WHAT'S NEW MODAL
   ============================================================================= */
.release-notes {
  padding: 0 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.release-block { display: flex; flex-direction: column; gap: 8px; }

.release-version {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--primary);
}

.release-block ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.release-block ul li {
  font-size: .85rem;
  color: var(--text);
  padding-left: 14px;
  position: relative;
}
.release-block ul li::before {
  content: '–';
  position: absolute;
  left: 0;
  color: var(--text-muted);
}

kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: .78rem;
  font-family: monospace;
}

/* =============================================================================
   PRIVACY MODAL
   ============================================================================= */
.privacy-content {
  padding: 0 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.privacy-lead {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
}
.privacy-content h3 {
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-top: 4px;
}
.privacy-content p {
  font-size: .875rem;
  color: var(--text);
  line-height: 1.6;
}
.privacy-footer-note {
  margin-top: 8px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: .82rem !important;
  font-style: italic;
  color: var(--text-muted) !important;
}

/* =============================================================================
   SITE FOOTER
   ============================================================================= */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 5px 20px;
  padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px));
  font-size: .7rem;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

/* =============================================================================
   TOAST NOTIFICATIONS
   ============================================================================= */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  /* Above .auth-screen (9999) and .context-menu (10000). At 999 every toast
     raised on the sign-in and verification screens rendered *underneath* them,
     so "email sent" and "could not send" were equally invisible. */
  z-index: 10050;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  transform: translateY(8px);
  opacity: 0;
  transition: transform 240ms ease, opacity 240ms ease;
  pointer-events: auto;
  max-width: 300px;
}
.toast--show    { transform: translateY(0); opacity: 1; }
.toast--success { background: #14532d; color: #fff; }
.toast--error   { background: #7f1d1d; color: #fff; }
.toast--warning { background: #78350f; color: #fff; }
.toast--info    { background: var(--header-bg); color: #fff; }

/* =============================================================================
   CONFIRM DIALOG
   ============================================================================= */
.confirm-box {
  max-width: 360px;
  padding: 32px 28px 24px;
  text-align: center;
}

.confirm-icon {
  font-size: 2.4rem;
  line-height: 1;
  margin-bottom: 14px;
}

.confirm-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.35;
}

.confirm-message {
  font-size: .85rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 0;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 22px;
}
.confirm-actions .btn { min-width: 88px; }

/* =============================================================================
   FAQ ACCORDION
   ============================================================================= */
.faq-list { border-top: 1px solid var(--border); }
.faq-item { border-bottom: 1px solid var(--border); }
.faq-question {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 13px 4px;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  line-height: 1.4;
}
.faq-question::after { content: '+'; font-size: 1rem; color: var(--text-muted); flex-shrink: 0; }
.faq-item.open .faq-question::after { content: '\2212'; }
.faq-answer {
  display: none;
  font-size: .85rem;
  color: var(--text-muted);
  padding: 0 4px 14px;
  line-height: 1.65;
}
.faq-answer strong { color: var(--text); }
.faq-item.open .faq-answer { display: block; }

/* =============================================================================
   AUTH SCREEN
   ============================================================================= */
.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.auth-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.spinner {
  width: 44px;
  height: 44px;
  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); } }

/* Loading state shown inside the main panel while Firestore data is fetching */
.data-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 32px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.data-loading .spinner {
  width: 36px;
  height: 36px;
}

.auth-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 44px 40px 40px;
  text-align: center;
  max-width: 400px;
  width: 92%;
}
.auth-logo {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -.02em;
}
.auth-tagline {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 28px;
}
.btn-google-signin {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 4px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t), box-shadow var(--t);
  width: 100%;
  justify-content: center;
}
.btn-google-signin:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.btn-google-signin svg { flex-shrink: 0; }

/* Auth form fields */
.auth-field { margin-bottom: 10px; }
.auth-field input {
  width: 100%;
  padding: 11px 14px;
  font-size: .95rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  transition: border-color var(--t);
  box-sizing: border-box;
}
.auth-field input:focus { outline: none; border-color: var(--primary); }
.auth-error { color: var(--danger); font-size: .8rem; margin: 4px 0 8px; text-align: left; }
.auth-submit-btn { width: 100%; margin-top: 4px; padding: 11px; font-size: .95rem; }
.auth-links {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  font-size: .82rem;
}
.auth-muted { color: var(--text-muted); }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0;
  color: var(--text-muted);
  font-size: .78rem;
}
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-reset-hint { font-size: .88rem; color: var(--text-muted); margin-bottom: 18px; text-align: left; }
#email-auth-form { margin-bottom: 0; }

/* User area in header */
.user-area {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,.3);
}
.user-name {
  font-size: 0.85rem;
  color: var(--header-text);
  opacity: 0.9;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-sign-out {
  font-size: 0.78rem;
  padding: 3px 10px;
  background: transparent;
  color: var(--header-text);
  border: 1px solid rgba(255,255,255,.35);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--t);
}
.btn-sign-out:hover { background: rgba(255,255,255,.12); }

/* =============================================================================
   APP WRAPPER
   ============================================================================= */
#app-wrapper:not(.hidden) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* =============================================================================
   MULTI-SELECT
   ============================================================================= */
.hw-item.sel-active {
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  box-shadow: inset 3px 0 0 var(--primary);
}
.folder.sel-active { border-color: var(--primary); }
.folder.sel-active > .folder-header {
  background: color-mix(in srgb, var(--primary) 16%, var(--surface));
  box-shadow: inset 3px 0 0 var(--primary);
}
.class-row.sel-active {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
.class-row.sel-active > .class-header {
  background: color-mix(in srgb, var(--primary) 14%, var(--surface));
}

/* Everything a multi-item drag picked up fades out at once */
.drag-source { opacity: .35; }

/* Count riding on the drag clone when a whole selection is in flight */
.drag-count-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--primary);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

.selection-bar {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom, 18px));
  transform: translateX(-50%);
  z-index: 9000;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 16px;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.selection-count { font-size: .83rem; font-weight: 600; white-space: nowrap; }

/* =============================================================================
   THEMES
   ============================================================================= */
[data-theme="dark"] {
  --bg:          #0f172a;
  --surface:     #1e293b;
  --header-bg:   #020617;
  --header-text: #f1f5f9;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --border:      #334155;
  --shadow:      0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md:   0 4px 8px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.2);
  --shadow-lg:   0 12px 28px rgba(0,0,0,.4), 0 4px 8px rgba(0,0,0,.2);
}
[data-theme="dark"] .class-header {
  background: color-mix(in srgb, var(--color, #94a3b8) 14%, #1e293b);
}
[data-theme="dark"] .hw-item:hover      { background: #263348; }
[data-theme="dark"] .hw-item--expanded  { background: #1e293b; }
[data-theme="dark"] .btn-icon-sm.hw-edit-btn:hover { background: #1e3052; }
[data-theme="dark"] .badge--pending { background: #451a03; color: #fdba74; }
[data-theme="dark"] .badge--done    { background: #052e16; color: #86efac; }
[data-theme="dark"] .deadline--overdue { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .deadline--today   { background: #431407; color: #fdba74; }
[data-theme="dark"] .deadline--soon    { background: #451a03; color: #fde68a; }
[data-theme="dark"] .deadline--ok      { background: #1e293b; color: #94a3b8; }
[data-theme="dark"] .summary-btn       { background: #1e293b; border-color: #334155; color: #cbd5e1; }
[data-theme="dark"] .summary-btn:hover { background: #0f172a; border-color: #475569; }
[data-theme="dark"] .summary-btn--edit { color: #93c5fd; border-color: #3b82f6; }
[data-theme="dark"] .summary-btn--edit:hover { background: #1e3a5f; }
[data-theme="dark"] .summary-btn--done { color: #86efac; border-color: #22c55e; }
[data-theme="dark"] .summary-btn--done:hover { background: #052e16; }
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="date"],
[data-theme="dark"] select,
[data-theme="dark"] textarea { background: #0f172a; color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] .btn-secondary { background: #334155; color: #e2e8f0; }
[data-theme="dark"] .btn-secondary:hover { background: #475569; }
[data-theme="dark"] .close-btn:hover { background: #334155; }
[data-theme="dark"] .help-item { background: #0f172a; }
[data-theme="dark"] .help-item:hover { background: #334155; }

[data-theme="sepia"] {
  --bg:          #f0e8d8;
  --surface:     #faf6f0;
  --header-bg:   #3d2b1f;
  --header-text: #fdf6ee;
  --text:        #3d2b1f;
  --text-muted:  #7c6a5e;
  --border:      #d4c4b0;
  --primary:        #8b6914;
  --primary-hover:  #6d5210;
}
[data-theme="sepia"] .class-header {
  background: color-mix(in srgb, var(--color, #94a3b8) 9%, #faf6f0);
}

[data-theme="high-contrast"] {
  --bg:          #000;
  --surface:     #111;
  --header-bg:   #000;
  --header-text: #fff;
  --text:        #fff;
  --text-muted:  #ccc;
  --border:      #555;
  --primary:        #ffff00;
  --primary-hover:  #cccc00;
  --danger:         #ff4444;
  --danger-hover:   #cc0000;
}
[data-theme="high-contrast"] .settings-nav--active { color: #000; }
[data-theme="high-contrast"] input[type="text"],
[data-theme="high-contrast"] input[type="date"],
[data-theme="high-contrast"] select,
[data-theme="high-contrast"] textarea { background: #000; color: #fff; border-color: #888; }
[data-theme="high-contrast"] .badge--pending { background: #333; color: #ffcc00; }
[data-theme="high-contrast"] .badge--done    { background: #003300; color: #00ff88; }

/* ── Cyber ─────────────────────────────────────────────────────────────────── */
[data-theme="cyber"] {
  --bg:          #050d14;
  --surface:     #0a1a26;
  --header-bg:   #020a10;
  --header-text: #00e5ff;
  --text:        #c8f0ff;
  --text-muted:  #4a8fa8;
  --border:      #0d3347;
  --primary:        #00e5ff;
  --primary-hover:  #00b8d4;
  --danger:         #ff1744;
  --danger-hover:   #d50000;
}
[data-theme="cyber"] .class-header {
  background: color-mix(in srgb, var(--color, #00e5ff) 14%, #0a1a26);
}
[data-theme="cyber"] .hw-item:hover { background: #0d2233; }
[data-theme="cyber"] input[type="text"],
[data-theme="cyber"] input[type="date"],
[data-theme="cyber"] select,
[data-theme="cyber"] textarea { background: #020a10; color: #c8f0ff; border-color: #0d3347; }
[data-theme="cyber"] .btn-secondary { background: #0d2233; color: #c8f0ff; }
[data-theme="cyber"] .btn-secondary:hover { background: #0d3347; }
[data-theme="cyber"] .close-btn:hover { background: #0d2233; }
[data-theme="cyber"] .help-item { background: #020a10; }
[data-theme="cyber"] .help-item:hover { background: #0d2233; }
[data-theme="cyber"] .badge--pending { background: #001f3a; color: #00e5ff; }
[data-theme="cyber"] .badge--done    { background: #00190d; color: #00e676; }
[data-theme="cyber"] .deadline--overdue { background: #1a0008; color: #ff6090; }
[data-theme="cyber"] .deadline--today   { background: #1a0d00; color: #ffab40; }
[data-theme="cyber"] .deadline--soon    { background: #001f3a; color: #80d8ff; }
[data-theme="cyber"] .deadline--ok      { background: #001429; color: #4a8fa8; }
[data-theme="cyber"] .summary-btn       { background: #0a1a26; border-color: #0d3347; color: #c8f0ff; }
[data-theme="cyber"] .summary-btn:hover { background: #020a10; border-color: #00e5ff; }
[data-theme="cyber"] .summary-btn--edit { color: #00e5ff; border-color: #00e5ff; }
[data-theme="cyber"] .summary-btn--done { color: #00e676; border-color: #00e676; }

/* ── Neon ──────────────────────────────────────────────────────────────────── */
[data-theme="neon"] {
  --bg:          #080808;
  --surface:     #111111;
  --header-bg:   #030303;
  --header-text: #ff0080;
  --text:        #f5f5f5;
  --text-muted:  #666666;
  --border:      #222222;
  --primary:        #ff0080;
  --primary-hover:  #cc0066;
  --danger:         #ff3300;
  --danger-hover:   #cc2200;
}
[data-theme="neon"] .class-header {
  background: color-mix(in srgb, var(--color, #ff0080) 12%, #111111);
}
[data-theme="neon"] .hw-item:hover { background: #1a1a1a; }
[data-theme="neon"] input[type="text"],
[data-theme="neon"] input[type="date"],
[data-theme="neon"] select,
[data-theme="neon"] textarea { background: #030303; color: #f5f5f5; border-color: #222222; }
[data-theme="neon"] .btn-secondary { background: #1a1a1a; color: #f5f5f5; }
[data-theme="neon"] .btn-secondary:hover { background: #222222; }
[data-theme="neon"] .close-btn:hover { background: #1a1a1a; }
[data-theme="neon"] .help-item { background: #030303; }
[data-theme="neon"] .help-item:hover { background: #1a1a1a; }
[data-theme="neon"] .badge--pending { background: #1a0010; color: #ff0080; }
[data-theme="neon"] .badge--done    { background: #001a08; color: #39ff14; }
[data-theme="neon"] .deadline--overdue { background: #1a0800; color: #ff3300; }
[data-theme="neon"] .deadline--today   { background: #1a1000; color: #ffee00; }
[data-theme="neon"] .deadline--soon    { background: #001a14; color: #00ffcc; }
[data-theme="neon"] .deadline--ok      { background: #111111; color: #666666; }
[data-theme="neon"] .summary-btn       { background: #111111; border-color: #222222; color: #f5f5f5; }
[data-theme="neon"] .summary-btn:hover { background: #030303; border-color: #ff0080; }
[data-theme="neon"] .summary-btn--edit { color: #00ccff; border-color: #00ccff; }
[data-theme="neon"] .summary-btn--done { color: #39ff14; border-color: #39ff14; }

/* Compact mode */
.pref-compact .hw-item        { padding: 6px 14px; }
.pref-compact .folder-items .hw-item { padding-left: 22px; }
.pref-compact .folder         { margin: 4px 8px; }
.pref-compact .folder-header  { padding: 5px 10px; }
.pref-compact .class-header   { padding: 8px 14px; }
.pref-compact .tab-content    { padding: 12px 16px 32px; }
.pref-compact .class-row      { margin-bottom: 10px; }
.pref-compact .summary-item   { padding: 6px 14px 6px 0; }

/* =============================================================================
   ACCOUNT SETTINGS PAGE
   ============================================================================= */
.account-profile {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 0 20px;
}
.account-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  flex-shrink: 0;
}
.account-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.account-name  { font-size: 1rem; font-weight: 700; color: var(--text); }
.account-email { font-size: .82rem; color: var(--text-muted); }

/* =============================================================================
   PREFERENCES PAGE
   ============================================================================= */
.theme-cards {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.theme-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  font-size: .78rem;
  font-family: inherit;
  color: var(--text-muted);
  font-weight: 500;
  overflow: hidden;
  transition: border-color var(--t), color var(--t);
  width: 72px;
  padding-bottom: 8px;
}
.theme-card:hover { border-color: var(--primary); color: var(--text); }
.theme-card--active { border-color: var(--primary); color: var(--primary); font-weight: 700; }
.theme-preview {
  width: 100%;
  height: 44px;
  border-radius: 6px 6px 0 0;
  flex-shrink: 0;
}
.theme-preview--light { background: linear-gradient(135deg, #f1f5f9 50%, #fff 50%); }
.theme-preview--dark  { background: linear-gradient(135deg, #0f172a 50%, #1e293b 50%); }
.theme-preview--sepia { background: linear-gradient(135deg, #f0e8d8 50%, #faf6f0 50%); }
.theme-preview--hc    { background: linear-gradient(135deg, #000 50%, #111 50%); border-bottom: 1px solid #555; }
.theme-preview--cyber { background: linear-gradient(135deg, #050d14 50%, #0a1a26 50%); border-bottom: 1px solid #00e5ff44; }
.theme-preview--neon  { background: linear-gradient(135deg, #080808 50%, #111111 50%); border-bottom: 1px solid #ff008066; }

.accent-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 2px 0 8px;
}
.accent-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform var(--t), box-shadow var(--t);
  outline: none;
}
.accent-swatch:hover { transform: scale(1.18); }
.accent-swatch--active {
  border-color: #fff;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px currentColor;
}

.pref-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.pref-row:last-child { border-bottom: none; }
.pref-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pref-label { font-size: .88rem; font-weight: 600; color: var(--text); }
.pref-desc  { font-size: .75rem; color: var(--text-muted); }
.pref-select {
  font-size: .8rem;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  margin-left: auto;
}
.pref-select--sm {
  font-size: .75rem;
  height: 24px;
  max-width: 150px;
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
  cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  transition: background var(--t);
}
.toggle-track::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform var(--t);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked ~ .toggle-track { background: var(--primary); }
.toggle-switch input:checked ~ .toggle-track::after { transform: translateX(18px); }

/* Schedule transfer */
.transfer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.transfer-upload-label { cursor: pointer; }

/* Settings nav divider */
.settings-nav-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 4px;
}

/* User avatar in header is clickable */
.user-avatar { cursor: pointer; }

/* =============================================================================
   UTILITIES
   ============================================================================= */
.hidden { display: none !important; }

/* =============================================================================
   RESPONSIVE
   ============================================================================= */
@media (max-width: 820px) {
  /* Row height driven by JS inline style; these are CSS fallbacks only */
  .app-body { grid-template-columns: 1fr; grid-template-rows: 1fr 240px; }
  .app-body:has(.summary-panel--collapsed) { grid-template-columns: 1fr; grid-template-rows: 1fr 36px; }

  .site-footer { display: none; }

  .summary-panel { flex-direction: column; border-left: none; border-top: 1px solid var(--border); }

  /* Handle: horizontal bar at top of sheet */
  .summary-drag-handle {
    width: 100%;
    height: 36px;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    cursor: grab;
  }
  .summary-drag-handle:active { cursor: grabbing; }

  /* Override pill to horizontal on mobile */
  .summary-drag-pill {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    transition: opacity 120ms, width 120ms;
  }
  .summary-drag-handle:active .summary-drag-pill { height: 4px; width: 48px; }
}
/* iOS PWA: 100dvh excludes the home indicator zone — extend body to cover it */
html.pwa-mode body {
  height: calc(100dvh + env(safe-area-inset-bottom, 0px));
}
@media (max-width: 820px) {
  /* Collapsed handle stays fully visible above home indicator */
  html.pwa-mode .app-body:has(.summary-panel--collapsed) {
    grid-template-rows: 1fr calc(36px + env(safe-area-inset-bottom, 0px));
  }
  /* Scrollable content doesn't go behind home indicator */
  html.pwa-mode .summary-panel {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

@media (max-width: 600px) {
  .site-header { padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top, 10px)); }
  .logo { font-size: 1.1rem; }
  .tab-content { padding: 12px 12px 40px; }
  .form-row { flex-direction: column; }
  .hw-right { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 6px; justify-content: flex-end; flex-shrink: 1; max-width: 42%; }
  .hw-right .deadline-badge { order: -1; width: 100%; text-align: right; white-space: normal; overflow-wrap: anywhere; }
  .hw-item .btn-icon-sm { opacity: 1; }
  .hw-item .hw-attach-badge { opacity: .85; width: 24px; height: 24px; justify-content: center; }
  .modal-box--wide { max-width: 100%; }
  .settings-layout { flex-direction: column; }
  .settings-sidebar { width: 100%; flex-direction: row; border-right: none; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
}

/* =============================================================================
   ATTACHMENTS — form + hw-item + lightbox
   ============================================================================= */

/* Notes label row with attach button */
.notes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: .72rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: 5px;
  cursor: pointer;
  transition: background var(--t), color var(--t), border-color var(--t);
  letter-spacing: .02em;
}
.attach-btn:hover {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary);
  border-color: var(--primary);
}

/* Form preview area */
.form-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}
.form-attach-item {
  position: relative;
}
.form-attach-thumb {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  object-fit: cover;
  display: block;
}
.form-attach-thumb--loading {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
}
.form-attach-file {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: .78rem;
  color: var(--text-muted);
  background: var(--surface);
  max-width: 150px;
}
.form-attach-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.form-attach-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: .75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  transition: transform var(--t);
}
.form-attach-remove:hover { transform: scale(1.15); }

/* Small spinner for upload state */
.spinner-sm {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  flex-shrink: 0;
}

/* Attachment thumbnails inside hw-items */
.hw-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.hw-item--collapsible .hw-attachments { display: none; }
.hw-item--expanded    .hw-attachments { display: flex; }

.hw-attach-img {
  width: 72px;
  height: 72px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  object-fit: cover;
  cursor: zoom-in;
  transition: opacity var(--t), transform var(--t), box-shadow var(--t);
}
.hw-attach-img:hover {
  opacity: .9;
  transform: scale(1.04);
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.hw-attach-file {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: .73rem;
  color: var(--text-muted);
  text-decoration: none;
  background: var(--surface);
  max-width: 130px;
  transition: background var(--t), color var(--t);
}
.hw-attach-file:hover {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary);
}
.hw-attach-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 24px;
  cursor: zoom-out;
  animation: lightbox-in .15s ease;
}
.lightbox.hidden { display: none; }
@keyframes lightbox-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.lightbox-img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
  cursor: default;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  color: #fff;
  font-size: 2.2rem;
  background: none;
  border: none;
  cursor: pointer;
  opacity: .7;
  line-height: 1;
  transition: opacity .15s;
  padding: 0;
}
.lightbox-close:hover { opacity: 1; }

@media (max-width: 600px) {
  .lightbox { padding: 64px 20px 48px; }
  .lightbox-img { max-height: 68vh; }
  .lightbox-close {
    top: max(20px, env(safe-area-inset-top, 20px));
    right: 12px;
    padding: 10px;
    font-size: 2.4rem;
  }
}

/* Dark mode overrides */
[data-theme="dark"] .form-attach-thumb--loading { background: #1e293b; }
[data-theme="dark"] .hw-attach-img:hover { box-shadow: 0 4px 12px rgba(0,0,0,.4); }

/* Attachment badge on hw-item — hidden until hover, like edit/delete buttons */
.hw-attach-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: .72rem;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--t);
}
.hw-attach-badge svg { flex-shrink: 0; }
.hw-item:hover .hw-attach-badge { opacity: .85; }
