/* public/css/style.css */

:root {
  --color-bg: #F3F6F1;
  --color-surface: #FFFFFF;
  --color-sidebar: #123B2E;
  --color-sidebar-hover: #17483A;
  --color-sidebar-active: #1D5847;
  --color-primary: #5CAE44;
  --color-primary-dark: #3D8A34;
  --color-text: #16302E;
  --color-text-muted: #5C7A70;
  --color-text-inverse: #E7F1E9;
  --color-border: #DCE6DD;
  --color-warning: #E8A33D;
  --color-danger: #C1554A;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", monospace;

  --radius: 10px;
  --shadow-card: 0 1px 2px rgba(11, 61, 59, 0.06), 0 4px 12px rgba(11, 61, 59, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 4px;
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-sidebar);
  color: var(--color-text-inverse);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px 24px;
  border-bottom: 1px solid rgba(231, 241, 238, 0.12);
  margin-bottom: 16px;
}

.brand-logo-chip {
  background: var(--color-surface);
  border-radius: 10px;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.brand-logo-chip img {
  height: 22px;
  width: auto;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #FFFFFF;
}

.brand-caption {
  font-size: 11px;
  color: rgba(231, 241, 233, 0.6);
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: rgba(231, 241, 238, 0.75);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-text-inverse);
}

.nav-item.active {
  background: var(--color-sidebar-active);
  color: #FFFFFF;
}

.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1.5px solid rgba(231, 241, 238, 0.5);
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.nav-section-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 16px;
  color: rgba(231, 241, 238, 0.55);
  padding: 20px 12px 8px;
}

.nav-section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(231, 241, 238, 0.14);
}

.nav-item.active .nav-dot,
.nav-item:hover .nav-dot {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.nav-item-highlight {
  border-left: 3px solid var(--color-primary);
  padding-left: 9px;
}

.nav-item-highlight .nav-dot {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
 
.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid rgba(231, 241, 238, 0.12);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  color: rgba(231, 241, 238, 0.65);
}

.app-version {
  font-size: 11px;
  opacity: 0.7;
}

/* ---------------- Content ---------------- */

.content {
  flex: 1;
  padding: 40px 48px;
  max-width: 1300px;
}

.view { display: none; }
.view.active { display: block; }

.subtitle {
  color: var(--color-text-muted);
  font-size: 15px;
  margin-bottom: 32px;
}

/* ---------------- Stat cards ---------------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}

.stat-card {
  background: var(--color-surface);
  border-radius: 0 10px 10px 0;
  box-shadow: var(--shadow-card);
  border-left: 3px solid var(--color-border);
  padding: 12px 14px;
  position: relative;
  overflow: hidden;
}

.stat-card:has(.stat-dot.primary) { border-left-color: var(--color-primary); }
.stat-card:has(.stat-dot.warning) { border-left-color: var(--color-warning); }
.stat-card:has(.stat-dot.muted) { border-left-color: var(--color-text-muted); }

.stat-dot {
  display: none;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1;
  margin-bottom: 3px;
}

.stat-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}
 
/* ---------------- Secciones colapsables ---------------- */

.collapsible-section {
  margin-top: 20px;
}

.collapsible-section summary {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text);
  padding: 2px 0 4px;
}

.collapsible-section summary::-webkit-details-marker {
  display: none;
}

.collapsible-section summary::before {
  content: "▸";
  font-size: 12px;
  color: var(--color-text-muted);
  transition: transform 0.15s ease;
  display: inline-block;
}
 
.collapsible-section[open] summary::before {
  transform: rotate(90deg);
}

.collapsible-section .stats-grid {
  margin-top: 8px;
}

/* ---------------- Tables & forms ---------------- */

section h3 {
  font-size: 18px;
  margin-top: 20px;
  margin-bottom: 4px;
}

section h4 {
  font-size: 14px;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 24px;
  margin-bottom: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  margin: 12px 0;
}

#comprasTbody td {
  max-width: 300px;
}

#ordersTbody td {
  max-width: 230px;
}


th, td {
  padding: 10px 14px;
  text-align: left;
  font-size: 14px;
  border-bottom: 1px solid var(--color-border);
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  font-weight: 600;
  background: rgba(76, 154, 130, 0.06);
}

tr:last-child td { border-bottom: none; }

form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

input, select {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
}

input:focus, select:focus, button:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

button[type="submit"] {
  background: var(--color-primary);
  border-color: var(--color-primary-dark);
  color: #FFFFFF;
}

button[type="submit"]:hover { background: var(--color-primary-dark); }

button:not([type="submit"]):hover {
  border-color: var(--color-text-muted);
}

.selectors {
  display: flex;
  gap: 20px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.selectors label {
  font-size: 13px;
  color: var(--color-text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#recipeTotal {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
}

.recipe-category-label {
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.recipe-category-label select {
  min-width: 180px;
}

/* ---------------- Vista Productos ---------------- */

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.view-header .stats-grid { margin-top: 0; }

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary-dark);
  color: #FFFFFF;
}

.btn-primary:hover { background: var(--color-primary-dark); }

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.sync-status {
  font-size: 13px;
  margin: 8px 0 0;
  text-align: right;
}

.sync-status.success { color: var(--color-primary-dark); }
.sync-status.error { color: var(--color-danger); }

.margin-good { color: var(--color-primary-dark); font-weight: 600; }
.margin-warn { color: var(--color-warning); font-weight: 600; }
.margin-bad { color: var(--color-danger); font-weight: 600; }
.margin-muted { color: var(--color-text-muted); }

.stock-ok { font-family: var(--font-mono); font-weight: 600; color: var(--color-primary-dark); }
.stock-empty { font-family: var(--font-mono); font-weight: 600; color: var(--color-danger); }
.stock-muted { font-family: var(--font-mono); color: var(--color-text-muted); }

.products-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 20px 0 4px;
}

.products-toolbar input {
  min-width: 240px;
}

.search-fake-input {
  min-width: 240px;
  display: inline-block;
  font-family: var(--font-body);
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  cursor: text;
  white-space: nowrap;
  overflow: hidden;
}

.search-fake-input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.search-fake-input:empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-muted);
}

.last-synced {
  font-size: 12px;
  color: var(--color-text-muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--color-primary-dark);
  padding: 0;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  margin-right: 12px;
}

.link-btn:last-child { margin-right: 0; }

.link-btn:hover { color: var(--color-primary); }

.insumos-filters-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.critical-filter-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.critical-filter-label input { width: auto; }

.critical-filter-label input[type="checkbox"] {
  padding: 0;
  border: none;
  background: none;
  accent-color: var(--color-primary);
  min-width: auto;
}

tr.row-warning { background: rgba(232, 163, 61, 0.1); }
tr.row-danger { background: rgba(193, 85, 74, 0.1); }

.stock-critical-value {
  font-family: var(--font-mono);
  font-weight: 600;
}

.stock-critical-value.warning { color: var(--color-warning); }
.stock-critical-value.danger { color: var(--color-danger); }

.modal.modal-wide { max-width: 680px; }

.chart-range-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.chart-range-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--color-text-muted);
}

.chart-container {
  margin-top: 16px;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px;
  height: 320px;
  position: relative;
}

#movementForm {
  flex-direction: row;
  align-items: flex-end;
  flex-wrap: wrap;
}

#movementForm select,
#movementForm input {
  width: auto;
  flex: 1;
  min-width: 120px;
}

/* ---------------- Modal ---------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 36, 27, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--color-surface);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(11, 36, 27, 0.35);
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-header h3 {
  font-size: 17px;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  padding: 0;
  color: var(--color-text-muted);
  cursor: pointer;
}

.modal-close:hover { color: var(--color-text); }

.modal-footer {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.modal-body form {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  margin-top: 0;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--color-text-muted);
  text-align: left;
}

.modal-field input { width: 100%; }

.modal-field-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.modal-field-checkbox input { width: auto; }

.form-error {
  color: var(--color-danger);
  font-size: 13px;
  margin: 8px 0 0;
}

.badge-active {
  color: var(--color-primary-dark);
  font-weight: 600;
  font-size: 13px;
}

.badge-inactive {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 13px;
}

/* ---------------- Estados (tags) ---------------- */

.status-tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.status-tag.confirmada,
.status-tag.success {
  background: rgba(92, 174, 68, 0.15);
  color: var(--color-primary-dark);
}

.status-tag.otro,
.status-tag.warning {
  background: rgba(232, 163, 61, 0.15);
  color: var(--color-warning);
}

.status-tag.danger {
  background: rgba(193, 85, 74, 0.15);
  color: var(--color-danger);
}

.status-tag.neutral {
  background: rgba(92, 122, 112, 0.12);
  color: var(--color-text-muted);
}

/* ---------------- Detalle de factura (modal) ---------------- */

.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.invoice-header-main h4 {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0 0 4px;
  text-transform: none;
  letter-spacing: normal;
  color: var(--color-text);
}

.invoice-header-main p {
  margin: 0;
  font-size: 13px;
  color: var(--color-text-muted);
}

.invoice-header-meta {
  text-align: right;
  font-size: 13px;
  color: var(--color-text-muted);
}

.invoice-header-meta .invoice-folio {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
}

.invoice-totales {
  display: flex;
  justify-content: flex-end;
  gap: 24px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.invoice-totales div {
  text-align: right;
}

.invoice-totales .invoice-total-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.invoice-totales .invoice-total-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
}

.invoice-totales .invoice-total-value.grand {
  font-size: 19px;
  color: var(--color-primary-dark);
}

.invoice-download {
  margin-top: 16px;
  text-align: right;
}

/* ---------------- Topbar y menú móvil ---------------- */

.mobile-topbar {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 900px) {
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    padding: 0 16px;
    background: var(--color-sidebar);
    z-index: 210;
    box-shadow: var(--shadow-card);
  }

  .mobile-topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #FFFFFF;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 16px;
  }

  .mobile-topbar-brand img {
    height: 20px;
    width: auto;
  }

  .menu-toggle {
    width: 32px;
    height: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
  }

  .menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: #FFFFFF;
    border-radius: 2px;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .menu-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
  .menu-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .layout {
    display: block;
    padding-top: 56px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(280px, 85vw);
    z-index: 220;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 24px 60px rgba(11, 36, 27, 0.35);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(11, 36, 27, 0.45);
    z-index: 215;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .content {
    padding: 20px 16px 32px;
    max-width: 100%;
  }

  body.sidebar-locked {
    overflow: hidden;
  }
}

/* ---------------- Tablas con scroll horizontal (móvil y desktop angosto) ---------------- */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  margin: 12px 0;
}

.table-scroll table {
  width: max-content;
  min-width: 100%;
  margin: 0;
  box-shadow: none;
  border-radius: 0;
}
/* Barra de carga (la maneja common.js envolviendo fetch) */
#loadingBar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--color-primary);
  transform: scaleX(0);
  transform-origin: left;
  opacity: 0;
  z-index: 10000;
  pointer-events: none;
}
#loadingBar.is-loading {
  opacity: 1;
  animation: loading-bar-trickle 8s cubic-bezier(0.1, 0.6, 0.2, 1) forwards;
}
#loadingBar.is-done {
  transform: scaleX(1);
  opacity: 0;
  transition: transform 0.2s ease-out, opacity 0.3s ease 0.15s;
}
@keyframes loading-bar-trickle {
  0%   { transform: scaleX(0); }
  20%  { transform: scaleX(0.5); }
  100% { transform: scaleX(0.92); }
}
