/* =========================================================
   VARIABLES & RESET
   ========================================================= */
:root {
  --cream: #FAF7F2;
  --cream-dark: #F0EBE1;
  --ink: #1A1612;
  --ink-muted: #6B6257;
  --ink-light: #A89F94;
  --terracotta: #C4552A;
  --terracotta-light: #F0C5B2;
  --teal: #1F6B5E;
  --teal-light: #B2D9D3;
  --amber: #D4900A;
  --amber-light: #FAE8B0;
  --border: rgba(26,22,18,0.1);
  --border-strong: rgba(26,22,18,0.2);
  --shadow-sm: 0 1px 3px rgba(26,22,18,0.08);
  --shadow-md: 0 4px 16px rgba(26,22,18,0.1);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --sidebar-w: 220px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 15px;
  background: var(--cream);
  color: var(--ink);
  line-height: 1.6;
}

/* =========================================================
   LAYOUT
   ========================================================= */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* =========================================================
   SIDEBAR
   ========================================================= */
.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  color: var(--cream);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-icon {
  font-size: 22px;
  color: var(--terracotta);
  line-height: 1;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
}

.brand-sub {
  font-size: 10px;
  color: var(--ink-light);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
}

.nav-section-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-light);
  padding: 14px 8px 6px;
  font-weight: 500;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.65);
  font-size: 13.5px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  margin-bottom: 2px;
}

.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active { background: var(--terracotta); color: #fff; font-weight: 500; }

.nav-icon { font-size: 15px; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-date {
  font-size: 11.5px;
  color: var(--ink-light);
}

/* =========================================================
   MAIN CONTENT
   ========================================================= */
.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--cream);
  min-width: 0;
}

#page-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 36px 32px 60px;
}

/* =========================================================
   PAGE HEADER
   ========================================================= */
.page-header {
  margin-bottom: 32px;
}

.page-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
}

.page-subtitle {
  font-size: 13.5px;
  color: var(--ink-muted);
  margin-top: 4px;
}

/* =========================================================
   CARDS
   ========================================================= */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* =========================================================
   STAT CHIPS
   ========================================================= */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-chip {
  background: var(--cream-dark);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.stat-chip-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  font-weight: 500;
}

.stat-chip-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  margin-top: 2px;
}

.stat-chip.accent-teal  { background: var(--teal-light); }
.stat-chip.accent-terra { background: var(--terracotta-light); }
.stat-chip.accent-amber { background: var(--amber-light); }

/* =========================================================
   FORMS
   ========================================================= */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  align-items: end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-input, .form-select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 11px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.15s;
  outline: none;
}

.form-input:focus, .form-select:focus {
  border-color: var(--terracotta);
  box-shadow: 0 0 0 3px rgba(196,85,42,0.12);
}

textarea.form-input {
  height: auto;
  padding: 9px 11px;
  resize: vertical;
  min-height: 70px;
}

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  outline: none;
}

.btn-primary {
  background: var(--terracotta);
  color: #fff;
}
.btn-primary:hover { background: #AE4A23; }
.btn-primary:active { transform: scale(0.98); }

.btn-teal {
  background: var(--teal);
  color: #fff;
}
.btn-teal:hover { background: #175B50; }
.btn-teal:active { transform: scale(0.98); }

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--border-strong);
}
.btn-ghost:hover { background: var(--cream-dark); color: var(--ink); }

.btn-danger {
  background: transparent;
  color: #b33;
  border: 1px solid rgba(180,40,40,0.25);
  padding: 0 10px;
  height: 30px;
  font-size: 12px;
}
.btn-danger:hover { background: #fff0f0; }

.btn-sm {
  height: 30px;
  padding: 0 12px;
  font-size: 12.5px;
}

/* =========================================================
   TABLE
   ========================================================= */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  background: var(--cream-dark);
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--cream); }

/* =========================================================
   BADGE / PILL
   ========================================================= */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}

.badge-teal   { background: var(--teal-light); color: var(--teal); }
.badge-terra  { background: var(--terracotta-light); color: #7A3015; }
.badge-amber  { background: var(--amber-light); color: #7A5500; }
.badge-gray   { background: var(--cream-dark); color: var(--ink-muted); }

/* =========================================================
   EMPTY STATE
   ========================================================= */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--ink-light);
}

.empty-icon {
  font-size: 36px;
  margin-bottom: 10px;
  opacity: 0.5;
}

.empty-text {
  font-size: 14px;
  color: var(--ink-muted);
}

/* =========================================================
   TOAST
   ========================================================= */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 24px);
}

.toast {
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
}

.toast.success { border-left: 3px solid #4CAF50; }
.toast.error   { border-left: 3px solid var(--terracotta); }

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* =========================================================
   DIVIDER
   ========================================================= */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* =========================================================
   QUANTITY CONTROL
   ========================================================= */
.qty-ctrl {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.qty-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition: background 0.12s;
  flex: 0 0 auto;
}

.qty-btn:hover { background: var(--cream-dark); }

.qty-value {
  font-size: 14px;
  font-weight: 500;
  min-width: 24px;
  text-align: center;
}

/* =========================================================
   SECTION TABS (Categorías)
   ========================================================= */
.cat-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.cat-tab {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--ink-muted);
  transition: all 0.13s;
}

.cat-tab:hover { border-color: var(--terracotta); color: var(--terracotta); }
.cat-tab.active { background: var(--terracotta); color: #fff; border-color: var(--terracotta); }

/* =========================================================
   VENTA ITEM ROW (carrito)
   ========================================================= */
.cart-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.cart-row:last-child { border-bottom: none; }

.cart-row-name {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
}

.cart-row-meta {
  font-size: 12px;
  color: var(--ink-muted);
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  padding: 14px 0 0;
  margin-top: 4px;
  border-top: 2px solid var(--border);
  font-weight: 500;
  font-size: 15px;
  gap: 12px;
}

/* =========================================================
   LOW STOCK
   ========================================================= */
.low-stock {
  color: #b33;
  font-size: 11px;
  font-weight: 500;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 900px) {
  #page-container {
    padding: 24px 20px 48px;
  }
}

@media (max-width: 680px) {
  :root { --sidebar-w: 0px; }

  html, body {
    height: auto;
    min-height: 100%;
  }

  #app {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    display: block;
    width: 100%;
    overflow: visible;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: var(--shadow-sm);
  }

  .sidebar-brand,
  .sidebar-footer {
    display: none;
  }

  .sidebar-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    padding: 10px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .nav-section-label {
    display: none;
  }

  .nav-item {
    flex: 0 0 auto;
    margin-bottom: 0;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    padding: 8px 12px;
    font-size: 12px;
  }

  .nav-item.active {
    background: var(--terracotta);
    border-color: var(--terracotta);
  }

  .main-content {
    overflow: visible;
  }

  #page-container {
    max-width: 100%;
    padding: 16px 12px 40px;
  }

  .page-header {
    margin-bottom: 20px;
  }

  .page-title {
    font-size: 22px;
  }

  .page-subtitle {
    font-size: 13px;
  }

  .card {
    padding: 16px;
    border-radius: 14px;
  }

  .card-title {
    font-size: 15px;
    padding-bottom: 10px;
    margin-bottom: 12px;
  }

  .stat-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .stat-chip {
    padding: 12px 14px;
  }

  .stat-chip-value {
    font-size: 20px;
  }

  .form-grid,
  #inv-form-grid {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  .btn {
    width: 100%;
  }

  .btn-sm,
  .btn-danger {
    width: auto;
  }

  .cat-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .cat-tab {
    flex: 0 0 auto;
  }

  .cart-row {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .cart-row > div {
    min-width: 0;
  }

  .cart-total-row {
    flex-wrap: wrap;
  }

  .table-wrap {
    overflow-x: auto;
  }

  table {
    min-width: 600px;
  }

  #toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }

  .toast {
    width: 100%;
    font-size: 13px;
  }
}