/* ── Variables dark mode ───────────────────────────────────────── */
:root {
  --green-light: #A8C97F;
  --green-mid:   #7FAF52;
  --green-dark:  #6B8F47;
  --green-deep:  #4A6630;
  --green-glow:  rgba(107,143,71,.18);

  --bg-base:     #0F0F0F;
  --bg-surface:  #1A1A1A;
  --bg-elevated: #222222;
  --bg-hover:    #2A2A2A;
  --bg-input:    #1F1F1F;

  --border:      #2E2E2E;
  --border-mid:  #383838;

  --text-primary:  #F0F0F0;
  --text-secondary:#A0A0A0;
  --text-muted:    #606060;

  --danger:      #F87171;
  --danger-bg:   rgba(248,113,113,.12);
  --warning:     #FBBF24;
  --warning-bg:  rgba(251,191,36,.12);
  --success:     #6EE7A0;
  --success-bg:  rgba(110,231,160,.12);

  --sidebar-w:   220px;
  --radius:      8px;
  --shadow:      0 2px 8px rgba(0,0,0,.4);
  --shadow-md:   0 4px 16px rgba(0,0,0,.5);
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-base);
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0 0 24px;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
}

.logo-link {
  display: block;
  padding: 20px 16px 18px;
  border-bottom: 1px solid var(--border);
}
.logo-svg { width: 150px; height: auto; display: block; }

/* Recolor logo for dark mode */
.logo-svg text:first-of-type { fill: #E0E0E0 !important; }

.nav-section { padding: 16px 8px 4px; }
.nav-label {
  font-size: 10px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 0 8px; display: block; margin-bottom: 4px;
}

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius);
  color: var(--text-secondary); text-decoration: none;
  font-weight: 500; transition: all .15s;
}
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-link.active {
  background: var(--green-glow);
  color: var(--green-light);
  font-weight: 600;
  border-left: 2px solid var(--green-dark);
  padding-left: 8px;
}

.nav-bottom { margin-top: auto; border-top: 1px solid var(--border); padding-top: 16px; }
.nav-user { padding: 8px 10px 0; }
.nav-user-name { font-size: 11px; color: var(--text-muted); display: block; margin-bottom: 2px; padding: 0 2px; }
.nav-logout { color: var(--danger) !important; }
.nav-logout:hover { background: var(--danger-bg) !important; }

/* ── Main content ──────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;           /* permite que las tablas anchas scrolleen adentro, sin estirar la página */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.page-header h1 { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.header-actions { display: flex; gap: 8px; }

.page-body { padding: 28px 32px; flex: 1; }

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  container-type: inline-size;   /* permite que .card-value se ajuste al ancho real de la tarjeta */
  min-width: 0;                  /* evita que se desborde dentro de grids */
}
.card-accent {
  border-left: 3px solid var(--green-dark);
  background: linear-gradient(135deg, var(--bg-surface), #1E2A18);
}
.card-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted); margin-bottom: 8px;
}
.card-value {
  font-size: 22px;                       /* fallback si el navegador no soporta container queries */
  font-size: clamp(15px, 9cqi, 26px);    /* grande si el número es corto; se achica si es largo y no entra */
  font-weight: 800; color: var(--text-primary); line-height: 1.1;
}
.card-sub { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.card-action-center { display: flex; align-items: center; justify-content: center; }

.cards-grid { display: grid; gap: 14px; }
.cards-2 { grid-template-columns: repeat(2, 1fr); }
.cards-3 { grid-template-columns: repeat(3, 1fr); }
.cards-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1.5px solid transparent; text-decoration: none;
  transition: all .15s; white-space: nowrap;
}
.btn-primary {
  background: var(--green-dark);
  color: #fff;
  border-color: var(--green-dark);
}
.btn-primary:hover { background: var(--green-mid); border-color: var(--green-mid); }

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-mid);
}
.btn-outline:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-icon {
  background: none; border: none; cursor: pointer;
  padding: 4px 6px; border-radius: 4px; font-size: 12px;
  transition: all .15s;
}
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: .85; }
.btn-danger-icon { color: var(--text-muted); }
.btn-danger-icon:hover { color: var(--danger); background: var(--danger-bg); }

.ml-2 { margin-left: 8px; }

/* ── Table ─────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  max-width: 100%;          /* no crece más que el contenedor → la tabla ancha scrollea adentro */
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.table { width: 100%; border-collapse: collapse; background: var(--bg-surface); }
.table th {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; padding: 10px 14px;
  text-align: left; border-bottom: 1px solid var(--border);
}
.table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-hover); }

/* Tabla ANCHA con scroll horizontal (Profit). Las celdas no se achican (nowrap),
   la tabla crece a lo ancho y el contenedor (.table-wrap) scrollea de costado. */
.table.table-wide { width: max-content; min-width: 100%; }
.table.table-wide th,
.table.table-wide td { white-space: nowrap; padding: 12px 20px; }
.table-wrap { -webkit-overflow-scrolling: touch; }
/* Barra de scroll visible y prolija */
.table-wrap::-webkit-scrollbar { height: 10px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.text-right { text-align: right; }
.text-center { text-align: center; }

.row-positive { background: rgba(110,231,160,.04); }
.row-positive:hover { background: rgba(110,231,160,.08) !important; }

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge-ok, .badge-success { background: var(--success-bg); color: var(--success); }
.badge-alerta, .badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-critico, .badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border); }

/* ── Stock cards ───────────────────────────────────────────────── */
.stock-card { position: relative; }
.stock-ok    { border-left: 3px solid var(--success); }
.stock-alerta { border-left: 3px solid var(--warning); }
.stock-critico { border-left: 3px solid var(--danger); }

.stock-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.stock-nombre { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.stock-big-num { font-size: 40px; font-weight: 800; color: var(--green-light); margin: 10px 0; }
.stock-unit { font-size: 16px; font-weight: 400; color: var(--text-muted); }

.stock-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.meta-label { font-size: 10px; color: var(--text-muted); display: block; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.meta-value { font-size: 15px; font-weight: 600; display: block; color: var(--text-primary); }

.stock-sugerido {
  margin-top: 14px; padding: 10px 14px;
  background: var(--warning-bg); border: 1px solid rgba(251,191,36,.2);
  border-radius: var(--radius); font-size: 13px; color: var(--warning);
}
.alert-box {
  margin-top: 14px; padding: 10px 14px;
  background: var(--danger-bg); border: 1px solid rgba(248,113,113,.2);
  border-radius: var(--radius); font-size: 13px; color: var(--danger);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

/* ── Forms ─────────────────────────────────────────────────────── */
.form-container { max-width: 720px; }
.form-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 140px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 24px; padding-top: 20px;
  border-top: 1px solid var(--border);
}
.form-hint { font-size: 11px; color: var(--text-muted); }
.form-group-action { justify-content: flex-end; padding-bottom: 2px; }

input[type="text"], input[type="number"], input[type="date"],
select, textarea {
  background: var(--bg-input);
  border: 1.5px solid var(--border-mid);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text-primary);
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green-dark);
  box-shadow: 0 0 0 3px var(--green-glow);
}
select option { background: var(--bg-elevated); color: var(--text-primary); }
input::placeholder { color: var(--text-muted); }

.input-sm { width: 90px; }
.input-md { width: 180px; }

/* ── Filter bar ────────────────────────────────────────────────── */
.filter-bar {
  display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap;
  background: var(--bg-surface); padding: 14px 18px;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.filter-bar label {
  font-size: 12px; font-weight: 600; color: var(--text-secondary);
  display: flex; flex-direction: column; gap: 4px;
}
.filter-bar input, .filter-bar select { width: auto; }

/* ── Collapsible forms ─────────────────────────────────────────── */
.collapsible-form {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.collapsible-btn {
  width: 100%; text-align: left; padding: 12px 18px;
  background: var(--bg-elevated); border: none; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--green-light);
  transition: background .15s;
}
.collapsible-btn:hover { background: var(--bg-hover); }
.collapsible-body {
  padding: 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}

.inline-form { display: block; }
.inline-edit-form { display: contents; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.sub-form summary { cursor: pointer; font-size: 12px; color: var(--green-light); font-weight: 600; }

/* ── Total display ─────────────────────────────────────────────── */
.total-display {
  font-size: 30px; font-weight: 800; color: var(--green-light);
  padding: 14px 16px;
  background: linear-gradient(135deg, #1A2A12, #1E3015);
  border-radius: var(--radius);
  border: 1px solid var(--green-deep);
}

/* ── Section titles ────────────────────────────────────────────── */
.section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted); margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

/* ── Colors ────────────────────────────────────────────────────── */
.text-muted   { color: var(--text-muted) !important; }
.text-danger  { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }

/* ── Spacing ───────────────────────────────────────────────────── */
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.small { font-size: 12px; }

.link-muted { color: var(--text-muted); font-size: 12px; text-decoration: none; transition: color .15s; }
.link-muted:hover { color: var(--green-light); }

.empty-state {
  text-align: center; padding: 40px;
  color: var(--text-muted); font-size: 14px;
  border: 1px dashed var(--border); border-radius: var(--radius);
}

.action-cell { white-space: nowrap; }
.inline-recibir { display: flex; gap: 6px; align-items: center; }

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Mobile header ─────────────────────────────────────────────── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 54px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  padding: 0 16px;
  z-index: 200;
  gap: 12px;
}
.hamburger {
  background: none; border: none;
  color: var(--text-primary); cursor: pointer;
  padding: 8px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
}
.hamburger:hover { background: var(--bg-hover); }
.mobile-title {
  font-size: 16px; font-weight: 800; color: var(--text-primary);
}
.mobile-title span { color: var(--green-light); font-style: italic; }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 150;
}
.sidebar-overlay.open { display: block; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .cards-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .mobile-header { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 175;
    width: var(--sidebar-w);
  }
  .sidebar.open { transform: translateX(0); }

  .main-content {
    margin-left: 0;
    padding-top: 54px;
  }

  .cards-2, .cards-3, .cards-4 { grid-template-columns: 1fr; }
  .page-body { padding: 14px; }
  .page-header { padding: 12px 14px; }
  .page-header h1 { font-size: 15px; }

  .form-container { max-width: 100%; }
  .form-card { padding: 16px; }
  .form-row { flex-direction: column; gap: 10px; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }

  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input, .filter-bar select { width: 100%; }

  .table th, .table td { padding: 8px 10px; font-size: 12px; }
}
