:root {
  --bg: #f5f1e9;
  --surface: #fffdf8;
  --ink: #24211c;
  --muted: #6b655c;
  --line: #ded4c5;
  --accent: #793027;
  --accent-dark: #55201b;
  --blue: #315d72;
  --shadow: 0 18px 42px rgba(40, 33, 25, 0.11);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  padding: 0 12px;
}

button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

button:disabled,
button:disabled:hover {
  border-color: var(--line);
  background: #ece5da;
  color: #9c9286;
  cursor: not-allowed;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  outline: none;
  padding: 10px 11px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(121, 48, 39, 0.14);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-card h1,
.topbar h1,
.section-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-card button,
.actions button[type="submit"],
#saveRecipeButton {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.login-card button:hover,
#saveRecipeButton:hover {
  background: var(--accent-dark);
  color: white;
}

.hint,
.field-hint,
.error,
.status {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.field-hint {
  font-size: 0.82rem;
}

.error {
  color: #a33125;
  font-weight: 800;
}

.admin-shell {
  min-height: 100vh;
}

.app-view {
  padding: 20px;
}

.topbar,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 14px;
}

.topbar-side {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.header-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.stat-pill {
  display: grid;
  min-width: 96px;
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 8px 10px;
}

.stat-pill span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.stat-pill strong {
  color: var(--blue);
  font-size: 1.15rem;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.session-box,
.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.action-panel {
  display: grid;
  gap: 6px;
  justify-items: end;
  max-width: 100%;
}

.action-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
  line-height: 1.3;
  text-align: right;
}

.action-status.error {
  color: #a33125;
}

.action-status.success {
  color: #2f6b3f;
}

.session-box span {
  color: var(--muted);
  font-weight: 800;
}

.env-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffefa;
  color: var(--blue) !important;
  font-size: 0.72rem;
  letter-spacing: 0;
  padding: 5px 8px;
  text-transform: uppercase;
}

.env-badge.local {
  border-color: #b8862b;
  color: #8a5a05 !important;
}

.env-badge.prod {
  border-color: var(--blue);
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.tabs button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}

.tab-panel {
  display: grid;
  grid-template-columns: minmax(320px, 0.78fr) minmax(420px, 1.22fr);
  gap: 16px;
  align-items: start;
}

.list-panel,
.editor-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.list-panel {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 110px);
  overflow: hidden;
}

.list-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 12px;
}

.search-box {
  position: relative;
}

.search-box input {
  padding-right: 42px;
}

.search-clear {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 28px;
  min-height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  line-height: 1;
  padding: 0;
}

.search-clear:hover {
  background: #efe4d5;
  color: var(--accent);
}

.recipe-list,
.user-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 178px);
  overflow: auto;
  padding: 12px;
}

.recipe-row,
.user-row {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 10px;
  text-align: left;
}

.recipe-row.active,
.user-row.active {
  border-color: var(--blue);
  box-shadow: inset 4px 0 0 var(--blue);
}

.recipe-row strong,
.recipe-row span,
.user-row strong,
.user-row span {
  overflow-wrap: anywhere;
}

.recipe-row span,
.recipe-row small,
.user-row span,
.user-row small {
  color: var(--muted);
}

.editor-panel {
  padding: 18px;
  scroll-margin-top: 64px;
}

.editor-form {
  display: grid;
  gap: 14px;
}

.photo-assist {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 12px;
}

.photo-assist-main {
  display: grid;
  gap: 12px;
}

.assist-grid {
  align-items: end;
}

.file-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.file-action-row button {
  min-width: 190px;
  margin-bottom: 0;
}

.photo-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.photo-preview {
  width: 132px;
  height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}

.photo-assist .status {
  grid-column: 1 / -1;
}

.mold-editor {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 12px;
}

.mold-editor legend {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  padding: 0 6px;
}

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

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row input {
  width: auto;
}

@media (max-width: 920px) {
  .app-view {
    padding: 12px;
  }

  .topbar,
  .section-head {
    display: grid;
    grid-template-columns: 1fr;
  }

  .topbar-side,
  .session-box,
  .action-panel {
    justify-content: stretch;
    justify-items: stretch;
    width: 100%;
  }

  .header-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .stat-pill {
    min-width: 0;
  }

  .tabs {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg);
    padding: 4px 0;
  }

  .tabs button {
    flex: 1;
  }

  .tab-panel,
  .grid.two {
    grid-template-columns: 1fr;
  }

  .list-panel {
    position: static;
    max-height: none;
  }

  .list-tools {
    grid-template-columns: 1fr;
  }

  .recipe-list,
  .user-list {
    max-height: min(48vh, 380px);
  }

  .editor-panel {
    padding: 12px;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
  }

  .actions button {
    width: 100%;
  }

  #saveRecipeButton {
    grid-column: 1 / -1;
  }

  .photo-assist {
    grid-template-columns: 1fr;
  }

  .file-action-row {
    grid-template-columns: 1fr;
  }

  .file-action-row button {
    min-width: 0;
  }

  .photo-actions {
    justify-items: stretch;
  }

  .photo-preview {
    width: 100%;
    height: 160px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 520px) {
  .actions {
    grid-template-columns: 1fr;
  }
}
