:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --ink: #17212b;
  --muted: #6a7480;
  --line: #dce3ea;
  --teal: #0f766e;
  --cobalt: #2556d9;
  --soft-teal: #e7f5f2;
  --soft-blue: #e9efff;
  --warning: #a16207;
  --radius: 8px;
  --shadow: 0 14px 30px rgba(31, 41, 55, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
textarea,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: #101820;
  color: #f8fafc;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #35c2ac;
  color: #08111a;
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.source-panel span,
.nav-item {
  color: #b7c2ce;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 10px 12px;
  color: #cbd5e1;
  display: flex;
  gap: 10px;
  align-items: center;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.source-panel {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  display: grid;
  gap: 4px;
}

.source-panel strong {
  font-size: 24px;
}

.source-refresh {
  margin-top: 8px;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  background: #35c2ac;
  color: #08111a;
  font-weight: 800;
  cursor: pointer;
}

.source-refresh:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.refresh-status {
  overflow-wrap: anywhere;
}

.workspace {
  padding: 28px;
  display: grid;
  gap: 20px;
  align-content: start;
}

.topbar,
.capture-grid,
.content-grid,
.panel-head,
.button-row,
.status-stack {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
  line-height: 1.25;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.status-stack {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--teal);
}

.capture-grid {
  align-items: stretch;
  gap: 20px;
}

.capture-panel {
  flex: 1;
}

.summary-panel {
  width: 340px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-head {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--ink);
  min-height: 118px;
}

textarea:focus {
  outline: 3px solid var(--soft-blue);
  border-color: var(--cobalt);
}

.button-row {
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  background: var(--cobalt);
  color: white;
}

.primary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary-button {
  background: var(--soft-teal);
  color: var(--teal);
}

.icon-button {
  width: 42px;
  padding: 0;
  background: #fee2e2;
  color: #b91c1c;
}

.icon-button.recording {
  background: #b91c1c;
  color: #ffffff;
}

.hint,
.eyeline {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.toggle {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.voice-choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.voice-choice select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--ink);
}

.metric {
  padding: 12px;
  border-radius: var(--radius);
  background: #f8fafc;
  border: 1px solid var(--line);
}

.metric span,
.audit-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 4px;
}

.metric strong {
  font-size: 28px;
}

.content-grid {
  align-items: stretch;
  gap: 20px;
}

.prediction-panel {
  min-width: 0;
  flex: 1;
}

.audit-panel {
  width: 390px;
  align-self: stretch;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

td input {
  width: 82px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  background: var(--soft-blue);
  color: var(--cobalt);
}

.pill.low {
  background: #fef3c7;
  color: var(--warning);
}

.empty {
  color: var(--muted);
  text-align: center;
}

pre {
  min-height: 230px;
  max-height: 340px;
  overflow: auto;
  background: #0f172a;
  color: #e5f4ff;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 12px;
  line-height: 1.45;
}

.audit-box {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.audit-box ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.voice-disclosure {
  display: block;
  color: var(--muted);
  line-height: 1.4;
  margin-top: 8px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }

  .source-panel {
    margin-top: 0;
  }

  .capture-grid,
  .content-grid,
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .summary-panel,
  .audit-panel {
    width: auto;
  }
}

@media (max-width: 640px) {
  body {
    background: var(--surface);
  }

  .app-shell {
    min-height: 100svh;
  }

  .workspace {
    padding: 12px;
    gap: 12px;
  }

  .sidebar {
    padding: 12px;
    gap: 12px;
    display: grid;
    grid-template-columns: 1fr;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .nav-list {
    display: none;
  }

  .source-panel {
    padding: 10px;
    gap: 6px;
  }

  .source-panel strong {
    font-size: 18px;
  }

  .source-panel > span:not(.eyeline):not(.refresh-status) {
    display: none;
  }

  .source-refresh {
    width: 100%;
    min-height: 42px;
  }

  .topbar {
    gap: 10px;
  }

  h1 {
    font-size: 22px;
  }

  .topbar p {
    display: none;
  }

  .status-stack {
    justify-content: flex-start;
  }

  .status-dot {
    font-size: 12px;
    padding: 6px 9px;
  }

  .panel {
    padding: 12px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .panel-head {
    align-items: flex-start;
    gap: 10px;
  }

  .capture-panel .panel-head {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  textarea {
    min-height: 104px;
    font-size: 16px;
  }

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

  .primary-button,
  .secondary-button,
  .icon-button,
  .voice-choice select {
    min-height: 46px;
  }

  .voice-choice {
    grid-column: 1 / -1;
    justify-content: space-between;
    width: 100%;
  }

  .voice-choice select {
    flex: 1;
    max-width: 180px;
  }

  .summary-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    padding: 10px;
  }

  .metric span {
    font-size: 10px;
  }

  .metric strong {
    font-size: 20px;
    overflow-wrap: anywhere;
  }

  .prediction-panel .panel-head,
  .audit-panel .panel-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  #saveBtn {
    width: 100%;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  table {
    border-collapse: separate;
    border-spacing: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
  }

  td {
    min-height: 42px;
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    overflow-wrap: anywhere;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    flex: 0 0 38%;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
  }

  td[data-label="Predicted ingredient"] {
    display: grid;
    grid-template-columns: 38% 1fr;
    align-items: start;
  }

  td[data-label="Predicted ingredient"]::before {
    grid-row: span 2;
  }

  td input {
    width: 112px;
    min-height: 38px;
    font-size: 16px;
  }

  .empty {
    display: block;
    text-align: left;
  }

  .empty::before {
    content: none;
  }

  pre {
    min-height: 140px;
    max-height: 220px;
    font-size: 11px;
  }
}
