* {
  box-sizing: border-box;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #f8f9fa;
}
header {
  background-color: #2c3e50;
  color: white;
  padding: 12px 20px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  z-index: 3;
}
header h1 {
  margin: 0;
  font-size: 1.4rem;
  text-wrap: balance;
}
.header-button {
  flex-shrink: 0;
  background: #ffffff;
  color: #2c3e50;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
#main-container {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}
#map {
  flex: 1;
  height: 100%;
  width: 100%;
  z-index: 1;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#sidebar {
  width: 320px;
  background: #f8f9fa;
  border-left: 1px solid #dee2e6;
  overflow-y: auto;
  padding: 15px;
  padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2;
  box-shadow: -2px 0 5px rgba(0,0,0,0.05);
}
.hint {
  margin: 0;
  font-size: 0.85rem;
  color: #6c757d;
  text-align: center;
}
#places-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.location-card {
  background: white;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 12px 15px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.location-card:hover,
.location-card:focus-visible {
  border-color: #3498db;
  box-shadow: 0 3px 8px rgba(0,0,0,0.08);
  transform: translateY(-2px);
  outline: none;
}
.badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.location-info {
  flex: 1;
  min-width: 0;
}
.location-info h3 {
  margin: 0 0 5px 0;
  font-size: 1rem;
  color: #2c3e50;
  overflow-wrap: anywhere;
}
.location-info p {
  margin: 0;
  font-size: 0.85rem;
  color: #6c757d;
  overflow-wrap: anywhere;
}
.added-tag {
  display: inline-block;
  margin-top: 6px;
  font-size: 0.75rem;
  color: #16a085;
  font-weight: 600;
}

.leaflet-popup-content-wrapper {
  direction: rtl;
  text-align: right;
  border-radius: 8px;
  padding: 5px;
}
.popup-title {
  font-weight: bold;
  font-size: 1.1rem;
  color: #2c3e50;
  margin-bottom: 5px;
}
.popup-desc {
  color: #555;
  font-size: 0.9rem;
}
.popup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.popup-actions a,
.popup-actions button {
  font-size: 0.85rem;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}
.popup-actions a {
  background: #3498db;
  color: #ffffff;
}
.leaflet-container .popup-actions a {
  color: #ffffff;
}
.popup-actions button {
  background: #ffffff;
  color: #c0392b;
  border: 1px solid #e6b0aa;
}

.locate-control {
  width: 34px;
  height: 34px;
  background: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #2c3e50;
}
.locate-control.active {
  color: #1a73e8;
}
.locate-control svg {
  width: 20px;
  height: 20px;
}

dialog {
  border: none;
  border-radius: 12px;
  padding: 20px;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  direction: rtl;
}
dialog::backdrop {
  background: rgba(44, 62, 80, 0.45);
}
dialog h2 {
  margin: 0 0 14px 0;
  font-size: 1.2rem;
  color: #2c3e50;
}
dialog h3 {
  margin: 0 0 6px 0;
  font-size: 1rem;
  color: #2c3e50;
}
dialog p,
dialog li {
  font-size: 0.9rem;
  color: #555;
  line-height: 1.5;
}
dialog section {
  padding-block: 12px;
  border-top: 1px solid #e9ecef;
}
dialog ol {
  margin: 0 0 12px 0;
  padding-inline-start: 20px;
}
#add-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#add-form label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #2c3e50;
}
#add-form input,
#add-form textarea {
  font-size: 1rem;
  padding: 10px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  margin-bottom: 8px;
  resize: vertical;
}
#add-form input:focus,
#add-form textarea:focus {
  outline: 2px solid #3498db;
  border-color: #3498db;
}
.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
dialog button,
.button-link {
  font-size: 0.95rem;
  padding: 10px 16px;
  border-radius: 6px;
  border: 1px solid #ced4da;
  background: #ffffff;
  color: #2c3e50;
  cursor: pointer;
}
dialog .primary {
  background: #2c3e50;
  border-color: #2c3e50;
  color: #ffffff;
}
.button-link {
  display: inline-block;
  text-decoration: none;
}
dialog button:disabled {
  opacity: 0.6;
  cursor: wait;
}
.form-error {
  color: #c0392b;
  margin: 0;
}
.note {
  font-size: 0.85rem;
  color: #8a6d3b;
}

#toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: #2c3e50;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.9rem;
  z-index: 1000;
  max-width: calc(100vw - 32px);
  text-align: center;
}

@media (max-width: 768px) {
  header h1 {
    font-size: 1.05rem;
  }
  .header-button {
    font-size: 0.85rem;
    padding: 7px 10px;
  }
  #main-container {
    flex-direction: column-reverse;
  }
  #sidebar {
    width: 100%;
    height: 40%;
    border-left: none;
    border-top: 1px solid #dee2e6;
  }
  #map {
    height: 60%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .location-card {
    transition: none;
  }
  .location-card:hover {
    transform: none;
  }
}
