:root {
  --sidebar-bg: #2c2622;
  --sidebar-fg: #cfc3b6;
  --sidebar-fg-active: #f3ede4;
  --accent: #e3d4b3;
  --accent-soft: #e7d2b8;
  --bg-top: #d8c9b3;
  --bg-bottom: #c3ae91;
  --card-bg: #faf6ef;
  --card-border: #e4d8c6;
  --text-main: #362f28;
  --text-muted: #8a7d6c;
  --line: #ddd0bc;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(60, 45, 25, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-main);
}

.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 68px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0 22px;
}

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

.nav-icon {
  width: 42px;
  height: 42px;
  border: none;
  background: transparent;
  color: var(--sidebar-fg);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-icon:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-icon.active {
  background: var(--accent);
  color: var(--sidebar-bg);
}

.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-fg);
}

.brand-year {
  font-size: 11px;
  letter-spacing: 2px;
  opacity: 0.6;
}

.brand-name {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 11px;
  letter-spacing: 4px;
  font-weight: 600;
  opacity: 0.85;
}

/* ---------- Content ---------- */
.content {
  flex: 1;
  min-width: 0;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  padding: 22px 28px 40px;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 22px;
}

.month-tabs, .day-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.35);
  padding: 6px;
  border-radius: 999px;
  width: fit-content;
}

.tab-btn {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-main);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.6);
}

.tab-btn.active {
  background: var(--sidebar-bg);
  color: #fff;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.view {
  display: grid;
  gap: 18px;
}

/* Grid items default to min-width:auto, which refuses to shrink below a
   descendant's intrinsic content width (e.g. a native date input) and can
   silently blow out the whole page's layout viewport on narrow screens.
   Force every direct grid child back to shrinkable. */
.view > *,
.daily-layout > *,
.daily-top-row > *,
.notebook-layout > *,
.page-list-col > * {
  min-width: 0;
}

/* ---------- Daily view ---------- */
.daily-layout {
  display: grid;
  gap: 18px;
}

.daily-top-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

.plan-card {
  padding: 18px 20px 24px;
}

.plan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.plan-header h2 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.notes-link-btn {
  border: 1px solid var(--card-border);
  background: var(--accent-soft);
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.notes-link-btn:hover { filter: brightness(0.96); }

.slot-row {
  display: grid;
  grid-template-columns: 66px 1fr 58px 30px;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  border-bottom: 1px solid var(--line);
}

.slot-row.hour-mark {
  border-top: 1px solid var(--line);
}

.slot-row.no-border {
  border-bottom: none;
}

.slot-row.block-start,
.slot-row.block-covered {
  grid-template-columns: 66px 1fr;
}

.block-body {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 38px;
  background: #fff;
}

.block-title-input {
  font-weight: 500;
  flex: 1 1 auto;
  width: auto;
}

.block-filler {
  height: 100%;
}

.slot-time {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 8px 0;
}

.slot-time-half {
  font-weight: 400;
  font-size: 13px;
  color: #cabfae;
}

.slot-input {
  border: none;
  background: transparent;
  padding: 8px 4px;
  font-size: 16px;
  color: var(--text-main);
  width: 100%;
  outline: none;
}

.slot-input:focus {
  background: rgba(227, 212, 179, 0.35);
  border-radius: 6px;
}

.slot-end-select {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  outline: none;
  cursor: pointer;
  max-width: 58px;
}

.reminder-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.35;
  padding: 4px;
  border-radius: 6px;
}

.reminder-btn:hover {
  opacity: 1;
  background: rgba(227, 212, 179, 0.5);
}

.block-remove-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  opacity: 0.5;
  padding: 4px;
}

.block-remove-btn:hover {
  opacity: 1;
  color: #b6462f;
}

.side-card {
  padding: 14px 16px 16px;
}

.side-card h3 {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.priority-group {
  margin-bottom: 12px;
}

.priority-group:last-child { margin-bottom: 0; }

.priority-label {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.priority-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.priority-must .priority-dot { background: #b6462f; }
.priority-should .priority-dot { background: #c58a2e; }
.priority-nice .priority-dot { background: #6e8f5c; }

.todo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.todo-item input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--sidebar-bg);
}

.todo-item input[type="text"] {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  outline: none;
  padding: 4px 2px;
}

.todo-item.done input[type="text"] {
  text-decoration: line-through;
  color: var(--text-muted);
}

.todo-item .del-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  opacity: 0;
  padding: 0 4px;
}

.todo-item:hover .del-btn { opacity: 1; }

.add-todo-btn {
  border: none;
  background: transparent;
  color: var(--sidebar-bg);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
}

.goals-textarea {
  width: 100%;
  min-height: 90px;
  border: none;
  background: transparent;
  resize: vertical;
  font-family: inherit;
  font-size: 15px;
  outline: none;
  line-height: 1.5;
}

/* ---------- Daily notes / journal ---------- */
.journal-card {
  padding: 20px 24px 24px;
  min-height: 60vh;
}

.journal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.journal-header h2 {
  margin: 0;
  font-size: 16px;
}

.back-link {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
}

.journal-textarea {
  width: 100%;
  min-height: 55vh;
  border: none;
  background: repeating-linear-gradient(
    var(--card-bg),
    var(--card-bg) 27px,
    var(--line) 28px
  );
  line-height: 28px;
  font-family: inherit;
  font-size: 16px;
  outline: none;
  resize: vertical;
  padding-top: 2px;
}

/* ---------- Monthly view ---------- */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.month-weekday-label {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding-bottom: 4px;
}

.month-day-cell {
  padding: 8px;
  min-height: 84px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.month-day-cell:hover { border-color: var(--sidebar-bg); }

.month-day-cell.empty {
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: default;
}

.month-day-num {
  font-size: 13px;
  font-weight: 600;
}

.month-day-cell.today .month-day-num {
  color: var(--sidebar-bg);
  background: var(--accent);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.month-day-dot {
  margin-top: auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* ---------- Notebook view ---------- */
.notebook-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: start;
}

.section-list {
  padding: 14px 10px;
  display: grid;
  gap: 4px;
}

.section-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}

.section-item:hover { background: rgba(227, 212, 179, 0.4); }
.section-item.active { background: var(--accent); color: var(--sidebar-bg); }

.section-item .del-btn {
  opacity: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  color: inherit;
}
.section-item:hover .del-btn { opacity: 0.7; }

.add-section-btn {
  margin-top: 6px;
  border: 1px dashed var(--card-border);
  background: transparent;
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.page-list-col {
  display: grid;
  gap: 14px;
}

.page-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.page-pill {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  font-size: 12px;
  cursor: pointer;
}

.page-pill.active {
  background: var(--accent);
  color: var(--sidebar-bg);
  border-color: var(--accent);
}

.notebook-page-card {
  padding: 18px 22px 22px;
}

.notebook-page-header {
  display: flex;
  gap: 16px;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.notebook-page-header input[type="text"] {
  border: none;
  background: transparent;
  font-size: 16px;
  font-weight: 600;
  outline: none;
  flex: 1;
  min-width: 0;
}

.notebook-page-header input[type="date"] {
  border: none;
  background: transparent;
  font-size: 12px;
  color: var(--text-muted);
  outline: none;
}

.notebook-page-body {
  width: 100%;
  min-height: 55vh;
  border: none;
  outline: none;
  resize: vertical;
  font-family: inherit;
  font-size: 16px;
  line-height: 26px;
  background-image: radial-gradient(circle, var(--line) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: 4px 8px;
}

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

/* ---------- Attachments ---------- */
.attachment-list {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.attachment-empty {
  font-size: 12px;
  color: var(--text-muted);
}

.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}

.attachment-item a {
  font-size: 13px;
  color: var(--text-main);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-item a:hover { text-decoration: underline; }

.attachment-item .del-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 6px;
  flex-shrink: 0;
}

.attachment-item .del-btn:hover { color: #b6462f; }

.attachment-actions {
  display: flex;
  gap: 8px;
}

.add-link-btn, .add-file-btn {
  border: 1px solid var(--card-border);
  background: var(--accent-soft);
  color: var(--text-main);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.add-link-form {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.add-link-form[hidden] {
  display: none;
}

.add-link-form input[type="text"] {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
}

.add-link-form input[type="text"]:focus {
  border-color: var(--sidebar-bg);
}

/* ---------- Inline confirm / add forms ---------- */
.form-actions {
  display: flex;
  gap: 8px;
}

.form-actions button {
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.form-actions button:first-child {
  background: var(--accent);
  color: var(--sidebar-bg);
  border-color: var(--accent);
}

.inline-input {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 16px;
  outline: none;
  font-family: inherit;
  width: 100%;
  margin-bottom: 6px;
}

.inline-input:focus { border-color: var(--sidebar-bg); }

#addSectionRow { margin-top: 6px; }

.confirm-pending {
  color: #b6462f !important;
  font-weight: 600;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .notebook-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .content {
    padding: 14px 12px 32px;
  }
  .month-tabs, .day-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    scrollbar-width: none;
  }
  .month-tabs::-webkit-scrollbar, .day-tabs::-webkit-scrollbar {
    display: none;
  }
  .tab-btn {
    flex-shrink: 0;
  }
  .plan-header {
    flex-wrap: wrap;
    gap: 8px;
  }
  .block-body {
    flex-wrap: wrap;
    padding: 4px 0;
  }
  .block-body .block-title-input {
    flex: 1 1 100%;
  }
  .block-body .block-remove-btn {
    margin-left: auto;
  }
  .month-grid {
    gap: 4px;
  }
  .month-day-cell {
    min-height: 46px;
    padding: 6px 4px;
  }
  .notebook-page-header {
    flex-wrap: wrap;
    gap: 8px;
  }
  .notebook-page-header input[type="text"] {
    flex: 1 1 100%;
  }
}
