:root {
  --bg: #f4f6f3;
  --ink: #17201b;
  --muted: #637068;
  --line: #dce3de;
  --panel: #ffffff;
  --green: #246b4b;
  --red: #b6403b;
  --gold: #b88925;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.auth-pending .sidebar,
body.auth-pending main,
body.auth-required .sidebar,
body.auth-required main {
  display: none;
}

body.authenticated .login-screen {
  display: none;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: #18241f;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  background: white;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .22);
}

.login-brand {
  color: var(--ink);
  margin-bottom: 6px;
}

.login-brand span,
.login-panel p {
  color: var(--muted);
}

.login-panel p {
  margin: 0;
  font-size: 13px;
}

.sidebar {
  min-height: 100vh;
  background: #18241f;
  color: white;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand span, .sidebox span, .sidebox small { color: #b8c7bf; display: block; font-size: 12px; }
.mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #e9f3ec;
  color: #18241f;
  display: grid;
  place-items: center;
  font-weight: 800;
}

nav { display: grid; gap: 8px; }
.nav {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  color: #dce8e0;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
}
.nav.active, .nav:hover { background: #2a3b33; color: white; }

.sidebox {
  margin-top: auto;
  border: 1px solid #34473d;
  border-radius: 8px;
  padding: 14px;
  background: #202f28;
}

main { padding: 28px; overflow: auto; }
header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 24px;
}
h1, h2, p { margin-top: 0; }
h1 { font-size: 28px; margin-bottom: 6px; }
h2 { font-size: 17px; margin-bottom: 0; }
header p, .panel p { color: var(--muted); }
.header-actions { display: flex; gap: 10px; }
.compact { width: 78px; }

button, input, select {
  font: inherit;
}

.primary, .iconbtn {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  min-height: 40px;
}
.primary { color: white; background: var(--green); }
.iconbtn { background: white; border: 1px solid var(--line); color: var(--ink); }
.smallbtn {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.view { display: none; }
.view.active { display: block; }

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.metrics article, .panel, .label-preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.metrics article { padding: 18px; }
.metrics span { display: block; color: var(--muted); font-size: 13px; }
.metrics strong { display: block; font-size: 30px; margin-top: 8px; }
.metrics .warn strong { color: var(--red); }

.grid { display: grid; gap: 16px; }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.panel { padding: 18px; margin-bottom: 16px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.form.vertical { grid-template-columns: 1fr; }
.compact-form { grid-template-columns: 1.1fr 1.2fr .8fr .7fr .5fr; }
.trace-form { grid-template-columns: minmax(260px, 1fr) 140px; }
.user-form { grid-template-columns: 1fr 1.2fr .9fr 1fr 150px; }
.password-form { grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) 140px; }
.audit-filter-form { grid-template-columns: 1fr 1fr 160px 110px 130px; }
.hidden { display: none; }
input, select {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: white;
}

.table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
}
th { color: var(--muted); font-weight: 650; background: #f8faf8; }
td .pill, .pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  background: #edf4ef;
  color: var(--green);
}
.quality-pending {
  background: #fff7df;
  color: #8a5d00;
}
.quality-released {
  background: #edf4ef;
  color: var(--green);
}
.quality-blocked {
  background: #ffecec;
  color: var(--red);
}
.danger { color: var(--red); font-weight: 700; }

.precheck {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.precheck-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fbfcfb;
}
.precheck-row strong {
  font-size: 13px;
}
.precheck-row small {
  color: var(--muted);
}
.precheck-row.ok strong { color: var(--green); }
.precheck-row.warn strong { color: var(--gold); }
.precheck-row.blocked strong { color: var(--red); }

.offer-item-editor {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1.5fr .7fr .7fr .8fr .8fr auto;
  gap: 8px;
  align-items: end;
}

.list { display: grid; gap: 8px; }
.item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}
.item small { color: var(--muted); }
.item b { color: var(--green); }
.customer-history {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0;
  background: #fbfcfb;
}
.customer-history h3 {
  margin: 10px 0 8px;
  font-size: 14px;
}

.checklist {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.checklist span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f9fbfa;
}

.yield-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.yield-summary span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
  color: var(--muted);
  font-size: 13px;
}
.yield-summary b {
  display: block;
  color: var(--ink);
  font-size: 20px;
  margin-top: 6px;
}

.temperature-trend {
  display: grid;
  gap: 12px;
}
.trend-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}
.trend-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.trend-head span {
  color: var(--muted);
  font-size: 13px;
}
.trend-bars {
  height: 78px;
  display: grid;
  grid-template-columns: repeat(18, minmax(6px, 1fr));
  align-items: end;
  gap: 5px;
  border-bottom: 1px solid var(--line);
}
.trend-bars span {
  display: block;
  min-height: 6px;
  border-radius: 5px 5px 0 0;
  background: #7aa48d;
}
.trend-bars span.warn {
  background: var(--gold);
}

.label-preview {
  min-height: 280px;
  padding: 22px;
  outline: 8px solid white;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.label-preview small { color: var(--gold); font-weight: 800; }
.label-preview h2 { font-size: 28px; margin: 8px 0 12px; }
.label-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 0;
}
.label-meta span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}
.label-meta b { display: block; color: var(--ink); font-size: 14px; margin-top: 3px; }
.qr {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, #111 8px, transparent 8px) 0 0/16px 16px,
    linear-gradient(#111 8px, transparent 8px) 0 0/16px 16px,
    #fff;
  border: 6px solid white;
  box-shadow: 0 0 0 1px var(--line);
  color: transparent;
}

pre {
  white-space: pre-wrap;
  background: #101815;
  color: #dce8e0;
  border-radius: 8px;
  padding: 14px;
  overflow: auto;
}

.trace {
  display: grid;
  gap: 10px;
}
.trace-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}
.trace-card h3 {
  margin: 0 0 8px;
  font-size: 15px;
}
.trace-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}
.label-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.label-actions a {
  color: var(--green);
  text-decoration: none;
  font-weight: 700;
}
.integration-flow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.integration-flow span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #f9fbfa;
}
.integration-flow b { color: var(--gold); }
.backup-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfb;
}
.backup-box button { margin-right: 8px; margin-bottom: 8px; }
.status-ok { color: var(--green); font-weight: 800; }
.status-warning { color: var(--gold); font-weight: 800; }
.status-blocked { color: var(--red); font-weight: 800; }

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #18241f;
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(10px);
  transition: .2s ease;
}
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
  nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metrics, .yield-summary, .two, .three, .form, .compact-form, .trace-form, .user-form, .password-form, .audit-filter-form { grid-template-columns: 1fr; }
  header { flex-direction: column; }
}
