/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f1f5f9;
  --surface:   #ffffff;
  --border:    #e2e8f0;
  --text:      #1e293b;
  --muted:     #64748b;
  --primary:   #2563eb;
  --primary-h: #1d4ed8;
  --danger:    #dc2626;
  --danger-h:  #b91c1c;
  --booked-bg: #fee2e2;
  --booked-fg: #991b1b;
  --pending-bg:#fef3c7;
  --pending-fg:#92400e;
  --admin-bg:  #dbeafe;
  --admin-fg:  #1e40af;
  --sel-bg:    #bfdbfe;
  --sel-fg:    #1e40af;
  --radius:    10px;
  --shadow:    0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

/* ── Layout helpers ───────────────────────────────────────── */
.hidden { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.page-center {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

/* ── Buttons ──────────────────────────────────────────────── */
button { font: inherit; cursor: pointer; border: none; border-radius: 6px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  font-size: .875rem;
  font-weight: 500;
  border-radius: 6px;
  transition: background .15s, opacity .15s;
}
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: var(--danger-h); }
.btn-ghost     { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover   { background: var(--bg); }
.btn-sm        { padding: .3rem .65rem; font-size: .8rem; }
.btn:disabled  { opacity: .45; cursor: not-allowed; }

/* ── Forms ────────────────────────────────────────────────── */
input[type=text],
input[type=password],
input[type=date],
input[type=email],
textarea,
select {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
textarea { resize: vertical; min-height: 80px; }

label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }

.error-msg   { color: var(--danger); font-size: .85rem; margin-top: .5rem; }
.success-msg { color: #16a34a;       font-size: .85rem; margin-top: .5rem; }

/* ── Auth / key entry card ────────────────────────────────── */
.auth-card {
  width: 100%;
  max-width: 380px;
}
.auth-card h1 { font-size: 1.4rem; margin-bottom: .25rem; }
.auth-card p  { color: var(--muted); font-size: .9rem; margin-bottom: 1.25rem; }

.key-input-wrap {
  position: relative;
  display: flex;
  gap: .5rem;
}
.key-input-wrap input { flex: 1; font-family: monospace; letter-spacing: .05em; }

/* ── Top bar (guest) ─────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title { font-weight: 600; font-size: 1rem; }
.topbar-user  { font-size: .85rem; color: var(--muted); }

/* ── Calendar wrapper ─────────────────────────────────────── */
.cal-wrapper {
  max-width: 520px;
  margin: 1.25rem auto;
  padding: 0 .75rem;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}
.cal-nav-label {
  font-size: 1.05rem;
  font-weight: 600;
}
.cal-nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .35rem .75rem;
  font-size: 1rem;
  color: var(--text);
  transition: background .15s;
}
.cal-nav-btn:hover:not(:disabled) { background: var(--bg); }
.cal-nav-btn:disabled { opacity: .3; cursor: default; }

/* ── Calendar grid ────────────────────────────────────────── */
.cal-head {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.cal-head-cell {
  text-align: center;
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  padding: .2rem 0 .4rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

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

.cal-day {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(.65rem, 2.8vw, .875rem);
  cursor: pointer;
  user-select: none;
  transition: background .1s;
  -webkit-tap-highlight-color: transparent; /* suppress grey iOS tap flash */
  touch-action: manipulation;               /* eliminate 300 ms tap delay  */
}
.cal-day.empty { cursor: default; }
.cal-day.other-month { color: var(--border); cursor: default; }

/* today indicator */
.cal-day.today .day-num::after {
  content: '';
  display: block;
  width: 4px;
  height: 4px;
  background: var(--primary);
  border-radius: 50%;
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
}
.day-num {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.cell-label {
  position: absolute;
  left: 4px;
  bottom: 2px;
  font-size: clamp(.55rem, 1.8vw, .68rem);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 8px);
  pointer-events: none;
  opacity: .85;
}

/* ── Range colouring (guest = red, admin-booking = blue, pending = amber) */
/* Applied to the .cal-day element; border-radius shapes the band ends */
.cal-day.booked          { background: var(--booked-bg); color: var(--booked-fg); }
.cal-day.admin-booked    { background: var(--admin-bg);  color: var(--admin-fg);  cursor: pointer; }
.cal-day.admin-pending   { background: var(--pending-bg);color: var(--pending-fg);cursor: pointer; }
.cal-day.selected        { background: var(--sel-bg);    color: var(--sel-fg); }
.cal-day.sel-start-anchor .day-num,
.cal-day.sel-end-anchor   .day-num {
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
}

.cal-day.range-start  { border-radius: 50% 0 0 50%; }
.cal-day.range-end    { border-radius: 0 50% 50% 0; }
.cal-day.range-single { border-radius: 50%; }
.cal-day.range-mid    { border-radius: 0; }
/* Row-boundary closures */
.cal-day.range-row-open  { border-radius: 50% 0 0 50%; }
.cal-day.range-row-close { border-radius: 0 50% 50% 0; }

/* Temporarily blocked (pending request) — guest calendar only */
.cal-day.guest-pending { background: #e2e8f0; color: #475569; cursor: pointer; }

.cal-day.past { opacity: .45; cursor: default; pointer-events: none; }
.cal-day.booked-past { opacity: .6; cursor: default; }

/* ── Legend ───────────────────────────────────────────────── */
.cal-legend {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: .75rem;
  flex-wrap: wrap;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .78rem;
  color: var(--muted);
}
.legend-dot {
  width: 12px; height: 12px;
  border-radius: 3px;
}
.legend-dot.booked          { background: var(--booked-bg);  border: 1px solid var(--booked-fg); }
.legend-dot.temp-blocked    { background: #e2e8f0;           border: 1px solid #94a3b8;          }
.legend-dot.pending         { background: var(--pending-bg); border: 1px solid var(--pending-fg);}
.legend-dot.approved        { background: var(--admin-bg);   border: 1px solid var(--admin-fg);  }
.legend-dot.selected        { background: var(--sel-bg);     border: 1px solid var(--primary);   }

/* ── Vertical calendar toolbar ────────────────────────────── */
.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .85rem;
  flex-wrap: wrap;
}
.cal-toolbar > span { font-size: .82rem; color: var(--muted); }

/* ── Month blocks (vertical scroll) ──────────────────────── */
.month-block-title {
  font-size: .95rem;
  font-weight: 700;
  text-align: center;
  padding: .3rem 0 .6rem;
  color: var(--primary);
  letter-spacing: .02em;
}
.month-block + .month-block {
  border-top: 1px solid var(--border);
  padding-top: 1.1rem;
  margin-top: .25rem;
}
.load-more-wrap {
  text-align: center;
  padding: .6rem 0 .25rem;
}

/* ── Request form (guest) ─────────────────────────────────── */
.request-panel {
  max-width: 520px;
  margin: 0 auto 2rem;
  padding: 0 .75rem;
}
.request-panel .card { border-top: 3px solid var(--primary); }
.request-panel h3 { font-size: 1rem; margin-bottom: .5rem; }
.request-dates { font-size: .9rem; color: var(--primary); font-weight: 500; margin-bottom: 1rem; }

/* ── My requests list (guest) ─────────────────────────────── */
.my-requests-panel {
  max-width: 520px;
  margin: 0 auto 2rem;
  padding: 0 .75rem;
}
.my-requests-panel h3 { font-size: .9rem; font-weight: 600; color: var(--muted); margin-bottom: .5rem; }

.request-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .75rem;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: .4rem;
  font-size: .85rem;
}
.request-item .ri-dates { flex: 1; font-weight: 500; }
.request-item .ri-note  { color: var(--muted); font-size: .78rem; }
.badge {
  font-size: .7rem;
  font-weight: 600;
  padding: .15rem .45rem;
  border-radius: 99px;
  white-space: nowrap;
}
.badge-pending  { background: var(--pending-bg);  color: var(--pending-fg); }
.badge-approved { background: var(--admin-bg);    color: var(--admin-fg);   }
.badge-rejected { background: #f1f5f9;            color: var(--muted);      }

/* ── Admin layout ─────────────────────────────────────────── */
.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  background: var(--primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.admin-topbar h1 { font-size: 1.05rem; font-weight: 600; letter-spacing: .02em; }

.admin-tabs {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 49px;
  z-index: 15;
}
.admin-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: .75rem 1.1rem;
  font-size: .875rem;
  font-weight: 500;
  background: transparent;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover   { color: var(--text); }
.tab-btn.active  { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn .badge-count {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--danger); color: #fff;
  font-size: .65rem; font-weight: 700;
  border-radius: 99px;
  min-width: 17px; height: 17px;
  padding: 0 .3rem;
  margin-left: .3rem;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Mobile hamburger menu ───────────────────────────────── */
.mobile-menu {
  position: sticky;
  top: 49px;
  z-index: 25;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
}
.mobile-menu.hidden { display: none; }
.mobile-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: .85rem 1.25rem;
  font-size: .95rem;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  text-align: left;
  cursor: pointer;
}
.mobile-menu-item:last-child { border-bottom: none; }
.mobile-menu-item.active { color: var(--primary); font-weight: 600; }
.mobile-menu-item:hover   { background: var(--bg); }

/* On wide screens: hide hamburger, show tab bar */
@media (min-width: 600px) {
  #menu-toggle-btn { display: none; }
  .mobile-menu     { display: none !important; }
}

/* On narrow screens: hide tab bar */
@media (max-width: 599px) {
  .admin-tabs { display: none; }
}

.admin-panel {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem .75rem 3rem;
}

/* ── Admin calendar ───────────────────────────────────────── */
.admin-cal-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.admin-cal-header .cal-nav-label { flex: 1; }

/* Detail panel below calendar */
.detail-panel {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: .875rem;
}
.detail-panel h4 { font-size: .95rem; margin-bottom: .4rem; }
.detail-panel .detail-meta { color: var(--muted); margin-bottom: .75rem; }
.detail-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Requests list (admin) ────────────────────────────────── */
.req-list { display: flex; flex-direction: column; gap: .5rem; }
.req-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
}
.req-card-header {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  margin-bottom: .5rem;
}
.req-card-name   { font-weight: 600; flex: 1; }
.req-card-dates  { color: var(--muted); font-size: .83rem; margin-bottom: .35rem; }
.req-card-note   { color: var(--muted); font-size: .82rem; font-style: italic; margin-bottom: .35rem; }
.req-card-ts     { color: var(--muted); font-size: .78rem; margin-bottom: .6rem; }
.req-card-actions { display: flex; gap: .5rem; }
.req-filter { display: flex; gap: .5rem; margin-bottom: .75rem; flex-wrap: wrap; }
.filter-btn { padding: .3rem .7rem; font-size: .8rem; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); }
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Keys list (admin) ────────────────────────────────────── */
.keys-list { display: flex; flex-direction: column; gap: .5rem; }
.key-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem 1rem;
}
.key-item.revoked { opacity: .5; }
.key-name { font-weight: 500; flex: 1; }
.key-meta  { font-size: .78rem; color: var(--muted); }
.key-status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}
.key-item.revoked .key-status-dot { background: var(--border); }

/* key reveal box */
.key-reveal {
  background: #0f172a;
  color: #86efac;
  font-family: monospace;
  font-size: .9rem;
  letter-spacing: .1em;
  padding: .85rem 1rem;
  border-radius: 8px;
  word-break: break-all;
  margin: .75rem 0;
  user-select: all;
}

/* ── Settings (admin) ─────────────────────────────────────── */
.settings-section { margin-bottom: 1.5rem; }
.settings-section h3 { font-size: .9rem; font-weight: 600; color: var(--muted); margin-bottom: .75rem; text-transform: uppercase; letter-spacing: .05em; }

/* ── Modal (dialog) ───────────────────────────────────────── */
dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  padding: 1.5rem;
  width: min(420px, 95vw);
  background: var(--surface);
}
dialog::backdrop {
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(2px);
}
dialog h3 { font-size: 1.05rem; margin-bottom: 1rem; }
.dialog-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

/* ── Booking data tables (Dates List / History) ───────────── */
.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  white-space: nowrap;
}
.data-table th {
  text-align: left;
  padding: .55rem .85rem;
  background: var(--bg);
  border-bottom: 2px solid var(--border);
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.data-table td {
  padding: .6rem .85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: normal;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td      { background: var(--bg); }
.data-table .td-note         { color: var(--muted); font-size: .82rem; }
.data-table .td-date         { white-space: nowrap; font-variant-numeric: tabular-nums; }

.log-filters {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  align-items: flex-end;
}
.log-filters .field label { font-size: .78rem; }
.log-filters input,
.log-filters select { font-size: .85rem; padding: .3rem .5rem; }
.log-action-label {
  display: inline-block;
  font-size: .75rem;
  font-weight: 600;
  padding: .15rem .45rem;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.table-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: .875rem;
}

/* ── Responsive tweaks ────────────────────────────────────── */
@media (max-width: 420px) {
  .card { padding: 1.1rem; }
  .cal-head-cell { font-size: .62rem; letter-spacing: 0; }
  .admin-panel { padding: .75rem .5rem 3rem; }
}
