:root {
  --color-background-primary: #ffffff;
  --color-background-secondary: #f5f4f0;
  --color-background-tertiary: #eceae3;
  --color-text-primary: #1a1a18;
  --color-text-secondary: #5f5e5a;
  --color-text-tertiary: #888780;
  --color-border-tertiary: rgba(0, 0, 0, 0.12);
  --color-border-secondary: rgba(0, 0, 0, 0.22);
  --color-accent: #c9a96a;
  --color-success: #1f7a3d;
  --color-danger: #c0392b;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-background-primary: #1e1e1c;
    --color-background-secondary: #2a2a27;
    --color-background-tertiary: #343430;
    --color-text-primary: #e8e6df;
    --color-text-secondary: #a8a69e;
    --color-text-tertiary: #6e6d68;
    --color-border-tertiary: rgba(255, 255, 255, 0.1);
    --color-border-secondary: rgba(255, 255, 255, 0.18);
  }
}

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

body {
  font-family: var(--font-sans);
  background: var(--color-background-tertiary);
  color: var(--color-text-primary);
  padding: 2rem 1rem;
  min-height: 100vh;
}

h1 {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.subtitle {
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 1.5rem;
}

.cal {
  max-width: 1080px;
  margin: 0 auto;
}

.metrics-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.metric-pill {
  background: var(--color-background-primary);
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--color-text-secondary);
}

.metric-pill strong {
  color: var(--color-text-primary);
  font-weight: 600;
}

.today-block {
  background: var(--color-background-primary);
  border: 1px solid var(--color-accent);
  border-radius: var(--border-radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.today-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-accent);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.today-empty {
  color: var(--color-text-tertiary);
  font-size: 13px;
}

.today-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.phase-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  margin: 1.5rem 0 0.5rem;
}

.week-block {
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-lg);
  overflow: hidden;
  margin-bottom: 12px;
  background: var(--color-background-primary);
}

.week-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.6rem 1rem;
  border-bottom: 0.5px solid var(--color-border-tertiary);
  background: var(--color-background-secondary);
}

.week-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.week-title {
  font-size: 13px;
  font-weight: 500;
}

.week-meta {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-left: auto;
  white-space: nowrap;
}

.days-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.day-col {
  border-right: 0.5px solid var(--color-border-tertiary);
  padding: 0.5rem 0.4rem;
  min-height: 90px;
}

.day-col:last-child {
  border-right: none;
}

.day-col.is-today {
  background: rgba(201, 169, 106, 0.08);
}

.day-name {
  font-size: 10px;
  color: var(--color-text-tertiary);
  font-weight: 500;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.day-num {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.post-pill {
  font-size: 10px;
  padding: 4px 6px;
  border-radius: 4px;
  margin-bottom: 3px;
  line-height: 1.3;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.post-pill:hover {
  opacity: 0.75;
}

.post-pill:active {
  transform: scale(0.97);
}

.post-pill.is-published::before {
  content: "✓";
  font-weight: 700;
  color: var(--color-success);
  margin-right: 2px;
}

.post-pill .ch-tag {
  font-weight: 700;
  text-transform: uppercase;
  font-size: 9px;
  margin-right: 2px;
}

.p-fb { background: #eeedfe; color: #3c3489; }
.p-ig { background: #fbeaf0; color: #72243e; }
.p-li { background: #e6f1fb; color: #0c447c; }
.p-wa { background: #eaf3de; color: #27500a; }
.p-all { background: #faeeda; color: #633806; }

.empty {
  color: var(--color-text-tertiary);
  font-size: 10px;
  padding-top: 8px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 1rem 0 0.5rem;
}

.leg-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--color-text-secondary);
}

.leg-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 4rem 1rem;
  overflow-y: auto;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  width: 100%;
  max-width: 720px;
  background: var(--color-background-primary);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--color-border-secondary);
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 1rem 1.25rem;
  border-bottom: 0.5px solid var(--color-border-tertiary);
}

.modal-title {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
}

.modal-meta {
  font-size: 11px;
  color: var(--color-text-tertiary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-body {
  padding: 1.25rem;
}

.modal-section {
  margin-bottom: 1rem;
}

.modal-section h3 {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
  font-weight: 600;
}

.text-preview {
  background: var(--color-background-secondary);
  border-radius: var(--border-radius-md);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 320px;
  overflow-y: auto;
}

.image-preview {
  background: var(--color-background-secondary);
  border-radius: var(--border-radius-md);
  padding: 12px;
  text-align: center;
}

.image-preview img {
  max-width: 100%;
  max-height: 320px;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
}

.notes-input {
  width: 100%;
  background: var(--color-background-secondary);
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  padding: 10px 12px;
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--color-text-primary);
  resize: vertical;
  min-height: 60px;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.btn {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--color-border-secondary);
  background: var(--color-background-primary);
  color: var(--color-text-primary);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--color-text-primary);
  color: var(--color-background-primary);
  border-color: var(--color-text-primary);
}

.btn-success {
  background: var(--color-success);
  color: white;
  border-color: var(--color-success);
}

.base-selector-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.base-label {
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.base-select {
  font-family: var(--font-sans);
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--border-radius-md);
  background: var(--color-background-primary);
  color: var(--color-text-primary);
  cursor: pointer;
  flex: 1;
}

.prompt-details {
  margin-top: 10px;
  border: 1px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  overflow: hidden;
}

.prompt-details summary {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--color-text-tertiary);
  cursor: pointer;
  user-select: none;
}

.prompt-details summary:hover { color: var(--color-text-secondary); }

.prompt-text {
  padding: 8px 12px 10px;
  font-size: 11px;
  color: var(--color-text-secondary);
  font-style: italic;
  border-top: 1px solid var(--color-border-tertiary);
  line-height: 1.5;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text-primary);
  color: var(--color-background-primary);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 12px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--color-border-tertiary);
  margin-bottom: 14px;
}

.tab {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--color-text-secondary);
}

.tab.active {
  border-bottom-color: var(--color-accent);
  color: var(--color-text-primary);
}

@media (max-width: 720px) {
  .days-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .week-meta {
    display: none;
  }
}
