/* ── Variables ──────────────────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --surface:     #161b22;
  --surface-2:   #1c2128;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #388bfd;
  --success:     #3fb950;
  --danger:      #f85149;
  --radius:      8px;
  --radius-lg:   14px;
  --gap:         1.5rem;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Layout ─────────────────────────────────────────────────── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 2rem;
}

.page-header {
  padding: 2rem 0 1.5rem;
}

.modules-grid {
  display: grid;
  /* Habit tracker needs more horizontal space than the todo list (full-year
     pixel grid is ~600px wide). 1fr : 1.28fr gives the habit column ~56% of
     the available width — equivalent to the 0.78fr : 1fr ratio you tested. */
  grid-template-columns: 1fr 1.28fr;
  gap: var(--gap);
  align-items: start;
  padding-bottom: 3rem;
}

.module-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  /* Grid items default to min-width:auto which lets content push them wider
     than their track. min-width:0 allows the item to stay within its track
     so overflow-x:auto on .habit-grid-wrap can do its job. */
  min-width: 0;
  overflow: hidden;
}

/* ── Search ─────────────────────────────────────────────────── */
.search-form {
  display: flex;
  gap: 8px;
}

.search-select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.search-select:focus { border-color: var(--accent); }

.search-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.search-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}
.search-btn:hover { opacity: 0.85; }

/* ── Module Header ──────────────────────────────────────────── */
.mod-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.mod-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { background: var(--border); }

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

.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 16px;
  line-height: 1;
  transition: color 0.15s;
}
.btn-icon:hover { color: var(--danger); }

/* ── Todo Module ────────────────────────────────────────────── */
.todo-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 0.9rem;
}

.todo-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.todo-input:focus { border-color: var(--accent); }
.todo-input::placeholder { color: var(--text-muted); }

.todo-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.todo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--surface-2);
  transition: background 0.1s;
}
.todo-item:hover { background: var(--border); }

.todo-check {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  font-size: 11px;
  color: transparent;
  user-select: none;
}
.todo-check:hover { border-color: var(--success); }
.todo-check.done {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.todo-text {
  flex: 1;
  font-size: 14px;
  word-break: break-word;
}
.todo-text.done {
  text-decoration: line-through;
  color: var(--text-muted);
}

.todo-del {
  opacity: 0;
  transition: opacity 0.15s;
}
.todo-item:hover .todo-del { opacity: 1; }

.todo-footer {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.todo-section-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 0 2px 2px;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Habit Module ───────────────────────────────────────────── */
.habits-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.habit-card {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 11px 12px 10px;
}

.habit-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
}

.habit-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  min-width: 0;
}

.habit-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Shortcut hints ─────────────────────────────────────────── */
.shortcut-hint {
  font-size: 11px;
  font-family: ui-monospace, 'Cascadia Code', 'Fira Code', monospace;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}
.shortcut-hint.visible { opacity: 1; }

/* Highlight the todo placeholder when shortcut mode is active */
.shortcut-active::placeholder { color: var(--accent); opacity: 0.8; }

.habit-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.habit-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* "Mark today" button */
.today-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.today-btn:hover {
  border-color: var(--success);
  color: var(--success);
}
.today-btn.done {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.habit-edit-btn,
.habit-del-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 4px;
  transition: opacity 0.15s, color 0.15s;
}
.habit-card:hover .habit-edit-btn,
.habit-card:hover .habit-del-btn { opacity: 1; }
.habit-edit-btn:hover { color: var(--accent); }
.habit-del-btn:hover { color: var(--danger); }

/* Pixel grid */
.habit-grid-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 3px;
  /* Contain the grid within the card — prevents page-level horizontal scroll */
  width: 100%;
}

.habit-grid-container {
  display: flex;
  gap: 5px;
  align-items: flex-start;
  width: max-content; /* scrolls inside the wrap, not the page */
}

/* Day-of-week labels: ma di wo do vr za zo */
.day-labels {
  display: grid;
  grid-template-rows: repeat(7, 9px);
  gap: 2px;
  flex-shrink: 0;
  font-size: 8px;
  line-height: 9px;
  color: var(--text-muted);
  user-select: none;
  padding-top: 1px;
}

.habit-grid {
  display: grid;
  grid-template-rows: repeat(7, 9px);
  grid-auto-columns: 9px;
  grid-auto-flow: column;
  gap: 2px;
  width: max-content;
}

.hday {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--border);
  cursor: pointer;
  transition: opacity 0.12s;
  position: relative;
}
.hday:hover { opacity: 0.75; }

.hday.done { /* background set inline by habit color */ }

.hday.today {
  box-shadow: 0 0 0 1.5px var(--text-muted);
}

.hday.future {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

.hday.pad {
  visibility: hidden;
  pointer-events: none;
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(3px);
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 420px;
  max-width: 92vw;
  max-height: 82vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 1.25rem;
}

/* Form elements inside modal */
.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--accent); }

/* Color swatches */
.color-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  border: 2.5px solid transparent;
  transition: transform 0.12s, border-color 0.12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { border-color: #fff; }

/* Modal footer */
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 1.25rem;
}

/* Archive */
.archive-date-group { margin-bottom: 1.25rem; }
.archive-date-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

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

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 800px) {
  .modules-grid { grid-template-columns: 1fr; }
  .container { padding: 0 1rem; }
  .page-header { padding: 1.25rem 0 1rem; }

  /* Smaller dots on mobile so more weeks fit without scrolling */
  .habit-grid {
    grid-template-rows: repeat(7, 7px);
    grid-auto-columns: 7px;
    gap: 1.5px;
  }
  .hday { width: 7px; height: 7px; }
  .day-labels {
    grid-template-rows: repeat(7, 7px);
    gap: 1.5px;
    font-size: 7px;
    line-height: 7px;
  }

  /* Always show edit/delete on touch devices (no hover) */
  .habit-edit-btn,
  .habit-del-btn { opacity: 1; }

  /* Slightly larger touch area for action buttons */
  .today-btn { width: 30px; height: 30px; }
}
