/* ============================================================
   SIGI-PEMEX — Sistema Integral de Gestión de Inventario
   Estilos corporativos institucionales
   ============================================================ */

:root {
  --green: #006837;
  --green-dark: #004d28;
  --green-deep: #062818;
  --green-mid: #0b7a44;
  --green-soft: #e7f4ec;
  --green-mist: #f3f8f5;
  --graphite: #2c3136;
  --graphite-2: #4a5158;
  --graphite-3: #6b737b;
  --line: #d8e0db;
  --paper: #f4f6f5;
  --white: #ffffff;
  --alert: #c8102e;
  --alert-soft: #fdecee;
  --amber: #b45309;
  --amber-soft: #fff6e8;
  --gold: #c5a35a;
  --shadow: 0 10px 30px rgba(6, 40, 24, 0.08);
  --shadow-lg: 0 24px 50px rgba(6, 40, 24, 0.14);
  --radius: 16px;
  --sidebar: 272px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--graphite);
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button, input, select, textarea { font-family: inherit; }
button { -webkit-tap-highlight-color: transparent; }
body.nav-open { overflow: hidden; }

.app-shell {
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar);
  background:
    radial-gradient(circle at 20% -10%, rgba(197, 163, 90, 0.18), transparent 42%),
    linear-gradient(180deg, #083820 0%, #062818 48%, #041910 100%);
  color: #eaf4ee;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  padding: 22px 16px max(16px, env(safe-area-inset-bottom));
  box-shadow: 8px 0 30px rgba(4, 25, 16, 0.18);
}

.sidebar-close {
  display: none;
  appearance: none;
  border: 0;
  background: rgba(255,255,255,0.08);
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  cursor: pointer;
  font-size: 18px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 4px 4px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-logo {
  width: 100%;
  height: auto;
  display: block;
  background: #f3f4f4;
  border-radius: 14px;
  padding: 10px 12px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.brand-kicker {
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--gold);
  font-weight: 700;
}

.brand-name {
  font-family: Outfit, sans-serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1;
}

.brand-sub {
  font-size: 12px;
  color: rgba(234, 244, 238, 0.68);
  margin-top: 3px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 22px;
}

.nav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: rgba(234, 244, 238, 0.82);
  text-align: left;
  padding: 12px 12px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: 0.18s ease;
}

.nav-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }

.nav-btn.active {
  background: linear-gradient(90deg, rgba(11, 122, 68, 0.95), rgba(0, 104, 55, 0.75));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(197, 163, 90, 0.28);
}

.nav-ico {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.06);
}

.nav-btn.active .nav-ico { background: rgba(255,255,255,0.14); }

.sidebar-foot {
  margin-top: auto;
  padding: 14px;
  border-radius: 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.06);
}

.user-role { font-size: 12px; color: var(--gold); font-weight: 700; letter-spacing: 0.04em; }
.user-name { font-weight: 700; margin-top: 2px; }
.user-meta { font-size: 12px; color: rgba(234,244,238,0.62); }

/* ---------- Main ---------- */
.main {
  margin-left: var(--sidebar);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(244, 246, 245, 0.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  padding: max(12px, env(safe-area-inset-top)) 28px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-kicker {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
  font-weight: 700;
}

.page-title {
  font-family: Outfit, sans-serif;
  font-size: 26px;
  margin: 2px 0 0;
  letter-spacing: -0.03em;
}

.content { padding: 24px 28px 48px; }

/* ---------- Cards / KPI ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.card {
  background: var(--white);
  border: 1px solid #e4ebe6;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.kpi {
  padding: 18px 18px 16px;
  position: relative;
  overflow: visible;
}

.kpi > * {
  position: relative;
  z-index: 1;
}

.kpi::after {
  content: "";
  position: absolute;
  right: -18px;
  top: -18px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: var(--green-soft);
}

.kpi-label { color: var(--graphite-3); font-size: 13px; font-weight: 600; }
.kpi-value {
  font-family: Outfit, sans-serif;
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
  margin: 8px 0 4px;
}
.kpi-hint { font-size: 13px; color: var(--graphite-2); }
.kpi.alert .kpi-value { color: var(--alert); }
.kpi.warn .kpi-value { color: var(--amber); }
.kpi.ok .kpi-value { color: var(--green); }

/* ---------- Toolbar / filters ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 18px 0;
}

.search, .select, .input, .textarea {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 14px;
  color: var(--graphite);
  outline: none;
  transition: 0.15s ease;
}

.search { min-width: min(260px, 100%); flex: 1; }
.select { min-width: 160px; }
.toolbar-filters, .toolbar-views { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-copy { color: var(--graphite-2); margin: 0; flex: 1; min-width: 200px; }
.toolbar-cta { white-space: nowrap; }
.section-title {
  font-family: Outfit, sans-serif;
  font-size: 20px;
  margin: 8px 0 14px;
  letter-spacing: -0.03em;
}
.section-head {
  padding: 16px 20px;
  border-bottom: 1px solid #e4ebe6;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.pad-card { padding: 16px 18px; }

.search:focus, .select:focus, .input:focus, .textarea:focus {
  border-color: var(--green-mid);
  box-shadow: 0 0 0 4px rgba(0, 104, 55, 0.12);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: 0.15s ease;
}

.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-ghost { background: #fff; color: var(--graphite); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--green-mist); }
.btn-danger { background: var(--alert); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-amber { background: #8a4b12; color: #fff; }
.btn-sm { padding: 8px 10px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

table.data th {
  text-align: left;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--graphite-3);
  padding: 14px 14px;
  background: #f7faf8;
  border-bottom: 1px solid var(--line);
}

table.data td {
  padding: 13px 14px;
  border-bottom: 1px solid #eef2ef;
  vertical-align: middle;
  font-size: 14.5px;
}

table.data tr:hover td { background: #f8fbf9; }

.item-cell { display: flex; align-items: center; gap: 12px; }
.thumb {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--green-soft);
  border: 1px solid #dce8e0;
}

.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 12.5px; color: var(--graphite-2); }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge-green { background: var(--green-soft); color: var(--green-dark); }
.badge-red { background: var(--alert-soft); color: var(--alert); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-gray { background: #eef1f3; color: var(--graphite-2); }
.badge-gold { background: #f8efd8; color: #7a5b16; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Grid inventory ---------- */
.inv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.inv-card { overflow: hidden; }
.inv-card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  background: linear-gradient(135deg, #0b7a44, #062818);
}
.inv-card-body { padding: 14px; }
.inv-card h3 { margin: 0 0 4px; font-family: Outfit, sans-serif; font-size: 17px; }
.inv-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.inv-card .actions .btn { flex: 1; justify-content: center; }

/* ---------- Category cards ---------- */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.cat-card { padding: 18px; }
.swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
}

/* ---------- Modal / toast ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 22, 16, 0.48);
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  animation: fade 0.16s ease;
}

.modal {
  width: min(720px, 100%);
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  max-height: 92vh;
  overflow: auto;
  animation: rise 0.2s ease;
}

.modal-head {
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.modal-head h2 {
  margin: 4px 0 0;
  font-family: Outfit, sans-serif;
  font-size: 22px;
}

.modal-body { padding: 18px 20px 8px; }
.modal-foot {
  padding: 12px 20px 18px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 700; color: var(--graphite-2); }
.textarea { min-height: 84px; resize: vertical; }

.photo-preview {
  width: 100%;
  height: 140px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px dashed var(--line);
  background: var(--green-mist);
}

.toast-wrap {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  min-width: 280px;
  max-width: 380px;
  background: #123022;
  color: #fff;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--gold);
  animation: rise 0.2s ease;
}

.toast.error { background: #4a1018; border-left-color: #ff8a9a; }
.toast.warn { background: #4a320d; border-left-color: #f5c16c; }

.empty {
  padding: 42px 20px;
  text-align: center;
  color: var(--graphite-3);
}

.menu-toggle { display: none; }

.alert-row { background: #fff8f8 !important; }
.warn-row { background: #fffaf0 !important; }

.sig-pad {
  width: 100%;
  height: 110px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fbfdfb;
  cursor: crosshair;
  touch-action: none;
}

.two-col {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 16px;
}

.list-compact { display: flex; flex-direction: column; gap: 10px; }
.mini {
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.backdrop {
  display: none;
}

/* Toques cómodos en táctil: evita zoom de iOS y alcanza 44px */
@media (pointer: coarse) {
  .search, .select, .input, .textarea, .btn {
    font-size: 16px;
    min-height: 44px;
  }
  .nav-btn { min-height: 48px; }
  .btn-sm { min-height: 42px; }
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; }
  table.data { min-width: 720px; }
  .col-hide-md { display: none; }
}

@media (max-width: 1024px) {
  .sidebar {
    width: min(320px, 88vw);
    transform: translateX(-110%);
    transition: transform 0.22s ease, visibility 0.22s ease;
    padding-top: max(22px, env(safe-area-inset-top));
    visibility: hidden;
    pointer-events: none;
  }
  .sidebar.open {
    transform: none;
    visibility: visible;
    pointer-events: auto;
  }
  .sidebar-close { display: grid; place-items: center; }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; min-width: 44px; justify-content: center; }
  .content {
    padding: 16px max(16px, env(safe-area-inset-right)) 88px max(16px, env(safe-area-inset-left));
  }
  .topbar {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .page-title { font-size: 22px; }
  .page-kicker { font-size: 11px; letter-spacing: 0.08em; }
  .backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 35;
  }
}

@media (max-width: 760px) {
  .kpi-grid { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 28px; }
  .kpi::after { width: 64px; height: 64px; }
  .toolbar { margin-top: 10px; }
  .toolbar-filters, .toolbar-views { width: 100%; }
  .toolbar-filters .select, .search, .toolbar-cta { width: 100%; min-width: 0; }
  .toolbar-views .btn { flex: 1; justify-content: center; }
  .toolbar-copy { min-width: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .inv-grid, .cat-grid { grid-template-columns: 1fr; }
  .mini { flex-direction: column; align-items: flex-start; }
  .section-head { padding: 14px 14px; }
  .toast-wrap {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }
  .toast { min-width: 0; max-width: none; }
  .overlay {
    padding: 0;
    align-items: end;
    place-items: end center;
  }
  .modal {
    width: 100%;
    max-height: min(94vh, 100%);
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-foot {
    flex-direction: column-reverse;
    position: sticky;
    bottom: 0;
    background: #fff;
  }
  .modal-foot .btn { width: 100%; justify-content: center; }

  /* Tablas → tarjetas apiladas */
  .table-wrap { overflow: visible; }
  table.data { min-width: 0; }
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td {
    display: block;
    width: 100%;
  }
  table.data tr {
    padding: 14px;
    border-bottom: 10px solid var(--paper);
  }
  table.data tr:last-child { border-bottom: 0; }
  table.data td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 0;
  }
  table.data td::before {
    content: attr(data-label);
    flex: 0 0 34%;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--graphite-3);
    padding-top: 3px;
  }
  table.data td.td-main {
    display: block;
    padding-bottom: 10px;
  }
  table.data td.td-main::before { display: none; }
  table.data td.td-actions {
    display: block;
    padding-top: 10px;
  }
  table.data td.td-actions::before { display: none; }
  table.data td.td-actions .actions,
  table.data td.td-actions .btn {
    width: 100%;
  }
  table.data td.td-actions .btn { justify-content: center; }
  .col-hide-md { display: flex; }
}

@media (max-width: 760px) {
  .quick-actions { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .brand-kicker { font-size: 10px; }
  .welcome-title { font-size: 24px; }
}

.app-shell.is-locked { display: none; }

.welcome-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(900px 480px at 50% -8%, rgba(197, 163, 90, 0.22), transparent 58%),
    radial-gradient(800px 500px at 100% 100%, rgba(200, 16, 46, 0.12), transparent 50%),
    #062818;
  overflow: auto;
}

.welcome-screen.is-gone {
  display: none;
}

.welcome-card {
  width: min(460px, 100%);
  background: #fff;
  border-radius: 24px;
  padding: 28px 24px 22px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: rise 0.45s ease;
}

.welcome-logo {
  display: block;
  width: min(320px, 100%);
  height: auto;
  margin: 0 auto 18px;
}

.welcome-kicker {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
}

.welcome-title {
  margin: 0 0 10px;
  font-family: Outfit, sans-serif;
  font-size: 28px;
  line-height: 1.15;
  color: var(--graphite);
}

.welcome-lead {
  margin: 0 0 18px;
  color: var(--graphite-2);
  line-height: 1.45;
}

.welcome-steps {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  text-align: left;
  display: grid;
  gap: 8px;
}

.welcome-steps li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--green-mist);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--graphite);
  font-size: 15px;
}

.welcome-steps span {
  flex: 0 0 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

.welcome-cta {
  width: 100%;
  justify-content: center;
  min-height: 48px;
  font-size: 16px;
}

#welcome-login {
  margin-top: 8px;
}

.welcome-cta:disabled {
  opacity: 0.65;
  cursor: wait;
}

.login-logo {
  display: block;
  width: min(280px, 100%);
  height: auto;
  margin: 0 auto 14px;
}

.login-kicker {
  margin: 0 0 8px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
}

.guide-box {
  background: #fff;
  border: 1px solid #cfe0d5;
  border-left: 5px solid var(--green);
  border-radius: 14px;
  padding: 14px 16px 12px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.guide-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 4px;
}

.guide-box strong {
  display: block;
  font-family: Outfit, sans-serif;
  font-size: 16px;
  color: var(--graphite);
}

.guide-box p {
  margin: 6px 0 0;
  color: var(--graphite-2);
  line-height: 1.45;
  font-size: 14px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.quick-card {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 16px;
  padding: 16px 14px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.quick-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.quick-ico {
  font-size: 22px;
  display: block;
  margin-bottom: 8px;
}

.quick-card strong {
  display: block;
  font-family: Outfit, sans-serif;
  font-size: 16px;
  color: var(--graphite);
}

.quick-card span {
  display: block;
  margin-top: 4px;
  color: var(--graphite-3);
  font-size: 13px;
  line-height: 1.35;
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(11, 122, 68, 0.45), transparent 55%),
    #062818;
}

.login-gate.hidden { display: none; }

.login-card {
  width: min(440px, 100%);
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.login-copy {
  margin: 0 0 18px;
  color: var(--graphite-2);
  line-height: 1.45;
}

.login-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--alert);
  font-size: 14px;
}

.user-email {
  margin-top: 4px;
  font-size: 12px;
  color: #9bb5a4;
  word-break: break-all;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
