:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --muted: #94a3b8;
  --text: #1e293b;
  --text-light: #64748b;
  --accent: #3b82f6;
  --gap: 5px;
  --max-width: 1100px;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  padding: 20px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.page { max-width: var(--max-width); margin: 0 auto; }
.admin-page { width: 100%; }

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  flex-wrap: wrap;
  gap: 8px;
}
.header h1 { margin: 0; font-size: 18px; font-weight: 700; }
.header nav a { color: var(--accent); text-decoration: none; font-size: 13px; margin-left: 12px; }
.header nav a:hover { text-decoration: underline; }

/* ── Month controls ──────────────────────────────────────────────────────── */
.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.controls button {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}
.controls button:hover { background: var(--border); border-color: #cbd5e1; }
.month-label { font-weight: 700; font-size: 17px; min-width: 180px; text-align: center; }

/* ── Calendar ────────────────────────────────────────────────────────────── */
.calendar { width: 100%; }
.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--gap); margin-bottom: var(--gap); }
.weekday {
  text-align: center;
  font-weight: 600;
  font-size: 11px;
  color: var(--muted);
  padding: 6px 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.days-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--gap); }
.day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px;
  min-height: 0;
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  transition: border-color 0.12s, box-shadow 0.12s;
  overflow: visible;
}
.day:hover { border-color: #93c5fd; box-shadow: 0 2px 8px rgba(59,130,246,0.12); z-index: 2; }
.day.prev-month, .day.next-month { background: #f8fafc; }
.day.prev-month .date, .day.next-month .date { opacity: 0.35; }

/* Date number */
.date { font-weight: 600; font-size: 13px; margin-bottom: 2px; line-height: 1; flex-shrink: 0; }
.date.today {
  background: var(--accent);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

/* ── Feature image in day cell ───────────────────────────────────────────── */
.day-feature-img {
  width: 100%;
  flex: 1;
  min-height: 0;
  object-fit: cover;
  border-radius: 4px;
  display: block;
  margin: 2px 0;
}

/* ── Center icons in blank space ─────────────────────────────────────────── */
.day-center-icons {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 2px 0;
  min-height: 0;
  overflow: hidden;
}

/* Icon size scales down as count increases */
.day-center-icons[data-count="1"] .day-center-icon,
.day-center-icons[data-count="1"] .day-center-icon-img { width: 44px; height: 44px; }
.day-center-icons[data-count="1"] .day-center-icon-emoji { font-size: 34px; }

.day-center-icons[data-count="2"] .day-center-icon,
.day-center-icons[data-count="2"] .day-center-icon-img { width: 32px; height: 32px; }
.day-center-icons[data-count="2"] .day-center-icon-emoji { font-size: 26px; }

/* 3 icons → default size (28px defined on .day-center-icon below) */

/* Mask-based colored icon base */
.event-icon,
.tooltip-icon,
.event-icon-sm,
.day-center-icon {
  display: inline-block;
  flex-shrink: 0;
  background-color: var(--icon-color, #000000);
  -webkit-mask-image: var(--icon-url);
  mask-image: var(--icon-url);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}
.event-icon { width: 14px; height: 14px; }
.day-center-icon { width: 28px; height: 28px; }

/* Original-color image icons (shown as <img>) */
.event-icon-img      { width: 14px;  height: 14px;  object-fit: contain; display: inline-block; flex-shrink: 0; vertical-align: middle; }
.tooltip-icon-img    { width: 16px;  height: 16px;  object-fit: contain; display: inline-block; vertical-align: middle; margin-right: 3px; }
.event-icon-sm-img   { width: 16px;  height: 16px;  object-fit: contain; display: inline-block; vertical-align: middle; }
.day-center-icon-img { width: 28px;  height: 28px;  object-fit: contain; display: block; flex-shrink: 0; }

/* Emoji icons */
.event-icon-emoji      { font-size: 12px; line-height: 1; display: inline-block; flex-shrink: 0; vertical-align: middle; }
.tooltip-icon-emoji    { font-size: 14px; line-height: 1; display: inline-block; vertical-align: middle; margin-right: 3px; }
.event-icon-sm-emoji   { font-size: 14px; line-height: 1; display: inline-block; vertical-align: middle; }
.day-center-icon-emoji { font-size: 22px; line-height: 1; display: block; }

/* Events */
.events { display: flex; flex-direction: column; gap: 2px; overflow: hidden; flex-shrink: 0; }
.event {
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
  font-weight: 500;
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 4px;
}
.event-weekly { background: #dbeafe; color: #1d4ed8; }
.event-custom  { background: #dcfce7; color: #15803d; }
.event.cancelled { background: #f1f5f9 !important; color: var(--muted) !important; text-decoration: line-through; }

.more { font-size: 10px; color: var(--muted); padding-left: 4px; }

/* ── Tooltip ─────────────────────────────────────────────────────────────── */
.tooltip {
  display: none;
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  min-width: 200px;
  max-width: 260px;
  width: max-content;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.06);
  pointer-events: none;
  line-height: 1.5;
}
.day.flip-tooltip .tooltip { bottom: auto; top: calc(100% + 6px); }
.day.tooltip-right .tooltip { left: auto; right: 0; }
.day:hover .tooltip, .day.show-tooltip .tooltip { display: block; }
.tooltip-icon { width: 16px; height: 16px; vertical-align: middle; margin-right: 3px; }
.event-icon-sm { width: 16px; height: 16px; }
.tooltip-meta { font-size: 12px; color: var(--text-light); margin-top: 1px; }
.tooltip-desc { font-size: 12px; color: var(--text-light); margin-top: 6px; }
.tooltip-hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

/* Legend */
.legend {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Admin layout ────────────────────────────────────────────────────────── */
.admin-grid { display: grid; grid-template-columns: 380px 1fr; gap: 14px; align-items: start; }
.admin-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.card-title { margin: 0 0 12px 0; font-size: 14px; font-weight: 700; color: var(--text); }

@media (min-width: 981px) {
  .admin-right {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
  }
}

.preview-card { }
.preview-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }

/* ── Admin tabs ──────────────────────────────────────────────────────────── */
.admin-tabs-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
}
.admin-tab-btn {
  flex: 1;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  border-radius: 5px;
  background: none;
  color: var(--text-light);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.admin-tab-btn:hover { background: var(--surface); color: var(--text); }
.admin-tab-btn.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* ── Form elements ───────────────────────────────────────────────────────── */
.field-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0;
  display: block;
}
.label-hint { font-size: 10px; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }

.form-row-2 { display: flex; gap: 10px; }
.form-row-2 > * { flex: 1; min-width: 0; }

/* Icon field with original-colors toggle */
.icon-row { display: flex; gap: 10px; align-items: flex-start; }
.icon-row select { margin-top: 4px; }
.color-group { flex-shrink: 0; display: flex; flex-direction: column; gap: 4px; }
.color-group label { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.06em; cursor: pointer; user-select: none; white-space: nowrap; }
.color-group input[type=checkbox] { width: auto; margin: 0; accent-color: var(--accent); }
.color-group input[type=color] { width: 60px; height: 32px; padding: 2px 3px; border: 1px solid var(--border); border-radius: 5px; cursor: pointer; }
.color-group input[type=color]:disabled { opacity: 0.35; cursor: not-allowed; }

.field-row { display: flex; gap: 10px; }
.input-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.input-row input { margin-top: 0; flex: 1; }

input, textarea, select {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  margin-top: 5px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
textarea { height: 60px; resize: vertical; }

.day-checks { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.day-check {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.day-check input[type=checkbox] { width: auto; margin: 0; accent-color: var(--accent); }
.day-check:has(input:checked) { background: #eff6ff; border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button { font-family: inherit; font-size: 13px; padding: 7px 12px; cursor: pointer; border-radius: 6px; border: 1px solid var(--border); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; transition: background 0.12s; }
.btn-primary:hover { background: #2563eb; border-color: #2563eb; }
.btn-add { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; font-weight: 600; width: 100%; transition: background 0.12s; }
.btn-add:hover { background: #dcfce7; }
.btn-danger { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-remove { background: none; border: none; color: var(--muted); font-size: 16px; line-height: 1; padding: 3px 7px; border-radius: 4px; cursor: pointer; flex-shrink: 0; transition: color 0.12s, background 0.12s; }
.btn-remove:hover { color: #dc2626; background: #fef2f2; }
.btn-edit { background: none; border: none; color: var(--muted); font-size: 14px; padding: 3px 7px; border-radius: 4px; cursor: pointer; flex-shrink: 0; transition: color 0.12s, background 0.12s; }
.btn-edit:hover { color: var(--accent); background: #eff6ff; }
.btn-sm { font-size: 11px; padding: 4px 8px; }

/* ── Edit mode banner ────────────────────────────────────────────────────── */
.edit-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  font-size: 13px;
  color: var(--accent);
}
.edit-banner strong { color: var(--text); }
.edit-banner .btn-remove { margin-left: auto; }

/* ── Existing events list ────────────────────────────────────────────────── */
.existing-list-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 16px 0 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.event-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 5px;
  background: var(--bg);
}
.event-list-info { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; font-size: 13px; flex: 1; min-width: 0; }
.event-list-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

/* Pills */
.pill { font-size: 11px; padding: 2px 7px; border-radius: 20px; font-weight: 500; white-space: nowrap; }
.pill-blue { background: #dbeafe; color: #1d4ed8; }
.pill-green { background: #dcfce7; color: #15803d; }
.pill-red { background: #fee2e2; color: #dc2626; }

/* ── Media upload area ───────────────────────────────────────────────────── */
.upload-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--text-light);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  line-height: 1.6;
}
.upload-drop:hover, .upload-drop.drag-over { border-color: var(--accent); background: #eff6ff; color: var(--text); }
.upload-drop-icon { font-size: 32px; margin-bottom: 8px; }

/* ── Media gallery ───────────────────────────────────────────────────────── */
.media-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}
.media-thumb {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  cursor: default;
  transition: border-color 0.12s;
  position: relative;
}
.media-thumb:hover { border-color: #93c5fd; }
.media-thumb img, .media-thumb .thumb-svg {
  width: 100%;
  height: 64px;
  object-fit: contain;
  display: block;
  padding: 6px;
}
.media-thumb .thumb-name {
  font-size: 10px;
  color: var(--text-light);
  padding: 3px 5px 5px;
  text-align: center;
  word-break: break-all;
  line-height: 1.3;
}
.media-thumb .thumb-copy {
  display: none;
  position: absolute;
  top: 3px;
  right: 3px;
}
.media-thumb:hover .thumb-copy { display: block; }

/* ── Site footer ─────────────────────────────────────────────────────────── */
.site-footer {
  margin-top: 28px;
  padding: 14px 18px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.site-footer p { margin: 0; }

/* ── Shared utilities ────────────────────────────────────────────────────── */
.small { font-size: 12px; }
.muted { color: var(--muted); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body { padding: 8px; }
  .header { padding: 10px 12px; }
  .header h1 { font-size: 15px; }
  .weekday { font-size: 9px; padding: 4px 1px; letter-spacing: 0; }
  .date { font-size: 10px; }
  .month-label { font-size: 15px; min-width: 130px; }
  .field-row, .form-row-2 { flex-direction: column; gap: 0; }
  .icon-row { flex-direction: column; gap: 8px; }

  /* Keep 1:1 ratio but tighten padding */
  .day { padding: 4px 3px; }

  /* Hide event text labels on mobile — date cells are too small */
  .events { display: none; }
  .more { display: none; }

  /* Scale down center icons to fit 1:1 cells */
  .day-center-icons { gap: 2px; }
  .day-center-icon, .day-center-icon-img { width: 20px; height: 20px; }
  .day-center-icon-emoji { font-size: 16px; }

  .day-center-icons[data-count="1"] .day-center-icon,
  .day-center-icons[data-count="1"] .day-center-icon-img { width: 28px; height: 28px; }
  .day-center-icons[data-count="1"] .day-center-icon-emoji { font-size: 22px; }

  .day-center-icons[data-count="2"] .day-center-icon,
  .day-center-icons[data-count="2"] .day-center-icon-img { width: 22px; height: 22px; }
  .day-center-icons[data-count="2"] .day-center-icon-emoji { font-size: 18px; }

  /* Fixed tooltip pinned to bottom on mobile */
  .day.show-tooltip .tooltip {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    bottom: 12px !important;
    top: auto !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    z-index: 10000 !important;
    pointer-events: auto;
    font-size: 14px;
    line-height: 1.6;
    padding: 14px 16px;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  }
}

@media (max-width: 400px) {
  .days-grid { gap: 3px; }
  .weekdays { gap: 3px; }
  .weekday { font-size: 8px; }
  .date { font-size: 9px; }
  .day { border-radius: 5px; padding: 3px 2px; }
  .date.today { width: 18px; height: 18px; font-size: 9px; }
}
