:root {
  --green-900: #0b2e22;
  --green-800: #0f3d2e;
  --green-700: #14533d;
  --green-600: #1b6b4e;
  --green-100: #e6f2ec;
  --green-50: #f3f8f5;
  --gray-900: #1d2724;
  --gray-700: #475550;
  --gray-500: #70807a;
  --gray-300: #d7dedb;
  --gray-100: #f1f4f2;
  --white: #ffffff;
  --danger: #b42318;
  --warning: #b54708;
  --info: #175cd3;
  --shadow: 0 8px 24px rgba(11, 46, 34, .08);
  --radius: 14px;
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--gray-100); color: var(--gray-900); font-size: 15px; }
.hidden { display: none !important; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.2; }
p { margin: 0 0 1rem; }
button, input, select, textarea { font: inherit; }
a { color: var(--green-600); }

/* Login */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(135deg, var(--green-900), var(--green-600)); }
.login-card { width: 100%; max-width: 430px; background: var(--white); border-radius: 20px; padding: 2.25rem; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.login-brand { display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem; }
.login-brand h1 { font-size: 1.5rem; color: var(--green-900); }
.login-brand p { font-size: .85rem; color: var(--gray-500); margin: 0; }
.brand-mark { width: 52px; height: 52px; border-radius: 14px; background: var(--green-700); color: white; display: grid; place-items: center; font-weight: 800; letter-spacing: -.04em; font-size: 1.1rem; flex: 0 0 auto; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 10px; font-size: .85rem; }
.login-form { display: grid; gap: .5rem; }
.login-form label { font-weight: 600; font-size: .85rem; color: var(--gray-700); margin-top: .5rem; }
.login-form input { width: 100%; padding: .8rem 1rem; border: 1px solid var(--gray-300); border-radius: 10px; outline: none; }
.login-form input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(27,107,78,.12); }
.form-error { color: var(--danger); font-size: .85rem; min-height: 1.2rem; margin-top: .75rem; }
.login-hint { font-size: .78rem; color: var(--gray-500); line-height: 1.5; margin-top: 1rem; }
.backend-badge { display: inline-block; font-size: .72rem; color: var(--green-700); background: var(--green-100); padding: .35rem .65rem; border-radius: 999px; }

/* Layout */
.app-screen { display: flex; min-height: 100vh; }
.sidebar { width: 260px; background: var(--green-900); color: white; display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 20; }
.sidebar-brand { padding: 1.25rem; display: flex; gap: .75rem; align-items: center; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-brand strong { display: block; font-size: .95rem; }
.sidebar-brand span { font-size: .72rem; opacity: .7; }
.main-nav { padding: 1rem .75rem; overflow-y: auto; flex: 1; }
.nav-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; opacity: .5; padding: 1rem .75rem .4rem; }
.nav-item { width: 100%; display: flex; align-items: center; gap: .75rem; border: 0; background: transparent; color: rgba(255,255,255,.78); padding: .7rem .8rem; border-radius: 9px; cursor: pointer; text-align: left; margin-bottom: .15rem; }
.nav-item:hover { background: rgba(255,255,255,.08); color: white; }
.nav-item.active { background: var(--green-600); color: white; font-weight: 600; }
.nav-icon { width: 20px; text-align: center; font-size: 1rem; }
.sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255,255,255,.1); }
.app-main { flex: 1; margin-left: 260px; min-width: 0; }
.topbar { height: 72px; background: white; border-bottom: 1px solid var(--gray-300); display: flex; align-items: center; padding: 0 1.5rem; gap: 1rem; position: sticky; top: 0; z-index: 10; }
.topbar-title { flex: 1; }
.topbar-title h2 { font-size: 1.1rem; margin: 0; }
.topbar-title span { font-size: .78rem; color: var(--gray-500); }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.icon-btn { position: relative; border: 1px solid var(--gray-300); background: white; border-radius: 10px; width: 40px; height: 40px; cursor: pointer; font-size: 1rem; }
.icon-btn:hover { background: var(--green-50); }
.badge { position: absolute; top: -6px; right: -6px; background: var(--danger); color: white; border-radius: 999px; font-size: .65rem; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 4px; }
.user-chip { display: flex; align-items: center; gap: .5rem; border: 1px solid var(--gray-300); background: white; border-radius: 999px; padding: .3rem .75rem .3rem .35rem; cursor: pointer; max-width: 220px; }
.user-chip span:first-child { width: 30px; height: 30px; border-radius: 50%; background: var(--green-700); color: white; display: grid; place-items: center; font-size: .7rem; font-weight: 700; flex: 0 0 auto; }
.user-chip span:last-child { font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-toggle { display: none; }
.nav-backdrop { display: none; }
.content { padding: 1.5rem; max-width: 1500px; margin: 0 auto; }

/* Reusable */
.btn { border: 1px solid transparent; border-radius: 9px; padding: .65rem 1rem; cursor: pointer; font-weight: 600; font-size: .85rem; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; background: white; color: var(--gray-900); }
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--green-700); color: white; }
.btn-secondary { background: var(--green-100); color: var(--green-800); border-color: var(--green-100); }
.btn-danger { background: #fee4e2; color: var(--danger); border-color: #fee4e2; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.2); color: inherit; }
.btn-block { width: 100%; }
.btn-sm { padding: .4rem .65rem; font-size: .75rem; }
.card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.card + .card { margin-top: 1rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.section-head h3 { margin: 0; }
.muted { color: var(--gray-500); }
.small { font-size: .78rem; }
.right { text-align: right; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > * { min-width: 0; }
.grid { display: grid; gap: 1rem; }
.grid > * { min-width: 0; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid-kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi { background: white; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; border-left: 4px solid var(--green-600); }
.kpi .label { font-size: .75rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.5rem; font-weight: 800; color: var(--green-900); margin-top: .3rem; }
.kpi .detail { font-size: .72rem; color: var(--gray-500); margin-top: .25rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: .7rem .65rem; text-align: left; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-500); background: var(--green-50); }
tr:hover td { background: #fafcfb; }
.pill { display: inline-block; padding: .25rem .55rem; border-radius: 999px; font-size: .7rem; font-weight: 700; }
.pill.pendiente { background: #fef0c7; color: #93370d; }
.pill.en-revisión { background: #d1e9ff; color: #175cd3; }
.pill.aprobado { background: #dcfae6; color: #067647; }
.pill.rechazado { background: #fee4e2; color: var(--danger); }
.pill.entregado { background: var(--green-700); color: white; }
.pill.activo { background: #dcfae6; color: #067647; }
.pill.inactivo { background: var(--gray-100); color: var(--gray-500); }
.pill.pendiente-precio { background: #fef0c7; color: #93370d; }
.field { display: grid; gap: .35rem; }
.field label { font-size: .78rem; font-weight: 600; color: var(--gray-700); }
.field input, .field select, .field textarea { width: 100%; padding: .65rem .75rem; border: 1px solid var(--gray-300); border-radius: 9px; outline: none; background: white; }
.field textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; align-items: end; }
.filters .field label { font-size: .7rem; }
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.search-input { flex: 1; min-width: 220px; padding: .7rem 1rem; border: 1px solid var(--gray-300); border-radius: 10px; outline: none; }
.search-input:focus { border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(27,107,78,.1); }
.empty { text-align: center; padding: 3rem 1rem; color: var(--gray-500); }
.empty .emoji { font-size: 2.5rem; display: block; margin-bottom: .5rem; }

/* Products */
.product-card { background: white; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.product-photo { height: 150px; background: var(--green-50); display: grid; place-items: center; overflow: hidden; position: relative; }
.product-photo img { width: 100%; height: 100%; object-fit: contain; }
.photo-placeholder { text-align: center; color: var(--green-700); font-size: .72rem; padding: 1rem; }
.photo-placeholder .icon { font-size: 2rem; display: block; margin-bottom: .25rem; }
.product-body { padding: 1rem; display: flex; flex-direction: column; flex: 1; }
.product-name { font-weight: 700; font-size: .88rem; min-height: 2.4em; }
.product-desc { font-size: .75rem; color: var(--gray-500); margin: .4rem 0; min-height: 2.2em; }
.product-meta { font-size: .72rem; color: var(--gray-500); margin-bottom: .6rem; }
.product-price { font-size: 1.15rem; font-weight: 800; color: var(--green-800); margin-top: auto; }
.product-actions { display: flex; gap: .5rem; margin-top: .8rem; }
.qty-input { width: 72px; padding: .6rem; border: 1px solid var(--gray-300); border-radius: 9px; text-align: center; }
.cart-badge { display: inline-block; min-width: 20px; padding: 0 5px; background: var(--green-700); color: white; border-radius: 999px; font-size: .7rem; text-align: center; }
.product-stock { margin: .45rem 0 .2rem; }
.stock-badge { display: inline-block; padding: .28rem .5rem; border-radius: 999px; font-size: .7rem; font-weight: 700; white-space: nowrap; }
.stock-badge.stock-ok { background: var(--green-100); color: var(--green-800); }
.stock-badge.stock-low { background: #fef0c7; color: #93370d; }
.stock-badge.stock-unknown { background: var(--gray-100); color: var(--gray-500); }
.stock-notice { margin-top: 1rem; padding: .75rem 1rem; border: 1px solid #fdb022; border-left: 4px solid #f79009; border-radius: 9px; background: #fffaeb; color: #93370d; font-size: .82rem; }
.stock-notice-muted { border-color: var(--gray-300); border-left-color: var(--gray-500); background: var(--green-50); color: var(--gray-500); }

/* Charts */
.chart { width: 100%; height: 220px; display: flex; align-items: flex-end; gap: 8px; padding: 1rem 0 .5rem; border-bottom: 1px solid var(--gray-300); }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: .35rem; min-width: 30px; }
.chart-bar { width: 100%; max-width: 56px; background: linear-gradient(180deg, var(--green-600), var(--green-800)); border-radius: 6px 6px 0 0; min-height: 3px; position: relative; }
.chart-bar:hover::after { content: attr(data-value); position: absolute; top: -26px; left: 50%; transform: translateX(-50%); background: var(--gray-900); color: white; padding: .2rem .4rem; border-radius: 5px; font-size: .65rem; white-space: nowrap; }
.chart-label { font-size: .65rem; color: var(--gray-500); text-align: center; }
.bar-list { display: grid; gap: .7rem; }
.bar-item { display: grid; grid-template-columns: 1fr auto; gap: .3rem; font-size: .8rem; }
.bar-track { grid-column: 1 / -1; background: var(--gray-100); border-radius: 999px; height: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--green-600); border-radius: 999px; }

/* Notifications & modal */
.notification-item { display: flex; gap: .8rem; padding: .9rem 0; border-bottom: 1px solid var(--gray-100); }
.notification-item.unread { background: var(--green-50); }
.notif-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green-600); margin-top: .4rem; flex: 0 0 auto; }
.notif-dot.read { background: var(--gray-300); }
.modal-root { position: fixed; inset: 0; background: rgba(11,46,34,.55); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal { background: white; border-radius: 16px; width: min(760px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1.2rem 1.4rem; border-bottom: 1px solid var(--gray-100); position: sticky; top: 0; background: white; }
.modal-header h3 { margin: 0; }
.modal-body { padding: 1.4rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.4rem; border-top: 1px solid var(--gray-100); position: sticky; bottom: 0; background: white; }
.toast-root { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 100; }
.toast { background: var(--green-900); color: white; padding: .8rem 1rem; border-radius: 10px; box-shadow: var(--shadow); font-size: .85rem; max-width: 340px; animation: slidein .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } }
.timeline { list-style: none; padding: 0; margin: 1rem 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.4rem; border-left: 2px solid var(--green-100); font-size: .8rem; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--green-600); }
.timeline strong { display: block; }
.dropzone { border: 2px dashed var(--green-300); border-radius: 12px; padding: 2rem; text-align: center; background: var(--green-50); cursor: pointer; }
.dropzone:hover { background: var(--green-100); }
.diff-up { color: var(--danger); font-weight: 700; }
.diff-down { color: #067647; font-weight: 700; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .nav-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(11,46,34,.45); z-index: 15; }
  .app-main { margin-left: 0; }
  .menu-toggle { display: block; }
  .content { padding: 1rem; }
  .topbar { padding: 0 1rem; }
  .user-chip span:last-child { display: none; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
}
@media (max-width: 520px) {
  .login-card { padding: 1.5rem; }
  .grid-kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .kpi .value { font-size: 1.15rem; }
  .modal-body, .modal-header, .modal-footer { padding: 1rem; }
  /* Evita el zoom automático de Safari/iOS al enfocar campos (mínimo 16px). */
  input, select, textarea { font-size: 16px; }
  /* Objetos táctiles más grandes. */
  .btn { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .nav-item { padding: .85rem .8rem; }
  /* Catálogo: dos productos por fila con foto legible. */
  .grid-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
  .product-card { border-radius: 12px; }
  .product-photo { height: 132px; background: #fff; border-bottom: 1px solid var(--gray-100); }
  .product-photo img { object-fit: contain; padding: .35rem; }
  .photo-placeholder { font-size: .62rem; line-height: 1.25; padding: .5rem .35rem; }
  .photo-placeholder .icon { font-size: 2.2rem; margin-bottom: .2rem; }
  .product-body { padding: .7rem; }
  .product-name { font-size: .78rem; line-height: 1.25; min-height: 3.8em; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .product-desc { font-size: .68rem; line-height: 1.25; min-height: 2.6em; margin: .3rem 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .product-meta { font-size: .64rem; margin-bottom: .4rem; }
  .product-price { font-size: .95rem; margin-top: auto; }
  .product-price .muted { font-size: .62rem; }
  .product-stock { margin: .35rem 0 .1rem; }
  .stock-badge { font-size: .62rem; padding: .22rem .4rem; white-space: normal; }
  .product-actions { flex-direction: column; gap: .4rem; margin-top: .6rem; }
  .product-actions .qty-input { width: 100%; }
  /* El gráfico de 12 meses debe caber o desplazarse sin ensanchar la página. */
  .chart { gap: 4px; overflow-x: auto; }
  .chart-col { min-width: 20px; }
  .chart-label { font-size: .55rem; }
  .toast { max-width: calc(100vw - 2rem); }
}
