:root {
  --primary: #ff6400;
  --bg: #f5f3ee;
  --card: #ffffff;
  --text: #2b2b2b;
  --muted: #777;
  --border: #e8e2da;
  --success: #167c3c;
  --danger: #b52323;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}
body.modal-open { overflow: hidden; }

.topbar {
  background: var(--primary);
  color: white;
  padding: 28px 24px;
}
.topbar h1 { margin: 0 0 6px; font-size: 28px; }
.topbar p { margin: 0; color: rgba(255,255,255,.9); }
.version-badge {
  display: inline-block;
  vertical-align: middle;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(255,255,255,.18);
}

.container {
  width: min(1150px, calc(100% - 32px));
  margin: 24px auto 48px;
  display: grid;
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,.04);
}

h2, h3 { margin-top: 0; }
h2 { font-size: 20px; }
h3 { margin-bottom: 6px; }
p { color: var(--muted); }
.section-head p, .modal-header p { margin-bottom: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

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

label { display: grid; gap: 8px; font-weight: 600; }
small { font-weight: 400; color: var(--muted); }
input, select, textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid #d9d2ca;
  border-radius: 9px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
  outline: none;
}
textarea { resize: vertical; font-family: inherit; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255,100,0,.10);
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 13px; color: #666; background: #fbfaf8; }
td input { min-width: 120px; }

.btn {
  border: 0;
  border-radius: 9px;
  padding: 11px 15px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.secondary { background: #eee8df; color: #3c3c3c; }
.btn.success { background: var(--success); color: #fff; }
.btn.danger { background: #ffe8e8; color: var(--danger); padding: 8px 10px; }
.btn:hover { filter: brightness(.98); }

.summary-line {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff7f1;
  border: 1px solid #ffd7be;
  padding: 14px 16px;
  border-radius: 10px;
}
.summary-line strong { color: var(--primary); font-size: 20px; }
.summary-line.compact { max-width: 520px; margin-left: auto; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.result-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  background: #fcfbf9;
}
.result-box span { display: block; color: var(--muted); margin-bottom: 8px; }
.result-box strong { font-size: 24px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.money { font-weight: 700; }
.muted { color: var(--muted); }

.cost-table { min-width: 1050px; }
.cost-table th:nth-child(1) { min-width: 190px; }
.cost-table th:nth-child(2) { min-width: 155px; }
.cost-table th:nth-child(3) { min-width: 135px; }
.cost-table th:nth-child(4) { min-width: 110px; }
.cost-table th:nth-child(5) { min-width: 120px; }
.cost-table th:nth-child(6) { min-width: 170px; }
.material-name-cell { display: grid; gap: 4px; }
.material-name-cell small { font-size: 11px; }
.readonly-value {
  min-width: 110px;
  padding: 10px 11px;
  border-radius: 8px;
  background: #f6f4f1;
  border: 1px solid #ece7e0;
}

.example-box {
  margin: 16px 0;
  padding: 13px 15px;
  border: 1px solid #ffd7be;
  border-radius: 10px;
  background: #fff7f1;
  line-height: 1.55;
}
.formula-note {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.formula-highlight {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #d9e4ff;
  border-radius: 9px;
  background: #f6f8ff;
  color: #3d4d70;
  font-size: 13px;
}
.unit-cost, .row-warning {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.3;
}
.row-warning { display: none; color: var(--danger); }
.row-warning.show { display: block; }

.operational-table { min-width: 820px; }
.operational-table th:nth-child(1) { min-width: 260px; }
.operational-table th:nth-child(2) { min-width: 160px; }
.operational-table th:nth-child(3) { min-width: 170px; }
.operational-table th:nth-child(4) { min-width: 180px; }

.total-card { padding: 0; overflow: hidden; }
.total-production {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 19px 20px;
  background: #fff7f1;
  border-left: 5px solid var(--primary);
}
.total-production span { display: block; font-size: 16px; font-weight: 700; }
.total-production small { display: block; margin-top: 5px; }
.total-production strong { color: var(--primary); font-size: 26px; white-space: nowrap; }

.live-note {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 9px;
  background: #f4f8f4;
  border: 1px solid #d7ead9;
  color: #3f6545;
  font-size: 13px;
}
#priceModeText.manual-mode { color: #9a5a00; }

.empty-state {
  margin-top: 10px;
  padding: 16px;
  border: 1px dashed #d8d0c8;
  border-radius: 10px;
  background: #fbfaf8;
  color: var(--muted);
  text-align: center;
}

.recipe-card { border-top: 4px solid var(--primary); }
.recipe-headline {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
  margin: 16px 0;
}
.recipe-headline > div {
  padding: 14px;
  border-radius: 10px;
  background: #fbfaf8;
  border: 1px solid var(--border);
}
.recipe-headline span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.recipe-headline strong { font-size: 18px; }
.recipe-table { min-width: 650px; }

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  padding: 28px 18px;
  background: rgba(20, 18, 16, .48);
  overflow-y: auto;
}
.modal-backdrop.show { display: flex; align-items: flex-start; justify-content: center; }
.modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 56px);
  overflow: auto;
  background: #fff;
  border-radius: 15px;
  box-shadow: 0 24px 70px rgba(0,0,0,.25);
  padding: 20px;
}
.modal-lg { width: min(880px, 100%); }
.modal-xl { width: min(1080px, 100%); }
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 15px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header p { margin-top: 0; }
.icon-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #f1eee9;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}
.modal-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin: 16px 0;
}
.modal-table-wrap { max-height: 420px; }

.material-form {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1.2fr;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.material-form .form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
}
#cancelMaterialEditBtn { display: none; }
.action-cell { display: flex; gap: 8px; }
.db-material-table { min-width: 820px; }

@media (max-width: 760px) {
  .grid.two, .result-grid, .recipe-headline { grid-template-columns: 1fr; }
  .row-between { align-items: flex-start; flex-direction: column; }
  .topbar { padding: 22px 18px; }
  .topbar h1 { font-size: 23px; }
  .total-production { align-items: flex-start; flex-direction: column; }
  .summary-line.compact { max-width: none; }
  .modal-toolbar { grid-template-columns: 1fr; }
  .material-form { grid-template-columns: 1fr; }
  .material-form .form-actions { grid-column: auto; }
  .modal-backdrop { padding: 12px; }
}

/* Riwayat produk V2: aksi menu dan pemilihan resep */
.history-row { cursor: pointer; transition: background .15s ease; }
.history-row:hover { background: #fffaf6; }
.history-row.selected-history { background: #fff3ea; box-shadow: inset 4px 0 0 var(--primary); }
.history-product-link {
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.history-product-link:hover { color: var(--primary); }
.history-actions {
  min-width: 370px;
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}
.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #f1ede7;
  color: #3c3c3c;
  border: 1px solid #e5ddd4;
}
.action-btn.action-update-cost { background: #eef6ff; color: #235b8d; border-color: #d5e8fa; }
.action-btn.action-edit-material { background: #fff6e9; color: #8a570f; border-color: #f3dfbf; }
.action-btn.action-delete { background: #ffe8e8; color: var(--danger); border-color: #f8cccc; }
.action-icon { font-size: 14px; line-height: 1; }

.history-material-note {
  margin: 16px 0;
  padding: 12px 14px;
  background: #fff7f1;
  border: 1px solid #ffd7be;
  border-radius: 10px;
  color: #6b4a34;
  line-height: 1.5;
}
.history-material-table { min-width: 850px; }
.history-material-table th:nth-child(1) { min-width: 180px; }
.history-material-table th:nth-child(2) { min-width: 135px; }
.history-material-table th:nth-child(3) { min-width: 150px; }
.history-material-table th:nth-child(4) { min-width: 155px; }
.history-material-table th:nth-child(5) { min-width: 150px; }
.modal-footer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

@media (max-width: 760px) {
  .history-actions { min-width: 300px; }
  .action-btn { padding: 8px 9px; }
  .modal-footer-actions { justify-content: stretch; flex-direction: column-reverse; }
  .modal-footer-actions .btn { width: 100%; }
}

/* Branding & aksi resep - tetap V2, tanpa badge versi pada nama aplikasi */
.recipe-section-head { align-items: flex-start; }
.recipe-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.recipe-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  padding: 10px 12px;
}
.recipe-action-btn.whatsapp { background: #eefaf1; color: #207239; border-color: #d2ecd9; }
.recipe-action-btn.pdf { background: #fff1f1; color: #9b2d2d; border-color: #f2d4d4; }
.recipe-action-btn.print { background: #f3f4f6; color: #3b4652; border-color: #dde1e6; }
.recipe-action-btn:hover { filter: brightness(.98); }

.app-footer {
  width: 100%;
  border-top: 1px solid var(--border);
  background: #ffffff;
  color: #6f6f6f;
}
.footer-inner {
  width: min(1150px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  font-size: 13px;
}
.footer-brand { font-weight: 700; color: var(--text); }
.footer-copyright { text-align: right; }

@media (max-width: 760px) {
  .recipe-actions { width: 100%; justify-content: flex-start; }
  .recipe-action-btn { flex: 1 1 auto; justify-content: center; }
  .footer-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .footer-copyright { text-align: left; }
}
