:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --accent: #3a7d44;
  --border: #e2e2e6;
  --nav-height: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #232427;
    --text: #f0f0f2;
    --muted: #9a9a9f;
    --border: #34353a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

h1 {
  font-size: 1.6rem;
  margin: 8px 0 4px;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 0.95rem;
}

.pillar-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 640px) {
  .pillar-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.pillar-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.1s ease;
}

.pillar-card:active {
  transform: scale(0.98);
}

.pillar-card .icon {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 8px;
}

.pillar-card .name {
  font-weight: 600;
  display: block;
}

.pillar-card .status {
  color: var(--muted);
  font-size: 0.85rem;
  display: block;
  margin-top: 4px;
}

.back-link {
  display: inline-block;
  margin-bottom: 16px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95rem;
}

.placeholder {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  color: var(--muted);
}

/* Bottom tab bar on narrow / mobile viewports */
nav.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: var(--nav-height);
  z-index: 10;
}

nav.tabbar::-webkit-scrollbar {
  display: none;
}

nav.tabbar a {
  flex: 0 0 auto;
  min-width: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.7rem;
  min-height: 44px;
  padding: 0 4px;
}

nav.tabbar a.active {
  color: var(--accent);
  font-weight: 600;
}

nav.tabbar a .tab-icon {
  font-size: 1.3rem;
}

/* Business pillar: projects + nested tasks */
.new-project-form {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.new-project-form input {
  flex: 1;
  min-width: 0;
}

input[type="text"] {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
}

button {
  font-size: 0.95rem;
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: white;
  min-height: 44px;
  cursor: pointer;
}

button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

button.icon-btn {
  background: none;
  color: var(--muted);
  padding: 6px 10px;
  min-height: 36px;
}

.project-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 16px 18px;
  min-height: 44px;
}

.header-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: inherit;
  text-align: left;
  padding: 0;
  min-height: auto;
  cursor: pointer;
}

.name-slot {
  min-width: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.project-header .name {
  font-weight: 600;
  display: block;
}

.project-header .progress {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
}

.project-header .chevron {
  transition: transform 0.15s ease;
  color: var(--muted);
  margin-left: 10px;
}

.project-header[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}

.project-body {
  padding: 0 18px 18px;
  border-top: 1px solid var(--border);
}

.project-body .new-project-form {
  margin: 16px 0;
}

.project-body .delete-project-btn {
  margin-top: 14px;
}

.empty-state {
  color: var(--muted);
  padding: 12px 0;
}

ul.task-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul.task-tree ul.task-tree {
  padding-left: 22px;
  border-left: 1px solid var(--border);
  margin-top: 6px;
}

li.task-item {
  margin: 8px 0;
}

.task-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.task-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.task-row .title-slot {
  flex: 1;
  min-width: 0;
}

.task-row .title {
  display: block;
  word-break: break-word;
}

.task-row .title.done {
  text-decoration: line-through;
  color: var(--muted);
}

/* Depth styling: each nesting level reads progressively lighter/smaller,
   so a 3+ level tree is scannable without counting indent lines. */
.task-row.depth-1 .title:not(.done) {
  font-weight: 600;
}

.task-row.depth-2 .title:not(.done) {
  font-size: 0.93rem;
  color: var(--text);
}

.task-row.depth-3-plus .title:not(.done) {
  font-size: 0.87rem;
  color: var(--muted);
}

.task-row .collapse-btn,
.task-row .collapse-spacer {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.task-row .collapse-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  min-height: auto;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.task-row .collapse-btn[aria-expanded="true"] {
  transform: rotate(90deg);
}

.task-row .child-count {
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
  margin-right: 2px;
}

.task-actions {
  display: flex;
  gap: 2px;
}

.add-subtask-form {
  display: flex;
  gap: 6px;
  margin: 6px 0 0 30px;
}

.add-subtask-form input {
  flex: 1;
}

.rename-form {
  display: flex;
  width: 100%;
}

.rename-form .rename-input {
  width: 100%;
  min-width: 0;
  padding: 4px 8px;
  font-size: inherit;
  font-weight: inherit;
  min-height: 32px;
}

/* Daily Notebook */
.notebook-cta {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent);
  color: white;
  border-radius: 14px;
  padding: 16px 18px;
  text-decoration: none;
  margin-bottom: 16px;
  font-weight: 600;
}

.notebook-cta .icon {
  font-size: 1.4rem;
}

.hour-slot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

.hour-slot .hour-label {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.hour-slot .slot-tasks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.slot-task-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slot-task-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.slot-task-row .title {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.slot-task-row .title.done {
  text-decoration: line-through;
  color: var(--muted);
}

.slot-task-row .project-tag {
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.hour-picker {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  margin: 6px 0 0 28px;
}

.hour-picker-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.hour-picker-item {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
  min-height: auto;
  border-radius: 8px;
  font-size: 0.85rem;
}

.wrap-up-section {
  margin-top: 24px;
}

.wrap-up-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  margin-top: 12px;
}

.wrap-up-summary h3 {
  font-size: 0.95rem;
  margin: 0 0 8px;
}

.wrap-up-summary .completed-list {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 16px;
  padding-left: 18px;
}

.wrap-up-summary .incomplete-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.incomplete-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.incomplete-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.incomplete-row .title {
  flex: 1;
  min-width: 0;
}

.incomplete-row .project-tag {
  color: var(--muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

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

.wrap-up-message {
  color: var(--accent);
  font-size: 0.9rem;
  margin-top: 10px;
}

.task-picker {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-top: 8px;
}

.task-picker input {
  margin-bottom: 8px;
}

.task-picker-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.task-picker-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: inherit;
  text-align: left;
  padding: 8px;
  border-radius: 8px;
  min-height: auto;
}

.task-picker-item:hover,
.task-picker-item:active {
  background: var(--bg);
}

.picker-project-group {
  margin-bottom: 6px;
}

.picker-project-name {
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 10px 4px 2px;
}

ul.picker-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

ul.picker-tree ul.picker-tree {
  padding-left: 16px;
  border-left: 1px solid var(--border);
  margin-top: 2px;
}

.picker-group-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 6px 4px;
  min-height: auto;
  cursor: pointer;
}

.picker-group-toggle .chevron {
  color: var(--muted);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.picker-group-toggle[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}

.task-picker-item.depth-1,
.picker-group-toggle.depth-1 {
  font-weight: 600;
}

.task-picker-item.depth-2,
.picker-group-toggle.depth-2 {
  font-size: 0.93rem;
}

.task-picker-item.depth-3-plus,
.picker-group-toggle.depth-3-plus {
  font-size: 0.87rem;
  color: var(--muted);
}

/* Wider screens: top nav instead of bottom tab bar */
@media (min-width: 640px) {
  body {
    padding-bottom: 0;
  }

  nav.tabbar {
    position: static;
    height: auto;
    border-top: none;
    border-bottom: 1px solid var(--border);
    justify-content: center;
    gap: 8px;
    padding: 12px 0;
  }

  nav.tabbar a {
    flex: none;
    flex-direction: row;
    padding: 8px 16px;
    border-radius: 10px;
  }

  nav.tabbar a.active {
    background: var(--bg);
  }
}
