:root {
  --bg: #0f1419;
  --panel: #1a222c;
  --line: #2c3846;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #e8a838;
  --ok: #3dba7a;
  --err: #e85a5a;
  --warn: #d4a017;
  --radius: 10px;
  --font: "Segoe UI", system-ui, sans-serif;
  --wrap: 960px;
  --pad: clamp(12px, 3vw, 20px);
  --sidebar-w: 248px;
  --bottom-h: 68px;
  --mobile-top-h: 56px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #1e2a38 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}
img, video, canvas { max-width: 100%; height: auto; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* —— App shell —— */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.auth-shell .wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 28px) var(--pad) 40px;
}

.wrap {
  width: 100%;
  max-width: var(--wrap);
  margin: 0 auto;
  padding: clamp(18px, 4vw, 28px) var(--pad) 40px;
  flex: 1;
}

/* —— Sidebar (PC) —— */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: rgba(15, 20, 25, .96);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.sidebar-brand strong { display: block; font-size: 1rem; }
.sidebar-brand small { color: var(--muted); font-size: .78rem; }
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), #c4841f);
  color: #1a1205;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  flex-shrink: 0;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--text);
  opacity: .82;
  text-decoration: none;
  min-height: 44px;
}
.nav-link:hover {
  background: #12181f;
  opacity: 1;
  text-decoration: none;
  color: var(--text);
}
.nav-link.is-active {
  background: rgba(232, 168, 56, .14);
  color: var(--accent);
  opacity: 1;
  font-weight: 600;
}
.nav-ico {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nav-ico svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #12181f;
  color: var(--text);
  text-decoration: none;
  margin-top: 12px;
}
.sidebar-profile:hover { border-color: var(--accent); text-decoration: none; color: var(--text); }
.sidebar-profile.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(232,168,56,.25); }
.sidebar-profile-text { min-width: 0; }
.sidebar-profile-text strong {
  display: block;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-profile-text small { color: var(--muted); font-size: .78rem; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(145deg, #3a4a5c, #243040);
  border: 2px solid var(--accent);
  color: var(--text);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: .95rem;
}
.avatar-lg { width: 64px; height: 64px; font-size: 1.4rem; }
.avatar-link {
  display: inline-flex;
  text-decoration: none;
}
.avatar-link.is-active .avatar {
  box-shadow: 0 0 0 2px rgba(232,168,56,.35);
}

/* —— Mobile top + bottom —— */
.mobile-top,
.bottom-nav {
  display: none;
}

h1 { font-size: clamp(1.35rem, 4vw, 1.6rem); margin: 0 0 8px; }
.lead { color: var(--muted); margin: 0 0 22px; }
.card-title { font-size: 1.1rem; margin: 0 0 12px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(14px, 3vw, 20px);
  margin-bottom: 18px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
  gap: 12px;
}
.stat {
  background: #12181f;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .n { font-size: clamp(1.35rem, 4vw, 1.6rem); font-weight: 700; color: var(--accent); }
.stat .l { color: var(--muted); font-size: .85rem; margin-top: 4px; }

label { display: block; font-size: .9rem; margin-bottom: 6px; color: var(--muted); }
input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #12181f;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 14px;
  min-height: 46px;
}
input[type="file"] {
  padding: 10px;
  cursor: pointer;
}
select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #12181f;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 14px;
  min-height: 46px;
}
.inline-form { margin: 0; }
.inline-form select {
  margin: 0;
  min-height: 38px;
  padding: 8px 10px;
  width: auto;
  max-width: 160px;
}
.user-actions summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}
.user-actions[open] {
  background: #12181f;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

/* —— Usuarios (rediseño) —— */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
.users-hero {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
}
.users-hero .lead { margin-bottom: 0; }
.users-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.users-stat {
  min-width: 72px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: center;
}
.users-stat strong {
  display: block;
  font-size: 1.25rem;
  color: var(--accent);
  line-height: 1.1;
}
.users-stat span {
  color: var(--muted);
  font-size: .75rem;
}
.users-create {
  margin-bottom: 22px;
  background:
    radial-gradient(600px 180px at 100% 0%, rgba(232,168,56,.08), transparent 55%),
    var(--panel);
}
.users-create-head { margin-bottom: 18px; }
.users-hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .92rem;
}
.users-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 6px;
}
.users-form .field { margin: 0; }
.users-form .field input { margin-bottom: 0; }
.field-label {
  margin: 14px 0 10px;
  font-size: .9rem;
  color: var(--muted);
}
.role-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.role-card { cursor: pointer; margin: 0; }
.role-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.role-card-body {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #12181f;
  min-height: 88px;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.role-card:hover .role-card-body {
  border-color: rgba(232,168,56,.45);
}
.role-card input:checked + .role-card-body {
  border-color: var(--accent);
  background: rgba(232,168,56,.1);
  box-shadow: 0 0 0 1px rgba(232,168,56,.2);
}
.role-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(232,168,56,.12);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.role-card-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.role-card-text strong {
  display: block;
  margin-bottom: 2px;
}
.role-card-text small {
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.35;
}
.users-form-actions { margin-top: 4px; }

.users-list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.users-list-head .card-title { margin: 0; }
.users-count { color: var(--muted); font-size: .85rem; }
.users-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.user-card {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.user-card-main {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
  flex: 1 1 220px;
}
.user-card-avatar { width: 44px; height: 44px; }
.user-card-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.user-card-name strong { font-size: 1.02rem; }
.user-chip {
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(232,168,56,.18);
  color: var(--accent);
}
.user-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}
.role-badge {
  font-size: .72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}
.role-badge-admin {
  background: rgba(232,168,56,.16);
  color: var(--accent);
}
.role-badge-vendedor {
  background: rgba(61,186,122,.16);
  color: var(--ok);
}
.user-date { color: var(--muted); font-size: .8rem; }
.user-card-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.user-role-form select {
  margin: 0;
  min-height: 42px;
  width: auto;
  min-width: 140px;
}
.user-more { position: relative; }
.user-more-btn {
  min-height: 42px;
  padding: 8px 14px;
}
.user-more-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 12;
  width: min(320px, 86vw);
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #12181f;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
}
.user-pass-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.user-pass-row input {
  margin-bottom: 0;
  flex: 1;
}
.user-delete-btn { width: 100%; }
.users-empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 16px;
}

@media (max-width: 720px) {
  .users-form-grid,
  .role-picker {
    grid-template-columns: 1fr;
  }
  .user-card-controls {
    width: 100%;
  }
  .user-role-form,
  .user-role-form select,
  .user-more,
  .user-more-btn {
    width: 100%;
  }
  .user-more-panel {
    left: 0;
    right: 0;
    width: auto;
  }
}


.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: #1a1205;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 1rem;
  min-height: 46px;
  text-align: center;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}
.btn-danger { background: var(--err); color: #fff; }
.btn-file { cursor: pointer; margin: 0; }
.btn-row, .form-actions, .actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: stretch;
}
.btn-row .btn, .form-actions .btn, .actions-row .btn { flex: 1 1 auto; }

.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  border: 1px solid;
  word-break: break-word;
}
.alert-ok { background: rgba(61,186,122,.12); border-color: var(--ok); color: #b8f0d0; }
.alert-error { background: rgba(232,90,90,.12); border-color: var(--err); color: #ffc9c9; }
.alert-info { background: rgba(232,168,56,.12); border-color: var(--accent); color: #ffe2a8; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 480px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

.login-box { max-width: 400px; margin: clamp(24px, 8vw, 60px) auto; width: 100%; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; word-break: break-all; }

.profile-card .profile-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}
.profile-meta {
  display: grid;
  gap: 12px;
  margin: 0 0 20px;
}
.profile-meta dt {
  color: var(--muted);
  font-size: .8rem;
  margin: 0 0 2px;
}
.profile-meta dd { margin: 0; font-weight: 600; }

.logo-preview-wrap {
  margin-bottom: 18px;
  padding: 14px;
  background: #fff;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: inline-block;
  max-width: 100%;
}
.logo-preview {
  display: block;
  max-width: min(220px, 100%);
  max-height: 90px;
  object-fit: contain;
}

.scan-list { list-style: none; padding: 0; margin: 12px 0 16px; }
.scan-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: #12181f;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 8px;
}
.btn-remove {
  flex-shrink: 0;
  padding: 8px 10px;
  font-size: .75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
}
.badge-ok { background: rgba(61,186,122,.2); color: var(--ok); }
.badge-used { background: rgba(232,90,90,.2); color: var(--err); }
.badge-wait { background: rgba(232,168,56,.2); color: var(--accent); }

.count-label { margin: 0 0 12px; font-weight: 600; }
.progress {
  height: 10px;
  background: #12181f;
  border-radius: 999px;
  overflow: hidden;
  margin: 0 0 12px;
  border: 1px solid var(--line);
}
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #f0c46a);
  width: 0%;
  transition: width .2s ease;
}

.scanner-panel { margin-bottom: 18px; }
.reader-box {
  width: 100%;
  max-width: 420px;
  margin: 0 auto 12px;
  min-height: 240px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: #12181f;
  overflow: hidden;
  position: relative;
}
.reader-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  pointer-events: none;
}
.reader-title { margin: 0 0 6px; font-weight: 700; }
.reader-hint { margin: 0; color: var(--muted); font-size: .9rem; }
.scanner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-bottom: 8px;
}
.scanner-actions .btn { flex: 1 1 140px; max-width: 220px; }
.scanner-status {
  min-height: 1.4em;
  margin: 0 0 10px;
  text-align: center;
  font-size: .9rem;
  color: var(--muted);
}
.scanner-status.is-ok { color: var(--ok); }
.scanner-status.is-error { color: var(--err); }
.scanner-status.is-warn { color: var(--accent); }
.scanner-status.is-info { color: var(--muted); }

.manual-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.manual-row input {
  flex: 1 1 180px;
  margin-bottom: 0;
}
.manual-row .btn { flex: 0 0 auto; }

#reader video,
#reader canvas,
#reader img {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  border-radius: 12px;
}
#reader__scan_region { min-height: 220px; }
#reader__dashboard_section { padding: 8px !important; }

.scan-public {
  text-align: center;
  padding: clamp(24px, 6vw, 40px) var(--pad);
}
.scan-public .icon { font-size: 3rem; margin-bottom: 12px; }
.scan-public .card { max-width: 440px; margin: 0 auto; }

/* —— Mobile layout —— */
@media (max-width: 900px) {
  .app-shell { display: block; }
  .sidebar { display: none; }

  .mobile-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--mobile-top-h);
    padding: 0 var(--pad);
    background: rgba(15, 20, 25, .94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
  }
  .mobile-top .brand { font-weight: 700; }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    height: calc(var(--bottom-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    background: rgba(15, 20, 25, .96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
  }
  .bottom-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--muted);
    text-decoration: none;
    font-size: .68rem;
    font-weight: 600;
    min-height: 52px;
    border-radius: 10px;
  }
  .bottom-link:hover,
  .bottom-link.is-active {
    color: var(--accent);
    text-decoration: none;
    background: rgba(232, 168, 56, .08);
  }
  .bottom-link .nav-ico { width: 22px; height: 22px; }

  .app-shell .wrap {
    padding-bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom, 0px) + 24px);
  }

  .scanner-actions .btn { max-width: none; }
  .form-actions .btn { width: 100%; }
  table { font-size: .85rem; min-width: 420px; }
}

@media (max-width: 420px) {
  .stat .n { font-size: 1.25rem; }
  .reader-box { min-height: 200px; }
  .bottom-link { font-size: .62rem; }
}
