/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #fafafa;
  --card: #ffffff;
  --border: #e5e7eb;
  --ring: #d1d5db;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0f172a;
  --primary-fg: #ffffff;
  --accent: #f1f5f9;
  --accent-fg: #0f172a;
  --destructive: #ef4444;
  --destructive-fg: #ffffff;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 0.5rem;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --sidebar-width: 240px;
  --topbar-height: 3rem;
}
html { font-size: 14px; scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }
a { color: var(--primary); text-decoration: underline; }
a:hover { opacity: 0.8; }

/* ===== Utility ===== */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid { display: grid; }

/* ===== SVG Icon base ===== */
.card-title svg, .btn svg, .sidebar-link svg, .sidebar-brand svg { flex-shrink: 0; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--accent);
  border-right: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow-x: visible;
  overflow-y: auto;
}
.sidebar-header {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar-brand svg {
  display: block;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  overflow: visible;
}
.sidebar-brand > div {
  flex: 1;
  min-width: 0;
}
.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}
.sidebar-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.2;
}
.sidebar-close {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
}
.sidebar-close:hover { color: var(--text); }
.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sidebar-link:hover {
  background: rgba(255,255,255,0.6);
  color: var(--text);
  opacity: 1;
}
.sidebar-link.active {
  background: var(--card);
  color: var(--text);
  border-left-color: var(--primary);
  font-weight: 600;
}
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 1rem;
}

/* ===== Mobile Top Bar ===== */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 150;
  height: var(--topbar-height);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
}
.hamburger-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 0.25rem;
  display: flex;
  align-items: center;
}
.topbar-title {
  font-size: 0.95rem;
  font-weight: 700;
}

/* ===== Sidebar Backdrop (Mobile) ===== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 190;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}
.sidebar-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* ===== Main Content ===== */
.main-content {
  margin-left: var(--sidebar-width);
  max-width: 1200px;
  padding: 0 1rem;
}

/* ===== Scroll margin for anchor navigation ===== */
[data-nav-section] {
  scroll-margin-top: 1.5rem;
}

/* ===== Components ===== */
/* Card */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { padding: 1.25rem 1.5rem 0.75rem; }
.card-header.collapsible { cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
.card-header.collapsible:hover { background: var(--accent); border-radius: var(--radius) var(--radius) 0 0; }
.card.collapsed .card-header.collapsible { border-radius: var(--radius); }
.collapse-chevron { flex-shrink: 0; color: var(--text-muted); transition: transform 0.2s; }
.card.collapsed .collapse-chevron { transform: rotate(-90deg); }
.card.collapsed .card-content { display: none; }
.card-title { font-size: 1.1rem; font-weight: 600; letter-spacing: -0.01em; display: flex; align-items: center; gap: 0.5rem; }
.card-description { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }
.card-content { padding: 0.75rem 1.5rem 1.25rem; }

/* Button */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; border-radius: var(--radius); font-size: 0.875rem; font-weight: 500; padding: 0.5rem 1rem; border: 1px solid transparent; cursor: pointer; transition: all 0.15s; white-space: nowrap; font-family: var(--font); }
.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: #1e293b; }
.btn-outline { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--accent); }
.btn-destructive { background: var(--destructive); color: var(--destructive-fg); }
.btn-destructive:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--accent); }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; width: 2.25rem; height: 2.25rem; }

/* Input / Select */
.input, .select, .textarea { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.75rem; font-size: 0.875rem; font-family: var(--font); background: var(--card); color: var(--text); transition: border-color 0.15s, box-shadow 0.15s; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 3px rgba(15,23,42,0.08); }
.textarea { resize: vertical; min-height: 4rem; }
.label { font-size: 0.85rem; font-weight: 500; display: block; margin-bottom: 0.35rem; }
.form-group { display: flex; flex-direction: column; }
.form-error { color: var(--destructive); font-size: 0.75rem; margin-top: 0.25rem; }

/* Badge */
.badge { display: inline-flex; align-items: center; border-radius: 9999px; padding: 0.15rem 0.65rem; font-size: 0.75rem; font-weight: 500; border: 1px solid var(--border); background: var(--accent); color: var(--accent-fg); }
.badge-primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.badge-success { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.badge-warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }

/* Shop name link (looks normal, underline on hover) */
.shop-name-link { color: inherit; text-decoration: none; }
.shop-name-link:hover { text-decoration: underline; color: var(--primary); opacity: 1; }

/* Table */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
thead th { background: var(--accent); padding: 0.6rem 0.75rem; text-align: left; font-weight: 600; white-space: nowrap; border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; }
thead th:hover { background: #e2e8f0; }
tbody td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--accent); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; opacity: 0; visibility: hidden; transition: opacity 0.2s, visibility 0.2s; }
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-md); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; transform: scale(0.95); transition: transform 0.2s; }
.modal-overlay.active .modal { transform: scale(1); }
.modal-header { padding: 1.25rem 1.5rem 0.5rem; display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 1.1rem; font-weight: 600; }
.modal-body { padding: 0.75rem 1.5rem; }
.modal-footer { padding: 0.75rem 1.5rem 1.25rem; display: flex; justify-content: flex-end; gap: 0.5rem; }

/* Toast */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 2000; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: var(--primary); color: var(--primary-fg); padding: 0.75rem 1.25rem; border-radius: var(--radius); font-size: 0.85rem; box-shadow: var(--shadow-md); animation: slideIn 0.3s ease; }
.toast.error { background: var(--destructive); }
.toast.success { background: #15803d; }
@keyframes slideIn { from { opacity: 0; transform: translateY(1rem); } to { opacity: 1; transform: translateY(0); } }

/* Recommendation Card */
.recommend-card { background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); color: #fff; border-radius: var(--radius); padding: 2rem; text-align: center; box-shadow: var(--shadow-md); }
.recommend-card .shop-name { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; letter-spacing: -0.02em; }
.recommend-card .shop-meta { font-size: 0.9rem; opacity: 0.85; margin-bottom: 0.5rem; }
.recommend-card .shop-comment { font-size: 0.9rem; opacity: 0.75; font-style: italic; }
.recommend-card .shop-ref { font-size: 0.8rem; opacity: 0.6; margin-top: 0.75rem; word-break: break-all; }
.recommend-card .shop-ref a { color: #93c5fd; }
.recommend-card .recommend-label { font-size: 0.8rem; opacity: 0.6; margin-bottom: 0.5rem; display: flex; align-items: center; justify-content: center; gap: 0.4rem; }
.recommend-card .recommend-label svg { opacity: 0.7; }
.recommend-empty { background: var(--accent); border: 2px dashed var(--border); border-radius: var(--radius); padding: 2rem; text-align: center; color: var(--text-muted); }

/* Stars */
.stars { color: var(--warning); letter-spacing: 0.1em; }

/* Sort indicator */
.sort-indicator { font-size: 0.7rem; color: var(--text-muted); margin-left: 0.2rem; }

/* Score dots */
.score-dots { display: inline-flex; gap: 2px; }
.score-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.score-dot.active { background: var(--primary); }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; }
.stat-card { background: var(--accent); border-radius: var(--radius); padding: 1rem; text-align: center; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ===== Filter Section ===== */
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; align-items: end; }
.filter-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ===== Section spacing ===== */
.section { margin-top: 1.25rem; }

/* ===== Responsive ===== */
@media (max-width: 767px) {
  html { font-size: 13px; }

  /* Fix date input / select overflow in filter grid */
  .filter-grid .form-group { min-width: 0; }
  .filter-grid .input,
  .filter-grid .select { min-width: 0; }

  /* Sidebar: hidden by default on mobile */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-close { display: block; }
  .sidebar-backdrop { display: block; }

  /* Mobile top bar: visible */
  .mobile-topbar { display: flex; }

  /* Main content: no sidebar margin */
  .main-content { margin-left: 0; }

  /* Scroll offset accounts for topbar */
  [data-nav-section] {
    scroll-margin-top: calc(var(--topbar-height) + 0.75rem);
  }

  .filter-grid { grid-template-columns: 1fr 1fr; }
  .recommend-card .shop-name { font-size: 1.25rem; }
  .recommend-card { padding: 1.5rem; }
  .card-header { padding: 1rem 1rem 0.5rem; }
  .card-content { padding: 0.5rem 1rem 1rem; }
  .modal { max-width: 100%; }
  .modal-header, .modal-body, .modal-footer { padding-left: 1rem; padding-right: 1rem; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .toast-container { bottom: 1rem; right: 1rem; left: 1rem; }
  .toast { width: 100%; }
}
@media (min-width: 768px) {
  /* Desktop: hide mobile-only elements */
  .mobile-topbar { display: none; }
  .sidebar-backdrop { display: none; }
  .sidebar-close { display: none; }
}
@media (min-width: 768px) and (max-width: 1023px) {
  .filter-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .filter-grid { grid-template-columns: repeat(5, 1fr); }
}
