@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;1,9..40,300&display=swap');

:root {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --surface2: #F0EDE6;
  --border: #E2DDD4;
  --border2: #C8C2B5;
  --text: #1A1814;
  --text2: #6B6459;
  --text3: #9C9589;
  --accent: #2D5016;
  --accent-light: #EAF0E2;
  --accent-mid: #4A7A28;
  --red: #8B2020;
  --red-light: #F5E8E8;
  --amber: #7A4F10;
  --amber-light: #FBF0E0;
  --blue: #1A3A5C;
  --blue-light: #E5EDF5;
  --serif: 'DM Serif Display', Georgia, serif;
  --sans: 'DM Sans', system-ui, sans-serif;
  --r: 8px;
  --r2: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow2: 0 4px 16px rgba(0,0,0,.10);
  --bottom-nav-h: 64px;
}

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

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  /* Prevent horizontal scroll on mobile */
  overflow-x: hidden;
}

/* ── LOGIN ──────────────────────────────── */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--text);
  position: relative;
  overflow: hidden;
  padding: 16px;
}
#login-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 60% at 50% 100%, #2D5016 0%, transparent 70%);
  opacity: .6;
}
.login-card {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 32px 80px rgba(0,0,0,.4);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.login-logo-mark {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px; flex-shrink: 0;
}
.login-logo h1 { font-family: var(--serif); font-size: 18px; font-weight: 400; line-height: 1.2; }
.login-logo span { font-size: 11px; color: var(--text3); font-weight: 300; }
.login-title { font-family: var(--serif); font-size: 26px; font-weight: 400; margin-bottom: 6px; }
.login-sub { color: var(--text2); font-size: 13px; margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 6px; letter-spacing: .04em; text-transform: uppercase; }
.form-group input, .form-group select {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  font-family: var(--sans); font-size: 16px; /* 16px prevents iOS auto-zoom */
  color: var(--text); background: var(--bg);
  transition: border-color .15s;
  outline: none;
  -webkit-appearance: none;
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); }

/* ── BUTTONS ──────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--r);
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1.5px solid transparent; transition: all .15s;
  min-height: 44px; /* touch target */
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover, .btn-primary:active { background: var(--accent-mid); }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border2); }
.btn-secondary:hover, .btn-secondary:active { background: var(--surface2); }
.btn-danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn-danger:hover, .btn-danger:active { background: var(--red-light); }
.btn-full { width: 100%; justify-content: center; padding: 14px; font-size: 15px; }
.login-error { background: var(--red-light); color: var(--red); border-radius: var(--r); padding: 10px 14px; font-size: 13px; margin-bottom: 16px; display: none; }

/* ══════════════════════════════════════════
   MOBILE-FIRST LAYOUT
   ══════════════════════════════════════════ */

#app { display: flex; min-height: 100vh; }

/* ── SIDEBAR OVERLAY (mobile) ──────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
}
.sidebar-overlay.open { display: block; }

/* ── SIDEBAR ──────────────────────────────── */
.sidebar {
  width: 260px;
  background: var(--text);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform .25s ease;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; }
.sidebar-logo-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; flex-shrink: 0;
}
.sidebar-logo-text { font-family: var(--serif); font-size: 14px; color: #fff; line-height: 1.2; }
.sidebar-logo-text small { font-family: var(--sans); font-size: 10px; color: rgba(255,255,255,.4); font-style: normal; display: block; font-weight: 300; }
.sidebar-close {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,.5); padding: 6px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-close:hover { color: #fff; background: rgba(255,255,255,.1); }
nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-section { margin-bottom: 20px; }
.nav-label { font-size: 10px; font-weight: 500; letter-spacing: .08em; color: rgba(255,255,255,.3); text-transform: uppercase; padding: 0 8px; margin-bottom: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: var(--r);
  color: rgba(255,255,255,.55); font-size: 14px;
  cursor: pointer; transition: all .15s; margin-bottom: 2px;
  border: none; background: none; width: 100%; text-align: left;
  min-height: 44px;
}
.nav-item:hover, .nav-item:active { color: #fff; background: rgba(255,255,255,.08); }
.nav-item.active { color: #fff; background: var(--accent); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-sub { padding-left: 8px; margin-top: -2px; margin-bottom: 4px; }
.nav-sub-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px 7px 32px; border-radius: var(--r);
  color: rgba(255,255,255,.42); font-size: 12.5px;
  cursor: pointer; transition: all .15s; margin-bottom: 1px;
  text-decoration: none; width: 100%;
}
.nav-sub-item::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: rgba(255,255,255,.25); flex-shrink: 0; }
.nav-sub-item:hover { color: rgba(255,255,255,.85); background: rgba(255,255,255,.06); }
.nav-sub-item.active { color: #fff; background: rgba(255,255,255,.12); }
.nav-sub-label { display:block; padding:4px 10px 2px; font-size:9px; font-weight:700; text-transform:uppercase; letter-spacing:.08em; color:rgba(255,255,255,.4); }
.nav-sub-item.active::before { background: var(--accent-light); }
.nav-badge { margin-left: auto; background: var(--red); color: #fff; font-size: 10px; font-weight: 500; padding: 1px 6px; border-radius: 10px; }
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--r);
  background: rgba(255,255,255,.06);
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 500; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { color: #fff; font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: rgba(255,255,255,.4); font-size: 10px; }
.logout-btn { background: none; border: none; cursor: pointer; color: rgba(255,255,255,.4); padding: 6px; border-radius: 4px; transition: color .15s; min-height: 36px; }
.logout-btn:hover { color: #fff; }

/* ── MAIN AREA ──────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── TOPBAR ──────────────────────────────── */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 16px; height: 52px;
  display: flex; align-items: center; gap: 10px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-menu-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text2); padding: 6px; border-radius: 6px;
  display: flex; align-items: center; flex-shrink: 0;
}
.topbar-menu-btn:hover { background: var(--surface2); }
.topbar-title { font-family: var(--serif); font-size: 17px; font-weight: 400; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-date { font-size: 11px; color: var(--text3); display: none; }
.topbar-new-btn-text { display: none; }

/* ── CONTENT ──────────────────────────────── */
.content {
  padding: 14px 14px;
  flex: 1;
  padding-bottom: calc(14px + var(--bottom-nav-h));
}

/* ── BOTTOM NAV (mobile) ──────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; align-items: stretch;
  z-index: 90;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; cursor: pointer;
  color: var(--text3); font-size: 10px; font-weight: 500;
  padding: 6px 4px;
  transition: color .15s;
  position: relative;
}
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item svg { width: 22px; height: 22px; }
.bottom-nav-item .bnav-badge {
  position: absolute; top: 6px; right: calc(50% - 18px);
  background: var(--red); color: #fff; font-size: 9px;
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
}

/* ── SCREENS ──────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ── DASHBOARD — mobile first ──────────────────────────────── */
.metrics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 14px;
}
.metric-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r2); padding: 14px 14px;
  box-shadow: var(--shadow);
}
.metric-label { font-size: 10px; font-weight: 500; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.metric-value { font-family: var(--serif); font-size: 30px; font-weight: 400; color: var(--text); line-height: 1; margin-bottom: 4px; }
.metric-sub { font-size: 11px; color: var(--text2); }
.metric-accent { border-left: 3px solid var(--accent); }
.metric-red { border-left: 3px solid var(--red); }
.metric-amber { border-left: 3px solid #C87F20; }
.metric-blue { border-left: 3px solid #2A6099; }
.charts-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px; margin-bottom: 14px;
}
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r2); padding: 16px;
  box-shadow: var(--shadow);
}
.chart-title { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 2px; }
.chart-sub { font-size: 11px; color: var(--text3); margin-bottom: 12px; }
.chart-wrap { position: relative; }
.bottom-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.list-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r2); padding: 16px;
  box-shadow: var(--shadow);
}
.list-title { font-size: 13px; font-weight: 500; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }

/* ── TABLES ──────────────────────────────── */
.table-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r2); box-shadow: var(--shadow); overflow: hidden;
}
.table-header {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.table-header h2 { font-size: 15px; font-weight: 500; flex: 1; min-width: 0; }
.search-box {
  position: relative; display: flex; align-items: center;
  width: 100%;
}
.search-box svg { position: absolute; left: 10px; color: var(--text3); width: 14px; height: 14px; }
.search-box input {
  padding: 10px 12px 10px 32px; border: 1.5px solid var(--border);
  border-radius: var(--r); font-size: 16px; width: 100%;
  background: var(--bg); color: var(--text); outline: none;
  -webkit-appearance: none;
}
.search-box input:focus { border-color: var(--accent); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
thead th {
  padding: 10px 12px; text-align: left;
  font-size: 10px; font-weight: 500; color: var(--text3);
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--bg); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; }
tbody tr:hover td { background: var(--surface2); }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 20px; font-size: 10px; font-weight: 500;
  white-space: nowrap;
}
.badge-ok { background: var(--accent-light); color: var(--accent); }
.badge-warn { background: var(--amber-light); color: var(--amber); }
.badge-err { background: var(--red-light); color: var(--red); }
.badge-blue { background: var(--blue-light); color: var(--blue); }
.badge-gray { background: var(--surface2); color: var(--text2); }

/* ── FORM — mobile first ──────────────────────────────── */
.form-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r2); padding: 16px 14px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.form-card-title { font-size: 13px; font-weight: 500; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.form-card-title svg { color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 12px; }
.form-group-inline { display: flex; flex-direction: column; gap: 4px; }
.form-group-inline label { font-size: 11px; font-weight: 500; color: var(--text2); text-transform: uppercase; letter-spacing: .04em; }
.form-group-inline input, .form-group-inline select, .form-group-inline textarea {
  padding: 11px 12px; border: 1.5px solid var(--border);
  border-radius: var(--r); font-family: var(--sans); font-size: 16px; /* no zoom */
  color: var(--text); background: var(--bg); outline: none; transition: border-color .15s;
  -webkit-appearance: none; min-height: 44px;
}
.form-group-inline input:focus, .form-group-inline select:focus, .form-group-inline textarea:focus { border-color: var(--accent); }
.form-group-inline textarea { resize: vertical; min-height: 80px; font-size: 14px; }
.form-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.form-actions .btn { justify-content: center; }

/* ── MODAL ──────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(20,18,15,.65); z-index: 500;
  align-items: flex-end; justify-content: center;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 100%;
  box-shadow: var(--shadow2);
  overflow: hidden;
  animation: modalUp .2s ease;
  max-height: 92vh;
  overflow-y: auto;
}
@keyframes modalUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header {
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-title { font-family: var(--serif); font-size: 18px; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text3); padding: 6px; border-radius: var(--r); transition: background .1s; min-height: 36px; min-width: 36px; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-body { padding: 16px 18px 24px; }

/* ── CERTIFICATE ──────────────────────────────── */
.cert-doc {
  font-family: 'Times New Roman', Georgia, serif;
  font-size: 11px; color: #111; background: #fff;
  padding: 20px 16px; border: 1px solid #ccc; border-radius: 6px;
  line-height: 1.5; position: relative;
  overflow-x: auto;
}
.cert-top { display: flex; align-items: flex-start; justify-content: space-between; padding-bottom: 12px; border-bottom: 2px solid #1a1a1a; margin-bottom: 14px; }
.cert-company { font-size: 9px; font-weight: 700; text-align: center; flex: 1; }
.cert-company .main-name { font-size: 11px; margin-bottom: 2px; }
.cert-company .cert-heading { font-size: 11px; font-weight: 700; margin-top: 8px; text-decoration: underline; }
.cert-code-box { font-size: 9px; text-align: right; color: #333; }
.cert-qr-box { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.cert-qr-box canvas, .cert-qr-box img { width: 56px !important; height: 56px !important; }
.cert-verified { font-size: 8px; background: #e8f5e0; color: #2d5016; padding: 2px 5px; border-radius: 3px; font-weight: 700; }
.cert-meta-grid { display: grid; grid-template-columns: 1fr; gap: 2px; margin-bottom: 10px; }
.cert-meta-row { display: flex; gap: 4px; font-size: 9.5px; }
.cert-meta-row strong { min-width: 120px; font-weight: 600; }
.cert-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 9px; }
.cert-table th { background: #e8e8e8; padding: 3px 5px; border: 0.5px solid #bbb; font-weight: 700; text-align: left; }
.cert-table td { padding: 3px 5px; border: 0.5px solid #ccc; }
.cert-table tr:nth-child(even) td { background: #f9f9f9; }
.cert-notice { font-size: 8px; color: #555; margin: 6px 0; font-style: italic; }
.cert-obs-box { background: #f5f5f5; border: 0.5px solid #ccc; padding: 5px 7px; border-radius: 3px; margin: 6px 0; font-size: 9.5px; }
.cert-sigs { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 16px; border-top: 0.5px solid #ccc; padding-top: 10px; flex-wrap: wrap; gap: 10px; }
.cert-sig { text-align: center; font-size: 12px; color: #111; }
.cert-sig-space { height: 60px; }
.cert-sig .sig-name { font-size: 14px; font-weight: 700; display: block; margin-bottom: 2px; }
.cert-sig .sig-cargo { font-size: 11px; display: block; }
.cert-footer-info { font-size: 8px; text-align: center; color: #777; margin-top: 12px; border-top: 0.5px solid #ddd; padding-top: 6px; }

/* ── LOG ──────────────────────────────── */
.log-entry {
  display: flex; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); font-size: 12px;
  align-items: flex-start;
}
.log-entry:last-child { border-bottom: none; }
.log-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 5px; }
.log-dot-ok { background: var(--accent-mid); }
.log-dot-warn { background: #C87F20; }
.log-dot-err { background: var(--red); }
.log-dot-info { background: #2A6099; }
.log-time { color: var(--text3); white-space: nowrap; min-width: 90px; font-size: 11px; }
.log-user { color: var(--text2); font-weight: 500; }
.log-msg { color: var(--text); flex: 1; }
.log-type { font-size: 10px; padding: 2px 7px; border-radius: 10px; }

/* ── LOG TABLE (mobile stacked) ──────────────────────────────── */
.log-row-mobile {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.log-row-mobile:last-child { border-bottom: none; }
.log-row-top { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.log-row-msg { font-size: 12px; color: var(--text); }

/* ── USERS ──────────────────────────────── */
.user-row { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.user-row:last-child { border-bottom: none; }
.user-row-top { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.user-av { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 500; flex-shrink: 0; }
.user-av-gray { background: var(--text3); }
.user-details { flex: 1; min-width: 0; }
.user-uname { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta { font-size: 11px; color: var(--text3); }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── VERIFY ──────────────────────────────── */
.verify-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r2); padding: 18px 14px; box-shadow: var(--shadow);
}
.verify-result { padding: 14px; border-radius: var(--r); margin-top: 14px; }
.verify-ok { background: var(--accent-light); border: 1px solid var(--accent); }
.verify-fail { background: var(--red-light); border: 1px solid var(--red); }
.input-row { display: flex; flex-direction: column; gap: 10px; }
.input-row > * { width: 100%; }
.input-row .btn { min-height: 44px; justify-content: center; }

/* ── MISC ──────────────────────────────── */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text3); }
.tag-role-admin { background: #FBF0E0; color: #7A4F10; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 500; }
.tag-role-lab { background: var(--blue-light); color: var(--blue); padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 500; }
.tag-role-viewer { background: var(--surface2); color: var(--text2); padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 500; }
.text-xs { font-size: 11px; color: var(--text3); }
.text-sm { font-size: 12px; color: var(--text2); }
.fw-500 { font-weight: 500; }
.mt-16 { margin-top: 16px; }

/* ══════════════════════════════════════════
   TABLET BREAKPOINT ≥ 640px
   ══════════════════════════════════════════ */
@media (min-width: 640px) {
  .content { padding: 18px 20px; padding-bottom: calc(18px + var(--bottom-nav-h)); }
  .metrics-row { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .form-actions { flex-direction: row; }
  .form-actions .btn { justify-content: flex-start; }
  .input-row { flex-direction: row; align-items: flex-end; }
  .input-row > * { width: auto; flex: 1; }
  .search-box { width: 280px; }
  .search-box input { font-size: 13px; }
  .form-group-inline input, .form-group-inline select, .form-group-inline textarea { font-size: 14px; }
  .form-group input, .form-group select { font-size: 14px; }
  .cert-meta-grid { grid-template-columns: 1fr 1fr; }
}

/* ══════════════════════════════════════════
   DESKTOP BREAKPOINT ≥ 900px
   Sidebar visible, bottom nav hidden
   ══════════════════════════════════════════ */
@media (min-width: 900px) {
  .sidebar {
    transform: translateX(0) !important;
    width: 220px;
    position: fixed;
  }
  .sidebar-close { display: none; }
  .sidebar-overlay { display: none !important; }
  .main { margin-left: 220px; }
  .topbar { padding: 0 24px; height: 56px; }
  .topbar-menu-btn { display: none; }
  .topbar-title { font-size: 20px; }
  .topbar-date { display: block; }
  .topbar-new-btn-text { display: inline; }
  .content { padding: 22px 24px; padding-bottom: 22px; }
  .bottom-nav { display: none; }
  .metrics-row { grid-template-columns: repeat(4, 1fr); gap: 14px; }
  .charts-row { grid-template-columns: 2fr 1fr; gap: 14px; }
  .bottom-row { grid-template-columns: 1fr 1fr; gap: 14px; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .modal { border-radius: 16px; max-width: 720px; max-height: none; }
  @keyframes modalUp { from { opacity: 0; transform: translateY(-16px) scale(.98); } to { opacity: 1; transform: none; } }
  .modal-overlay { align-items: flex-start; padding: 40px 20px; }
  .cert-meta-grid { grid-template-columns: 1fr 1fr; }
  .cert-doc { padding: 28px 32px; }
  .cert-company { font-size: 10px; }
  .cert-company .main-name { font-size: 13px; }
  .cert-company .cert-heading { font-size: 13px; }
  .cert-qr-box canvas, .cert-qr-box img { width: 64px !important; height: 64px !important; }
  .cert-meta-row { font-size: 10.5px; }
  .cert-table { font-size: 10px; }
  .cert-table th { padding: 4px 7px; }
  .cert-table td { padding: 4px 7px; }
  .verify-box { max-width: 520px; }
}

@media (min-width: 1100px) {
  .sidebar { width: 240px; }
  .main { margin-left: 240px; }
  .content { padding: 24px 28px; }
}

/* ── JAPAN CERTIFICATES ─────────────────── */
.jp-cert {
  font-family: 'Times New Roman', Georgia, serif;
  font-size: 11px; color: #111; background: #fff;
  padding: 24px 28px; border: 1px solid #ccc; border-radius: 6px;
  margin-bottom: 28px; line-height: 1.55; page-break-after: always;
}
.jp-header { text-align: center; padding-bottom: 6px; margin-bottom: 8px; }
.jp-company-name { font-size: 15px; font-weight: 900; letter-spacing: .04em; }
.jp-company-sub { font-size: 9.5px; font-weight: 600; }
.jp-logo-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; border-bottom: 2.5px solid #111; padding-bottom: 12px; }
.jp-logo-box { width: 90px; height: 90px; flex-shrink: 0; }
.jp-doc-title { flex: 1; text-align: center; font-size: 16px; font-weight: 900; text-transform: uppercase; letter-spacing: .06em; color: #111; text-decoration: underline; }
.jp-seal-box { width: 110px; }
.jp-seal-circle { width: 72px; height: 72px; border: 2px solid #aaa; border-radius: 50%; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 9px; font-weight: 700; color: #aaa; line-height: 1.3; }
.jp-details-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.jp-details-table tr { border-bottom: 0.5px solid #ddd; }
.jp-details-table td { padding: 4px 8px; font-size: 10px; }
.jp-lbl { font-weight: 700; width: 38%; color: #333; background: #f5f5f5; }
.jp-analysis-table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.jp-analysis-table th { background: #222; color: #fff; padding: 5px 8px; font-size: 10px; text-align: left; border: 0.5px solid #555; }
.jp-analysis-table td { padding: 4px 8px; font-size: 10px; border: 0.5px solid #ccc; }
.jp-analysis-table tr:nth-child(even) td { background: #f8f8f8; }
.jp-declaration { border: 1.5px solid #333; border-radius: 4px; padding: 20px 24px; margin: 18px 0; background: #fafafa; font-size: 12px; line-height: 1.8; }
.jp-obs { font-size: 10px; color: #444; margin: 8px 0; padding: 6px 10px; background: #f5f5f5; border-left: 3px solid #666; }
.jp-sigs { display: flex; justify-content: space-around; margin-top: 30px; padding-top: 12px; border-top: 0.5px solid #ccc; gap: 20px; }
.jp-sig { text-align: center; flex: 1; }
.jp-sig-space { height: 55px; border-bottom: 1px solid #333; margin-bottom: 6px; }
.jp-sig-name { font-size: 13px; font-weight: 800; }
.jp-sig-cargo { font-size: 10px; color: #444; }
.jp-footer-info { text-align: center; font-size: 8.5px; color: #777; margin-top: 14px; border-top: 0.5px solid #ddd; padding-top: 6px; }

/* ── PRINT ──────────────────────────────── */
@page { size: letter portrait; margin: 18mm 16mm; }

@media print {
  /* Ocultar UI */
  .sidebar, .sidebar-overlay, .topbar, .modal-header, .form-actions,
  #print-btns, .bottom-nav, #cert-actions, .flash-container { display: none !important; }

  html, body { height: auto; }
  .main  { margin: 0 !important; }
  .content { padding: 0 !important; }

  /* ── Certificado normal — una sola hoja ── */
  .cert-doc {
    border: none; box-shadow: none;
    padding: 10px 14px;
    font-size: 10px;
  }
  .cert-top { padding-bottom: 4px; margin-bottom: 6px; }
  .cert-top > div:first-child,
  .cert-top > div:first-child div { width: 58px !important; height: 58px !important; }
  .cert-qr-box img, .cert-qr-box canvas { width: 52px !important; height: 52px !important; }
  .cert-company .main-name { font-size: 10px; }
  .cert-company .cert-heading { font-size: 10px; margin-top: 4px; }
  .cert-meta-grid { gap: 1px; margin-bottom: 6px; }
  .cert-meta-row { font-size: 9px; }
  .cert-meta-row strong { min-width: 105px; }
  .cert-table th, .cert-table td { padding: 2px 4px; font-size: 8.5px; }
  .cert-notice { font-size: 7.5px; margin: 3px 0; }
  .cert-obs-box { padding: 3px 6px; margin: 4px 0; font-size: 8.5px; }
  .cert-sig-space { height: 38px; }
  .cert-sig .sig-name { font-size: 11px; }
  .cert-sig .sig-cargo { font-size: 9px; }
  .cert-sigs { margin-top: 8px; padding-top: 5px; gap: 6px; }
  .cert-footer-info { margin-top: 6px; padding-top: 3px; font-size: 7.5px; }

  /* ── Certificados Japón — uno por hoja ── */
  .jp-cert {
    border: none; box-shadow: none;
    padding: 10px 14px; margin-bottom: 0;
    page-break-after: always;
    break-after: page;
    font-size: 10px;
  }
  .jp-cert:last-child { page-break-after: auto; break-after: auto; }
  .jp-header { padding-bottom: 5px; margin-bottom: 7px; }
  .jp-company-name { font-size: 13px; }
  .jp-company-sub { font-size: 9px; }
  .jp-logo-row { margin-bottom: 8px; }
  .jp-logo-box { width: 70px; height: 70px; }
  .jp-logo-box > div { width: 70px !important; height: 70px !important; }
  .jp-seal-box { width: 110px; }
  .jp-doc-title { font-size: 14px; }
  .jp-details-table { margin-bottom: 8px; }
  .jp-details-table td { padding: 3px 6px; font-size: 9.5px; }
  .jp-analysis-table th, .jp-analysis-table td { padding: 3px 6px; font-size: 9.5px; }
  .jp-declaration { padding: 12px 16px; margin: 10px 0; font-size: 11px; line-height: 1.6; }
  .jp-sigs { margin-top: 16px; padding-top: 8px; }
  .jp-sig-space { height: 40px; }
  .jp-sig-name { font-size: 11px; }
  .jp-sig-cargo { font-size: 9px; }
  .jp-footer-info { margin-top: 8px; padding-top: 4px; font-size: 8px; }
}

/* ── DATA TABLE ── */
.data-table { width:100%; border-collapse:collapse; font-size:13px; }
.data-table thead { background:var(--surface2); }
.data-table th { padding:10px 14px; text-align:left; font-weight:600; color:var(--text2); font-size:11.5px; text-transform:uppercase; letter-spacing:.04em; border-bottom:1px solid var(--border); }
.data-table td { padding:10px 14px; border-bottom:1px solid var(--border); vertical-align:middle; }
.data-table tbody tr:last-child td { border-bottom:none; }
.data-table tbody tr:hover { background:var(--surface2); }

/* Badges */
.badge { display:inline-block; padding:2px 9px; border-radius:99px; font-size:11.5px; font-weight:500; }
.badge-ok   { background:var(--accent-light); color:var(--accent); }
.badge-warn { background:var(--amber-light); color:var(--amber); }
.badge-info { background:var(--blue-light); color:var(--blue); }

/* Btn sizes */
.btn-sm { padding:4px 10px; font-size:12px; }
.btn-danger { background:var(--red-light); color:var(--red); border:1px solid var(--red); }
.btn-danger:hover { background:var(--red); color:#fff; }

/* ── LOTE ANÁLISIS TABLE ── */
.lote-analisis-table { border:1px solid var(--border); border-radius:var(--r); overflow:hidden; }
.lote-analisis-header { display:grid; grid-template-columns:1fr 100px 180px; padding:8px 14px; background:var(--surface2); font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.06em; color:var(--text2); border-bottom:2px solid var(--border); }
.lote-analisis-group { padding:6px 14px; background:var(--accent-light); color:var(--accent); font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.06em; border-bottom:1px solid var(--border); }
.lote-analisis-row { display:grid; grid-template-columns:1fr 100px 180px; align-items:center; padding:5px 14px; border-bottom:1px solid var(--border); gap:8px; }
.lote-analisis-row:last-child { border-bottom:none; }
.lote-analisis-row:hover { background:var(--surface2); }
.lote-analisis-row span { font-size:13px; }
.lote-unit { color:var(--text3); font-size:12px; }
.lote-analisis-row input { width:100%; padding:5px 8px; border:1px solid var(--border); border-radius:var(--r); font-size:13px; background:var(--surface); font-family:var(--sans); color:var(--text); }
.lote-analisis-row input:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 2px var(--accent-light); }
.lote-analisis-row input.na-cleared { color:var(--text); }
.lote-analisis-row input:not(:focus)[value="No aplica"],
.lote-analisis-row input:not(.na-cleared) { color:var(--text3); }
.lote-select { width:100%; padding:5px 8px; border:1px solid var(--border); border-radius:var(--r); font-size:13px; background:var(--surface); font-family:var(--sans); color:var(--text); }

/* ── LOTES TOOLBAR & PAGINATION ── */
.lotes-toolbar { display:flex; justify-content:space-between; align-items:center; margin-bottom:.7rem; flex-wrap:wrap; gap:.5rem; }
.per-page-btn { display:inline-block; padding:4px 10px; border:1px solid var(--border); border-radius:var(--r); font-size:12px; font-weight:500; color:var(--text2); text-decoration:none; background:var(--surface); }
.per-page-btn:hover { border-color:var(--accent); color:var(--accent); }
.per-page-btn.active { background:var(--accent); color:#fff; border-color:var(--accent); }

.pagination-wrap { display:flex; justify-content:center; align-items:center; gap:4px; margin-top:1rem; flex-wrap:wrap; }
.page-btn { display:inline-flex; align-items:center; justify-content:center; min-width:32px; height:32px; padding:0 6px; border:1px solid var(--border); border-radius:var(--r); font-size:13px; text-decoration:none; color:var(--text2); background:var(--surface); }
.page-btn:hover:not(.disabled):not(.active) { border-color:var(--accent); color:var(--accent); }
.page-btn.active { background:var(--accent); color:#fff; border-color:var(--accent); font-weight:600; }
.page-btn.disabled { opacity:.4; cursor:default; pointer-events:none; }

.sort-link { color:inherit; text-decoration:none; white-space:nowrap; display:flex; align-items:center; gap:4px; }
.sort-link:hover { color:var(--accent); }

.icon-btn { display:inline-flex; align-items:center; justify-content:center; width:30px; height:30px; border-radius:var(--r); border:1px solid var(--border); background:var(--surface); color:var(--text2); text-decoration:none; cursor:pointer; padding:0; }
.icon-btn:hover { border-color:var(--accent); color:var(--accent); background:var(--accent-light); }
.icon-btn-danger { color:var(--red,#e53e3e); border-color:var(--red,#e53e3e); }
.icon-btn-danger:hover { background:var(--red-light,#fff5f5); border-color:var(--red,#e53e3e); color:var(--red,#e53e3e); }

/* ── LOTES TABLA RESPONSIVE ── */
.lotes-table-wrap { display:block; }

/* Lote view row (solo lectura) */
.lote-view-row { cursor:default; }
.lote-view-row:hover { background:var(--surface2); }
.na-value { color:var(--text3); font-size:13px; }
.val-value { color:var(--text); font-size:13px; font-weight:500; }

/* Tarjetas móvil para lotes */
.lote-cards { display:none; flex-direction:column; gap:.7rem; }
.lote-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--r2); padding:14px 16px; }
.lote-card-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:4px; }
.lote-card-num { font-weight:700; font-size:14px; }
.lote-card-producto { font-size:13px; color:var(--text2); margin-bottom:6px; }
.lote-card-meta { display:flex; gap:10px; flex-wrap:wrap; font-size:12px; color:var(--text3); margin-bottom:10px; }
.lote-card-actions { display:flex; gap:8px; }

@media (max-width: 700px) {
  .lotes-table-wrap { display:none !important; }
  .lote-cards { display:flex; }
}

/* ── FLASH MESSAGES ── */
.flash-container { position:fixed; top:60px; right:16px; z-index:999; display:flex; flex-direction:column; gap:8px; }
.flash { padding:10px 16px; border-radius:var(--r); font-size:13px; font-weight:500; box-shadow:var(--shadow2); animation: slideIn .2s ease; }
.flash-ok { background:var(--accent-light); color:var(--accent); border:1px solid var(--accent); }
.flash-error { background:var(--red-light); color:var(--red); border:1px solid var(--red); }
@keyframes slideIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:none; } }

/* ── DROPDOWN CLIENTES ── */
.cliente-select-wrap { position:relative; width:100%; }
.cliente-select-wrap input[type="text"] { width:100%; }
.cliente-dropdown { position:absolute; top:calc(100% + 4px); left:0; right:0; background:var(--surface); border:1px solid var(--border); border-radius:var(--r2); box-shadow:var(--shadow2); z-index:200; max-height:260px; overflow-y:auto; }
.cliente-group { padding:6px 12px 4px; font-size:10px; font-weight:700; letter-spacing:.6px; text-transform:uppercase; color:var(--text3); background:var(--bg2); position:sticky; top:0; }
.cliente-option { padding:8px 14px; font-size:13px; color:var(--text1); cursor:pointer; }
.cliente-option:hover { background:var(--accent-light); color:var(--accent); }

/* ── BADGES TIPO ANÁLISIS ── */
.tag-analisis { display:inline-block; padding:3px 10px; border-radius:20px; font-size:11px; font-weight:600; letter-spacing:.3px; }
.tag-analisis-microbiologicos   { background:#fce4ec; color:#c2185b; }
.tag-analisis-fisico-quimicos   { background:#e8eaf6; color:#3949ab; }
.tag-analisis-metales-pesados   { background:#fbe9e7; color:#bf360c; }
.tag-analisis-micotoxinas       { background:#f3e5f5; color:#6a1b9a; }
.tag-analisis-organolepticos    { background:#e8f5e9; color:#2e7d32; }

/* ── CHECKLIST ANÁLISIS ── */
.analisis-checklist { display:grid; grid-template-columns:repeat(auto-fill,minmax(220px,1fr)); gap:4px 12px; border:1px solid var(--border); border-radius:var(--r2); padding:12px; background:var(--bg2); }
.analisis-grupo { grid-column:1/-1; font-size:10px; font-weight:700; letter-spacing:.6px; text-transform:uppercase; color:var(--text3); padding:8px 0 4px; border-top:1px solid var(--border); margin-top:4px; }
.analisis-grupo:first-child { margin-top:0; border-top:none; padding-top:0; }
.analisis-item { display:flex; align-items:center; gap:7px; padding:4px 6px; border-radius:6px; cursor:pointer; font-size:13px; }
.analisis-item:hover { background:var(--accent-light); }
.analisis-item input[type="checkbox"] { width:15px; height:15px; accent-color:var(--accent); cursor:pointer; flex-shrink:0; }

/* ── CLIENTES ── */
.tag-tipo { display:inline-block; padding:3px 10px; border-radius:20px; font-size:11px; font-weight:600; letter-spacing:.3px; }
.tag-tipo-extranjero   { background:#e0f0ff; color:#1565c0; }
.tag-tipo-nacional     { background:#e8f5e9; color:#2e7d32; }
.tag-tipo-a-detalle    { background:#fff8e1; color:#f57f17; }
.tag-tipo-especial     { background:#f3e5f5; color:#6a1b9a; }

/* ── PRINT ── */
