:root {
  --ink: #14231d;
  --muted: #66746d;
  --paper: #f4f7f3;
  --panel: #ffffff;
  --line: #e2e9e3;
  --green: #1d6b50;
  --deep-green: #173f32;
  --lime: #dcef91;
  --orange: #ef9a61;
  --blue: #6da6d3;
  --violet: #aa88c9;
  --danger: #b8463e;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: Inter, "Segoe UI", Arial, sans-serif; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }
.view { display: none; }
.view.active { display: block; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 225px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; z-index: 5; height: 100vh; padding: 28px 18px 20px; background: var(--deep-green); color: white; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 28px; border: 0; background: transparent; color: white; font-size: 21px; font-weight: 850; letter-spacing: -.03em; cursor: pointer; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; background: var(--lime); color: var(--deep-green); box-shadow: inset 0 0 0 1px rgba(23,63,50,.08); }
nav { display: grid; gap: 6px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 13px; border: 0; border-radius: 10px; background: transparent; color: #d3e2db; text-align: left; cursor: pointer; transition: .18s ease; }
.nav-item > span { display: grid; place-items: center; width: 22px; color: #a7c5b8; font-weight: 850; }
.nav-item:hover, .nav-item.active { transform: translateX(2px); background: rgba(255,255,255,.12); color: white; }
.nav-item.active > span { color: var(--lime); }
.sidebar-footer { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 14px 10px 2px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-footer div:last-child { min-width: 0; }
.sidebar-footer strong, .sidebar-footer span { display: block; }
.sidebar-footer strong { font-size: 11px; }
.sidebar-footer span { margin-top: 3px; overflow: hidden; color: #abc0b7; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.connection-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: #f2b45f; box-shadow: 0 0 0 4px rgba(242,180,95,.1); }
.connection-dot.connected { background: #60d394; box-shadow: 0 0 0 4px rgba(96,211,148,.1); }
.connection-dot.error { background: #ef7469; }

.workspace { min-width: 0; padding: 34px 42px 52px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 24px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(30px, 4vw, 42px); letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: 22px; letter-spacing: -.028em; }
.eyebrow { margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .14em; }
.primary-button, .secondary-button, .outline-button, .whatsapp-button { border-radius: 11px; padding: 12px 17px; font-weight: 780; cursor: pointer; transition: transform .16s ease, opacity .16s ease; }
.primary-button:hover, .secondary-button:hover, .outline-button:hover, .whatsapp-button:hover { transform: translateY(-1px); }
.primary-button { border: 0; background: var(--ink); color: white; box-shadow: 0 8px 24px rgba(20,35,29,.16); }
.secondary-button { border: 0; background: var(--lime); color: var(--deep-green); }
.outline-button { border: 1px solid #bccbc1; background: white; color: var(--deep-green); }
.text-button { border: 0; background: none; color: var(--green); font-weight: 780; cursor: pointer; }
.wide { width: 100%; }
.notice { display: flex; align-items: center; gap: 12px; padding: 13px 16px; margin-bottom: 24px; border: 1px solid #d6e9ae; border-radius: 12px; background: #f5fadf; color: #325629; font-size: 13px; }
.notice p { margin: 0; }
.toast { position: fixed; top: 24px; right: 28px; z-index: 20; max-width: 390px; padding: 13px 17px; border-radius: 12px; background: var(--ink); color: white; box-shadow: 0 18px 50px rgba(20,35,29,.24); font-size: 13px; animation: toast-in .22s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat-card { position: relative; overflow: hidden; min-height: 136px; padding: 21px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: 0 8px 28px rgba(31,64,50,.04); }
.stat-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--card-accent); }
.stat-card p { margin-bottom: 13px; color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-bottom: 8px; font-size: 27px; letter-spacing: -.04em; }
.stat-card span { color: var(--muted); font-size: 12px; }
.accent-blue { --card-accent: var(--blue); }
.accent-orange { --card-accent: var(--orange); }
.accent-green { --card-accent: var(--lime); }
.accent-violet { --card-accent: var(--violet); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(270px, .7fr); gap: 16px; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: 0 8px 28px rgba(31,64,50,.04); }
.sales-panel, .data-panel { padding: 22px; }
.panel-heading, .section-title, .settings-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 11px 9px; border-bottom: 1px solid var(--line); color: var(--muted); text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
td { padding: 15px 9px; border-bottom: 1px solid #eef1ed; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.status, .stock-pill { display: inline-block; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 780; }
.status.pagado, .stock-pill.ok { background: #e3f3e9; color: #236c43; }
.status.pendiente { background: #fff0df; color: #9a541d; }
.status.vencido, .stock-pill.low { background: #ffe5e2; color: #a84038; }
.block { display: block; margin-top: 4px; color: var(--muted); }
.balance-due { color: #a84038; }
.collection-card { padding: 25px; background: var(--deep-green); color: white; }
.collection-card .eyebrow { color: var(--lime); }
.collection-card > p:not(.eyebrow) { margin: 18px 0 22px; color: #c9dbd3; font-size: 14px; line-height: 1.55; }
.whatsapp-line { margin-top: 24px; padding-top: 18px; border-top: 1px solid rgba(255,255,255,.15); color: #c9dbd3; font-size: 12px; }
.whatsapp-line span { display: inline-grid; place-items: center; width: 28px; height: 28px; margin-right: 8px; border-radius: 50%; background: #29a96c; color: white; font-size: 9px; font-weight: 850; }

.sale-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(330px, .65fr); gap: 16px; align-items: start; }
.product-picker, .cart-panel { padding: 23px; }
.search-input { width: min(280px, 44vw); padding: 11px 13px; border: 1px solid #d6dfd8; border-radius: 10px; background: #fbfcfa; outline: none; }
.search-input:focus, input:focus, select:focus { border-color: #79aa95; box-shadow: 0 0 0 3px rgba(29,107,80,.08); }
.product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.product-card { min-height: 142px; padding: 16px; border: 1px solid var(--line); border-radius: 13px; background: #fbfcfa; text-align: left; cursor: pointer; transition: .18s ease; }
.product-card:hover { transform: translateY(-2px); border-color: #b7c8bc; background: white; box-shadow: 0 8px 24px rgba(31,64,50,.07); }
.product-card:disabled { opacity: .5; cursor: not-allowed; }
.product-card strong, .product-card span, .product-card small { display: block; }
.product-card strong { min-height: 40px; margin: 10px 0 8px; font-size: 14px; }
.product-card > span:not(.product-category) { font-weight: 800; }
.product-card small { margin-top: 8px; color: var(--muted); }
.product-category { width: max-content; padding: 4px 7px; border-radius: 6px; background: #edf3ee; color: var(--green); font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.cart-panel { position: sticky; top: 24px; }
.cart-panel > h2 { margin-bottom: 18px; }
label { display: grid; gap: 7px; color: #48564f; font-size: 12px; font-weight: 700; }
label + label { margin-top: 14px; }
input, select { width: 100%; min-height: 42px; padding: 10px 11px; border: 1px solid #d5dfd7; border-radius: 9px; background: white; color: var(--ink); outline: none; }
label small { color: var(--muted); font-size: 10px; font-weight: 500; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 4px; margin: 14px 0; border-radius: 10px; background: #edf1ed; }
.segmented button { padding: 9px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 750; cursor: pointer; }
.segmented button.selected { background: white; color: var(--ink); box-shadow: 0 2px 8px rgba(20,35,29,.08); }
.cart-lines { min-height: 145px; max-height: 320px; margin: 18px 0; overflow-y: auto; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.empty-state { min-height: 145px; display: grid; place-content: center; text-align: center; }
.empty-state strong, .empty-state span { display: block; }
.empty-state span { margin-top: 6px; color: var(--muted); font-size: 11px; }
.cart-line { display: flex; justify-content: space-between; gap: 12px; padding: 13px 0; border-bottom: 1px solid #edf1ed; }
.cart-line:last-child { border: 0; }
.cart-line > div:first-child strong, .cart-line > div:first-child span { display: block; }
.cart-line > div:first-child strong { font-size: 12px; }
.cart-line > div:first-child span { margin-top: 5px; color: var(--muted); font-size: 11px; }
.quantity { display: flex; align-items: center; gap: 8px; }
.quantity button { display: grid; place-items: center; width: 25px; height: 25px; border: 1px solid #d4ddd6; border-radius: 7px; background: white; cursor: pointer; }
.quantity span { min-width: 18px; text-align: center; font-size: 12px; font-weight: 800; }
.cart-total { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.cart-total span { color: var(--muted); }
.cart-total strong { font-size: 24px; }

.collection-summary { display: grid; grid-template-columns: .55fr .55fr 1.5fr; gap: 14px; margin-bottom: 16px; }
.payment-form { display: grid; grid-template-columns: 1.1fr 1.15fr .65fr auto; gap: 10px; align-items: end; padding: 18px; }
.payment-form h2 { font-size: 18px; }
.payment-form select, .payment-form input { min-width: 0; }
.whatsapp-button { padding: 8px 11px; border: 1px solid #b9dfc8; background: #edfaf2; color: #147545; font-size: 11px; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.settings-card, .message-preview { padding: 24px; }
.settings-card h2, .message-preview h2 { margin-bottom: 14px; }
.support-copy { margin-bottom: 20px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.settings-card .outline-button { margin-top: 16px; }
.connection-result { display: flex; align-items: center; gap: 9px; margin-top: 14px; color: var(--muted); font-size: 11px; }
.connection-result span { width: 8px; height: 8px; border-radius: 50%; background: #efb15a; }
.connection-result.connected span { background: #43b77a; }
.connection-result.error span { background: #de675e; }
.settings-heading { align-items: center; }
.switch { display: inline-block; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: relative; display: block; width: 44px; height: 25px; border-radius: 999px; background: #cbd4cd; cursor: pointer; transition: .18s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px; border-radius: 50%; background: white; box-shadow: 0 2px 8px rgba(0,0,0,.16); transition: .18s; }
.switch input:checked + span { background: #25a969; }
.switch input:checked + span::after { transform: translateX(19px); }
.secret-status { display: flex; align-items: center; gap: 11px; padding: 12px; margin-bottom: 16px; border: 1px solid #cde9d8; border-radius: 10px; background: #f0faf4; }
.secret-status > span { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 50%; background: #45b877; color: white; }
.secret-status.pending { border-color: #ead6ad; background: #fff9ec; }
.secret-status.pending > span { background: #d39535; }
.secret-status strong, .secret-status small { display: block; }
.secret-status strong { font-size: 12px; }
.secret-status small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.message-preview { grid-column: span 2; display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px 24px; align-items: start; background: var(--deep-green); color: white; }
.message-preview .eyebrow { grid-column: 1; color: var(--lime); }
.message-preview h2 { grid-column: 1; }
.chat-bubble { grid-column: 2; grid-row: 1 / span 3; padding: 16px; border-radius: 14px 14px 4px 14px; background: #daf8e7; color: #1c4e38; font-size: 13px; line-height: 1.55; }
.safe-note { color: #bfd1c9; font-size: 11px; line-height: 1.5; }
.message-preview .primary-button { width: max-content; min-width: 210px; background: var(--lime); color: var(--deep-green); }

@media (max-width: 1160px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .collection-summary { grid-template-columns: 1fr 1fr; }
  .payment-form { grid-column: span 2; }
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 14px 16px; }
  .brand { padding: 0 4px 12px; }
  nav { display: flex; overflow-x: auto; }
  .nav-item { width: auto; flex: 0 0 auto; white-space: nowrap; }
  .nav-item:hover, .nav-item.active { transform: none; }
  .sidebar-footer { display: none; }
  .workspace { padding: 26px 20px 42px; }
  .sale-layout, .dashboard-grid { grid-template-columns: 1fr; }
  .cart-panel { position: static; }
  .settings-grid { grid-template-columns: 1fr; }
  .message-preview { grid-column: auto; }
}
@media (max-width: 660px) {
  .topbar, .section-title, .panel-heading { align-items: stretch; }
  .topbar, .section-title { display: grid; }
  .topbar .primary-button { width: 100%; }
  .stats-grid, .collection-summary, .product-grid { grid-template-columns: 1fr; }
  .payment-form { grid-column: auto; grid-template-columns: 1fr; }
  .search-input { width: 100%; }
  .message-preview { grid-template-columns: 1fr; }
  .message-preview .eyebrow, .message-preview h2, .chat-bubble { grid-column: 1; grid-row: auto; }
  .message-preview .primary-button { width: 100%; }
  .toast { right: 16px; left: 16px; max-width: none; }
}
