:root {
  --brown: #3A261D;
  --brown-soft: #563A2E;
  --pink: #E0BCB1;
  --beige: #F5F0EB;
  --gold: #C9A96E;
  --white: #FFFFFF;
  --text: #211A17;
  --muted: #756A64;
  --line: #E7DDD8;
  --danger: #9A2F2F;
  --shadow: 0 18px 45px rgba(58, 38, 29, 0.12);
  --radius-lg: 26px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--beige);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: "Open Sans", "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(224, 188, 177, 0.55), transparent 38rem),
    linear-gradient(180deg, #fff 0, var(--beige) 38rem);
}

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

button {
  cursor: pointer;
}

.auth-locked .app-header,
.auth-locked .tabs,
.auth-locked .app-main {
  display: none !important;
}

.auth-unlocked .login-screen {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background:
    radial-gradient(circle at top left, rgba(224, 188, 177, 0.65), transparent 34rem),
    linear-gradient(180deg, #fff 0, var(--beige) 100%);
}

.login-card {
  width: min(100%, 460px);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(58, 38, 29, 0.08);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: clamp(1.25rem, 4vw, 2rem);
}

.login-intro {
  color: var(--muted);
  line-height: 1.45;
  margin: 0.8rem 0 0;
}

.login-form {
  margin-top: 1rem;
}

.login-form .primary-button {
  width: 100%;
  margin-top: 1rem;
}

.login-error {
  margin: 0.85rem 0 0;
  color: var(--danger);
  font-weight: 900;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: flex-end;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem clamp(1rem, 3vw, 2.5rem) 0.75rem;
  max-width: 1440px;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--brown-soft);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  font-family: Georgia, "Times New Roman", serif;
  color: var(--brown);
  line-height: 1.05;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.5rem);
}

h2 {
  margin: 0;
  font-size: clamp(1.45rem, 2.4vw, 2.1rem);
}

h3 {
  margin: 0;
  font-size: 1.18rem;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 0.5rem;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.5rem clamp(1rem, 3vw, 2.5rem) 0.85rem;
  background: rgba(245, 240, 235, 0.92);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(58, 38, 29, 0.07);
}

.tab {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.75);
  color: var(--brown-soft);
  padding: 0.8rem 1.05rem;
  border-radius: 999px;
  font-weight: 800;
  min-height: 44px;
}

.tab.active {
  background: var(--brown);
  border-color: var(--brown);
  color: var(--white);
}

.app-main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 1rem clamp(1rem, 3vw, 2.5rem) 2.5rem;
}

.tab-panel {
  display: none;
}

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

.panel-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.8fr) minmax(420px, 1.2fr);
  gap: 1.25rem;
  align-items: start;
}

.card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(58, 38, 29, 0.08);
  border-radius: var(--radius-lg);
  padding: clamp(1rem, 2.1vw, 1.6rem);
  box-shadow: var(--shadow);
}

.input-card {
  position: sticky;
  top: 6.25rem;
}

.card-title-row,
.result-header,
.editor-title-row,
.ingredients-title-row,
.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.4rem;
  margin-top: 1rem;
}

.field span {
  color: var(--brown);
  font-weight: 800;
  font-size: 0.92rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.85rem 0.95rem;
  min-height: 46px;
  outline: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(201, 169, 110, 0.18);
}

.inline-fields,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.button-row,
.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.15rem;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.small-button {
  border: 0;
  border-radius: 999px;
  min-height: 44px;
  padding: 0.78rem 1.05rem;
  font-weight: 900;
}

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

.secondary-button,
.ghost-button,
.small-button {
  background: var(--beige);
  color: var(--brown);
  border: 1px solid rgba(58, 38, 29, 0.12);
}

.danger-button {
  background: #FFF4F4;
  color: var(--danger);
  border: 1px solid rgba(154, 47, 47, 0.18);
}

.compact {
  min-height: 38px;
  padding: 0.55rem 0.85rem;
  font-size: 0.9rem;
}

.total-pill {
  white-space: nowrap;
  border-radius: 999px;
  background: var(--beige);
  color: var(--brown);
  font-weight: 900;
  padding: 0.65rem 0.9rem;
  border: 1px solid rgba(58, 38, 29, 0.08);
}

.result-content-table,
.ingredients-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}

.result-section {
  margin-top: 1.25rem;
}

.result-section-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0 0 0.55rem;
  color: var(--brown);
}

.result-section-title::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pink);
  border: 2px solid var(--brown);
}

.result-table-wrapper,
.ingredients-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.result-content-table th,
.result-content-table td,
.ingredients-table th,
.ingredients-table td {
  padding: 0.85rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.result-content-table th,
.ingredients-table th {
  background: var(--beige);
  color: var(--brown);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result-content-table tr:last-child td,
.ingredients-table tr:last-child td {
  border-bottom: 0;
}

.amount-main {
  display: block;
  font-weight: 950;
  color: var(--brown);
  font-size: 1.05rem;
}

.amount-sub {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 0.15rem;
}

.empty-state {
  margin-top: 1rem;
  color: var(--muted);
  background: var(--beige);
  border-radius: var(--radius-md);
  padding: 2rem;
  text-align: center;
}

.process-box,
.backup-note,
.special-input,
.note-box {
  margin-top: 1rem;
  border-radius: var(--radius-md);
  background: var(--beige);
  padding: 1rem;
  border: 1px solid rgba(58, 38, 29, 0.08);
}

.process-box h3,
.note-box h3 {
  margin-bottom: 0.45rem;
}

.process-box p,
.note-box p,
.backup-card p,
.hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.recipes-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.recipe-list-card {
  position: sticky;
  top: 6.25rem;
}

.list-search {
  margin-top: 1rem;
}

.recipe-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 1rem;
  max-height: 70vh;
  overflow: auto;
  padding-right: 0.25rem;
}

.recipe-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-md);
  padding: 0.8rem 0.9rem;
  color: var(--brown);
  font-weight: 900;
}

.recipe-item span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  margin-top: 0.15rem;
}

.recipe-item.active {
  border-color: var(--brown);
  background: var(--brown);
  color: #fff;
}

.recipe-item.active span {
  color: rgba(255,255,255,0.76);
}

.ingredients-title-row {
  margin-top: 1.3rem;
  align-items: center;
}

.ingredients-table input,
.ingredients-table select {
  min-width: 140px;
  padding: 0.65rem;
}

.ingredients-table .qty-input {
  min-width: 110px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(154, 47, 47, 0.2);
  color: var(--danger);
  background: #fff;
  font-weight: 950;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0), #fff 25%);
  padding-top: 1.2rem;
  padding-bottom: 0.2rem;
}

.hidden,
.visually-hidden {
  display: none !important;
}

.help-dialog {
  border: 0;
  border-radius: var(--radius-lg);
  max-width: 800px;
  width: calc(100% - 2rem);
  padding: 1.4rem;
  box-shadow: var(--shadow);
}

.help-dialog::backdrop {
  background: rgba(33, 26, 23, 0.45);
  backdrop-filter: blur(6px);
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

.help-grid > div {
  background: var(--beige);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.help-grid p {
  color: var(--muted);
  line-height: 1.4;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.1rem;
  transform: translateX(-50%) translateY(140%);
  background: var(--brown);
  color: #fff;
  padding: 0.85rem 1.1rem;
  border-radius: 999px;
  font-weight: 900;
  box-shadow: var(--shadow);
  z-index: 80;
  transition: transform 0.25s ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.file-button {
  display: inline-flex;
  align-items: center;
}

.settings-card {
  max-width: 860px;
}

.settings-box {
  margin-top: 1rem;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(245, 240, 235, 0.9), #fff);
  border: 1px solid rgba(58, 38, 29, 0.1);
  padding: 1rem;
}

.settings-form {
  margin-top: 1rem;
}

@media (max-width: 1000px) {
  .panel-grid,
  .recipes-layout {
    grid-template-columns: 1fr;
  }

  .input-card,
  .recipe-list-card {
    position: static;
  }

  .recipe-list {
    max-height: none;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}

@media (max-width: 680px) {
  .app-header {
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    flex: 1 0 auto;
  }

  .inline-fields,
  .form-grid,
  .help-grid {
    grid-template-columns: 1fr;
  }

  .result-header,
  .card-title-row,
  .editor-title-row {
    flex-direction: column;
  }

  .total-pill {
    white-space: normal;
  }

  .editor-actions,
  .button-row {
    width: 100%;
  }

  .primary-button,
  .secondary-button,
  .danger-button,
  .file-button {
    justify-content: center;
    flex: 1 1 auto;
  }
}

@media print {
  body {
    background: #fff;
  }

  .login-screen,
  .app-header,
  .tabs,
  .input-card,
  .recipe-list-card,
  .editor-card,
  .backup-card,
  .toast {
    display: none !important;
  }

  .app-main,
  .panel-grid {
    display: block;
    padding: 0;
    max-width: none;
  }

  .result-card {
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .result-content-table th,
  .result-content-table td {
    padding: 0.45rem;
  }
}

.base-info-box,
.base-editor-box {
  margin-top: 1rem;
  border: 1px solid rgba(58, 38, 29, 0.1);
  background: linear-gradient(180deg, rgba(245, 240, 235, 0.9), #fff);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.base-info-box strong,
.base-info-box span,
.base-info-box small {
  display: block;
}

.base-info-box strong {
  color: var(--brown);
  font-weight: 950;
}

.base-info-box span {
  margin-top: 0.2rem;
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--brown-soft);
}

.base-info-box small {
  margin-top: 0.45rem;
  color: var(--muted);
  line-height: 1.35;
}

.mini-title-row {
  align-items: center;
  margin-bottom: 0.35rem;
}

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

.compact-note p {
  font-size: 0.95rem;
}

.base-row-button {
  border: 1px solid rgba(58, 38, 29, 0.16);
  color: var(--brown);
  background: var(--beige);
  border-radius: 999px;
  min-height: 34px;
  padding: 0.35rem 0.65rem;
  font-weight: 900;
  font-size: 0.82rem;
}

.ingredients-table th:nth-child(1),
.ingredients-table td:nth-child(1) {
  min-width: 130px;
}

.ingredients-table th:nth-child(2),
.ingredients-table td:nth-child(2) {
  min-width: 190px;
}

.ingredients-table th:nth-child(5),
.ingredients-table td:nth-child(5) {
  min-width: 130px;
}

@media (max-width: 680px) {
  .three-cols {
    grid-template-columns: 1fr;
  }
}
