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

:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --border: #e5e2dc;
  --text: #1a1714;
  --muted: #7c7570;
  --accent: #c8602a;
  --accent-hover: #a84e20;
  --accent-light: #f8ede6;
  --select: #3d5e8c;
  --select-light: #edf1f8;
  --pour-bg: #f5f3ef;
  --error-bg: #fff5f2;
  --error-border: #f5c6b8;
  --error-text: #9b2c0e;
  --radius: 8px;
  --gap: 20px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: grid;
  grid-template-columns: 380px 1fr;
  grid-template-rows: auto 1fr;
}

header {
  grid-column: 1 / -1;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
header h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -.3px; }
header span { font-size: .85rem; color: var(--muted); }

/* ── Form panel ── */
#form-panel {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Accordion sections ── */
details.section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

details.section summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  background: var(--pour-bg);
  transition: background .12s;
}
details.section summary::-webkit-details-marker { display: none; }
details.section summary:hover { background: #edeae4; }
details.section[open] summary { border-bottom: 1px solid var(--border); }

.section-num {
  width: 20px; height: 20px;
  background: var(--accent);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
details.section.secondary .section-num { background: var(--muted); }

.section-title {
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text);
  flex: 1;
}
.section-desc {
  font-size: .72rem;
  color: var(--muted);
}
.chevron {
  width: 10px; height: 10px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform .15s;
  margin-right: 2px;
}
details.section[open] .chevron { transform: rotate(-135deg); }

.section-body { padding: 14px 14px 16px; }

.fields { display: flex; flex-direction: column; gap: 11px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: .78rem; font-weight: 500; color: var(--muted); }

input[type=text], input[type=date], input[type=number], select {
  width: 100%;
  font-size: .88rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  outline: none;
  transition: border-color .15s;
  appearance: none;
  -webkit-appearance: none;
}
input[type=text]:focus, input[type=date]:focus, input[type=number]:focus, select:focus {
  border-color: var(--accent);
  background: var(--surface);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%237c7570'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-color: var(--bg);
  padding-right: 28px;
  cursor: pointer;
}

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* roast level as segmented control */
.roast-options {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.roast-options input[type=radio] { display: none; }
.roast-options label {
  font-size: .75rem;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  background: var(--bg);
  color: var(--muted);
  font-weight: 500;
  transition: all .12s;
  white-space: nowrap;
}
.roast-options input[type=radio]:checked + label {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* flavor goal segmented */
.flavor-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.flavor-options input[type=radio] { display: none; }
.flavor-options label {
  font-size: .8rem;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: var(--bg);
  color: var(--muted);
  transition: all .12s;
}
.flavor-options input[type=radio]:checked + label {
  background: var(--select-light);
  border-color: var(--select);
  color: var(--select);
  font-weight: 600;
}

/* preground */
.check-row { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check-row input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.check-row span { font-size: .88rem; }

/* coarseness slider */
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row input[type=range] {
  flex: 1; padding: 0;
  background: none; border: none; cursor: pointer;
  appearance: auto; -webkit-appearance: auto;
  accent-color: var(--accent);
}
.slider-val { font-size: .85rem; font-weight: 600; color: var(--accent); min-width: 28px; text-align: right; }

/* grinder cascade */
.cascade-indent { padding-left: 12px; border-left: 2px solid var(--border); display: flex; flex-direction: column; gap: 8px; }

/* yield preset buttons */
.yield-presets { display: flex; gap: 5px; margin-bottom: 6px; flex-wrap: wrap; }
.yield-btn {
  font-size: .74rem;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  background: var(--bg);
  color: var(--muted);
  font-family: inherit;
  transition: all .12s;
}
.yield-btn:hover { border-color: var(--accent); color: var(--accent); }

/* hint text */
.hint { font-size: .72rem; color: var(--muted); font-style: italic; }

/* ── Two-month date picker ── */
.cal-picker { position: relative; }

.cal-trigger {
  width: 100%;
  font-size: .88rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color .15s;
}
.cal-trigger:hover, .cal-trigger:focus { outline: none; border-color: var(--accent); }
.cal-trigger.has-value { background: var(--surface); }
.cal-trigger-placeholder { color: var(--muted); }

.cal-dropdown {
  position: fixed;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.10);
  padding: 12px;
  width: 348px;
}

.cal-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.cal-nav-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 26px; height: 26px;
  cursor: pointer;
  font-size: .9rem;
  color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: all .12s;
}
.cal-nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.cal-nav-btn:disabled { opacity: .3; cursor: not-allowed; }

.cal-months {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.cal-month-title {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  text-align: center;
  margin-bottom: 6px;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}

.cal-dow {
  font-size: .62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  text-align: center;
  padding: 2px 0 4px;
}

.cal-day {
  font-size: .78rem;
  text-align: center;
  padding: 4px 2px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text);
  transition: background .1s;
  line-height: 1.4;
}
.cal-day:hover:not(.cal-day-empty):not(.cal-day-future) { background: var(--pour-bg); }
.cal-day-empty { cursor: default; }
.cal-day-future { color: var(--border); cursor: not-allowed; }
.cal-day-today { font-weight: 700; color: var(--accent); }
.cal-day-selected {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 600;
  border-radius: 4px;
}

/* submit */
#submit-btn {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
  letter-spacing: .01em;
  margin-top: 6px;
}
#submit-btn:hover { background: var(--accent-hover); }
#submit-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Results panel ── */
#results-panel {
  overflow-y: auto;
  padding: 24px 28px;
}

.placeholder {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .9rem;
}

/* errors */
.error-box {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--error-text);
  font-size: .875rem;
}
.error-box strong { display: block; margin-bottom: 6px; }
.error-box ul { padding-left: 18px; }
.error-box li { margin-top: 3px; }

/* recipe cards */
.recipe-sets { display: flex; flex-direction: column; gap: 32px; }

.recipe-set-header { margin-bottom: 16px; }
.recipe-set-header h2 { font-size: 1.1rem; font-weight: 700; }
.coffee-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag {
  font-size: .75rem;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--pour-bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.tag.flavor { background: #f0f7f0; border-color: #c8e0c8; color: #3a6b3a; }

.recipes-grid { display: flex; flex-direction: column; gap: 16px; }

.recipe-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.recipe-card-header {
  padding: 14px 16px;
  background: var(--pour-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}
.recipe-card-header h3 { font-size: .95rem; font-weight: 700; flex: 1; min-width: 160px; }

.stats { display: flex; flex-wrap: wrap; gap: 12px; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.stat-val { font-size: .95rem; font-weight: 700; color: var(--accent); }
.stat-key { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.recipe-card-body { padding: 14px 16px; }

.notes {
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: 14px;
  font-style: italic;
  line-height: 1.5;
}
.filter-prep { font-size: .8rem; color: var(--muted); margin-bottom: 10px; }
.pro-tips {
  margin-top: 8px;
  padding-left: 18px;
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.6;
}

.pours-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .83rem;
}
.pours-table th {
  text-align: left;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 6px 6px;
  border-bottom: 1px solid var(--border);
}
.pours-table td {
  padding: 7px 6px;
  border-bottom: 1px solid var(--pour-bg);
  vertical-align: top;
}
.pours-table tr:last-child td { border-bottom: none; }
.pour-time { white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; }
.pour-weight { white-space: nowrap; font-variant-numeric: tabular-nums; }
.pour-action { line-height: 1.45; }

/* loading spinner */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--muted); font-size: .875rem; }

/* ── Feedback ── */
.feedback-box {
  margin-top: 24px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.feedback-prompt { font-size: .85rem; font-weight: 600; color: var(--muted); }
.feedback-stars { display: flex; gap: 2px; }
.star-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0 3px;
  cursor: pointer;
  color: var(--border);
  transition: color .1s;
}
.star-btn:hover, .star-btn.active { color: var(--accent); }
.feedback-notes {
  width: 100%;
  font-size: .85rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
.feedback-notes:focus { border-color: var(--accent); background: var(--surface); }
.feedback-submit {
  align-self: flex-start;
  padding: 7px 16px;
  background: var(--accent);
  color: #fff;
  font-size: .85rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s;
}
.feedback-submit:hover { background: var(--accent-hover); }
.feedback-submit:disabled { opacity: .5; cursor: not-allowed; }
.feedback-thanks { font-size: .85rem; color: var(--muted); font-style: italic; }

/* ── App feedback button (header) ── */
.header-feedback-btn {
  margin-left: auto;
  padding: 6px 16px;
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 20px;
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
}
.header-feedback-btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ── App feedback dialog ── */
#app-feedback-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  padding: 22px 24px;
  width: min(420px, 90vw);
  background: var(--surface);
  color: var(--text);
}
#app-feedback-dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#app-feedback-dialog::backdrop {
  background: rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
}
.dialog-title { font-size: .95rem; font-weight: 700; }
#app-feedback-msg {
  width: 100%;
  font-size: .88rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
#app-feedback-msg:focus { border-color: var(--accent); background: var(--surface); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions button {
  padding: 7px 18px;
  font-size: .85rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
}
#app-feedback-cancel {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
}
#app-feedback-cancel:hover { border-color: var(--text); color: var(--text); }
#app-feedback-submit {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
}
#app-feedback-submit:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
#app-feedback-submit:disabled { opacity: .5; cursor: not-allowed; }
