/* ============================================================
   SICCO — Bezalleel Petroleum Group
   Sprint 02: Topbar + Sidebar + SPA + Theme system
   ============================================================ */

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

/* ---------- Theme tokens (dark default) ---------- */
:root,
html.dark {
  --bg-primary:   #111111;
  --bg-surface:   #0D1525;
  --bg-surface-2: #111C33;
  --bg-hover:     #1A2840;
  --text-primary: #F1F5F9;
  --text-muted:   #64748B;
  --border:       #1A2840;
  --accent:       #F59E0B;
  --accent-soft:  rgba(245,158,11,0.15);
  --success:      #10B981;
  --danger:       #EF4444;
  --info:         #3B82F6;
  --brand-green:        #73A33B;
  --brand-green-bright: #8FBF4F;
  --brand-green-soft:   #2A3D17;
  --header-bg: rgba(13, 21, 37, 0.92);
  --bar-track: #0A1222;
  --kpi-shadow: 0 10px 24px -8px rgba(0,0,0,0.6);
  --scroll-thumb: #1A2840;
  --scroll-thumb-hover: #2A3A5A;
}

html.light {
  --bg-primary:   #FAFFF2;
  --bg-surface:   #FFFFFF;
  --bg-surface-2: #F1F7E4;
  --bg-hover:     #F1F5F9;
  --text-primary: #1E293B;
  --text-muted:   #64748B;
  --border:       #E2E8F0;
  --accent:       #D97706;
  --accent-soft:  rgba(217,119,6,0.12);
  --success:      #059669;
  --danger:       #DC2626;
  --info:         #2563EB;
  --header-bg: rgba(255,255,255,0.92);
  --bar-track: #E8EFD8;
  --kpi-shadow: 0 10px 24px -8px rgba(115,163,59,0.25);
  --scroll-thumb: #CBD5E1;
  --scroll-thumb-hover: #94A3B8;
}

/* aliases backwards-compat con tanks.js */
:root, html.dark, html.light {
  --bg: var(--bg-primary);
  --surface: var(--bg-surface);
  --surface-2: var(--bg-surface-2);
  --text: var(--text-primary);
  --muted: var(--text-muted);
}

html, body { height: 100%; }

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  overflow: hidden;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app {
  display: grid;
  grid-template-rows: 56px 1fr;
  grid-template-columns: 220px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar content";
  height: 100vh;
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  box-shadow: inset 0 -2px 0 0 var(--brand-green);
  z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-center { flex: 1; text-align: center; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.hamburger { display: none; }

.brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 800; letter-spacing: 0.5px; font-size: 14px;
}
.brand-bpg { color: var(--accent); }
.brand-sep { color: var(--text-muted); font-weight: 500; }
.brand-sicco { color: var(--text-muted); font-weight: 600; letter-spacing: 1.5px; font-size: 12px; }

.page-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-primary);
  text-transform: uppercase;
  opacity: 0.85;
}

.notif-badge {
  position: absolute;
  top: 4px; right: 4px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-surface);
  line-height: 1;
}
.notif-badge.is-hidden { display: none; }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #B45309);
  color: #1A0F00;
  font-weight: 800;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s ease;
}
.avatar:hover { border-color: var(--accent); }

/* Dropdowns */
.dropdown { position: relative; }
.dropdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 280px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px -8px rgba(0,0,0,0.5);
  padding: 8px;
  display: none;
  z-index: 200;
}
.dropdown.is-open .dropdown-panel { display: block; animation: fadeDown .18s ease; }

@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-header {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.dropdown-divider { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px; color: var(--text-primary);
  cursor: pointer;
  transition: background .12s ease;
  background: transparent; border: none; width: 100%; text-align: left;
}
.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-empty {
  padding: 24px 12px; text-align: center;
  color: var(--text-muted); font-size: 13px;
}

/* Notification list */
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 10px; align-items: start;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s ease;
}
.notif-item:hover { background: var(--bg-hover); }
.notif-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 6px;
}
.notif-dot.pending  { background: var(--accent); }
.notif-dot.approved { background: var(--success); }
.notif-dot.rejected { background: var(--danger); }
.notif-dot.info     { background: var(--info); }
.notif-msg { font-size: 13px; color: var(--text-primary); line-height: 1.35; }
.notif-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* User dropdown */
.user-meta { padding: 12px; }
.user-name { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.user-role { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
  z-index: 40;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.sidebar-flame {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
}
.sidebar-flame svg { width: 22px; height: 22px; fill: var(--accent); }
.sidebar-brand-text {
  font-size: 12px; color: var(--text-muted); font-weight: 600;
  letter-spacing: 0.4px;
}

.nav-section { margin-bottom: 14px; }
.nav-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 4px 12px 6px;
  text-transform: uppercase;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  font-size: 13px;
  color: #94A3B8;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  border-left: 3px solid transparent;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
html.light .nav-item { color: #475569; }
.nav-item .nav-icon { color: var(--text-muted); width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.is-active {
  background: var(--bg-hover);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-item.is-active .nav-icon { color: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.6px;
}

/* Sidebar mobile */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 56px 0 0 0;
  background: rgba(0,0,0,0.5);
  z-index: 30;
}
.sidebar-backdrop.is-open { display: block; }

/* ============================================================
   CONTENT
   ============================================================ */
.content {
  grid-area: content;
  overflow-y: auto;
  padding: 24px;
}

.page { display: none; }
.page.is-active { display: block; animation: fadePage .25s ease; }

@keyframes fadePage {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-inner { max-width: 1600px; margin: 0 auto; }

/* Placeholder page */
.placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  padding: 80px 24px;
  color: var(--text-muted);
}
.placeholder-icon {
  width: 72px; height: 72px;
  border-radius: 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 18px;
  color: var(--accent);
}
.placeholder-icon svg { width: 36px; height: 36px; }
.placeholder-title {
  font-size: 18px; font-weight: 700; color: var(--text-primary);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
.placeholder-desc { font-size: 13px; }

/* ============================================================
   KPI strip + dashboard tank cards (Sprint 01)
   ============================================================ */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 12px;
  padding: 16px 18px;
  position: relative;
  transition: transform 0.2s ease, border-color 0.2s ease;
  opacity: 0;
  animation: slideUp 0.5s ease forwards;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-label {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px;
}
.kpi-value {
  font-size: 24px; font-weight: 800; color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.kpi-unit { font-size: 12px; color: var(--text-muted); font-weight: 500; margin-left: 4px; }
.kpi-sub { margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.kpi-sub strong { color: var(--text-primary); }

.section { margin-bottom: 28px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.section-header::after {
  content: ""; position: absolute; left: 0; bottom: -1px;
  width: 60px; height: 2px;
  background: linear-gradient(90deg, var(--brand-green-bright), transparent);
}
.section-title {
  font-size: 16px; font-weight: 700; letter-spacing: 0.5px;
  text-transform: uppercase; color: var(--text-primary);
}
.section-meta { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.tanks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
.tank-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 12px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  position: relative; overflow: hidden;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  opacity: 0;
  animation: slideUp 0.5s ease forwards;
}
.tank-card:hover {
  transform: translateY(-3px);
  border-color: var(--tank-color, var(--accent));
  box-shadow: var(--kpi-shadow), 0 0 0 1px var(--tank-color, var(--accent)) inset;
}

/* Drag & drop */
.tank-card[draggable="true"] { cursor: grab; }
.tank-card.is-dragging {
  opacity: 0.4;
  cursor: grabbing;
  transform: scale(0.97);
}
.tank-card.drop-target {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent) inset, 0 8px 24px -6px rgba(245,158,11,0.4) !important;
  transform: translateY(-2px);
}
.dnd-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 16px 36px -10px rgba(0,0,0,0.55), 0 0 0 1px var(--accent) inset;
  z-index: 500;
  opacity: 0;
  pointer-events: none;
  transition: transform .25s cubic-bezier(.22,.61,.36,1), opacity .2s ease;
}
.dnd-bar.is-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.dnd-bar-text {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
}
.dnd-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.4px;
  transition: background .12s ease, border-color .12s ease, transform .1s ease;
}
.dnd-btn:hover { background: var(--bg-hover); }
.dnd-btn:active { transform: translateY(1px); }
.dnd-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1A0F00;
}
.dnd-btn-primary:hover { background: #FBBF24; }

.tanks-grid.drop-area {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
  border-radius: 14px;
  background: var(--accent-soft);
}
.tank-label {
  font-size: 13px; font-weight: 700; letter-spacing: 1px;
  color: var(--text-primary); text-transform: uppercase;
}
.tank-gauge { width: 150px; height: 150px; }
.tank-product {
  font-size: 11px; font-weight: 600;
  color: var(--tank-color, var(--text-muted));
  text-transform: uppercase; letter-spacing: 0.6px; text-align: center;
}
.tank-volume { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; font-weight: 500; }
.tank-volume strong { color: var(--text-primary); font-weight: 700; }
.tank-bar {
  width: 100%; height: 4px;
  background: var(--bar-track);
  border-radius: 999px; overflow: hidden; margin-top: 4px;
}
.tank-bar-fill {
  height: 100%; background: var(--tank-color, var(--accent));
  border-radius: 999px;
  transition: width 1.2s cubic-bezier(.22,.61,.36,1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   NEW OPERATION FORM
   ============================================================ */
.form-shell {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.form-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
.form-section-title {
  font-size: 12px; font-weight: 700; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 14px;
}

.op-types {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.op-type {
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 18px 12px;
  cursor: pointer;
  text-align: center;
  display: flex; flex-direction: column; gap: 6px;
  transition: all .15s ease;
}
.op-type:hover { border-color: var(--text-muted); }
.op-type.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.op-type-icon { font-size: 22px; }
.op-type-label { font-size: 13px; font-weight: 700; letter-spacing: 0.5px; color: var(--text-primary); }
.op-type-desc { font-size: 11px; color: var(--text-muted); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.4px; }
.field-hint { font-size: 11px; color: var(--text-muted); }

.input, .select, .textarea {
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input.is-error, .select.is-error { border-color: var(--danger); }
.textarea { resize: vertical; min-height: 70px; }

.select-wrap {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
}
.select-wrap .product-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-muted); flex-shrink: 0;
}
.select-wrap .select {
  border: none; padding: 10px 0; background: transparent; box-shadow: none;
}
.select-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.qty-input {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  gap: 8px;
  align-items: stretch;
}
.qty-btn {
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  font-weight: 700;
  transition: background .12s ease, border-color .12s ease;
}
.qty-btn:hover { background: var(--bg-hover); border-color: var(--accent); }

.qty-bar {
  width: 100%; height: 6px;
  background: var(--bar-track); border-radius: 999px;
  overflow: hidden; margin-top: 6px;
}
.qty-bar-fill {
  height: 100%; background: var(--accent);
  border-radius: 999px;
  width: 0%;
  transition: width .25s ease, background .15s ease;
}
.qty-bar-fill.is-over { background: var(--danger); }

.char-counter {
  font-size: 11px; color: var(--text-muted);
  text-align: right; margin-top: 4px;
}

.summary-card {
  background: var(--bg-surface-2);
  border: 1px solid var(--brand-green);
  border-radius: 12px;
  padding: 16px 18px;
}
.summary-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px 14px;
  font-size: 13px;
}
.summary-key { color: var(--text-muted); font-weight: 600; }
.summary-val { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #1A0F00;
  border: none;
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .15s ease, background .12s ease;
}
.btn-primary:hover { background: #FBBF24; box-shadow: 0 6px 18px -4px rgba(245,158,11,0.5); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.level-hint {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.level-hint.is-error { color: var(--danger); font-weight: 600; }

/* ============================================================
   TOAST
   ============================================================ */
.toast-stack {
  position: fixed;
  top: 72px; right: 18px;
  z-index: 999;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 260px; max-width: 360px;
  box-shadow: 0 12px 28px -8px rgba(0,0,0,0.5);
  animation: toastIn .25s ease forwards;
}
.toast.success { border-left-color: var(--success); }
.toast.danger  { border-left-color: var(--danger); }
.toast-title { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.toast-msg { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.toast.hide { animation: toastOut .25s ease forwards; }

@keyframes toastIn  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(20px); } }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "content";
  }
  .sidebar {
    position: fixed;
    top: 56px; left: 0; bottom: 0;
    width: 240px;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.is-open { transform: translateX(0); }
  .hamburger { display: inline-flex; }
  .topbar-center { display: none; }
}
@media (max-width: 720px) {
  .kpi-strip { grid-template-columns: 1fr 1fr; }
  .content { padding: 16px; }
  .op-types { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .kpi-strip { grid-template-columns: 1fr; }
  .tanks-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ============================================================
   PAGE HEAD (compartido)
   ============================================================ */
.page-head { margin-bottom: 22px; }
.page-h1 {
  font-size: 22px; font-weight: 800; color: var(--text-primary);
  letter-spacing: 0.3px; margin-bottom: 4px;
}
.page-sub { font-size: 13px; color: var(--text-muted); }

/* ============================================================
   CHIPS (botones pequeños tipo pill)
   ============================================================ */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .08s ease;
}
.chip:hover { background: var(--bg-hover); border-color: var(--accent); }
.chip:active { transform: translateY(1px); }
.chip-primary {
  background: var(--accent); border-color: var(--accent); color: #1A0F00;
}
.chip-primary:hover { background: #FBBF24; }

/* ============================================================
   PLANTILLAS — grid
   ============================================================ */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.tpl-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.tpl-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--kpi-shadow);
}
.tpl-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--bg-surface-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.tpl-info { flex: 1; }
.tpl-title { font-size: 14px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.tpl-desc { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.tpl-open { align-self: flex-start; }

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  position: fixed; inset: 0;
  z-index: 800;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.65);
  opacity: 0; transition: opacity .2s ease;
}
.modal-shell {
  position: relative;
  width: 100%; max-width: 920px; max-height: 90vh;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex; flex-direction: column;
  transform: translateY(20px) scale(0.98);
  opacity: 0;
  transition: transform .22s cubic-bezier(.22,.61,.36,1), opacity .2s ease;
  overflow: hidden;
}
.modal.is-open .modal-backdrop { opacity: 1; }
.modal.is-open .modal-shell { opacity: 1; transform: translateY(0) scale(1); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-2);
}
.modal-title { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.modal-actions { display: flex; gap: 8px; }
.modal-body {
  overflow-y: auto;
  padding: 24px;
  background: var(--bg-primary);
}

/* ============================================================
   DOC (estilo común para plantillas/print)
   ============================================================ */
.doc {
  background: #FFFFFF;
  color: #111111;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 28px 32px;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.45;
}
.doc-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 2px solid #73A33B;
  padding-bottom: 14px; margin-bottom: 18px;
}
.doc-brand { display: flex; gap: 12px; align-items: center; }
.doc-logo {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #8FBF4F, #73A33B);
  color: #fff;
  font-weight: 800; letter-spacing: 0.5px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.doc-co { font-weight: 800; font-size: 14px; }
.doc-co-sub { font-size: 11px; color: #555; }
.doc-meta { text-align: right; font-size: 11px; }
.doc-title { font-size: 14px; font-weight: 800; color: #73A33B; text-transform: uppercase; letter-spacing: 0.5px; }
.doc-num, .doc-date { color: #333; }

.doc-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
  margin-bottom: 16px;
}
.field-block label {
  display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: #666; font-weight: 700; margin-bottom: 4px;
}
.ed {
  border: 1px dashed #c8c8c8;
  border-radius: 4px;
  padding: 6px 8px;
  min-height: 22px;
  background: #fafafa;
  font-size: 12px;
  outline: none;
}
.ed:focus { border-color: #73A33B; background: #fff; }
.ed-multi { min-height: 60px; }
.ed .chk { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 2px 0; }
.ed .chk input { accent-color: #73A33B; }

.doc-tbl {
  width: 100%; border-collapse: collapse;
  margin: 8px 0 14px;
}
.doc-tbl th, .doc-tbl td {
  border: 1px solid #d4d4d4;
  padding: 6px 8px;
  font-size: 11px;
  vertical-align: top;
}
.doc-tbl th { background: #f3f7ec; color: #2a3d17; font-weight: 700; text-align: left; text-transform: uppercase; letter-spacing: 0.5px; font-size: 10px; }
.doc-tbl .r { text-align: right; font-variant-numeric: tabular-nums; }
.doc-tbl tfoot td { background: #f9fbf3; font-weight: 700; }
.doc-tbl td[contenteditable="true"]:focus { background: #fff8e0; outline: 2px solid #F59E0B; }

.doc-section {
  font-size: 12px; font-weight: 800; color: #73A33B;
  text-transform: uppercase; letter-spacing: 0.6px;
  margin: 16px 0 6px;
  border-left: 3px solid #73A33B; padding-left: 8px;
}
.doc-notes { margin: 12px 0; }
.doc-notes label {
  display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: #666; font-weight: 700; margin-bottom: 4px;
}
.doc-foot {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  margin-top: 36px;
  padding-top: 14px;
}
.doc-foot .sig { text-align: center; font-size: 11px; }
.sig-line { border-top: 1px solid #888; margin: 32px 12px 4px; }
.sig-label { color: #555; }
.doc-foot-note {
  margin-top: 18px;
  text-align: center;
  font-size: 9px; color: #999;
  border-top: 1px solid #eee;
  padding-top: 8px;
}

/* ============================================================
   REPORTES
   ============================================================ */
.report-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
}
.report-side { min-width: 0; }
.report-main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.report-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.report-card-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
  padding-bottom: 10px; margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.report-quick, .report-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.report-quick .chip, .report-actions .chip { font-size: 10px; padding: 4px 10px; }

/* Tank list */
.report-tank-list { max-height: 65vh; overflow-y: auto; padding-right: 4px; }
.rt-group { margin-bottom: 14px; }
.rt-group:last-child { margin-bottom: 0; }
.rt-group-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-muted); font-weight: 700;
  margin-bottom: 6px; padding-left: 4px;
}
.rt-row {
  display: grid;
  grid-template-columns: 18px 12px 1fr auto;
  gap: 8px; align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: background .12s ease;
}
.rt-row:hover { background: var(--bg-hover); }
.rt-row input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
.rt-dot { width: 10px; height: 10px; border-radius: 50%; }
.rt-dot.inline { display: inline-block; vertical-align: middle; margin-right: 4px; }
.rt-label { color: var(--text-primary); font-weight: 600; }
.rt-meta { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 11px; }

/* Totales */
.report-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.rt-tot {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.rt-tot-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); font-weight: 700;
  margin-bottom: 6px;
}
.rt-tot-value {
  font-size: 22px; font-weight: 800; color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.rt-tot-unit { font-size: 11px; color: var(--text-muted); margin-left: 4px; font-weight: 500; }

/* Tablas reporte */
.rt-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.rt-tbl th, .rt-tbl td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.rt-tbl th {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-muted); font-weight: 700;
}
.rt-tbl .r { text-align: right; font-variant-numeric: tabular-nums; }
.rt-tbl tfoot td { background: var(--bg-surface-2); font-weight: 700; }
.rt-empty { padding: 18px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* Responsive reportes */
@media (max-width: 900px) {
  .report-layout { grid-template-columns: 1fr; }
  .report-tank-list { max-height: 360px; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff !important; color: #000 !important; overflow: visible !important; }
  .app, .modal, .toast-stack, .dnd-bar { display: none !important; }
  #print-area { display: block !important; }
  .doc {
    box-shadow: none !important;
    border-radius: 0 !important;
    max-width: none !important;
    width: 100% !important;
    padding: 0 !important;
    page-break-inside: auto;
  }
  .doc-tbl tr { page-break-inside: avoid; }
  .ed, .doc-tbl td[contenteditable="true"] {
    border: none !important;
    background: transparent !important;
  }
}

/* Asegura que print-area no aparezca en pantalla normal */
#print-area { display: none; }
body.printing #print-area { display: block; }

/* =================== Página Autorizaciones =================== */
.auth-header {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.auth-title { font-size: 20px; font-weight: 800; color: var(--text, #e5e7eb); }
.auth-sub { font-size: 13px; color: var(--muted, #9ca3af); margin-top: 2px; }
.auth-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.auth-tab { cursor: pointer; }
.auth-tab.is-active { background: #73A33B; color: #0b1512; border-color: #73A33B; }
.auth-count {
  display: inline-block; min-width: 18px; padding: 0 6px;
  margin-left: 6px; border-radius: 10px;
  background: rgba(0,0,0,0.18); color: inherit;
  font-size: 11px; font-weight: 700; text-align: center;
}
.auth-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.auth-empty {
  grid-column: 1 / -1;
  padding: 40px 20px; text-align: center;
  color: var(--muted, #9ca3af);
  border: 1px dashed rgba(255,255,255,0.12); border-radius: 12px;
}
.auth-card {
  background: var(--panel, #1f2937);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.auth-card-top { display: flex; justify-content: space-between; align-items: center; }
.auth-card-id { font-family: ui-monospace, Menlo, monospace; font-size: 13px; font-weight: 700; color: #cbd5e1; }
.auth-pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  border: 1px solid transparent;
}
.auth-pill.is-pending  { background: rgba(245,158,11,0.15); color: #fbbf24; border-color: rgba(245,158,11,0.4); }
.auth-pill.is-approved { background: rgba(115,163,59,0.18); color: #a3e05a; border-color: rgba(115,163,59,0.45); }
.auth-pill.is-rejected { background: rgba(239,68,68,0.15);  color: #f87171; border-color: rgba(239,68,68,0.4); }
.auth-pill.is-printed  { background: rgba(148,163,184,0.15); color: #cbd5e1; border-color: rgba(148,163,184,0.35); }
.auth-card-body { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.auth-row { display: flex; justify-content: space-between; gap: 12px; }
.auth-row .auth-k { color: var(--muted, #9ca3af); font-size: 12px; }
.auth-row .auth-v { color: var(--text, #e5e7eb); text-align: right; }
.auth-card-actions { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }

html.light .auth-card { background: #fff; border-color: #e5e7eb; }
html.light .auth-card-id { color: #1f2937; }
html.light .auth-row .auth-v { color: #111827; }

/* Gate y sellos del documento */
.doc-gate { min-height: 320px; }
.doc-gate-msg {
  padding: 40px 20px; text-align: center; color: #555;
}
.doc-gate-icon { font-size: 42px; margin-bottom: 10px; }
.doc-gate-title { font-size: 16px; font-weight: 800; color: #2a3d17; margin-bottom: 6px; }
.doc-gate-desc { font-size: 13px; color: #666; max-width: 480px; margin: 0 auto; }
.doc-stamp {
  display: inline-block;
  border: 2px solid #73A33B; color: #2a3d17;
  padding: 4px 12px; border-radius: 4px;
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
  margin: 6px 0 10px;
  background: rgba(115,163,59,0.08);
}
.ed-ro {
  background: #f3f4f6 !important;
  color: #1f2937; cursor: default;
}

.op-submit-hint {
  margin-top: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: #b45309;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 8px;
}
html.dark .op-submit-hint { color: #fbbf24; }

/* Botón de imprimir deshabilitado */
#tpl-print:disabled {
  opacity: 0.5; cursor: not-allowed;
  background: #9ca3af !important; border-color: #9ca3af !important;
}

/* ============================
   Aprobación por enlace — Modal
   ============================ */
.approval-modal {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.approval-modal[hidden] { display: none; }
.approval-modal.is-open { opacity: 1; pointer-events: auto; }

.approval-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}

.approval-card {
  position: relative;
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  background: var(--panel, #1c2129);
  color: var(--text, #e6e8ec);
  border: 1px solid var(--border, rgba(255,255,255,.08));
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
  transform: translateY(8px) scale(.98);
  transition: transform .2s ease;
}
.approval-modal.is-open .approval-card {
  transform: translateY(0) scale(1);
}

.approval-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.approval-id {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted, #8a95a5);
  letter-spacing: .5px;
}
.approval-pill {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.approval-pill.is-pending {
  background: rgba(234, 179, 8, .15);
  color: #facc15;
  border: 1px solid rgba(234, 179, 8, .35);
}

.approval-icon {
  font-size: 36px;
  line-height: 1;
  text-align: center;
  margin: 8px 0 12px;
}
.approval-icon.ok { color: #22c55e; }
.approval-icon.bad { color: #ef4444; }

.approval-title {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}
.approval-desc {
  text-align: center;
  color: var(--muted, #8a95a5);
  font-size: 14px;
  margin-bottom: 16px;
}

.approval-summary {
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border, rgba(255,255,255,.08));
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.ap-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px dashed rgba(255,255,255,.05);
}
.ap-row:last-child { border-bottom: 0; }
.ap-row .ak { color: var(--muted, #8a95a5); }
.ap-row .av { color: var(--text, #e6e8ec); text-align: right; }

.approval-link-label {
  font-size: 13px;
  color: var(--muted, #8a95a5);
  margin-bottom: 6px;
}
.approval-link-box {
  display: flex; gap: 8px; margin-bottom: 14px;
}
.approval-link-box input {
  flex: 1;
  background: rgba(0,0,0,.3);
  border: 1px solid var(--border, rgba(255,255,255,.12));
  color: var(--text, #e6e8ec);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}
.approval-link-box input:focus {
  outline: none;
  border-color: var(--accent, #22c55e);
}

.approval-spinner-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: rgba(59, 130, 246, .08);
  border: 1px solid rgba(59, 130, 246, .25);
  border-radius: 10px;
  margin-bottom: 14px;
}
.approval-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.15);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: ap-spin .8s linear infinite;
  flex-shrink: 0;
}
.approval-waiting-txt {
  font-size: 13px;
  color: var(--text, #e6e8ec);
}
@keyframes ap-spin { to { transform: rotate(360deg); } }

.approval-actions {
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
}
.approval-actions .btn-primary,
.approval-actions .btn-secondary,
.approval-actions .chip {
  min-width: 120px;
  justify-content: center;
}
.approval-actions .btn-secondary {
  background: transparent;
  border: 1px solid #ef4444;
  color: #ef4444;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease;
}
.approval-actions .btn-secondary:hover {
  background: rgba(239, 68, 68, .1);
}
.approval-actions .ap-approve { min-width: 140px; }
.approval-actions .ap-reject { min-width: 140px; }

/* Vista solo-aprobación: oculta la app y deja un fondo limpio detrás del modal */
body.approval-only > .app,
body.approval-only > #tpl-modal,
body.approval-only > #toast-stack,
body.approval-only > .toast-stack {
  display: none !important;
}
body.approval-only {
  background: #0f1419;
  overflow: auto;
}
html.light body.approval-only {
  background: #eef2f7;
}
body.approval-only .approval-overlay {
  background: transparent;
}
