/* ─── Life Well Spent ─── */
/* All accent colors derive from --user-accent (set via JS on <html>).
   The grid canvas + legend read resolved colors from getComputedStyle. */

:root {
  --user-accent: #c9a84c;
  --accent: var(--user-accent);
  --filled: var(--user-accent);
  --filled-dim: rgba(201, 168, 76, 0.35);
  --past: #3d2a12;
  --past-border: #4a3518;
  --accent-glow: rgba(201, 168, 76, 0.15);
  --today: #e8e6f0;
  --today-glow: rgba(232, 230, 240, 0.3);

  --bg: #0f0f13;
  --surface: #1a1a24;
  --surface-hover: #242436;
  --border: #2a2a3d;
  --text: #e8e6f0;
  --text-dim: #8888a8;
  --text-muted: #555570;
  --future: #1e1e2a;
  --future-border: #252538;
  --danger: #c94c4c;
  --radius: 6px;
  --font: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

[data-theme="light"] {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-hover: #ede9e0;
  --border: #d4cfc4;
  --text: #2a2520;
  --text-dim: #6b6560;
  --text-muted: #9e9890;
  --future: #ebe8e0;
  --future-border: #ddd8cc;
  --today: #2a2520;
  --today-glow: rgba(42, 37, 32, 0.2);
}

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

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

/* ─── Header ─── */
.app-header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.app-header h1 {
  font-family: var(--font);
  font-size: 1.8rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 0.4rem;
  font-style: italic;
}

/* ─── Setup Panel ─── */
.setup-panel {
  max-width: 420px;
  margin: 3rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.setup-panel h2 {
  font-family: var(--font);
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
  color: var(--accent);
}

.setup-panel label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.setup-panel input,
.setup-panel select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
}

.setup-panel input:focus,
.setup-panel select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ─── Buttons ─── */
.btn-primary {
  display: inline-block;
  width: 100%;
  padding: 0.7rem 1.5rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  padding: 0.6rem 1.2rem;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover { background: var(--surface-hover); }

.btn-icon {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover { background: var(--surface-hover); color: var(--text); }

.btn-close {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.15s;
}

.btn-close:hover { background: var(--surface-hover); }

/* ─── Calendar Panel ─── */
.calendar-panel {
  padding: 1rem;
  max-width: 100%;
  margin: 0;
  box-sizing: border-box;
  overflow-x: hidden;
}

.calendar-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toolbar-center {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: center;
}

.toolbar-select {
  padding: 0.3rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.75rem;
  cursor: pointer;
  height: 36px;
}

.toolbar-select:focus {
  outline: none;
  border-color: var(--accent);
}

.toolbar-colors {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.toolbar-colors .color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.toolbar-colors .color-swatch:hover {
  transform: scale(1.15);
  border-color: var(--text);
}

.toolbar-colors .color-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.toolbar-right { display: flex; gap: 0.4rem; align-items: center; }

.breadcrumb {
  font-family: var(--font);
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 0.3rem 0;
  text-align: center;
}

.bc-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bc-link:hover {
  color: var(--text);
}

.bc-current {
  color: var(--text);
  font-weight: 600;
}

.bc-sep {
  color: var(--text-muted);
  margin: 0 0.3rem;
}

.life-stats {
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--text-dim);
}

.life-stats strong { color: var(--accent); }

/* ─── Grid ─── */
.grid-container {
  position: relative;
  overflow-x: auto;
  padding: 1rem 0;
  width: 100%;
  display: flex;
  justify-content: center;
}

#lifeGrid {
  display: block;
  cursor: pointer;
  flex-shrink: 0;
}

.grid-overlay {
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
}

/* ─── Selection Bar ─── */
.selection-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.4rem 1rem;
  margin: 0 auto 0.3rem;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.sel-label {
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.sel-date {
  font-family: var(--font);
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.sel-edit {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  width: 30px;
  height: 30px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.sel-edit:hover {
  opacity: 0.85;
  color: var(--bg);
}

/* ─── Legend ─── */
.legend {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid var(--border);
}

/* ─── Modal / Dialog ─── */
dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0;
  max-width: 480px;
  width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

dialog::backdrop {
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

dialog header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}

dialog header h3 {
  font-family: var(--font);
  font-size: 1rem;
  color: var(--accent);
}

.modal-body { padding: 1.2rem; }

.modal-body label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.modal-body textarea {
  display: block;
  width: 100%;
  min-height: 120px;
  margin-top: 0.3rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  resize: vertical;
  line-height: 1.5;
}

.modal-body textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.week-type {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

dialog footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.8rem 1.2rem;
  border-top: 1px solid var(--border);
}

dialog footer .btn-primary { width: auto; }

.btn-danger {
  padding: 0.6rem 1.2rem;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-danger:hover { opacity: 0.85; }
.btn-danger:disabled { opacity: 0.35; cursor: not-allowed; }

.reset-error {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 0.3rem;
  min-height: 1.2em;
}

#resetDialog .modal-body p {
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
  color: var(--text-dim);
}

#resetDialog .modal-body p strong {
  color: var(--danger);
}

#resetConfirmInput {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
}

#resetConfirmInput:focus {
  outline: none;
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(201, 76, 76, 0.2);
}

dialog hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

/* ─── Tooltip ─── */
.tooltip {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.7rem;
  font-family: var(--font);
  font-size: 0.78rem;
  color: var(--text);
  pointer-events: none;
  z-index: 1000;
  max-width: 220px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  line-height: 1.4;
}

.tooltip .tt-label { color: var(--accent); font-weight: 600; }
.tooltip .tt-date { color: var(--text-dim); }
.tooltip .tt-journal { color: var(--text); margin-top: 0.3rem; font-style: italic; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .selection-bar {
    padding: 0.35rem 0.6rem;
    gap: 0.4rem;
  }
  .sel-label {
    font-size: 0.75rem;
  }
  .sel-date {
    font-size: 0.65rem;
  }
  .app-header h1 { font-size: 1.4rem; }
  .calendar-panel { padding: 0.8rem; }
  .calendar-toolbar { flex-direction: column; align-items: center; }
  .toolbar-center { order: -1; }
  .toolbar-colors .color-swatch { width: 18px; height: 18px; }
}

/* ─── Print ─── */
@media print {
  body { background: white; color: black; }
  .app-header, .calendar-toolbar, .legend, .btn-icon { display: none !important; }
  .grid-container { overflow: visible; }
  #lifeGrid { max-width: 100%; }
}
