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

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface2: #f0f0ed;
  --border: rgba(0,0,0,0.09);
  --border-strong: rgba(0,0,0,0.16);
  --text: #1a1a1a;
  --text-2: #555;
  --text-3: #999;
  --accent: #1a1a2e;
  --accent-light: #eeeef6;
  --green: #aee8c5;
  --green-text: #1a6640;
  --purple: #eeeef6;
  --purple-text: #3d3a8c;
  --red: #fdecea;
  --red-text: #a8261d;
  --today-border: #3b5bdb;
  --blue: #b8ccff;
  --blue-text: #1e3a8a;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

/* Layout */
.app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px 16px;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 32px;
}

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

.nav-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border: none;
  background: none;
  color: rgba(255,255,255,0.65);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-btn.active { background: rgba(255,255,255,0.14); color: #fff; }

.sidebar-bottom { display: flex; flex-direction: column; gap: 20px; }

.stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: rgba(255,255,255,0.07);
  border-radius: var(--radius);
}
.stat-item { display: flex; justify-content: space-between; align-items: baseline; }
.stat-num { font-size: 18px; font-weight: 600; color: #fff; }
.stat-lbl { font-size: 11px; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 0.04em; }

.upload-section { display: flex; flex-direction: column; gap: 6px; }
.upload-label { font-size: 11px; color: rgba(255,255,255,0.5); text-transform: uppercase; letter-spacing: 0.04em; }

.upload-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.upload-btn:hover { background: rgba(255,255,255,0.16); }
#pdf-upload { display: none; }

.upload-status { font-size: 11px; color: rgba(255,255,255,0.4); }

.print-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  background: none;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.7);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.print-btn:hover { background: rgba(255,255,255,0.08); }

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 28px 32px;
  gap: 24px;
}

/* Add bar */
.add-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}

.task-input {
  flex: 1;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  outline: none;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.task-input:focus { border-color: var(--today-border); }
.task-input::placeholder { color: var(--text-3); }

.date-input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
  outline: none;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.date-input:focus { border-color: var(--today-border); }

.add-btn {
  height: 42px;
  padding: 0 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s;
}
.add-btn:hover { opacity: 0.88; }

/* Views */
.view { flex: 1; overflow-y: auto; min-height: 0; }
#view-week { overflow: hidden; display: flex; flex-direction: column; }

/* Week view */
.week-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.week-header-right { display: flex; align-items: center; gap: 12px; }
.week-title { font-size: 16px; font-weight: 600; color: var(--text); }
.week-nav { display: flex; gap: 6px; align-items: center; }
.proj-select {
  font: 500 12px/1 'Inter', sans-serif;
  padding: 5px 28px 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.week-nav-btn {
  padding: 5px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.week-nav-btn:hover { background: var(--surface2); }

/* ── Week calendar (cw-*) ───────────────────────────────────────────────────── */

.week-grid { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.cw-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Header row */
.cw-header {
  display: flex;
  border-bottom: 2px solid var(--border);
  background: var(--surface);
}
.cw-gutter {
  width: 52px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}
.cw-dh {
  flex: 1;
  padding: 10px 12px 8px;
  border-left: 1px solid var(--border);
}
.cw-dh.cw-today { background: #f0f4ff; }
.cw-dh-name {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3);
}
.cw-dh-num {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
  margin-top: 1px;
}
.cw-dh.cw-today .cw-dh-name,
.cw-dh.cw-today .cw-dh-num { color: var(--today-border); }

/* All-day tasks strip */
.cw-allday {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.cw-allday-cell {
  flex: 1;
  padding: 4px 6px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 28px;
}
.cw-pill {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 11px;
  line-height: 1.35;
  cursor: pointer;
  transition: opacity 0.15s;
}
.cw-pill:hover { opacity: 0.75; }
.cw-pill.cw-done { opacity: 0.35; text-decoration: line-through; }
.cw-pill-g { background: var(--purple); color: var(--purple-text); }
.cw-pill-m { background: var(--green);  color: var(--green-text); }
.cw-pill-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  flex-shrink: 0;
  margin-top: 2px;
}
.cw-pill.cw-done .cw-pill-dot { background: currentColor; }

/* Grid body — fills remaining height, scrolls internally */
.cw-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Time gutter */
.cw-gutter-body {
  position: relative;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}
.cw-time-label {
  position: absolute;
  right: 8px;
  font-size: 10px;
  color: var(--text-3);
  transform: translateY(-50%);
  white-space: nowrap;
  user-select: none;
  line-height: 1;
}

/* Main grid */
.cw-grid {
  flex: 1;
  position: relative;
  min-width: 0;
}
.cw-today-col {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(59,91,219,0.04);
  pointer-events: none;
  z-index: 0;
}
.cw-hline {
  position: absolute;
  left: 0; right: 0;
  border-top: 1px solid var(--border);
  pointer-events: none;
  z-index: 0;
}
.cw-vsep {
  position: absolute;
  top: 0; bottom: 0;
  border-left: 1px solid var(--border);
  pointer-events: none;
  z-index: 0;
}

/* Project filter */

/* Events */
.cw-ev {
  position: absolute;
  border-radius: 5px;
  padding: 4px 8px;
  overflow: hidden;
  box-sizing: border-box;
  z-index: 1;
  line-height: 1.35;
  border: 1px solid rgba(255,255,255,0.65);
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  cursor: grab;
}
.cw-ev-dragging { opacity: 0.25; cursor: grabbing; }
.cw-drag-ghost {
  opacity: 0.88;
  z-index: 100 !important;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18) !important;
  border: 2px dashed rgba(0,0,0,0.25) !important;
  cursor: grabbing;
}
.cw-ev-meeting {
  background: var(--green);
  border-left: 3px solid var(--green-text);
  color: #111;
}
.cw-ev-block {
  background: var(--blue);
  border-left: 3px solid var(--blue-text);
  color: #111;
}
.cw-ev-granola {
  background: var(--purple);
  border-left: 3px solid var(--purple-text);
  color: #111;
}
.cw-ev-time {
  display: block;
  font-size: 10px;
  font-weight: 600;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 1px;
}
.cw-ev-title {
  display: block;
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}
.cw-ev-compact {
  display: block;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-ev-dim { opacity: 0.2; }
.cw-ev-proj {
  display: block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  opacity: 0.55;
  margin-top: 3px;
}

/* Event edit popover */
.ev-popover {
  position: fixed;
  z-index: 500;
  width: 252px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.14), 0 2px 6px rgba(0,0,0,0.08);
  font-size: 13px;
  overflow: hidden;
}
.ev-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.ev-pop-x {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
}
.ev-pop-x:hover { background: var(--surface2); color: var(--text); }
.ev-pop-body { padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.ev-pop-lbl { font-size: 11px; font-weight: 600; color: var(--text-2); }
.ev-pop-input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: 13px/1.4 'Inter', sans-serif;
  color: var(--text);
  background: var(--bg);
  outline: none;
}
.ev-pop-input:focus { border-color: var(--today-border); }
.ev-pop-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ev-pop-row .ev-pop-input { width: 100%; }
.ev-pop-foot {
  display: flex;
  gap: 8px;
  padding: 8px 12px 12px;
}
.ev-pop-save {
  flex: 1;
  padding: 6px 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font: 600 13px 'Inter', sans-serif;
  cursor: pointer;
}
.ev-pop-save:hover { opacity: 0.88; }
.ev-pop-reset {
  padding: 6px 12px;
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: 13px 'Inter', sans-serif;
  color: var(--text-2);
  cursor: pointer;
}
.ev-pop-reset:hover { background: var(--surface2); }

/* List view */
.view-heading { font-size: 16px; font-weight: 600; margin-bottom: 16px; }

.group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  margin: 18px 0 6px;
  padding: 0 2px;
}
.group-label:first-child { margin-top: 0; }

.task-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 5px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.task-card:hover { border-color: var(--border-strong); }
.task-card.done-card { opacity: 0.42; }
.task-card.done-card .task-text { text-decoration: line-through; }

.check-btn {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid #ccc;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
}
.check-btn:hover { border-color: #3b5bdb; }
.check-btn.checked { background: #3b5bdb; border-color: #3b5bdb; }
.check-btn.checked::after { content: ''; display: block; width: 5px; height: 8px; border: 2px solid #fff; border-top: none; border-left: none; transform: rotate(45deg) translate(-1px, -1px); }

.task-body { flex: 1; min-width: 0; }
.task-text { font-size: 13px; color: var(--text); line-height: 1.5; }
.task-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; flex-wrap: wrap; }

.badge {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 20px;
  display: inline-block;
}
.badge-granola { background: var(--purple); color: var(--purple-text); }
.badge-manual { background: var(--green); color: var(--green-text); }

.task-due { font-size: 11px; color: var(--text-3); }
.task-due.overdue { color: var(--red-text); font-weight: 500; }

.del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  font-size: 16px;
  padding: 0;
  margin-left: auto;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}
.task-card:hover .del-btn { opacity: 1; }
.del-btn:hover { color: var(--red-text); }

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

.done-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-3);
  font-family: inherit;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}
.done-toggle:hover { color: var(--text-2); }

/* Print */
@media print {
  .sidebar { display: none; }
  .add-bar { display: none; }
  .week-nav { display: none; }
  .del-btn { display: none; }
  .done-toggle { display: none; }
  .main { padding: 20px; overflow: visible; }
  .view { overflow: visible; }
  .app { display: block; height: auto; }
  .week-grid { page-break-inside: avoid; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }
