:root {
  --bg:        #f5f5f5;
  --surface:   #ffffff;
  --border:    #e0e0e0;
  --text:      #1a1a1a;
  --text-muted:#6b7280;
  --primary:   #c0392b;
  --primary-h: #a93226;
  --danger:    #dc2626;
  --success:   #16a34a;
  --info:      #1d4ed8;
  --star-on:   #f59e0b;
  --star-off:  #d1d5db;
  --nav-bg:    #1f1f1f;
  --nav-text:  #f5f5f5;
  --radius:    8px;
  --shadow:    0 1px 3px rgba(0,0,0,.1),0 1px 2px rgba(0,0,0,.06);
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Nav ─── */
.nav {
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
}

.nav-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--nav-text);
  letter-spacing: -.02em;
}
.nav-brand:hover { text-decoration: none; opacity: .85; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}
.nav-links a { color: #d1d5db; font-size: .9rem; }
.nav-links a:hover { color: #fff; text-decoration: none; }
.nav-user { color: var(--text-muted); font-size: .85rem; }

/* ─── Main ─── */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 1.5rem;
}

/* ─── Flash ─── */
.flash {
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  font-size: .9rem;
}
.flash-success { background: #dcfce7; border-left: 4px solid var(--success); color: #14532d; }
.flash-error   { background: #fee2e2; border-left: 4px solid var(--danger);  color: #7f1d1d; }
.flash-info    { background: #dbeafe; border-left: 4px solid var(--info);    color: #1e3a8a; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  border: none;
  border-radius: var(--radius);
  padding: .5rem 1rem;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  background: #e5e7eb;
  color: var(--text);
  white-space: nowrap;
  transition: opacity .15s;
  text-decoration: none;
}
.btn:hover { opacity: .85; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-ghost   { background: transparent; border: 1px solid var(--border); }
.btn-sm      { padding: .3rem .7rem; font-size: .8rem; }
.btn-block   { width: 100%; }
.btn-group   { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ─── Auth ─── */
.auth-wrap {
  min-height: calc(100vh - 52px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}
.auth-card h1 { font-size: 1.4rem; margin: 0 0 1.5rem; }
.auth-note { font-size: .82rem; color: var(--text-muted); margin-top: 1rem; text-align: center; }

/* ─── Forms ─── */
label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: .75rem;
  color: var(--text);
}
input[type=text], input[type=email], input[type=password],
input[type=url], input[type=tel], input[type=number],
select, textarea {
  border: 1px solid var(--border);
  border-radius: calc(var(--radius)/2);
  padding: .5rem .75rem;
  font-size: .9rem;
  font-family: inherit;
  background: #fafafa;
  color: var(--text);
  width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}
textarea { resize: vertical; }

.inline-form { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 180px; }

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: .5rem;
  font-weight: 400;
  margin-bottom: .35rem;
}
.checkbox-label input { width: auto; }

/* ─── Dashboard ─── */
.dashboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.search-bar {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  align-items: center;
  flex: 1;
}
.search-input { min-width: 200px; flex: 1; }
.toolbar-actions { display: flex; gap: .5rem; }

.tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-bottom: 1rem;
}

/* ─── Cards ─── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.card-name { font-weight: 600; font-size: 1rem; color: var(--text); }
.card-name:hover { color: var(--primary); }
.card-meta { display: flex; gap: .35rem; flex-wrap: wrap; font-size: .78rem; color: var(--text-muted); }
.card-location { font-size: .83rem; color: var(--text-muted); }
.card-note { font-size: .85rem; color: #374151; background: #f9fafb; border-radius: 4px; padding: .35rem .5rem; white-space: pre-wrap; }
.card-tags { display: flex; flex-wrap: wrap; gap: .25rem; }
.card-actions { margin-top: auto; padding-top: .4rem; display: flex; gap: .4rem; }

/* ─── Tags ─── */
.tag {
  display: inline-block;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: .15rem .55rem;
  font-size: .75rem;
  color: var(--text);
  cursor: pointer;
}
.tag:hover { background: #e5e7eb; text-decoration: none; }
.tag-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tag span { color: var(--text-muted); font-size: .7rem; }
.tag-active span { color: rgba(255,255,255,.7); }

/* ─── Stars ─── */
.card-rating, .star-editor {
  display: flex;
  gap: 2px;
  cursor: pointer;
}
.star { color: var(--star-off); font-size: 1.2rem; line-height: 1; transition: color .1s; }
.star-on { color: var(--star-on); }
.star:hover { color: var(--star-on); }

/* ─── Badges ─── */
.price, .cuisine, .source-badge, .badge {
  display: inline-block;
  font-size: .75rem;
  padding: .1rem .4rem;
  border-radius: 4px;
}
.price    { color: #059669; font-weight: 600; }
.cuisine  { background: #ede9fe; color: #5b21b6; }
.source-badge, .badge-source { background: #f3f4f6; color: var(--text-muted); border: 1px solid var(--border); }
.badge-saved { background: #dcfce7; color: #15803d; }

/* ─── Restaurant detail ─── */
.restaurant-detail { max-width: 800px; }
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.detail-header h1 { margin: 0 0 .4rem; font-size: 1.6rem; }
.detail-meta { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
@media (max-width: 640px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-info p { margin: .35rem 0; font-size: .9rem; }
.detail-save { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.detail-save h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.list-membership h3 { font-size: .9rem; font-weight: 600; margin: 0 0 .5rem; }
.also-saved { color: var(--text-muted); font-size: .85rem; }

/* ─── Search page ─── */
.search-page { max-width: 780px; }
.search-form-wrap { margin-bottom: 1.25rem; }
.search-inputs { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .6rem; }
.search-input-lg { flex: 2; min-width: 240px; font-size: 1rem; padding: .6rem .85rem; }
.search-input    { flex: 1; min-width: 160px; }
.search-actions  { display: flex; gap: .4rem; flex-wrap: wrap; }
.search-status   { font-size: .85rem; color: var(--text-muted); margin-bottom: .75rem; }
.search-results  { display: flex; flex-direction: column; gap: .65rem; }

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  box-shadow: var(--shadow);
  transition: border-color .15s;
}
.result-card:hover  { border-color: #bbb; }
.result-saved       { border-left: 3px solid var(--success); }

.result-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: .75rem;
}
.result-name-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  flex: 1;
}
.result-name    { font-weight: 600; font-size: .98rem; }
.result-action  { flex-shrink: 0; }
.result-meta    { font-size: .82rem; color: var(--text-muted); }
.result-stars   { font-size: .9rem; }
.inline-stars   { color: var(--star-on); letter-spacing: 1px; }
.result-note    { font-size: .83rem; color: #374151; background: #f9fafb; border-radius: 4px; padding: .3rem .5rem; white-space: pre-wrap; }
.result-tags    { display: flex; flex-wrap: wrap; gap: .25rem; }
.result-saved-by { font-size: .8rem; color: var(--text-muted); }
.result-ext-links { display: flex; gap: .75rem; margin-top: .15rem; }
.result-ext-link  { font-size: .78rem; color: var(--text-muted); }
.result-ext-link:hover { color: var(--primary); }

.badge-save-count {
  font-size: .72rem;
  color: var(--primary);
  font-weight: 500;
}

.loading { color: var(--text-muted); padding: 1rem 0; }
.error, p.error { color: var(--danger); }
p.empty { color: var(--text-muted); }

/* ─── Import page ─── */
.import-page { max-width: 900px; }
.import-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1.25rem; margin-top: 1rem; }
.import-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.import-card h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.import-card p  { font-size: .85rem; color: var(--text-muted); margin: 0 0 1rem; }
.import-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }

/* Column mapping */
.map-table { border-collapse: collapse; width: 100%; font-size: .87rem; margin-bottom: 1rem; }
.map-table th, .map-table td { padding: .5rem .75rem; border: 1px solid var(--border); text-align: left; vertical-align: middle; }
.map-table th { background: #f9fafb; font-weight: 600; }
.sample-cell { color: var(--text-muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--text-muted); }

/* ─── Lists page ─── */
.lists-page { max-width: 800px; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.page-header h1 { margin: 0; }
.new-list-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.new-list-form form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.list-grid { display: flex; flex-direction: column; gap: .5rem; }
.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.list-name { font-weight: 600; flex: 1; color: var(--text); }
.list-name:hover { color: var(--primary); }
.list-count { font-size: .82rem; color: var(--text-muted); }

/* ─── Admin ─── */
.admin-page { max-width: 960px; }
.admin-page section { margin-bottom: 2.5rem; }
.admin-page h2 { font-size: 1.1rem; margin: 0 0 1rem; padding-bottom: .5rem; border-bottom: 1px solid var(--border); }
.data-table { border-collapse: collapse; width: 100%; font-size: .87rem; }
.data-table th, .data-table td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { background: #f9fafb; font-weight: 600; }
.copy-btn { background: none; border: none; cursor: pointer; color: var(--primary); font-family: monospace; font-size: .82rem; padding: 0; text-decoration: underline; }

/* ─── Modal ─── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.modal-title { margin: 0 0 1rem; font-size: 1.1rem; }
.modal-actions { display: flex; gap: .5rem; margin-top: 1rem; }

/* ─── Toast ─── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #1f2937;
  color: #fff;
  border-radius: var(--radius);
  padding: .65rem 1.2rem;
  font-size: .875rem;
  z-index: 300;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

/* ─── Empty state ─── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state p { margin-bottom: 1rem; font-size: 1.05rem; }
.empty-state .btn { margin: .25rem; }

/* ─── Responsive ─── */
@media (max-width: 640px) {
  .nav { padding: 0 1rem; }
  .main { padding: 1rem .75rem; }
  .card-grid { grid-template-columns: 1fr; }
  .import-grid { grid-template-columns: 1fr; }
  .dashboard-toolbar { flex-direction: column; align-items: stretch; }
  .search-bar { flex-direction: column; }
}
