:root {
  --tiger-orange: #ef7f1a;
  --tiger-orange-deep: #c85d0a;
  --tiger-black: #221a15;
  --tiger-cream: #fff6e9;
  --tiger-cream-dim: #fbe9d2;
  --paper: #ffffff;
  --ink: #2b1f16;
  --ink-soft: #7a6a5c;
  --border: #f0dcc2;

  --status-green: #2f9e44;
  --status-green-bg: #ebfbee;
  --status-yellow: #e8990c;
  --status-yellow-bg: #fff6da;
  --status-red: #e03131;
  --status-red-bg: #fff0f0;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px -12px rgba(34, 26, 21, 0.35);

  color-scheme: light;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--tiger-cream);
  color: var(--ink);
  font-family: "Nunito Sans", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand, .month-label {
  font-family: "Baloo 2", "Nunito Sans", system-ui, sans-serif;
}

img { max-width: 100%; }
[hidden] { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

/* ---------- Tiger stripe motif ---------- */
.gate-stripes,
.topbar-stripes {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    115deg,
    var(--tiger-black) 0px,
    var(--tiger-black) 10px,
    transparent 10px,
    transparent 26px
  );
  opacity: 0.09;
  pointer-events: none;
}

/* ---------- Passphrase gate ---------- */
.gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(circle at 50% 0%, var(--tiger-orange) 0%, var(--tiger-orange-deep) 55%, #a34808 100%);
}

.gate-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.gate-content {
  position: relative;
  padding: 40px 28px 32px;
  text-align: center;
}

.gate-emoji {
  font-size: 52px;
  display: inline-block;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15));
}

.gate-title {
  margin: 8px 0 4px;
  font-size: 30px;
  font-weight: 800;
  color: var(--tiger-orange-deep);
  letter-spacing: 0.2px;
}

.gate-subtitle {
  margin: 0 0 28px;
  color: var(--ink-soft);
  font-size: 14px;
}

.gate-form { text-align: left; }

.gate-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 8px;
}

.gate-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--tiger-cream);
  color: var(--ink);
  letter-spacing: 2px;
  transition: border-color .15s ease;
}

.gate-input:focus {
  outline: none;
  border-color: var(--tiger-orange);
}

.gate-error {
  color: var(--status-red);
  font-size: 13px;
  font-weight: 700;
  margin: 10px 0 0;
}

.gate-button {
  margin-top: 18px;
  width: 100%;
  padding: 15px;
  border-radius: var(--radius-sm);
  background: var(--tiger-orange);
  color: white;
  font-weight: 800;
  font-size: 16px;
  box-shadow: 0 8px 18px -6px rgba(239, 127, 26, 0.6);
  transition: transform .1s ease, background .15s ease;
}

.gate-button:active { transform: scale(0.98); background: var(--tiger-orange-deep); }

/* ---------- App shell ---------- */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: relative;
  background: linear-gradient(135deg, var(--tiger-orange) 0%, var(--tiger-orange-deep) 100%);
  color: white;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 18px 16px;
  box-shadow: 0 6px 16px -8px rgba(0,0,0,0.4);
}

.topbar-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.brand-sub {
  position: relative;
  margin: 2px 0 0;
  font-size: 12.5px;
  opacity: 0.9;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  color: white;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active { background: rgba(255,255,255,0.3); }

.main {
  flex: 1;
  padding: 18px 14px 32px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- Calendar card ---------- */
.calendar-card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 14px 18px;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.month-label {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
}

.nav-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--tiger-cream-dim);
  color: var(--tiger-orange-deep);
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn:active { background: var(--border); }

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: 32px 8px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
}

.day-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: var(--tiger-cream-dim);
  transition: transform .08s ease;
}

.day-cell.empty { background: transparent; }

.day-cell.status-green { background: var(--status-green-bg); color: #1e6e30; }
.day-cell.status-yellow { background: var(--status-yellow-bg); color: #8a5c00; }
.day-cell.status-red { background: var(--status-red-bg); color: #a11414; }

.day-cell .status-dot {
  position: absolute;
  bottom: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
}
.day-cell.status-green .status-dot { background: var(--status-green); }
.day-cell.status-yellow .status-dot { background: var(--status-yellow); }
.day-cell.status-red .status-dot { background: var(--status-red); }

.day-cell.is-today {
  box-shadow: inset 0 0 0 2px var(--tiger-orange);
}

.day-cell.is-past { opacity: 0.45; }

.day-cell.is-past { cursor: not-allowed; }

.day-cell:not(.empty):not(.is-past):active { transform: scale(0.93); }

.day-cell.is-selected {
  box-shadow: inset 0 0 0 2.5px var(--tiger-black);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 600;
}

.legend-item { display: inline-flex; align-items: center; gap: 6px; }

.book-buzz-btn { margin-top: 16px; }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--status-green); }
.dot-yellow { background: var(--status-yellow); }
.dot-red { background: var(--status-red); }

/* ---------- Day detail sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(34, 26, 21, 0.45);
  z-index: 40;
  animation: fade-in .18s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.day-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: var(--paper);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -12px 30px -10px rgba(0,0,0,0.35);
  padding: 10px 18px calc(env(safe-area-inset-bottom, 0px) + 20px);
  max-width: 480px;
  margin: 0 auto;
  max-height: 78dvh;
  overflow-y: auto;
  animation: slide-up .22s cubic-bezier(.32,.72,0,1);
}

@media (min-width: 480px) {
  .day-sheet { left: 50%; transform: translateX(-50%); right: auto; width: 480px; }
}

@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (min-width: 480px) {
  @keyframes slide-up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 6px auto 12px;
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-date {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 700;
}

.sheet-status {
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 20px;
}

.sheet-status.status-green { background: var(--status-green-bg); color: #1e6e30; }
.sheet-status.status-yellow { background: var(--status-yellow-bg); color: #8a5c00; }
.sheet-status.status-red { background: var(--status-red-bg); color: #a11414; }

.sheet-header .icon-btn { background: var(--tiger-cream-dim); color: var(--ink); }

.sheet-bookings {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.booking-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--tiger-cream);
  border-left: 4px solid var(--tiger-orange);
}

.booking-row.full-day { border-left-color: var(--status-red); }

.booking-time {
  font-weight: 800;
  font-size: 13px;
  color: var(--tiger-orange-deep);
  min-width: 92px;
}

.booking-row.full-day .booking-time { color: var(--status-red); }

.booking-info { flex: 1; min-width: 0; }

.booking-name {
  font-weight: 700;
  font-size: 14px;
  margin: 0 0 2px;
}

.booking-purpose {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.booking-delete-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--status-red);
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.booking-delete-btn:active { background: var(--status-red-bg); }

/* ---------- Confirm dialog ---------- */
.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.confirm-card {
  width: 100%;
  max-width: 340px;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px;
  animation: fade-in .15s ease;
}

.confirm-title {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 700;
}

.confirm-message {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-cancel-btn,
.confirm-delete-btn {
  flex: 1;
  padding: 13px;
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 14px;
}

.confirm-cancel-btn {
  background: var(--tiger-cream-dim);
  color: var(--ink);
}

.confirm-cancel-btn:active { background: var(--border); }

.confirm-delete-btn {
  background: var(--status-red);
  color: white;
}

.confirm-delete-btn:active { background: #b02525; }
.confirm-delete-btn:disabled { opacity: 0.5; }

.empty-state {
  text-align: center;
  padding: 24px 8px;
  color: var(--ink-soft);
  font-size: 14px;
}

.primary-btn {
  width: 100%;
  padding: 15px;
  border-radius: var(--radius-sm);
  background: var(--tiger-black);
  color: white;
  font-weight: 800;
  font-size: 15px;
}

.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { opacity: 0.4; }

/* ---------- Booking form ---------- */
.booking-form {
  display: flex;
  flex-direction: column;
}

.form-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-soft);
  margin: 14px 0 6px;
}

.form-label:first-child { margin-top: 0; }

.form-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--tiger-cream);
  color: var(--ink);
}

.form-input:focus {
  outline: none;
  border-color: var(--tiger-orange);
}

.form-textarea {
  resize: vertical;
  min-height: 68px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.booking-conflict {
  margin: 16px 0 4px;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: var(--status-red-bg);
  color: #a11414;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

#confirm-booking-btn { margin-top: 18px; }
