/* ── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #F7F4F1;
  --surface:      #FFFFFF;
  --surface-2:    #F0EBE8;
  --border:       #DDD0CC;
  --border-light: #EBE4E1;
  --text-1:       #150F0D;
  --text-2:       #5C3A42;
  --text-3:       #9C7A82;
  --accent:       #6B2737;
  --accent-hover: #531D2A;
  --accent-light: #F5ECEe;
  --danger:       #C03030;
  --shadow-sm:    0 1px 3px rgba(80,20,40,.08);
  --shadow-md:    0 4px 16px rgba(80,20,40,.10);
  --shadow-lg:    0 8px 32px rgba(80,20,40,.14);
  --radius:       12px;
  --radius-sm:    8px;
  --font-serif:   'Cormorant Garamond', Georgia, serif;
  --font-sans:    'Inter', system-ui, sans-serif;
  --transition:   0.2s ease;
}

html { font-size: 15px; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-icon { font-size: 22px; }
.header-brand h1 {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-1);
}

/* ── Toolbar ─────────────────────────────────────────────────────────────────── */
.toolbar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 0;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
#search {
  flex: 1;
  min-width: 200px;
  max-width: 360px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text-1);
  outline: none;
  transition: border-color var(--transition);
}
#search:focus { border-color: var(--accent); }
.filter-pills { display: flex; gap: 6px; }
.pill {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--transition);
}
.pill:hover { border-color: var(--accent); color: var(--accent); }
.pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Coffee Grid ────────────────────────────────────────────────────────────── */
#grid-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}
.coffee-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

/* ── Coffee Card ────────────────────────────────────────────────────────────── */
.coffee-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.coffee-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border);
}

.card-image {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  object-position: center;
  display: block;
  background: var(--surface-2);
}
.card-image-placeholder {
  width: 100%;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
}
.card-image-placeholder.light  { background: linear-gradient(135deg, #FFF3D4 0%, #EDCB8A 100%); }
.card-image-placeholder.medium { background: linear-gradient(135deg, #E8C070 0%, #C48A30 100%); }
.card-image-placeholder.dark   { background: linear-gradient(135deg, #9A5C20 0%, #4A2408 100%); }
.card-image-placeholder.none   { background: linear-gradient(135deg, #F2EAE0 0%, #DFD0BC 100%); }

.card-body { padding: 16px; }
.card-name {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-1);
  margin-bottom: 2px;
}
.card-roaster {
  font-size: 12px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.card-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.tag {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border-light);
}
.tag.roast-light  { background: #FFF8EC; color: #9A6820; border-color: #F0DDB0; }
.tag.roast-medium { background: #FFF0E0; color: #904A10; border-color: #E8C090; }
.tag.roast-dark   { background: #F5E8DE; color: #6A2E08; border-color: #D4A080; }

.card-notes {
  font-size: 13px;
  color: var(--text-2);
  font-style: italic;
  line-height: 1.4;
  margin-bottom: 12px;
  min-height: 18px;
}
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}
.card-price {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}
.card-cpc { font-weight: 400; color: var(--text-3); }
.stars { color: var(--accent); font-size: 14px; letter-spacing: 1px; }
.stars .empty { color: var(--border); }
.note-count { font-size: 12px; color: var(--text-3); }

/* ── Empty State ─────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 24px;
}
.empty-icon { font-size: 56px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h2 {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 8px;
}
.empty-state p { color: var(--text-3); margin-bottom: 24px; }

/* ── Detail View ─────────────────────────────────────────────────────────────── */
#detail-view { min-height: 100vh; }
.detail-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 100%;
}
.btn-back {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0;
  transition: color var(--transition);
}
.btn-back:hover { color: var(--text-1); }
.detail-header-actions { display: flex; gap: 8px; }

#detail-content { max-width: 900px; margin: 0 auto; padding: 40px 24px 80px; }

.detail-hero { margin-bottom: 36px; }
.detail-hero-img {
  width: 100%;
  max-height: 380px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 28px;
  box-shadow: var(--shadow-md);
}
.detail-hero-placeholder {
  width: 100%;
  height: 260px;
  border-radius: var(--radius);
  margin-bottom: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 72px;
}
.detail-hero-placeholder.light  { background: linear-gradient(135deg, #FFF3D4 0%, #EDCB8A 100%); }
.detail-hero-placeholder.medium { background: linear-gradient(135deg, #E8C070 0%, #C48A30 100%); }
.detail-hero-placeholder.dark   { background: linear-gradient(135deg, #9A5C20 0%, #4A2408 100%); }
.detail-hero-placeholder.none   { background: linear-gradient(135deg, #F2EAE0 0%, #DFD0BC 100%); }

.detail-name {
  font-family: var(--font-serif);
  font-size: 42px;
  font-weight: 600;
  line-height: 1.1;
  margin-bottom: 4px;
}
.detail-roaster {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-3);
  margin-bottom: 16px;
}

.detail-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-bottom: 40px;
}
@media (max-width: 640px) { .detail-body { grid-template-columns: 1fr; } }

.detail-specs { display: flex; flex-direction: column; gap: 12px; }
.spec-row { display: flex; gap: 12px; align-items: baseline; }
.spec-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-3);
  min-width: 80px;
}
.spec-value { font-size: 14px; color: var(--text-1); }

.detail-right {}
.detail-tasting {
  margin-bottom: 20px;
}
.detail-tasting-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-3);
  margin-bottom: 8px;
}
.detail-tasting-notes {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 18px;
  color: var(--text-1);
  line-height: 1.5;
}
.detail-rating-section {}
.detail-rating-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-3);
  margin-bottom: 8px;
}
.detail-avg-rating { display: flex; align-items: center; gap: 10px; }
.detail-stars { font-size: 22px; letter-spacing: 2px; }
.detail-avg-num { font-size: 13px; color: var(--text-3); }
.detail-price-row { margin-top: 16px; }
.detail-price {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-1);
}
.detail-price-label { font-size: 12px; color: var(--text-3); }
.detail-cpc { font-size: 16px; font-weight: 400; color: var(--text-3); }
.label-hint { font-size: 11px; font-weight: 400; color: var(--text-3); }

.detail-description {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text-2);
  background: var(--surface);
  padding: 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  margin-bottom: 40px;
}

/* ── Brew Notes ──────────────────────────────────────────────────────────────── */
.notes-section { margin-top: 8px; }
.notes-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.notes-section-title {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
}

/* Add note form */
.add-note-form {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}
.add-note-form h3 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}
.note-form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.note-form-row .form-group { flex: 1; min-width: 140px; }
.note-form-row .form-group.full { flex: 100%; }
.star-rating { display: flex; gap: 4px; }
.star-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--border);
  transition: color var(--transition), transform var(--transition);
  padding: 2px;
  line-height: 1;
}
.star-btn:hover, .star-btn.active { color: var(--accent); }
.star-btn:hover { transform: scale(1.15); }

/* Note cards */
.note-list { display: flex; flex-direction: column; gap: 12px; }
.note-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 16px;
  position: relative;
}
.note-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.note-date { font-size: 12px; color: var(--text-3); }
.note-method {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border-light);
}
.note-stars { font-size: 14px; letter-spacing: 1px; }
.note-text { font-size: 14px; color: var(--text-1); line-height: 1.6; }
.note-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}
.note-card:hover .note-actions { opacity: 1; }
.note-action-btn {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: 15px;
  padding: 3px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color var(--transition), background var(--transition);
}
.note-action-btn:hover { color: var(--text-1); background: var(--surface-2); }
.note-action-delete:hover { color: var(--danger); background: #FFF0F0; }
.note-card--editing { background: var(--bg); }
.no-notes {
  text-align: center;
  padding: 32px;
  color: var(--text-3);
  font-style: italic;
  font-size: 14px;
}

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 10, 5, 0.45);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 680px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--border-light);
}
.modal-header h2 {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 600;
}
.btn-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-3);
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color var(--transition), background var(--transition);
}
.btn-close:hover { color: var(--text-1); background: var(--surface-2); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
  margin-top: 16px;
}

/* URL fetch row */
.fetch-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}
.fetch-row input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-1);
  outline: none;
  transition: border-color var(--transition);
}
.fetch-row input:focus { border-color: var(--accent); background: var(--surface); }
.fetch-error {
  font-size: 13px;
  color: var(--danger);
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #FFF5F5;
  border-radius: 6px;
  border: 1px solid #FFD0D0;
}
.divider {
  text-align: center;
  position: relative;
  margin: 16px 0;
  color: var(--text-3);
  font-size: 12px;
}
.divider::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: var(--border-light);
}
.divider span {
  background: var(--surface);
  padding: 0 12px;
  position: relative;
}

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-row { display: flex; gap: 12px; margin-bottom: 0; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 140px; }
.form-row .form-group--wide { flex: 2; min-width: 200px; }
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--text-1);
  background: var(--surface);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184,101,42,.12);
}
.form-group textarea { resize: vertical; }
.form-group select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239C8878' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text-1);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border-light); }
.btn-ghost {
  background: none;
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text-1); }
.btn-danger-ghost {
  background: none;
  color: var(--danger);
  border: 1px solid transparent;
}
.btn-danger-ghost:hover { background: #FFF5F5; border-color: #FFD0D0; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── Spinner ─────────────────────────────────────────────────────────────────── */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner.dark {
  border-color: rgba(0,0,0,.15);
  border-top-color: var(--accent);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Bookmarklet modal ───────────────────────────────────────────────────────── */
.header-actions { display: flex; align-items: center; gap: 10px; }
.btn-bookmark-hint { font-size: 13px; color: var(--text-3); border-color: var(--border); }
.btn-bookmark-hint:hover { color: var(--accent); }

.modal--bm { max-width: 520px; }
.bm-intro { color: var(--text-2); font-size: 14px; line-height: 1.6; margin-bottom: 20px; }
.bm-steps { padding-left: 20px; margin-bottom: 24px; display: flex; flex-direction: column; gap: 8px; }
.bm-steps li { color: var(--text-1); font-size: 14px; line-height: 1.5; }
.bm-hint { color: var(--text-3); font-size: 12px; }
.bm-drag-area {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface-2);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.bm-bookmarklet {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: grab;
  user-select: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition);
}
.bm-bookmarklet:hover { background: var(--accent-hover); }
.bm-bookmarklet:active { cursor: grabbing; }
.bm-drag-hint { color: var(--text-3); font-size: 13px; }
.bm-note { color: var(--text-3); font-size: 12px; }
.bm-tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.bm-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 8px 14px; font-size: 13px; font-weight: 500; color: var(--text-3);
  cursor: pointer; margin-bottom: -1px; transition: color var(--transition);
}
.bm-tab:hover { color: var(--text-1); }
.bm-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.bm-tab-panel { }
.bm-copy-area { display: flex; gap: 8px; margin-bottom: 8px; }
.bm-copy-input {
  flex: 1; font-size: 11px; font-family: monospace; color: var(--text-3);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px; cursor: text;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bm-copied { color: var(--accent); font-size: 13px; font-weight: 500; }

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
