@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg-deep: #15120D;
  --bg-panel: #1C1710;
  --card: #241E15;
  --card-raised: #2C2418;
  --line: #3A3226;
  --ink: #EDE3D0;
  --ink-dim: #A99B82;
  --ink-faint: #766A56;
  --amber: #D69A3B;
  --amber-dim: #8C6A2F;
  --copper: #B5652D;
  --hop-green: #7A9B5C;
  --alert: #C1503D;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: 'Inter', sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(circle at 10% 0%, rgba(214,154,59,0.06), transparent 40%),
    radial-gradient(circle at 90% 100%, rgba(122,155,92,0.05), transparent 40%);
}

h1, h2, h3, .display {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.mono { font-family: 'JetBrains Mono', monospace; }

button {
  font-family: 'Inter', sans-serif;
  cursor: pointer;
}

/* ---- App shell ---- */
#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 22px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.sidebar-header .brand {
  font-size: 20px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.sidebar-header .brand .mark { color: var(--amber); font-size: 22px; }

.sidebar-header .tagline {
  font-size: 11px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
}

/* ---- Section nav (Recipes / Batches / Inventory / Equipment / Tools) ---- */
#sectionNav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.section-tab {
  padding: 6px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 6px;
  color: var(--ink-faint);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.section-tab:hover { background: var(--card); color: var(--ink-dim); }
.section-tab.active { background: var(--card-raised); color: var(--amber); }

.sidebar-actions {
  padding: 12px 14px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}
.sidebar-actions .btn { flex: 1; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--amber-dim); background: var(--card-raised); }
.btn-primary { background: var(--amber); color: #17130C; border-color: var(--amber); font-weight: 600; }
.btn-primary:hover { background: #E4AC50; }
.btn-danger { color: var(--alert); }
.btn-danger:hover { border-color: var(--alert); }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--card); }

.recipe-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.recipe-item {
  padding: 11px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 3px;
  border: 1px solid transparent;
}
.recipe-item:hover { background: var(--card); }
.recipe-item.active { background: var(--card-raised); border-color: var(--amber-dim); }
.recipe-item .name { font-weight: 600; font-size: 14px; }
.recipe-item .meta { font-size: 11px; color: var(--ink-faint); margin-top: 2px; font-family: 'JetBrains Mono', monospace; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-faint);
}
.sidebar-footer input[type=file] { display: none; }

/* ---- Tree view (folders + recipes) ---- */
.tree-root { min-height: 100%; padding-bottom: 20px; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  margin-bottom: 1px;
  border: 1px solid transparent;
  user-select: none;
}
.tree-row:hover { background: var(--card); }
.tree-row.active { background: var(--card-raised); border-color: var(--amber-dim); }
.tree-row.dragging { opacity: 0.4; }
.tree-row.drag-over { border-color: var(--amber); background: var(--card-raised); }
.tree-caret { width: 10px; color: var(--ink-faint); font-size: 10px; flex-shrink: 0; }
.tree-icon { flex-shrink: 0; font-size: 13px; }
.tree-folder .tree-label { font-weight: 600; font-size: 13px; color: var(--ink-dim); }
.tree-count { margin-left: auto; font-size: 10px; color: var(--ink-faint); font-family: 'JetBrains Mono', monospace; }
.tree-recipe .tree-label { font-weight: 600; font-size: 13.5px; }
.tree-recipe .tree-meta { font-size: 10.5px; color: var(--ink-faint); margin-top: 1px; font-family: 'JetBrains Mono', monospace; }

/* ---- Context menu ---- */
.context-menu {
  position: fixed;
  z-index: 200;
  background: var(--card-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px;
  min-width: 170px;
  box-shadow: var(--shadow);
}
.ctx-item {
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 5px;
  cursor: pointer;
}
.ctx-item:hover { background: var(--card); }
.ctx-item.danger { color: var(--alert); }
.ctx-divider { height: 1px; background: var(--line); margin: 4px 2px; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10,8,5,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  padding: 20px;
}
.modal-box {
  background: var(--card-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal-box h3 { margin-top: 0; }
.share-link-input {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  padding: 9px 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  margin-top: 8px;
}

/* ---- Main ---- */
.main {
  overflow-y: auto;
  padding: 26px 34px 60px;
}

.empty-state {
  height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: var(--ink-faint);
  text-align: center;
  gap: 14px;
}
.empty-state h2 { color: var(--ink-dim); }

.recipe-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 18px;
}

.recipe-title-input {
  background: transparent;
  border: none;
  font-family: 'Fraunces', serif;
  font-size: 30px;
  font-weight: 600;
  color: var(--ink);
  width: 100%;
  padding: 4px 0;
  border-bottom: 1px solid transparent;
}
.recipe-title-input:focus { outline: none; border-bottom: 1px solid var(--amber-dim); }

.header-actions { display: flex; gap: 8px; flex-shrink: 0; padding-top: 6px; }

/* ---- Gauge strip (signature element) ---- */
.gauge-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.gauge {
  background: var(--card);
  padding: 16px 18px;
  position: relative;
}

.gauge .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.gauge .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.gauge .value .unit { font-size: 12px; color: var(--ink-faint); font-weight: 400; }

.gauge .range-track {
  margin-top: 10px;
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  position: relative;
  overflow: visible;
}
.gauge .range-fill {
  position: absolute;
  top: 0; bottom: 0;
  background: var(--ink-faint);
  opacity: 0.35;
  border-radius: 2px;
}
.gauge .range-marker {
  position: absolute;
  top: -3px;
  width: 3px;
  height: 10px;
  border-radius: 1px;
  background: var(--amber);
  box-shadow: 0 0 6px rgba(214,154,59,0.7);
}
.gauge.out .range-marker { background: var(--alert); box-shadow: 0 0 6px rgba(193,80,61,0.7); }
.gauge .range-label { font-size: 10px; color: var(--ink-faint); margin-top: 6px; font-family: 'JetBrains Mono', monospace; }

.color-swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--line);
  box-shadow: inset 0 0 8px rgba(0,0,0,0.4);
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}
.tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-faint);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink-dim); }
.tab.active { color: var(--amber); border-bottom-color: var(--amber); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Cards / sections ---- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
}
.card h3 {
  font-size: 15px;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card h3 .btn { font-family: 'Inter', sans-serif; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}
.field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-faint);
  margin-bottom: 5px;
}
.field input, .field select {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
}
.field select { font-family: 'Inter', sans-serif; }
.field input:focus, .field select:focus { outline: none; border-color: var(--amber-dim); }

/* ---- Tables ---- */
table.ing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.ing-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  padding: 0 10px 8px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
table.ing-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.ing-table tr:last-child td { border-bottom: none; }
table.ing-table input, table.ing-table select {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink);
  padding: 5px 7px;
  font-size: 12.5px;
  width: 100%;
  font-family: 'JetBrains Mono', monospace;
}
table.ing-table select { font-family: 'Inter', sans-serif; }
table.ing-table .num { font-family: 'JetBrains Mono', monospace; text-align: right; color: var(--ink-dim); }
table.ing-table .del-btn { color: var(--ink-faint); background: none; border: none; font-size: 15px; padding: 2px 6px; }
table.ing-table .del-btn:hover { color: var(--alert); }
.add-row-btn { margin-top: 10px; }

.empty-row td { text-align: center; color: var(--ink-faint); padding: 18px; font-style: italic; }

/* ---- Style comparison bars ---- */
.style-compare-row {
  display: grid;
  grid-template-columns: 130px 1fr 90px;
  align-items: center;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.style-compare-row:last-child { border-bottom: none; }
.style-compare-row .metric-name { font-size: 12px; color: var(--ink-dim); font-weight: 600; }
.style-compare-row .track {
  height: 8px;
  background: var(--bg-panel);
  border-radius: 4px;
  position: relative;
}
.style-compare-row .band {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(122,155,92,0.35);
  border-radius: 4px;
}
.style-compare-row .dot {
  position: absolute;
  top: -3px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--amber);
  border: 2px solid var(--bg-deep);
  transform: translateX(-50%);
}
.style-compare-row.out .dot { background: var(--alert); }
.style-compare-row .value-label { font-family: 'JetBrains Mono', monospace; font-size: 12px; text-align: right; }

/* ---- Water page ---- */
.ion-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}
.ion-box {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}
.ion-box .ion-name { font-size: 11px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; }
.ion-box .ion-value { font-family: 'JetBrains Mono', monospace; font-size: 17px; margin-top: 4px; color: var(--amber); }

.stat-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.stat-row:last-child { border-bottom: none; }
.stat-row .stat-label { color: var(--ink-faint); }
.stat-row .stat-value { font-family: 'JetBrains Mono', monospace; color: var(--ink); }

/* ---- Mash steps ---- */
.mash-step {
  display: grid;
  grid-template-columns: 1fr 100px 100px 40px;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

/* ---- Notes ---- */
textarea.notes-area {
  width: 100%;
  min-height: 140px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  resize: vertical;
}
textarea.notes-area:focus { outline: none; border-color: var(--amber-dim); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-raised);
  border: 1px solid var(--amber-dim);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 5px; }

/* ---- Mobile top bar + drawer sidebar ---- */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-panel);
  }
  .mobile-topbar .brand { font-family: 'Fraunces', serif; font-size: 17px; }
  .mobile-topbar .brand .mark { color: var(--amber); }
  #sidebarToggle {
    background: var(--card);
    border: 1px solid var(--line);
    color: var(--ink);
    border-radius: 7px;
    padding: 7px 11px;
    font-size: 16px;
    line-height: 1;
  }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 82vw;
    max-width: 320px;
    z-index: 250;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(10,8,5,0.55);
    z-index: 240;
  }
  .sidebar-backdrop.open { display: block; }

  .main { padding: 16px 14px 60px; }

  .recipe-header { flex-direction: column; align-items: stretch; gap: 10px; }
  .recipe-title-input { font-size: 22px; }
  .header-actions { flex-wrap: wrap; }
  .header-actions .btn { flex: 1 1 auto; }

  .gauge-strip { grid-template-columns: repeat(2, 1fr); }

  .field-grid { grid-template-columns: 1fr 1fr; }

  .card { padding: 14px; overflow-x: auto; }
  table.ing-table { min-width: 560px; }

  .mash-step { grid-template-columns: 1fr 70px 70px 32px; gap: 6px; }
  .ion-grid { grid-template-columns: repeat(3, 1fr); }
}
