:root {
  color-scheme: light;
  --bg: #f5f2eb;
  --bg-2: #ece6da;
  --surface: #fffdf8;
  --surface-2: #f7f3eb;
  --surface-3: #ebe2d5;
  --ink: #211b16;
  --ink-soft: #43362c;
  --muted: #75695f;
  --line: #ded3c4;
  --line-strong: #cbbba8;
  --primary: #1f4d43;
  --primary-strong: #153a32;
  --primary-soft: #dce9e3;
  --accent: #a6402d;
  --accent-soft: #f0d4ca;
  --warning: #795a12;
  --danger: #9d2f39;
  --success: #1f6e48;
  --shadow-sm: 0 8px 24px rgba(33, 27, 22, 0.07);
  --shadow-md: 0 18px 48px rgba(33, 27, 22, 0.1);
  --radius: 8px;
  --radius-sm: 6px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(180deg, rgba(31, 77, 67, 0.12), rgba(245, 242, 235, 0) 340px),
    radial-gradient(circle at top left, rgba(166, 64, 45, 0.1), transparent 330px),
    var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  max-width: 760px;
  font-size: clamp(2.35rem, 6vw, 4.4rem);
  line-height: 0.95;
  font-weight: 780;
}

h2 {
  font-size: clamp(1.35rem, 2vw, 1.75rem);
  line-height: 1.15;
}

h3 {
  line-height: 1.2;
}

button,
.file-action {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  transition:
    background 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

button:focus-visible,
.file-action:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(31, 77, 67, 0.28);
  outline-offset: 2px;
}

button:hover,
.file-action:hover {
  transform: translateY(-1px);
}

button:active,
.file-action:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
}

.app-header,
.layout {
  width: min(100% - 40px, 1260px);
  margin: 0 auto;
}

.app-header {
  padding: 34px 0 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 24px;
}

.brand-lockup {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.brand-mark {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border: 1px solid rgba(255, 255, 255, 0.66);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

.header-copy {
  max-width: 720px;
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.55;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 780;
  letter-spacing: 0;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.muted,
.save-state {
  color: var(--muted);
}

.header-actions,
.form-actions,
.section-heading,
.tabs,
.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.header-actions {
  justify-content: flex-end;
  max-width: 360px;
}

.layout {
  padding-bottom: 56px;
}

.hidden {
  display: none !important;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.metric,
.stat {
  min-height: 88px;
  border: 1px solid rgba(222, 211, 196, 0.88);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.82);
  padding: 15px;
  box-shadow: var(--shadow-sm);
}

.metric span,
.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 6px;
}

.metric strong,
.stat strong {
  display: block;
  font-size: 1.15rem;
  line-height: 1.25;
}

.metric strong[data-mode="remote"] {
  color: var(--success);
}

.metric strong[data-mode="local"] {
  color: var(--danger);
}

.metric strong[data-mode="checking"] {
  color: var(--warning);
}

.inline-retry {
  min-height: 36px;
  margin-top: 10px;
  padding: 0 12px;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.tabs {
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.72);
  padding: 4px;
  box-shadow: var(--shadow-sm);
}

.tab {
  min-height: 42px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 720;
}

.tab span {
  color: inherit;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 10px 20px rgba(31, 77, 67, 0.18);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  justify-content: space-between;
  margin: 24px 0 14px;
}

.brew-form,
.table-wrap,
.detail-panel,
.filters {
  background: rgba(255, 253, 248, 0.95);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.brew-form {
  padding: 18px;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 16px;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255, 253, 248, 0.94), rgba(247, 243, 235, 0.72));
}

legend {
  padding: 0 8px;
  color: var(--ink);
  font-weight: 760;
}

.field-note {
  color: var(--muted);
  margin: -4px 0 14px;
  line-height: 1.5;
}

.optional-panel {
  background: linear-gradient(180deg, rgba(235, 226, 213, 0.8), rgba(255, 253, 248, 0.8));
}

.quick-groups {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.choice-group {
  display: grid;
  gap: 8px;
}

.choice-group p {
  font-weight: 760;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice {
  min-height: 40px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-weight: 680;
}

.choice:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.choice.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.advice-panel {
  display: grid;
  gap: 12px;
  border: 1px solid rgba(31, 77, 67, 0.22);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  background: linear-gradient(135deg, #eef7f2, #fffdf8);
  padding: 14px;
  margin: 0 0 16px;
}

.advice-panel span,
.advice-panel dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.advice-panel strong {
  display: block;
  margin-top: 5px;
  line-height: 1.4;
}

.advice-panel dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.advice-panel div,
.advice-panel dd {
  margin: 0;
}

.advice-panel dd {
  line-height: 1.38;
}

.recipe-hint {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.recipe-hint > div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbf7ef;
  padding: 12px;
}

.recipe-hint span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 5px;
}

.recipe-hint strong {
  display: block;
  line-height: 1.35;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffefa;
  color: var(--ink);
  padding: 11px 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transition:
    border-color 180ms ease,
    background 180ms ease,
    box-shadow 180ms ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
}

input[readonly] {
  background: var(--surface-2);
  color: var(--ink-soft);
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.wide {
  grid-column: 1 / -1;
}

.primary {
  background: var(--primary);
  color: #fff;
  font-weight: 780;
  box-shadow: 0 12px 24px rgba(31, 77, 67, 0.2);
}

.primary:hover {
  background: var(--primary-strong);
}

.secondary,
.ghost {
  background: rgba(255, 253, 248, 0.9);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 700;
}

.secondary:hover,
.ghost:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.danger {
  color: var(--danger);
}

.danger:hover {
  border-color: rgba(157, 47, 57, 0.34);
  background: rgba(157, 47, 57, 0.08);
}

#importFile {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.filters {
  align-items: end;
  padding: 14px;
  margin-bottom: 14px;
}

.filters label {
  flex: 1 1 220px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  min-height: 92px;
  background: rgba(255, 253, 248, 0.9);
}

.stat strong {
  font-size: 1.28rem;
  word-break: break-word;
}

.history-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 16px;
  align-items: start;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  font-weight: 780;
  background: #f3ece2;
}

td {
  font-size: 0.92rem;
}

tbody tr {
  transition: background 160ms ease;
}

tbody tr:hover {
  background: rgba(31, 77, 67, 0.05);
}

.row-actions {
  display: flex;
  gap: 8px;
}

.mini {
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.84rem;
}

.badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.8rem;
  font-weight: 780;
  white-space: nowrap;
}

.badge.test {
  background: rgba(121, 90, 18, 0.14);
  color: var(--warning);
}

.badge.success {
  background: rgba(31, 110, 72, 0.14);
  color: var(--success);
}

.badge.failed {
  background: rgba(157, 47, 57, 0.12);
  color: var(--danger);
}

.empty {
  display: none;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.empty.visible {
  display: block;
}

.detail-panel {
  padding: 16px;
  position: sticky;
  top: 16px;
}

.detail-panel h3 {
  margin: 0 0 12px;
  font-size: 1.28rem;
}

.detail-list {
  display: grid;
  gap: 10px;
}

.detail-item {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.detail-item strong,
.detail-item p {
  line-height: 1.45;
  white-space: pre-wrap;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

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

  .header-actions {
    justify-content: flex-start;
    max-width: none;
  }

  .grid.three,
  .grid.four,
  .recipe-hint,
  .advice-panel dl,
  .history-grid,
  .stats,
  .dashboard {
    grid-template-columns: 1fr 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 680px) {
  .app-header,
  .layout {
    width: min(100% - 28px, 1260px);
  }

  .app-header {
    padding-top: 22px;
  }

  .brand-lockup {
    gap: 12px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 14px;
  }

  .header-copy {
    font-size: 0.96rem;
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .recipe-hint,
  .advice-panel dl,
  .history-grid,
  .stats,
  .dashboard {
    grid-template-columns: 1fr;
  }

  .tabs,
  .tab {
    width: 100%;
  }

  fieldset,
  .brew-form,
  .filters,
  .detail-panel {
    padding: 14px;
  }

  .header-actions,
  .header-actions > *,
  .form-actions,
  .form-actions > * {
    width: 100%;
  }

  .choice {
    flex: 1 1 calc(50% - 8px);
  }
}
