:root {
  --hc-blue: #1F6FB5;
  --hc-blue-dark: #0d4d8f;
  --hc-blue-deep: #2A4858;
  --hc-cyan: #4FC3F7;
  --hc-cyan-light: #bfe0f5;
  --hc-gray: #5A6C7D;
  --hc-bg: #f5f8fb;
  --hc-bg-alt: #e8eef3;
  --hc-text: #1a2530;
  --hc-text-soft: #2A4858;
  --hc-accent: #f5b945;
  --hc-success: #3dc789;
  --hc-danger: #c0394e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 15px; line-height: 1.55; color: var(--hc-text);
  background: var(--hc-bg);
}

.mono { font-family: 'JetBrains Mono', "SF Mono", Menlo, Consolas, monospace; }
.num  { font-family: Georgia, serif; }

a { color: var(--hc-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ========= APP SHELL ========= */
body.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; background: var(--hc-bg); }

.sidebar {
  background: var(--hc-blue-deep); color: var(--hc-cyan-light);
  padding: 20px 16px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.sidebar .brand { padding: 6px 8px 20px; border-bottom: 1px solid rgba(255,255,255,0.07); margin-bottom: 16px; }
.sidebar .brand img { filter: brightness(0) invert(1); }
.sidebar nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }
.nav-title { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em; color: rgba(255,255,255,0.45); padding: 0 8px 4px; }
.sidebar a { color: var(--hc-cyan-light); padding: 7px 10px; border-radius: 6px; font-size: 0.92rem; }
.sidebar a:hover { background: rgba(255,255,255,0.05); text-decoration: none; color: white; }
.sidebar a.active { background: var(--hc-blue); color: white; }
.user-pill {
  background: rgba(255,255,255,0.04); border-radius: 8px;
  padding: 10px 12px; font-size: 0.78rem;
}
.user-pill strong { display: block; color: white; margin-bottom: 2px; font-size: 0.84rem; }
.user-pill span { color: var(--hc-cyan); font-family: 'JetBrains Mono', monospace; font-size: 0.7rem; }
.btn-logout {
  margin-top: 10px; width: 100%; padding: 8px;
  background: transparent; color: var(--hc-cyan-light);
  border: 1px solid rgba(255,255,255,0.10); border-radius: 6px;
  cursor: pointer; font-size: 0.82rem;
}
.btn-logout:hover { background: var(--hc-danger); color: white; border-color: var(--hc-danger); }

.content { padding: 28px 36px; max-width: 1280px; }

/* ========= PAGE HEADER ========= */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { font-size: 1.6rem; color: var(--hc-blue-dark); letter-spacing: -0.01em; }
.page-header .sub { font-size: 0.92rem; color: var(--hc-gray); margin-top: 2px; }
.page-header .actions { display: flex; gap: 8px; }

/* ========= CARDS / STATS ========= */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat-card {
  background: white; border: 1px solid rgba(31,111,181,0.08); border-radius: 12px;
  padding: 18px;
}
.stat-card .k { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--hc-gray); margin-bottom: 6px; }
.stat-card .v { font-family: Georgia, serif; font-weight: 700; font-size: 2.1rem; color: var(--hc-blue-dark); line-height: 1; }
.stat-card .h { margin-top: 4px; font-size: 0.78rem; color: var(--hc-gray); }

.card {
  background: white; border: 1px solid rgba(31,111,181,0.08); border-radius: 12px;
  padding: 20px; margin-bottom: 14px;
}
.card h2 { font-size: 1.1rem; color: var(--hc-blue-dark); margin-bottom: 12px; }
.card h3 { font-size: 0.96rem; color: var(--hc-blue); margin-bottom: 8px; }
.card .empty { padding: 24px; text-align: center; color: var(--hc-gray); border: 1px dashed rgba(31,111,181,0.16); border-radius: 8px; }

/* ========= TABLE ========= */
table.tbl {
  width: 100%; border-collapse: collapse; font-size: 0.88rem;
}
table.tbl thead th {
  text-align: left; padding: 10px 12px; background: var(--hc-bg);
  color: var(--hc-blue-dark); font-weight: 600; font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid rgba(31,111,181,0.10);
}
table.tbl tbody td {
  padding: 10px 12px; border-bottom: 1px solid rgba(31,111,181,0.06);
  vertical-align: top;
}
table.tbl tbody tr:hover { background: rgba(31,111,181,0.03); }
table.tbl .mono { font-size: 0.82rem; }

/* ========= FORM ========= */
form .field { margin-bottom: 14px; }
form label { display: block; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--hc-gray); margin-bottom: 5px; }
form input, form select, form textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid rgba(31,111,181,0.15); border-radius: 7px;
  background: white; color: var(--hc-text); font-size: 0.94rem; font-family: inherit;
}
form input:focus, form select:focus, form textarea:focus {
  outline: none; border-color: var(--hc-blue); box-shadow: 0 0 0 3px rgba(31,111,181,0.12);
}
form button[type=submit], .btn {
  padding: 9px 16px; background: var(--hc-blue); color: white;
  border: 0; border-radius: 7px; font-weight: 600; cursor: pointer; font-size: 0.92rem;
  font-family: inherit;
}
form button[type=submit]:hover, .btn:hover { background: var(--hc-blue-dark); text-decoration: none; color: white; }
.btn-secondary { background: white; color: var(--hc-blue-dark); border: 1px solid rgba(31,111,181,0.20); }
.btn-secondary:hover { background: var(--hc-bg); color: var(--hc-blue-dark); }
.btn-danger { background: var(--hc-danger); }
.btn-danger:hover { background: #8a1f30; }

.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

/* ========= AUTH PAGES ========= */
body.auth-page {
  background: radial-gradient(900px 500px at 80% -10%, #2a4858 0%, transparent 60%),
              radial-gradient(700px 400px at -10% 110%, #1F6FB5 0%, transparent 50%),
              #0b121b;
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  color: var(--hc-cyan-light);
}
.auth-card {
  background: rgba(18, 28, 42, 0.92);
  border: 1px solid rgba(79,195,247,0.12);
  border-radius: 16px;
  padding: 36px;
  width: 100%; max-width: 440px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
}
.auth-card h1 { font-size: 1.4rem; color: white; margin-bottom: 6px; }
.auth-card .sub { color: var(--hc-cyan-light); font-size: 0.88rem; margin-bottom: 20px; }
.auth-card .err { padding: 10px; background: rgba(192,57,78,0.15); border: 1px solid rgba(192,57,78,0.30); border-radius: 8px; color: #ffb4b4; font-size: 0.85rem; margin-top: 14px; }
.auth-card input { background: #0e1722; color: white; border-color: rgba(255,255,255,0.10); }
.auth-card input:focus { border-color: var(--hc-cyan); box-shadow: 0 0 0 3px rgba(79,195,247,0.18); }
.auth-card form button[type=submit] { width: 100%; padding: 12px; background: linear-gradient(135deg, #1F6FB5, #4FC3F7); margin-top: 8px; }
.auth-card .qr { background: white; border-radius: 12px; padding: 14px; display: grid; place-items: center; margin: 14px 0; }
.auth-card .qr img { max-width: 220px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.auth-brand img { height: 28px; filter: brightness(0) invert(1); }
.auth-brand small { color: rgba(255,255,255,0.5); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; }
.secret-key { font-family: 'JetBrains Mono', monospace; font-size: 0.74rem; color: var(--hc-cyan); word-break: break-all; background: rgba(255,255,255,0.04); padding: 8px; border-radius: 6px; margin-top: 6px; }

/* ========= BADGES ========= */
.badge {
  display: inline-block; padding: 3px 8px; border-radius: 10px;
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  background: rgba(31,111,181,0.10); color: var(--hc-blue-dark);
}
.badge.ok { background: rgba(61,199,137,0.15); color: #1e7f4a; }
.badge.warn { background: rgba(245,185,69,0.15); color: #b87a00; }
.badge.danger { background: rgba(192,57,78,0.15); color: #8a1f30; }
.badge.info { background: rgba(79,195,247,0.15); color: #0d4d8f; }

/* ========= ETIQUETA A4 (print) ========= */
.a4-sheet {
  width: 210mm; min-height: 297mm; margin: 20px auto;
  background: white; padding: 8mm; box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4mm; align-content: flex-start;
}
.etiq {
  border: 1.5px solid #0d4d8f; border-radius: 3mm;
  padding: 3mm 4mm; font-size: 8.5pt; line-height: 1.3;
  height: 50mm; display: flex; flex-direction: column; gap: 1mm;
  page-break-inside: avoid;
}
.etiq .head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #0d4d8f; padding-bottom: 1mm; }
.etiq .head .logo { font-weight: 800; color: #0d4d8f; letter-spacing: 0.05em; font-size: 10pt; }
.etiq .head .sku { font-family: 'JetBrains Mono', monospace; color: #0d4d8f; font-size: 7pt; }
.etiq .nome { font-weight: 700; color: #0d4d8f; font-size: 9.5pt; }
.etiq .desc { color: #5a6c7d; font-size: 7.5pt; }
.etiq .row { display: flex; justify-content: space-between; font-family: 'JetBrains Mono', monospace; font-size: 6.5pt; color: #2A4858; }
.etiq .qr-area { display: flex; gap: 2mm; margin-top: auto; align-items: flex-end; }
.etiq .qr-area img { width: 15mm; height: 15mm; }
.etiq .qr-info { font-family: 'JetBrains Mono', monospace; font-size: 5.5pt; color: #5a6c7d; flex: 1; word-break: break-all; }
@media print {
  body, body.app-shell { background: white !important; }
  .sidebar, .nav-print-hide { display: none !important; }
  .content { padding: 0 !important; max-width: none !important; }
  .a4-sheet { box-shadow: none; margin: 0; }
  @page { size: A4; margin: 0; }
}

/* ========= TOAST + LOADING ========= */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 10px;
  max-width: 380px;
}
.toast {
  background: white; border-left: 4px solid var(--hc-blue);
  padding: 12px 16px; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.12);
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 0.9rem; animation: toast-in 0.18s ease-out;
}
.toast.toast-ok { border-color: var(--hc-success); }
.toast.toast-err { border-color: var(--hc-danger); }
.toast.toast-warn { border-color: var(--hc-accent); }
.toast .toast-icon { font-weight: 700; line-height: 1; }
.toast.toast-ok .toast-icon { color: var(--hc-success); }
.toast.toast-err .toast-icon { color: var(--hc-danger); }
.toast.toast-warn .toast-icon { color: var(--hc-accent); }
.toast .toast-msg { flex: 1; color: var(--hc-text); }
.toast .toast-x { color: var(--hc-gray); cursor: pointer; padding: 0 4px; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

.flash-msg {
  padding: 10px 14px; border-radius: 8px;
  font-size: 0.9rem; margin-bottom: 14px;
}
.flash-msg.ok { background: rgba(61,199,137,0.12); border: 1px solid rgba(61,199,137,0.30); color: #1e7f4a; }
.flash-msg.err { background: rgba(192,57,78,0.10); border: 1px solid rgba(192,57,78,0.30); color: #8a1f30; }
.flash-msg.warn { background: rgba(245,185,69,0.12); border: 1px solid rgba(245,185,69,0.30); color: #b87a00; }

/* Loading overlay no form */
.loading-form button[type=submit][aria-busy=true] {
  opacity: 0.6; pointer-events: none; position: relative;
}
.loading-form button[type=submit][aria-busy=true]::after {
  content: "…"; margin-left: 4px;
}

/* ========= UTILS ========= */
.muted { color: var(--hc-gray); }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-20 { gap: 20px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.text-sm { font-size: 0.84rem; }
.text-xs { font-size: 0.74rem; }

/* ========= LANDING (logged-out) ========= */
body.landing { background: white; }
.landing-hero {
  padding: 100px 20px; text-align: center;
  background:
    radial-gradient(900px 500px at 90% -5%, rgba(79,195,247,0.18) 0%, transparent 55%),
    radial-gradient(700px 400px at -5% 110%, rgba(31,111,181,0.10) 0%, transparent 50%),
    white;
}
.landing-hero h1 { font-size: 3rem; margin-bottom: 14px; color: var(--hc-blue-dark); }
.landing-hero p { font-size: 1.15rem; color: var(--hc-text-soft); max-width: 720px; margin: 0 auto 28px; }
.landing-hero .ctas { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.landing-hero .btn-big { padding: 16px 36px; font-size: 1rem; border-radius: 10px; }
.landing-hero img.brand { height: 36px; margin-bottom: 28px; }

/* ========= PUBLIC DOC TEMPLATE ========= */
body.public-doc { background: var(--hc-bg); padding: 40px 24px; }
.public-doc .doc-card {
  max-width: 800px; margin: 0 auto;
  background: white; border-radius: 14px; overflow: hidden;
  box-shadow: 0 20px 60px rgba(31,111,181,0.10);
}
.public-doc .doc-card .head {
  background: linear-gradient(135deg, var(--hc-blue), var(--hc-blue-dark));
  color: white; padding: 28px 32px;
}
.public-doc .doc-card .head h1 { color: white; font-size: 1.4rem; }
.public-doc .doc-card .head .sub { color: var(--hc-cyan-light); font-size: 0.9rem; margin-top: 4px; }
.public-doc .doc-card .body { padding: 28px 32px; }
.public-doc .kv { display: grid; grid-template-columns: 200px 1fr; gap: 10px 24px; font-size: 0.94rem; }
.public-doc .kv dt { color: var(--hc-gray); }
.public-doc .kv dd { color: var(--hc-text); font-family: 'JetBrains Mono', monospace; }
.public-doc .actions { padding: 18px 32px; background: var(--hc-bg); border-top: 1px solid rgba(31,111,181,0.08); text-align: right; }
