:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666666;
  --border: #e0e2e6;
  --accent: #4a6fa5;
  --accent-hover: #3d5c8a;
  --danger: #c0392b;
  --danger-hover: #a53125;
  --success: #2e7d32;
  --tab-inactive: #eceef1;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #16181d;
  --surface: #1f2229;
  --text: #e8e9eb;
  --text-muted: #9a9ea6;
  --border: #2e323b;
  --accent: #6f93c9;
  --accent-hover: #82a4d6;
  --danger: #e05c4c;
  --danger-hover: #e87565;
  --success: #4caf50;
  --tab-inactive: #262a32;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }

/* Learned the hard way on a previous app: some classes below set their own
   display value, which otherwise silently defeats the native [hidden]
   attribute. This keeps hidden authoritative no matter what. */
[hidden], .hidden { display: none !important; }

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

/* ---- Login ---- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--surface); padding: 2.5rem; border-radius: 12px; box-shadow: var(--shadow); width: 320px; }
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.subtitle { color: var(--text-muted); margin: 0 0 1.5rem; font-size: 0.9rem; }
.login-card label { display: block; font-size: 0.85rem; margin-bottom: 0.3rem; color: var(--text-muted); }
.login-card input {
  width: 100%; padding: 0.6rem; margin-bottom: 1rem; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg); color: var(--text); font-size: 0.95rem;
}
.login-card button {
  width: 100%; padding: 0.7rem; border: none; border-radius: 6px;
  background: var(--accent); color: #fff; font-size: 0.95rem; cursor: pointer;
}
.login-card button:hover { background: var(--accent-hover); }
.error-text { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }
.success-text { color: var(--success); font-size: 0.85rem; margin-top: 0.5rem; }
.muted-text { color: var(--text-muted); font-size: 0.85rem; }

/* ---- Top bar ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.2rem; margin: 0; }
.topbar-actions { display: flex; gap: 0.5rem; }
.icon-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 0.4rem 0.6rem; cursor: pointer; color: var(--text); font-size: 1rem;
}
.icon-btn:hover { background: var(--tab-inactive); }

/* ---- View tabs (Day / Month) ---- */
.view-tabs {
  display: flex; gap: 0.25rem; padding: 0.75rem 1.5rem 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.view-tab-btn {
  padding: 0.6rem 1.2rem; border: none; background: var(--tab-inactive);
  color: var(--text-muted); border-radius: 8px 8px 0 0; cursor: pointer; font-size: 0.9rem;
}
.view-tab-btn.active { background: var(--bg); color: var(--accent); font-weight: 600; }

main { padding: 1.25rem 1.5rem 3rem; max-width: 800px; margin: 0 auto; }

.primary-btn {
  background: var(--accent); color: #fff; border: none; padding: 0.6rem 1.1rem;
  border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}
.primary-btn:hover { background: var(--accent-hover); }
.secondary-btn {
  background: var(--tab-inactive); color: var(--text); border: 1px solid var(--border);
  padding: 0.5rem 0.9rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.danger-btn {
  background: var(--danger); color: #fff; border: none; padding: 0.6rem 1.1rem;
  border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}
.danger-btn:hover { background: var(--danger-hover); }

/* ---- Day view ---- */
.day-toolbar { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 1rem; }
.day-label { font-weight: 600; font-size: 1.05rem; min-width: 220px; text-align: center; }
.day-actions { display: flex; justify-content: space-between; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }

.timeline-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.timeline { position: relative; }
.timeline-hour {
  position: relative; height: 60px; border-bottom: 1px solid var(--border);
  padding-left: 60px; font-size: 0.75rem; color: var(--text-muted);
}
.timeline-hour::before {
  content: attr(data-label); position: absolute; left: 8px; top: -0.5em;
}
.timeline-hour:last-child { border-bottom: none; }

.timeline-entry {
  position: absolute; left: 64px; right: 8px; border-radius: 6px; padding: 0.3rem 0.5rem;
  color: #fff; font-size: 0.8rem; overflow: hidden; cursor: pointer; box-shadow: var(--shadow);
}
.timeline-entry.readonly { cursor: default; opacity: 0.9; }
.timeline-entry .entry-title { font-weight: 600; }
.timeline-entry .entry-time { font-size: 0.7rem; opacity: 0.85; }
.timeline-untimed-list { padding: 0.75rem 1rem; border-top: 1px solid var(--border); }
.timeline-untimed-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.4rem 0.6rem; border-radius: 6px; margin-bottom: 0.4rem; cursor: pointer; color: #fff;
}

/* ---- Month view ---- */
.month-toolbar { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 1rem; }
.month-label { font-weight: 600; font-size: 1.05rem; min-width: 180px; text-align: center; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.month-day-header { text-align: center; font-size: 0.75rem; color: var(--text-muted); padding: 0.4rem 0; }
.month-day {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  min-height: 90px; padding: 0.35rem; cursor: pointer; font-size: 0.8rem;
}
.month-day:hover { border-color: var(--accent); }
.month-day.other-month { opacity: 0.35; }
.month-day.today { border-color: var(--accent); border-width: 2px; }
.month-day-num { font-weight: 600; }
.month-day-dots { display: flex; flex-direction: column; gap: 2px; margin-top: 0.3rem; }
.month-day-event { display: flex; align-items: center; gap: 4px; font-size: 0.68rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.month-day-dot { width: 6px; height: 6px; min-width: 6px; border-radius: 50%; }
.month-day-more { font-size: 0.68rem; color: var(--text-muted); margin-top: 1px; }

/* ---- Modals ---- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex;
  align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow-y: auto; z-index: 100;
}
.modal-content { background: var(--surface); border-radius: 12px; padding: 1.75rem; width: 100%; max-width: 520px; position: relative; }
.modal-close { position: absolute; top: 1rem; right: 1.1rem; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); }
.modal-content h2 { margin-top: 0; }
.modal-content h3 { font-size: 0.95rem; margin: 1.25rem 0 0.5rem; color: var(--text-muted); }
.settings-subhead { margin-top: 1.75rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }

.form-row { display: flex; gap: 1rem; }
.form-group { flex: 1; margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.55rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font-size: 0.9rem; font-family: inherit;
}
.form-group input[type="color"] { padding: 0.2rem; height: 2.4rem; }
.modal-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 1.25rem; }

.add-block-form { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1rem; }
.week-day-group { margin-bottom: 1rem; }
.week-day-title { font-weight: 600; font-size: 0.85rem; margin-bottom: 0.4rem; }
.week-block-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.4rem 0.6rem; border-radius: 6px; margin-bottom: 0.3rem; color: #fff; font-size: 0.82rem;
}
.week-block-remove { background: none; border: none; color: #fff; cursor: pointer; font-size: 0.9rem; }

@media (max-width: 600px) {
  .form-row { flex-direction: column; gap: 0; }
  main { padding: 0.75rem; }

  .topbar { padding: 0.75rem 1rem; }
  .topbar h1 { font-size: 1.05rem; }

  .day-toolbar { gap: 0.5rem; }
  .day-label { min-width: 0; font-size: 0.95rem; }
  .day-actions { gap: 0.4rem; }
  .day-actions .secondary-btn, .day-actions .primary-btn { font-size: 0.8rem; padding: 0.5rem 0.7rem; }

  /* Month view: title text takes too much room on narrow screens —
     drop to dot-only, matching the density expected on a phone. */
  .month-day-event span:last-child { display: none; }
  .month-day-event { justify-content: center; }
  .month-day-more { display: none; }
  .month-day { min-height: 56px; padding: 0.25rem; }
  .month-day-num { font-size: 0.75rem; }
  .month-day-dots { flex-wrap: wrap; flex-direction: row; justify-content: center; gap: 3px; }
  .month-day-dot { width: 7px; height: 7px; }

  .modal-content { padding: 1.25rem; max-width: 100%; }
  .modal { padding: 1rem 0.5rem; }
}
