/* ---------- LAYOUT ---------- */
#app { display: flex; width: 100%; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.88);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 4px 0 22px rgba(116, 49, 74, 0.04);
  backdrop-filter: blur(12px);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand img { width: 28px; height: 28px; }
.sidebar-brand span {
  position: relative;
  font-family: var(--font-title);
  font-size: 21px;
  font-weight: 700;
  color: var(--accent-strong);
}
.sidebar-brand span::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: -5px;
  width: 28px;
  height: 3px;
  border-radius: 999px;
  background: var(--secondary);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}
.nav-item:hover { background: var(--bg-elevated); color: var(--accent-strong); transform: translateX(2px); }
.nav-item.active { background: var(--accent-soft); border-color: rgba(201, 47, 102, 0.13); color: var(--accent-strong); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.nav-spacer { flex: 1; }

main#content {
  flex: 1;
  padding: 28px 32px;
  max-width: 1280px;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.page-header h1 { font-size: 22px; }
.page-header p { color: var(--text-dim); font-size: 13px; margin-top: 4px; }

/* ---------- CARDS ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card-actions { display: flex; gap: 8px; align-items: center; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.metric-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}
.metric-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--accent) 0 76%, var(--secondary) 76% 100%);
}
.metric-card .label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.metric-card .value { font-family: var(--font-mono); font-size: 24px; font-weight: 500; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:focus-visible { outline: 3px solid rgba(201, 47, 102, 0.20); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 5px 14px rgba(201, 47, 102, 0.18); }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 7px 18px rgba(201, 47, 102, 0.24); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg-elevated); border-color: #dfb8c5; }
.btn-danger { background: #fff; border-color: rgba(199, 53, 50, 0.38); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn:disabled { opacity: 0.48; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ---------- FORMS ---------- */
label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 10px;
  font-size: 13px;
  font-family: var(--font-body);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field { margin-bottom: 14px; }

/* ---------- CHIPS / BADGES ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: #fffafc;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.chip-accent { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }
.chip-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.chip-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---------- MODAL ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(63, 39, 50, 0.34);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  backdrop-filter: blur(3px);
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; width: 420px; max-width: 90vw; max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.modal h2 { font-size: 17px; margin-bottom: 16px; }

/* ---------- TABLE ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: rgba(201, 47, 102, 0.035); }

/* ---------- LOGIN ---------- */
.login-screen {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 100vh;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 18% 16%, rgba(201, 47, 102, 0.12), transparent 28rem),
    radial-gradient(circle at 82% 84%, rgba(244, 196, 78, 0.18), transparent 26rem);
}
.login-box {
  position: relative;
  width: 400px;
  max-width: 100%;
  padding: 32px 28px 28px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.login-box::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--accent) 0 78%, var(--secondary) 78% 100%);
}
.login-box h1 { text-align: center; color: var(--accent-strong); font-size: 30px; margin-bottom: 4px; }
.login-box p.sub { text-align: center; color: var(--text-dim); font-size: 13px; margin-bottom: 20px; }
.login-error { color: var(--danger); font-size: 12px; margin-top: 6px; min-height: 16px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-faint); }
.empty-state h3 { color: var(--text-dim); margin-bottom: 6px; }

.hidden { display: none !important; }

/* ---------- RECEITAS ---------- */
.table-wrap { overflow-x: auto; }

.recipe-table { min-width: 820px; }
.recipe-table td:nth-child(2) { color: var(--text-dim); }
.recipe-table td:nth-child(2) .chip { margin-left: 7px; }
.recipe-unit-cost { color: var(--accent-strong); font-weight: 600; }
.recipe-actions { justify-content: flex-end; }

.recipe-modal { width: 760px; }
.recipe-main-fields {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(150px, 1fr);
  gap: 14px;
}

.recipe-section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 4px 0 12px;
}
.recipe-section-header h3 { font-family: var(--font-body); font-size: 13px; }
.recipe-section-header p { color: var(--text-dim); font-size: 11px; margin: 4px 0 0; }

.recipe-items {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.recipe-item-head,
.recipe-item-row {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) minmax(100px, 0.8fr) 62px minmax(94px, 0.8fr) 34px;
  gap: 10px;
  align-items: center;
}
.recipe-item-head {
  padding: 8px 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.recipe-item-row {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
}
.recipe-item-row:last-child { border-bottom: 0; }
.recipe-item-row input,
.recipe-item-row select { padding: 7px 8px; }
.recipe-item-unit { color: var(--text-dim); font-size: 12px; text-align: center; }
.recipe-item-cost { font-size: 12px; text-align: right; }
.recipe-remove-item {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.recipe-remove-item:hover { color: var(--danger); border-color: var(--danger); }
.recipe-items-empty { padding: 22px; text-align: center; color: var(--text-faint); font-size: 12px; }

.recipe-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.recipe-summary > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
}
.recipe-summary span { color: var(--text-dim); font-size: 11px; }
.recipe-summary strong { color: var(--accent-strong); font-size: 14px; }
.recipe-modal-actions { justify-content: flex-end; margin-top: 10px; }

@media (max-width: 700px) {
  .recipe-modal { width: calc(100vw - 24px); max-width: none; padding: 18px 14px; }
  .recipe-main-fields { grid-template-columns: 1fr; gap: 0; }
  .recipe-section-header { align-items: stretch; flex-direction: column; gap: 10px; }
  .recipe-section-header .btn { justify-content: center; }
  .recipe-item-head { display: none; }
  .recipe-item-row {
    grid-template-columns: minmax(0, 1fr) 82px 32px;
    gap: 8px;
  }
  .recipe-item-row .recipe-ingredient-select { grid-column: 1 / 3; }
  .recipe-item-row .recipe-quantity-input { grid-column: 1; grid-row: 2; }
  .recipe-item-unit { grid-column: 2; grid-row: 2; text-align: left; }
  .recipe-item-cost { grid-column: 1 / 3; grid-row: 3; text-align: left; }
  .recipe-remove-item { grid-column: 3; grid-row: 1; }
  .recipe-summary { grid-template-columns: 1fr; }
}

/* ---------- CUSTOS INDIRETOS ---------- */
.costs-summary { margin-bottom: 14px; }
.costs-summary .metric-card { min-width: 0; }
.costs-summary .value { font-size: 20px; }
.costs-summary .metric-card small {
  color: var(--danger);
  font-size: 10px;
  line-height: 1.4;
}
.metric-warning { border-color: rgba(199, 53, 50, 0.38); }

.allocation-card {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 18px 24px;
  align-items: end;
  margin-bottom: 14px;
}
.allocation-copy h3 { font-family: var(--font-body); font-size: 14px; }
.allocation-copy p { color: var(--text-dim); font-size: 12px; margin: 5px 0 0; }
.allocation-form { display: flex; align-items: flex-end; gap: 8px; }
.allocation-form > div { width: 170px; }
.cost-inline-message { grid-column: 1 / -1; min-height: 0; font-size: 11px; margin-top: -10px; }
.cost-inline-message.is-error { color: var(--danger); }
.cost-inline-message.is-success { color: var(--success); }

.costs-table { min-width: 1040px; }
.costs-table td { vertical-align: middle; }
.costs-table td:first-child strong,
.costs-table td:nth-child(3) strong { display: block; }
.costs-table td:first-child small,
.costs-table td:nth-child(3) small {
  display: block;
  color: var(--text-faint);
  font-size: 10px;
  margin-top: 4px;
  max-width: 230px;
}
.cost-unit-equivalent { color: var(--accent-strong); }
.cost-actions { justify-content: flex-end; flex-wrap: nowrap; }
.cost-inactive { opacity: 0.55; }
.cost-inactive:hover { opacity: 0.8; }

.cost-modal { width: 700px; }
.cost-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 14px;
}
.cost-name-field,
.cost-note-field { grid-column: 1 / -1; }
.field-hint { display: block; color: var(--text-faint); font-size: 10px; line-height: 1.4; margin-top: 5px; }
.cost-preview {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
}
.cost-modal-actions { justify-content: flex-end; margin-top: 10px; }

@media (max-width: 700px) {
  .costs-page-header { align-items: stretch; flex-direction: column; gap: 12px; }
  .costs-page-header .btn { justify-content: center; }
  .allocation-card { grid-template-columns: 1fr; align-items: stretch; }
  .allocation-form { align-items: stretch; flex-direction: column; }
  .allocation-form > div { width: 100%; }
  .allocation-form .btn { justify-content: center; }
  .cost-inline-message { grid-column: 1; margin-top: -8px; }
  .cost-modal { width: calc(100vw - 24px); max-width: none; padding: 18px 14px; }
  .cost-form-grid { grid-template-columns: 1fr; }
  .cost-name-field,
  .cost-note-field { grid-column: 1; }
}
