:root {
  --accent: #2f5d8a;
  --text: #1f2933;
  --bg: #eef2f6;
  --overlay: 0.55;
  --heading-font: 'Playfair Display', Georgia, serif;
  --body-font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --card: rgba(255, 255, 255, 0.94);
  --line: #dde3ea;
  --muted: #5f6b7a;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body-font);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
/* Background image lives in a fixed layer so it also works on iPhone */
#bg { position: fixed; inset: 0; z-index: -2; background: var(--bg) center / cover no-repeat; }
#bg::after { content: ''; position: absolute; inset: 0; background: var(--bg); opacity: var(--overlay); }
h1, h2, h3 { font-family: var(--heading-font); margin: 0; line-height: 1.15; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- header ---------- */
.site-header { max-width: 1400px; margin: 0 auto; padding: 28px 20px 8px; text-align: center; }
.site-header h1 { font-size: clamp(1.7rem, 4vw, 2.8rem); }
.site-header .subtitle { margin: 6px 0 0; font-size: 1.05rem; color: var(--muted); }
.instructions { margin: 10px auto 0; max-width: 640px; font-size: 0.95rem; white-space: pre-line; }

/* ---------- layout ---------- */
.layout { max-width: 1400px; margin: 0 auto; padding: 16px 20px 40px; display: grid; grid-template-columns: 260px 1fr; gap: 20px; align-items: start; }
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(6px); }

/* ---------- companionship cards (left side) ---------- */
.comp-list { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 16px; }
.comp-card { padding: 14px 16px 14px 18px; border-left: 6px solid var(--c); }
.comp-card h3 { font-size: 1.15rem; margin-bottom: 4px; }
.comp-card .names { font-weight: 600; }
.comp-card dl { margin: 8px 0 0; font-size: 0.9rem; }
.comp-card dt { font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 6px; }
.comp-card dd { margin: 1px 0 0; white-space: pre-line; }
.comp-card .count { margin-top: 10px; font-size: 0.85rem; color: var(--muted); }

/* ---------- month bar ---------- */
.month-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; }
.month-bar h2 { font-size: clamp(1.3rem, 3vw, 1.9rem); text-align: center; flex: 1; }
.nav-btn { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.today-btn { margin-left: 6px; }

/* ---------- desktop / tablet grid ---------- */
.cal { padding: 0 12px 14px; overflow-x: auto; }
.cal-row { display: grid; grid-template-columns: 120px repeat(7, minmax(92px, 1fr)); }
.cal-head { position: sticky; top: 0; background: var(--card); z-index: 1; }
.cal-head div { padding: 8px 6px; font-weight: 600; text-align: center; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.week { border-top: 2px solid var(--line); }
.date-row > div { padding: 6px 8px 2px; font-weight: 700; font-size: 0.95rem; }
.date-row .out { color: transparent; }
.date-row .is-today span { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 8px; }
.lbl { display: flex; align-items: center; gap: 6px; padding: 4px 8px 4px 0; font-size: 0.8rem; font-weight: 600; line-height: 1.15; }
.lbl::before { content: ''; flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.cell { padding: 3px; min-height: 44px; }
.cell.past .slot { opacity: 0.55; }
.slot {
  width: 100%; height: 100%; min-height: 40px; border-radius: 8px; padding: 4px 6px; cursor: pointer; text-align: left;
  font-size: 0.82rem; line-height: 1.2; display: flex; flex-direction: column; justify-content: center;
  border: 1px dashed color-mix(in srgb, var(--c) 55%, #fff); background: color-mix(in srgb, var(--c) 6%, #fff);
}
.slot.open { color: color-mix(in srgb, var(--c) 80%, #000); font-weight: 500; }
.slot.open:hover, .slot.open:focus-visible { background: color-mix(in srgb, var(--c) 16%, #fff); outline: none; border-style: solid; }
.slot.filled { border: 0; background: var(--c); color: #fff; font-weight: 600; }
.slot.filled:hover, .slot.filled:focus-visible { filter: brightness(1.1); outline: none; }
.slot .t { font-weight: 400; font-size: 0.75rem; opacity: 0.9; }
.slot.empty-past { cursor: default; border: 0; background: transparent; }

/* ---------- phone list ---------- */
.day-list { display: none; padding: 0 12px 14px; }
.day { border-top: 1px solid var(--line); padding: 10px 0; }
.day.past { opacity: 0.6; }
.day h3 { font-family: var(--body-font); font-size: 1rem; margin-bottom: 6px; }
.day.is-today h3::after { content: 'Today'; margin-left: 8px; font-size: 0.7rem; background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 8px; vertical-align: middle; }
.day-slot { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; align-items: center; margin-top: 6px; }
.day-slot .slot { min-height: 44px; }
.past-toggle { margin: 4px 0 8px; }

/* ---------- empty state ---------- */
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(460px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,0.3); color: var(--text); }
dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.dlg { padding: 22px 22px 18px; }
.dlg h2 { font-size: 1.4rem; margin-bottom: 2px; }
.dlg .sub { color: var(--muted); margin: 0 0 14px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border: 1px solid #c9d2dc; border-radius: 8px; background: #fff; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
.field small { color: var(--muted); }
.row-2 { display: grid; grid-template-columns: 110px 1fr; gap: 10px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 14px; padding: 10px 12px; background: #f4f7fa; border-radius: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; flex: none; }
.info-box { border-left: 4px solid var(--c, var(--accent)); background: #f7f9fb; border-radius: 6px; padding: 8px 12px; font-size: 0.88rem; margin-bottom: 8px; }
.info-box b { display: block; }
.info-box .k { color: var(--muted); font-weight: 600; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.btn { border: 0; border-radius: 999px; padding: 10px 18px; cursor: pointer; font-weight: 600; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; border: 1px solid #c9d2dc; }
.btn-danger { background: #b42318; color: #fff; }
.btn:disabled { opacity: 0.6; cursor: wait; }
.err { color: #b42318; font-size: 0.9rem; min-height: 1.2em; margin: 6px 0 0; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #1f2933; color: #fff; padding: 12px 18px; border-radius: 999px; opacity: 0; transition: 0.25s; z-index: 100; max-width: calc(100vw - 32px); text-align: center; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.site-footer { text-align: center; font-size: 0.8rem; color: var(--muted); padding: 0 0 24px; }
.site-footer a { color: inherit; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .comp-list { position: static; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}
@media (max-width: 760px) {
  .site-header { padding-top: 18px; }
  .layout { padding: 10px 10px 30px; gap: 12px; }
  .cal { display: none; }
  .day-list { display: block; }
  .comp-card { padding: 10px 12px 10px 14px; }
  .month-bar { padding: 10px; }
  .nav-btn { padding: 8px 11px; }
  .today-btn { display: none; }
}
