:root {
  --bg: #faf8f4;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e5e1d8;
  --accent: #2f5d3f;
  --accent-soft: #e6efe8;
  --warn: #b25a1f;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }

#app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 20px;
  overflow-y: auto;
  position: relative; /* anchor for the collapse button */
}

.sidebar h1 { font-size: 20px; margin: 0 0 4px; }
.sidebar .subtitle { color: var(--muted); margin: 0 0 24px; font-size: 13px; }

.filter { margin-bottom: 16px; }
.filter label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 6px; }
.filter select { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: white; font-size: 14px; }
.filter.checkbox label { text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 14px; }

.states-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
#states-summary { font-size: 13px; color: var(--ink); }
.states-actions { display: flex; gap: 6px; }
.states-actions button {
  border: 1px solid var(--line); background: white; border-radius: 5px;
  font-size: 11px; padding: 2px 8px; cursor: pointer; color: var(--muted);
}
.states-actions button:hover { border-color: var(--accent); color: var(--accent); }
.states-list {
  max-height: 190px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; background: white;
}
.state-item {
  display: flex; align-items: center; gap: 8px; font-size: 13px;
  padding: 3px 0; cursor: pointer; text-transform: none; letter-spacing: 0;
  color: var(--ink); margin: 0;
}
.state-item input { margin: 0; }

.view-tabs { display: flex; gap: 4px; }
.view-tabs button { flex: 1; padding: 8px; border: 1px solid var(--line); background: white; border-radius: 6px; cursor: pointer; font-size: 13px; }
.view-tabs button.active { background: var(--accent); color: white; border-color: var(--accent); }

button.primary {
  width: 100%; padding: 10px; border: 0; border-radius: 6px;
  background: var(--accent); color: white; font-weight: 600; cursor: pointer;
  margin-top: 12px;
}
button.primary:disabled { opacity: 0.6; cursor: wait; }

.meta { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.meta div { margin-bottom: 4px; }

main { padding: 20px; overflow: hidden; display: flex; flex-direction: column; gap: 12px; }
.view { flex: 1; min-height: 0; }
.view.hidden { display: none; }

.empty-banner {
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 8px;
  padding: 12px 16px; font-size: 14px;
}
.empty-banner.hidden { display: none; }

/* List view: a month toolbar mirroring the map's, then the scrolling cards. */
#list { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
#list.hidden { display: none; }
#list-toolbar {
  display: flex; align-items: center; gap: 10px;
  background: white; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; flex: 0 0 auto;
}
#list-toolbar button {
  border: 1px solid var(--line); background: white; border-radius: 6px;
  cursor: pointer; font-size: 14px; padding: 4px 10px; color: var(--ink);
}
#list-toolbar button:hover { border-color: var(--accent); color: var(--accent); }
#list-prev, #list-next { font-size: 18px; line-height: 1; padding: 2px 10px; }
#list-month { font-weight: 600; font-size: 15px; min-width: 150px; text-align: center; }
#list-count { font-size: 13px; color: var(--muted); }
#list-today { margin-left: auto; font-size: 13px; }
#list-body { flex: 1; min-height: 0; overflow-y: auto; padding-right: 8px; }
.card {
  background: white; border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer;
}
.card:hover { border-color: var(--accent); }
.card .title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.card .meta-row { font-size: 13px; color: var(--muted); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; margin-right: 6px; }
.chip.fide { background: var(--accent-soft); color: var(--accent); }
.chip.aicf { background: #fff3e0; color: var(--warn); }
.chip.format { background: #eef0f3; color: #444; }
.chip.variant { background: #f1ecd9; color: #6b5b1f; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: #eef0f3; color: #444; font-size: 11px; font-weight: 500;
  margin-left: 6px; vertical-align: middle;
}

.variants {
  margin: 8px 0 0; padding-left: 20px; font-size: 14px;
}
.variants li { margin-bottom: 4px; }

/* FullCalendar overrides */
.fc { background: white; border-radius: 8px; padding: 12px; height: 100% !important; }
.fc-event { cursor: pointer; }

/* Leaflet map view */
#map-view { display: flex; flex-direction: column; gap: 10px; }
#map-view.hidden { display: none; }
#map-toolbar {
  display: flex; align-items: center; gap: 10px;
  background: white; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px;
}
#map-toolbar button {
  border: 1px solid var(--line); background: white; border-radius: 6px;
  cursor: pointer; font-size: 14px; padding: 4px 10px; color: var(--ink);
}
#map-toolbar button:hover { border-color: var(--accent); color: var(--accent); }
#map-prev, #map-next { font-size: 18px; line-height: 1; padding: 2px 10px; }
#map-month { font-weight: 600; font-size: 15px; min-width: 150px; text-align: center; }
#map-today { margin-left: auto; font-size: 13px; }
#map { flex: 1; min-height: 0; border-radius: 8px; overflow: hidden; background: white; }
.leaflet-container { height: 100%; width: 100%; font: inherit; }
.map-tip { font-size: 12px; line-height: 1.45; }
.map-tip strong { font-size: 13px; }

/* Collapse the left pane in place. A small "«" button sits at the top-right of
   the pane; when collapsed the pane's grid column goes to zero width and a small
   "☰" button appears to bring it back. Works on every screen size, but it's the
   default on mobile so the map/calendar/list get the full width. */
#sidebar-collapse {
  position: absolute; top: 10px; right: 10px; z-index: 5;
  width: 28px; height: 28px; padding: 0; line-height: 1;
  border: 1px solid var(--line); border-radius: 6px;
  background: white; color: var(--muted); font-size: 16px; cursor: pointer;
}
#sidebar-collapse:hover { border-color: var(--accent); color: var(--accent); }

#sidebar-show {
  display: none; /* only shown when the pane is collapsed */
  position: fixed; top: 12px; left: 12px; z-index: 60;
  width: 38px; height: 38px; padding: 0; line-height: 1;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 18px; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* Collapsed state (class on <body>, since the "show" button lives outside #app):
   hide the pane and let the content take the whole width. Because the hidden
   pane is removed from the grid, the remaining child (main) needs a single
   full-width column — otherwise it would land in a leftover narrow column. */
body.sidebar-collapsed #app { grid-template-columns: 1fr; }
body.sidebar-collapsed .sidebar { display: none; }
body.sidebar-collapsed #sidebar-show { display: block; }
/* Nudge the content down so the floating "show" button doesn't cover the
   calendar header / view tabs / map toolbar at the top of the pane. */
body.sidebar-collapsed main { padding-top: 56px; }

@media (max-width: 768px) {
  main { padding: 12px; }
}

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-card { background: white; border-radius: 10px; padding: 24px; max-width: 540px; width: 90%; max-height: 80vh; overflow-y: auto; position: relative; }
.modal-card .close { position: absolute; top: 12px; right: 12px; border: 0; background: transparent; font-size: 24px; cursor: pointer; color: var(--muted); }
.modal-card h2 { margin-top: 0; }
.modal-card dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 14px; }
.modal-card dt { color: var(--muted); }
.modal-card a { color: var(--accent); }
