/* ============================================================
   Thailand Travel — Modern UI with Dark/Light Mode
   ============================================================ */

/* ----- CSS Variables (Theme) ----- */
:root {
  --bg:           #f5f7fa;
  --surface:      #ffffff;
  --surface-2:    #f0f2f5;
  --text:         #1a1a1a;
  --text-muted:   #6b7280;
  --primary:      #e63946;       /* ไทยแดง */
  --primary-dark: #c1121f;
  --accent:       #f1a208;       /* ทอง */
  --border:       #e5e7eb;
  --shadow:       0 4px 12px rgba(0,0,0,0.08);
  --radius:       12px;
  --transition:   0.2s ease;
}

[data-theme="dark"] {
  --bg:         #0f172a;
  --surface:    #1e293b;
  --surface-2:  #334155;
  --text:       #f1f5f9;
  --text-muted: #94a3b8;
  --border:     #334155;
  --shadow:     0 4px 12px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Sarabun', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

/* ============ NAVBAR ============ */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brand .logo { font-size: 1.5rem; }
.nav-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* ============ BUTTONS ============ */
.btn-primary, .btn-ghost {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
  font-family: inherit;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

a.btn-ghost { text-decoration: none; display: inline-block; }

.btn-close {
  position: absolute;
  top: 0.5rem; right: 0.75rem;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}
.btn-close:hover { color: var(--primary); }

/* ============ MAIN LAYOUT ============ */
.main-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  padding: 1rem;
  height: calc(100vh - 70px);
}

.sidebar {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.sidebar h3 { margin-bottom: 1rem; color: var(--primary); }
.sidebar h4 { margin: 0.75rem 0; font-size: 1rem; }
.sidebar label {
  display: block;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}
.sidebar select {
  width: 100%;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
.sidebar hr { margin: 1rem 0; border: none; border-top: 1px solid var(--border); }

/* Place list */
.place-list { display: flex; flex-direction: column; gap: 0.5rem; }
.place-item {
  padding: 0.75rem;
  background: var(--surface-2);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
}
.place-item:hover {
  transform: translateX(3px);
  border-left-color: var(--primary);
}
.place-item h5 { font-size: 0.95rem; margin-bottom: 0.25rem; }
.place-item small { color: var(--text-muted); font-size: 0.8rem; }
.place-item .rating-stars { color: var(--accent); font-size: 0.85rem; margin-top: 0.25rem; }

/* ============ MAP ============ */
.content { position: relative; }
#map {
  width: 100%;
  height: 100%;
  min-height: 500px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ============ DETAIL PANEL ============ */
.detail-panel {
  position: absolute;
  top: 1rem; right: 1rem;
  width: 380px;
  max-height: calc(100% - 2rem);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  overflow-y: auto;
  box-shadow: var(--shadow);
  z-index: 500;
}
.detail-panel img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 0.75rem;
}
.detail-panel h2 { margin-bottom: 0.25rem; color: var(--primary); }
.detail-panel .location-tag { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.75rem; }
.detail-panel .description { margin: 0.75rem 0; line-height: 1.6; }

/* Star rating (interactive) */
.star-rating {
  display: flex;
  gap: 0.25rem;
  margin: 0.5rem 0;
  font-size: 1.5rem;
}
.star-rating span {
  cursor: pointer;
  color: #ccc;
  transition: var(--transition);
}
.star-rating span.active,
.star-rating span:hover,
.star-rating span:hover ~ span:not(.active) { color: var(--accent); }

/* Reviews */
.review-box {
  background: var(--surface-2);
  padding: 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}
.review-box .review-author {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary);
}
.review-box .review-date { font-size: 0.75rem; color: var(--text-muted); }
.review-box .review-text { margin-top: 0.25rem; }

textarea {
  width: 100%;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
}

/* ============ MODAL ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-box {
  position: relative;
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.modal-box.modal-wide { max-width: 600px; max-height: 80vh; overflow-y: auto; }
.modal-box h2 { margin-bottom: 1rem; color: var(--primary); }
.modal-box input, .modal-box select, .modal-box textarea {
  width: 100%;
  padding: 0.6rem;
  margin-bottom: 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
.modal-box button { width: 100%; padding: 0.6rem; }
.error-msg { color: var(--primary); font-size: 0.85rem; margin-top: 0.5rem; min-height: 1.2em; }
.small { font-size: 0.85rem; margin-top: 0.5rem; text-align: center; }
.small a { color: var(--primary); text-decoration: none; }

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--primary);
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 2000;
  animation: slide-in 0.3s ease;
}
@keyframes slide-in { from { transform: translateX(100%); opacity: 0; } }

/* ============ UTILS ============ */
.hidden { display: none !important; }

/* Top places list */
.top-item {
  display: flex;
  gap: 1rem;
  padding: 0.75rem;
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  align-items: center;
  transition: var(--transition);
}
.top-item:hover { transform: scale(1.02); }
.top-rank {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 40px;
  text-align: center;
}
.top-item img { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; }
.top-item-info h4 { margin-bottom: 0.25rem; }
.top-item-info small { color: var(--text-muted); }

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .sidebar { max-height: 300px; }
  #map { min-height: 400px; }
  .detail-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 70vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .nav-actions { gap: 0.25rem; }
  .btn-primary, .btn-ghost { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
}

/* ============ ADMIN PAGE ============ */
.admin-container {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 1rem;
}
.admin-container h1 { margin-bottom: 1.5rem; color: var(--primary); }
.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 768px) { .admin-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card h3 { margin-bottom: 1rem; }
.card input, .card select, .card textarea {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
table th, table td {
  padding: 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
table th { background: var(--surface-2); }
.action-btns { display: flex; gap: 0.25rem; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; border: none; border-radius: 4px; cursor: pointer; }
.btn-edit { background: var(--accent); color: white; }
.btn-del { background: var(--primary); color: white; }