:root {
  --bg: #f5f5f0;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666666;
  --border: #e0e0e0;
  --primary: #2d5a27;
  --primary-hover: #3d7a35;
  --danger: #c0392b;
  --danger-hover: #e74c3c;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --sidebar-width: 380px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
}

/* ── Language Switcher ── */

.lang-switcher {
  display: flex;
  gap: 0.25rem;
}

.lang-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: none;
  transition: all 0.15s;
  opacity: 0.5;
}

.lang-btn:hover {
  opacity: 0.8;
}

.lang-btn.active {
  opacity: 1;
  border-color: var(--primary);
}

.lang-flag {
  width: 28px;
  height: 18px;
  display: block;
  border-radius: 2px;
  overflow: hidden;
}

.login-lang {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
}

/* ── Login Page ── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-container {
  background: var(--surface);
  padding: 3rem 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  width: 100%;
  max-width: 360px;
}

.estonia-outline {
  width: 220px;
  margin: 0 auto 0.75rem;
  display: block;
  color: var(--primary);
}

.login-container h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

#login-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
  transition: border-color 0.15s;
}

#login-form input:focus {
  border-color: var(--primary);
}

#login-form button {
  width: 100%;
  padding: 0.75rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  transition: background 0.15s;
}

#login-form button:hover {
  background: var(--primary-hover);
}

.error {
  color: var(--danger);
  margin-top: 1rem;
  font-size: 0.875rem;
}

/* ── App Layout ── */

.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ── */

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.sidebar-header .user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.user-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: underline;
  padding: 0;
}

.logout-btn:hover {
  color: var(--text);
}

/* ── Filters ── */

.filters {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  flex-shrink: 0;
}

.filters select,
.filters input[type="date"] {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  background: var(--surface);
  outline: none;
}

.filters select:focus,
.filters input[type="date"]:focus {
  border-color: var(--primary);
}

.filter-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: underline;
  padding: 0;
}

/* ── View Toggle ── */

.view-toggle {
  display: flex;
  padding: 0.5rem 1.25rem;
  gap: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.view-toggle button {
  flex: 1;
  padding: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.view-toggle button:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.view-toggle button:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
  border-left: none;
}

.view-toggle button.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ── Event Timeline ── */

.timeline {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}

/* ── Calendar View ── */

#calendar-view {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1.25rem;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.cal-nav-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: capitalize;
}

.cal-nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 28px;
  height: 28px;
  font-size: 1.1rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-nav-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.cal-month {
  margin-bottom: 1rem;
}

.cal-month-name {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-align: center;
}

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

.cal-header {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  padding: 0.2rem 0;
  text-transform: uppercase;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  transition: background 0.1s;
}

.cal-day:hover {
  background: var(--bg);
}

.cal-day.cal-empty {
  cursor: default;
}

.cal-day.cal-today .cal-day-num {
  background: var(--text);
  color: white;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-day.cal-has-events {
  font-weight: 600;
}

.cal-dots {
  display: flex;
  gap: 2px;
  margin-top: 1px;
}

.cal-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.timeline-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

.date-group {
  margin-bottom: 1.5rem;
}

.date-group-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}

.event-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: box-shadow 0.15s;
  border: 2px solid transparent;
}

.event-card:hover {
  box-shadow: var(--shadow);
}

.event-card.active {
  border-color: var(--primary);
}

.event-card-header {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.event-card-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 0.35rem;
  flex-shrink: 0;
}

.event-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
}

.event-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 1.25rem;
}

.event-card-location {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 1.25rem;
  margin-top: 0.15rem;
}

.event-card-description {
  font-size: 0.85rem;
  margin: 0.5rem 0 0 1.25rem;
  color: var(--text);
}

.event-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
  margin-left: 1.25rem;
}

.rsvp-pills {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.rsvp-pill {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  color: white;
  font-weight: 500;
}

.rsvp-pill.maybe {
  opacity: 0.6;
}

.event-actions {
  display: flex;
  gap: 0.35rem;
}

.event-actions button {
  background: none;
  border: none;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

.event-actions button:hover {
  background: var(--border);
  color: var(--text);
}

/* ── Add Event Button ── */

.add-event-btn {
  margin: 0.75rem 1.25rem;
  padding: 0.65rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
  flex-shrink: 0;
}

.add-event-btn:hover {
  background: var(--primary-hover);
}

/* ── Map ── */

#map {
  width: 100%;
  height: 100%;
}

/* ── Dialog / Modal ── */

dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  padding: 0;
  max-width: 480px;
  width: 90vw;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.dialog-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-header h2 {
  font-size: 1.1rem;
}

.dialog-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  line-height: 1;
}

.dialog-body {
  padding: 1.25rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}

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

.form-row {
  display: flex;
  gap: 0.75rem;
}

.form-row .form-group {
  flex: 1;
}

.location-search {
  display: flex;
  gap: 0.5rem;
}

.location-search input {
  flex: 1;
}

.location-search button {
  padding: 0.6rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  white-space: nowrap;
}

.location-search button:hover {
  background: var(--border);
}

.location-results {
  list-style: none;
  max-height: 150px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.35rem;
}

.location-results:empty {
  display: none;
}

.location-results li {
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.location-results li:last-child {
  border-bottom: none;
}

.location-results li:hover {
  background: var(--bg);
}

.location-selected {
  font-size: 0.8rem;
  color: var(--primary);
  margin-top: 0.35rem;
}

.dialog-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.dialog-footer button {
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  border: 1px solid var(--border);
  background: var(--surface);
}

.dialog-footer .btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.dialog-footer .btn-primary:hover {
  background: var(--primary-hover);
}

.dialog-footer .btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.dialog-footer .btn-danger:hover {
  background: var(--danger-hover);
}

/* ── RSVP Buttons in Detail ── */

.rsvp-buttons {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.rsvp-buttons button {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.8rem;
  transition: all 0.15s;
}

.rsvp-buttons button.active-going {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.rsvp-buttons button.active-maybe {
  background: #f39c12;
  color: white;
  border-color: #f39c12;
}

.rsvp-buttons button:hover {
  background: var(--bg);
}

.rsvp-buttons button.active-going:hover,
.rsvp-buttons button.active-maybe:hover {
  opacity: 0.9;
}

/* ── Share Page ── */

.share-page {
  max-width: 600px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.share-page h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.share-event-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.share-event-card .meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.share-event-card .description {
  margin-bottom: 1rem;
}

.share-map {
  height: 250px;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}

.share-rsvps {
  margin-top: 1rem;
}

.share-rsvps h3 {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.share-login-link {
  text-align: center;
  margin-top: 2rem;
}

.share-login-link a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.share-login-link a:hover {
  text-decoration: underline;
}

.share-not-found {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}

/* ── Leaflet overrides ── */

.custom-marker {
  background: none !important;
  border: none !important;
}

/* ── Loading ── */

.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* ── Mobile ── */

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 300px;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  :root {
    --sidebar-width: 100%;
  }

  .filters {
    padding: 0.5rem 1rem;
  }

  .sidebar-header {
    padding: 0.75rem 1rem;
  }

  .timeline {
    padding: 0.75rem 1rem;
  }

  .add-event-btn {
    margin: 0.5rem 1rem;
  }
}
