/**
 * FrOdo Family Calendar — styles aligned with Family Hub palette.
 */

:root {
  --primary: #2d2a26;
  --accent: #d4af37;
  --bg: #f5f2eb;
  --card-bg: #fff;
  --text: #333;
  --soft-orange: #f4b251;
  --danger: #a33;
  --line: #e8e0d4;
  --muted: #666;
  --cal-cell-min: 96px;
}

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

body {
  font-family: Georgia, "Times New Roman", serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

body.modal-open {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* --- Header --- */
.site-header {
  background: var(--primary);
  color: #fff;
  padding: 1rem 1.25rem 1.1rem;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.site-header a {
  color: #ddd;
  text-decoration: none;
  font-family: Arial, sans-serif;
  font-size: 0.92rem;
}

.site-header h1 {
  font-size: 1.65rem;
  margin: 0.35rem 0 0.15rem;
}

.tagline {
  font-family: Arial, sans-serif;
  font-size: 0.9rem;
  color: #ccc;
  margin: 0;
}

.lab-badge {
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--soft-orange);
  color: var(--primary);
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-weight: bold;
}

/* --- Name gate --- */
.name-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 1.5rem;
}

.gate-box {
  background: var(--card-bg);
  padding: 2rem;
  border-radius: 16px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}

.gate-box h2 {
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.gate-box p {
  color: var(--muted);
  font-family: Arial, sans-serif;
  font-size: 0.92rem;
  margin-bottom: 1rem;
}

/* --- Main layout --- */
.calendar-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

.sync-status {
  font-family: Arial, sans-serif;
  font-size: 0.88rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: #fff8df;
  border: 1px solid #ead28c;
  margin-bottom: 1rem;
}

.sync-status.error {
  background: #fde8e8;
  border-color: #e8a8a8;
}

.sync-status code {
  font-size: 0.85em;
}

.offline-sync-panel {
  font-family: Arial, sans-serif;
  font-size: 0.88rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: #fff8df;
  border: 1px solid #ead28c;
  margin-bottom: 1rem;
}

.offline-sync-panel p {
  margin: 0.25rem 0;
}

.offline-sync-error {
  color: #b42318;
  font-weight: 600;
}

.event-chip-pending {
  opacity: 0.85;
  border: 1px dashed #c9a227;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  background: var(--card-bg);
  padding: 0.85rem 1rem;
  border-radius: 14px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.toolbar-left,
.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.user-line {
  font-family: Arial, sans-serif;
  font-size: 0.88rem;
  color: var(--muted);
}

.view-toggle {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.view-toggle button {
  border: 0;
  background: transparent;
  padding: 0.5rem 1rem;
  font-family: Arial, sans-serif;
  font-weight: bold;
  cursor: pointer;
  color: var(--primary);
  min-height: 40px;
}

.view-toggle button.active {
  background: var(--primary);
  color: #fff;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.month-nav-label {
  font-family: Arial, sans-serif;
  font-size: 0.85rem;
  min-width: 4.5rem;
  text-align: center;
}

/* --- Buttons & inputs --- */
button,
input,
select,
textarea {
  font-family: Arial, sans-serif;
  font-size: 1rem;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  margin-bottom: 0.75rem;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

label {
  display: block;
  font-weight: bold;
  font-size: 0.88rem;
  margin-bottom: 0.25rem;
}

.btn {
  border: 0;
  border-radius: 30px;
  padding: 0.55rem 1.1rem;
  font-weight: bold;
  cursor: pointer;
  min-height: 42px;
  background: var(--primary);
  color: #fff;
}

.btn-gold {
  background: var(--soft-orange);
  color: var(--primary);
}

.btn-ghost {
  background: #eee;
  color: var(--primary);
}

.btn-danger {
  background: #f4dddd;
  color: var(--danger);
}

.btn-icon {
  min-width: 42px;
  padding: 0.5rem 0.75rem;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* --- Calendar card --- */
.calendar-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  margin-bottom: 1rem;
}

.month-title {
  text-align: center;
  font-size: 1.35rem;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

/* One grid: 7 columns × (1 header row + 6 day rows) */
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: auto repeat(6, minmax(var(--cal-cell-min), auto));
  gap: 4px;
  width: 100%;
}

.cal-dow {
  text-align: center;
  font-family: Arial, sans-serif;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.4rem 0;
}

.cal-day {
  min-height: var(--cal-cell-min);
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #faf9f6;
  padding: 0.35rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  transition: background 0.15s;
}

.cal-day:focus-visible {
  outline: 2px solid var(--soft-orange);
  outline-offset: 1px;
}

.cal-day:hover {
  background: #fff8ef;
}

.cal-day.other-month {
  opacity: 0.45;
}

.cal-day.today {
  border-color: var(--soft-orange);
  box-shadow: inset 0 0 0 2px var(--soft-orange);
}

.cal-day.selected {
  background: #fff3dc;
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cal-day.selected.today {
  box-shadow: inset 0 0 0 2px var(--soft-orange), 0 0 0 2px var(--accent);
}

.day-num {
  flex: 0 0 auto;
  font-family: Arial, sans-serif;
  font-size: 0.82rem;
  font-weight: bold;
  color: var(--primary);
  line-height: 1.2;
}

.day-events {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 0.2rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  width: 100%;
}

.event-chip {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  flex-shrink: 0;
  border: 0;
  border-radius: 6px;
  padding: 2px 5px;
  font-size: 0.68rem;
  font-family: Arial, sans-serif;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  background: color-mix(in srgb, var(--chip-color) 18%, white);
  color: var(--primary);
  border-left: 3px solid var(--chip-color);
}

.more-count {
  font-size: 0.65rem;
  color: var(--muted);
  font-family: Arial, sans-serif;
}

/* Mobile selected-day panel (hidden on desktop) */
.selected-day-panel {
  display: none;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 2px solid var(--soft-orange);
}

.selected-day-panel-inner {
  background: #fffdf9;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.9rem 0.75rem;
}

.selected-day-heading {
  font-size: 0.95rem;
  color: var(--primary);
  margin: 0 0 0.25rem;
  font-family: Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.selected-day-date {
  font-size: 1rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
  font-family: Arial, sans-serif;
}

.selected-day-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.selected-day-empty {
  color: var(--muted);
  font-style: italic;
  font-family: Arial, sans-serif;
  font-size: 0.92rem;
  margin: 0;
  padding: 0.35rem 0;
}

.selected-day-item {
  margin-bottom: 0;
}

/* --- Agenda view --- */
.agenda-view {
  padding: 0.25rem 0;
}

.agenda-date {
  font-size: 1rem;
  color: var(--primary);
  margin: 1rem 0 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--soft-orange);
}

.agenda-date:first-child {
  margin-top: 0;
}

.agenda-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.15rem;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-left: 4px solid var(--item-color);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.5rem;
  background: #fffdf9;
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.agenda-item:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}

.agenda-cat {
  font-family: Arial, sans-serif;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.agenda-title {
  font-size: 1.05rem;
  font-weight: bold;
  color: var(--primary);
}

.agenda-meta {
  font-family: Arial, sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
}

.agenda-desc {
  font-size: 0.9rem;
  color: #555;
  margin-top: 0.15rem;
}

.empty-agenda {
  text-align: center;
  color: var(--muted);
  font-style: italic;
  padding: 2rem 1rem;
  font-family: Arial, sans-serif;
}

/* --- Legend --- */
.legend-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.75rem 0 0;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: Arial, sans-serif;
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--chip-color) 12%, white);
  border: 1px solid color-mix(in srgb, var(--chip-color) 35%, white);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chip-color);
}

.footer-meta {
  font-family: Arial, sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.5rem;
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  background: rgba(45, 42, 38, 0.55);
  overflow-y: auto;
}

.modal-panel {
  width: min(520px, 100%);
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
  margin: auto 0;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--card-bg);
  z-index: 1;
}

.modal-head h2 {
  font-size: 1.2rem;
  color: var(--primary);
}

.modal-body {
  padding: 1rem 1.1rem 1.15rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  font-family: Arial, sans-serif;
  font-size: 0.92rem;
}

.check-row input {
  width: auto;
  margin: 0;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.modal-actions .btn {
  flex: 1 1 auto;
}

/* --- Mobile --- */
@media (max-width: 768px) {
  :root {
    --cal-cell-min: 72px;
  }

  .calendar-shell {
    padding: 0.75rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-left,
  .toolbar-right {
    justify-content: center;
  }

  .cal-day {
    padding: 0.25rem;
  }

  .event-chip {
    font-size: 0.6rem;
    padding: 1px 3px;
  }

  .day-num {
    font-size: 0.75rem;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .site-header h1 {
    font-size: 1.35rem;
  }

  .selected-day-panel:not(.hidden) {
    display: block;
  }

  .cal-day.selected {
    background: #fff3dc;
  }
}

@media (max-width: 480px) {
  :root {
    --cal-cell-min: 58px;
  }

  .event-chip {
    display: none;
  }

  .cal-day.has-events .day-num::after {
    content: " •";
    color: var(--soft-orange);
  }
}
