/* ════════════════════════════════════════════════
   Parelmoer Agenda — v4 design tokens
   Mobile-first responsive
   ════════════════════════════════════════════════ */

@font-face {
  font-family: 'Ms Jollie';
  src: url('/fonts/Ms-Jollie.woff2') format('woff2'),
       url('/fonts/Ms.Jollie.otf') format('opentype');
  font-display: swap;
}

:root {
  --bg: #FAF6F0;
  --surface: #FFFFFF;
  --cream: #F2EAD8;
  --mist: #ECE4F0;
  --lavender: #D8CCE5;
  --lavender-strong: #B8A6CE;
  --pearl-1: #F8F4FB;
  --champagne: #C9A98E;
  --champagne-deep: #A8835E;
  --plum: #2A2533;
  --plum-soft: #4D4458;
  --lilac: #7A6F8C;
  --green-soft: #B8D8B8;
  --green-deep: #5D9E5D;
  --red-soft: #ECCFCF;
  --red-deep: #B86B6B;
  --line: rgba(216, 204, 229, 0.55);
  --line-strong: rgba(216, 204, 229, 0.9);
  --shadow-sm: 0 8px 24px -16px rgba(42, 37, 51, 0.18);
  --shadow-md: 0 24px 60px -28px rgba(42, 37, 51, 0.22);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--plum);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}
@media (min-width: 720px) { body { font-size: 17px; } }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ══════ Header ══════ */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(250, 246, 240, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
}
.brand .pearl {
  width: 28px; height: 28px;
  background: url('/img/pearl-sm.webp') center/contain no-repeat;
  filter: drop-shadow(0 1px 2px rgba(42,37,51,0.18));
  flex-shrink: 0;
}
.brand .wordmark {
  font-family: 'Ms Jollie', cursive;
  font-size: 28px;
  color: var(--plum);
  line-height: 1;
}
.brand .sub {
  display: none;
  font-size: 11px;
  color: var(--plum-soft);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-left: 8px;
  border-left: 1px solid var(--line);
  padding-left: 12px;
}
@media (min-width: 540px) {
  .brand .sub { display: inline-block; }
  .brand .wordmark { font-size: 32px; }
}

.header-actions { display: flex; gap: 8px; align-items: center; }

/* ══════ Viewer welcome badge ══════ */
#viewerWelcomeBadge:not(:empty) {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--mist);
  border: 1px solid var(--line);
  color: var(--plum);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
#viewerWelcomeBadge:not(:empty)::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

/* ══════ Buttons ══════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 500;
  border: 1px solid transparent;
  background: transparent;
  color: var(--plum);
  cursor: pointer;
  transition: all .2s;
}
.btn { min-height: 40px; touch-action: manipulation; }
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--plum); color: var(--bg);
}
.btn-primary:hover { background: var(--plum-soft); }
.btn-ghost { border-color: var(--plum); color: var(--plum); }
.btn-ghost:hover { background: var(--plum); color: var(--bg); }
.btn-sm { padding: 9px 14px; font-size: 11px; letter-spacing: 0.14em; min-height: 36px; }
.btn-icon { padding: 8px 10px; border-radius: 999px; min-width: 36px; }
.btn-danger { color: #B43A3A; }
.btn-danger:hover { background: var(--red-soft); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ══════ Layout containers ══════ */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
}
@media (min-width: 720px) { .container { padding: 24px; } }

.page-title {
  font-family: 'Fraunces', 'Times New Roman', serif;
  font-weight: 300;
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.1;
  color: var(--plum);
  margin-bottom: 6px;
}
.page-title .accent {
  font-family: 'Ms Jollie', cursive;
  color: var(--champagne-deep);
  font-weight: 400;
  font-size: 1.4em;
  line-height: 0.6;
  vertical-align: baseline;
  display: inline-block;
  transform: translateY(0.12em);
}
.page-eyebrow {
  font-size: 11px; letter-spacing: 0.28em; text-transform: uppercase;
  color: var(--champagne-deep);
  display: inline-flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.page-eyebrow::before { content: ""; width: 24px; height: 1px; background: var(--champagne); }
.page-sub {
  color: var(--plum-soft);
  margin-top: 8px;
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 17px;
  line-height: 1.5;
}

/* ══════ Login screen ══════ */
.login-card {
  max-width: 420px;
  margin: 8vh auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
  text-align: center;
}
.login-card .pearl-lg {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  background: url('/img/pearl.webp') center/contain no-repeat;
  filter: drop-shadow(0 6px 18px rgba(216, 204, 229, 0.55));
}
.login-card h1 {
  font-family: 'Fraunces', serif;
  font-weight: 300;
  font-size: 28px;
  color: var(--plum);
  margin-bottom: 6px;
}
.login-card p.hint {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-weight: 300;
  color: var(--plum-soft);
  margin-bottom: 24px;
  font-size: 15px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; text-align: left; }
.form-field label {
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--plum-soft);
  font-weight: 500;
}
.form-field input {
  padding: 13px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  font-size: 16px;
  background: var(--bg);
  color: var(--plum);
  outline: none;
  transition: border-color .2s, background .2s;
}
.form-field input:focus { border-color: var(--champagne); background: var(--surface); }
.form-field input.pin-input {
  text-align: center;
  letter-spacing: 0.5em;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}
.form-error {
  color: #B43A3A;
  background: var(--red-soft);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  margin-bottom: 14px;
  display: none;
}
.form-error.visible { display: block; }
.login-card .btn { width: 100%; padding: 14px; }

/* ══════ Week navigation ══════ */
.week-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  margin: 20px 0 14px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.week-nav .week-label {
  font-family: 'Fraunces', serif;
  font-weight: 400;
  font-size: 17px;
  color: var(--plum);
  text-align: center;
  flex: 1;
  line-height: 1.2;
}
.week-nav .week-label .week-range {
  display: block;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--plum-soft);
  letter-spacing: 0.08em;
  margin-top: 2px;
  text-transform: uppercase;
}
.week-nav .nav-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  color: var(--plum);
  transition: all .2s;
  flex-shrink: 0;
}
.week-nav .nav-btn:hover { background: var(--mist); border-color: var(--lavender-strong); }
.week-nav .nav-btn[disabled] { opacity: 0.3; }

/* ══════ Slot grid ══════ */
.grid {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.grid-head, .grid-row {
  display: grid;
  grid-template-columns: 56px repeat(6, 1fr);
}
.grid-head {
  background: var(--mist);
  border-bottom: 1px solid var(--line-strong);
}
.grid-head > div {
  padding: 10px 4px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--plum-soft);
  font-weight: 600;
}
.grid-head .day-name { line-height: 1.1; }
.grid-head .day-name .date-num { display: block; font-family: 'Fraunces', serif; font-size: 18px; font-weight: 400; letter-spacing: 0; color: var(--plum); text-transform: none; margin-top: 2px; }
.grid-head .day-name.today .date-num { color: var(--champagne-deep); position: relative; }
.grid-head .day-name.today .date-num::after {
  content: ""; position: absolute; bottom: -3px; left: 50%;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--champagne-deep);
  transform: translateX(-50%);
}
.grid-row { border-bottom: 1px solid var(--line); }
.grid-row:last-child { border-bottom: none; }
.grid-row .hour-label {
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--plum-soft);
  background: var(--bg);
  font-weight: 500;
  border-right: 1px solid var(--line);
}
.slot {
  appearance: none;
  border: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 0;
  padding: 0;
  min-height: 44px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  touch-action: manipulation;
}
.slot:last-child { border-right: none; }
.slot[disabled] { cursor: default; }
.slot.open {
  background: var(--green-soft);
}
.slot.open::after {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green-deep);
  box-shadow: 0 0 8px rgba(93, 158, 93, 0.4);
}
.slot.closed { background: var(--red-soft); }
.slot.past {
  background: repeating-linear-gradient(45deg, rgba(0,0,0,0.04) 0 4px, transparent 4px 8px), var(--bg);
  cursor: not-allowed;
  opacity: 0.55;
}
.slot.past.open { background: repeating-linear-gradient(45deg, rgba(0,0,0,0.04) 0 4px, transparent 4px 8px), var(--green-soft); }
.slot.past.closed { background: repeating-linear-gradient(45deg, rgba(0,0,0,0.04) 0 4px, transparent 4px 8px), var(--red-soft); }
.slot:not([disabled]):hover { transform: scale(1.02); z-index: 1; box-shadow: inset 0 0 0 2px var(--lavender-strong); }
.slot:not([disabled]):active { transform: scale(0.98); }
.slot.loading { opacity: 0.5; }

@media (min-width: 540px) {
  .grid-row .hour-label { font-size: 13px; }
  .slot { min-height: 44px; }
  .grid-head > div { padding: 14px 4px; }
}
@media (min-width: 720px) {
  .grid-head, .grid-row { grid-template-columns: 70px repeat(6, 1fr); }
  .slot { min-height: 52px; }
}

/* ══════ Legend ══════ */
.legend {
  display: flex; gap: 16px; align-items: center; justify-content: center; flex-wrap: wrap;
  margin: 12px 0;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--plum-soft);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 16px; height: 16px; border-radius: 4px; border: 1px solid var(--line); }
.legend-swatch.open { background: var(--green-soft); position: relative; }
.legend-swatch.open::after { content: ""; position: absolute; top: 50%; left: 50%; width: 6px; height: 6px; border-radius: 50%; background: var(--green-deep); transform: translate(-50%,-50%); }
.legend-swatch.closed { background: var(--red-soft); }
.legend-swatch.past { background: repeating-linear-gradient(45deg, rgba(0,0,0,0.06) 0 3px, transparent 3px 6px), var(--bg); }

/* ══════ Tabs ══════ */
.tabs {
  display: flex; gap: 6px;
  background: var(--surface);
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  margin: 16px 0;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 18px;
  min-height: 40px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--plum-soft);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab.active { background: var(--plum); color: var(--bg); }

/* ══════ Viewers list ══════ */
.viewer-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.viewer-card.revoked { opacity: 0.5; background: var(--bg); }
.viewer-name {
  font-family: 'Fraunces', serif;
  font-weight: 400;
  font-size: 17px;
  color: var(--plum);
  margin-bottom: 4px;
}
.viewer-meta {
  font-size: 12px;
  color: var(--plum-soft);
  letter-spacing: 0.04em;
  display: flex; flex-wrap: wrap; gap: 12px;
}
.viewer-meta code {
  font-family: 'SF Mono', Menlo, monospace;
  background: var(--mist);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--plum);
  font-size: 12px;
}
.viewer-card .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.viewer-link-copy {
  background: var(--mist);
  border: 1px dashed var(--lavender-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 12px;
  color: var(--plum);
  margin-top: 8px;
  word-break: break-all;
  grid-column: 1 / -1;
  position: relative;
}
.viewer-link-copy .copy-btn {
  position: absolute;
  top: 6px; right: 6px;
  font-size: 10px;
  letter-spacing: 0.14em;
  padding: 4px 10px;
  background: var(--plum);
  color: var(--bg);
  border: none;
  border-radius: 999px;
  text-transform: uppercase;
  cursor: pointer;
}
.viewer-link-copy .copy-btn.copied { background: var(--green-deep); }

/* ══════ Add viewer dialog ══════ */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(42, 37, 51, 0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center; justify-content: center;
  padding: 16px;
  z-index: 100;
}
.dialog-backdrop.visible { display: flex; }
.dialog {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 24px;
  width: 100%;
  max-width: 420px;
}
.dialog h2 {
  font-family: 'Fraunces', serif;
  font-weight: 300;
  font-size: 24px;
  color: var(--plum);
  margin-bottom: 16px;
}
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ══════ Activity log ══════ */
.activity-row {
  display: grid;
  grid-template-columns: 140px 1fr 1.4fr;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  align-items: center;
  font-size: 14px;
}
.activity-row:last-child { border-bottom: none; }
.activity-row:hover { background: var(--mist); }
.activity-when { color: var(--plum-soft); font-size: 13px; }
.activity-who { color: var(--plum); font-weight: 500; }
.activity-slot { color: var(--plum); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.activity-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.activity-badge.open { background: var(--green-soft); color: #2d5a2d; }
.activity-badge.bezet { background: var(--red-soft); color: #8a2828; }
.activity-badge.type-open { background: var(--lavender-soft, var(--mist)); color: var(--plum); }
.activity-row--open { opacity: 0.85; }
.activity-action { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
@media (max-width: 600px) {
  .activity-row { grid-template-columns: 1fr; gap: 4px; padding: 10px 12px; }
  .activity-when { order: 3; font-size: 12px; }
}

/* ══════ Toast ══════ */
.toast {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(180%);
  background: var(--plum);
  color: var(--bg);
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.06em;
  box-shadow: var(--shadow-md);
  z-index: 200;
  transition: transform .3s ease;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
}
.toast.visible { transform: translateX(-50%) translateY(0); }

/* ══════ Empty state ══════ */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--plum-soft);
}
.empty-state h3 {
  font-family: 'Fraunces', serif;
  font-weight: 300;
  font-size: 22px;
  color: var(--plum);
  margin-bottom: 8px;
}

/* ══════ Footer ══════ */
.app-footer {
  text-align: center;
  padding: 32px 16px 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  color: var(--plum-soft);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.app-footer .wm {
  font-family: 'Ms Jollie', cursive;
  font-size: 24px;
  color: var(--plum);
  text-transform: none;
  letter-spacing: 0;
  display: block;
  margin-bottom: 6px;
}

/* ══════ Util ══════ */
.hidden { display: none !important; }
.loading-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  transition: opacity .3s;
}
.loading-screen.hide { opacity: 0; pointer-events: none; }
.loading-screen .pearl-lg {
  width: 56px; height: 56px;
  background: url('/img/pearl.webp') center/contain no-repeat;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.08); opacity: 0.7; } }
