:root {
  --cream: #faf7f2;
  --warm-white: #fffcf8;
  --ink: #1a1410;
  --ink-light: #4a3f35;
  --ink-muted: #9a8a7a;
  --accent: #c9773a;
  --accent-light: #f0d5b8;
  --accent-dark: #a05a22;
  --blush: #f5e6d8;
  --gold: #d4b483;
  --border: #e8ddd0;
  --shadow: rgba(26, 20, 16, 0.08);
  --shadow-md: rgba(26, 20, 16, 0.14);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 20% 10%, rgba(201, 119, 58, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 90%, rgba(212, 180, 131, 0.08) 0%, transparent 50%);
}

/* HEADER */
header {
  background: var(--ink);
  padding: 0 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 70px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px var(--shadow-md);
}

.logo {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  color: #fff;
  letter-spacing: 0.02em;
}

.logo span {
  color: var(--gold);
  font-style: italic;
}

.header-stats {
  display: flex;
  gap: 32px;
  align-items: center;
}

.stat-pill {
  text-align: center;
}

.stat-pill .val {
  display: block;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gold);
  line-height: 1;
}

.stat-pill .lbl {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-divider {
  width: 1px;
  height: 28px;
  background: rgba(255, 255, 255, 0.12);
}

/* LAYOUT */
.app {
  max-width: 1300px;
  margin: 0 auto;
  padding: 36px 40px;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 32px;
  align-items: start;
}

/* FORMULARIO */
.panel-form {
  background: var(--warm-white);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  position: sticky;
  top: 102px;
  box-shadow: 0 4px 24px var(--shadow);
}

.panel-header {
  background: var(--accent);
  padding: 24px 28px;
}

.panel-header h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  color: #fff;
  margin-bottom: 4px;
}

.panel-header p {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.75);
}

.form-body {
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.field label .req {
  color: var(--accent);
}

.field input,
.field select,
.field textarea {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--cream);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 119, 58, 0.12);
  background: #fff;
}

.field textarea {
  resize: none;
  height: 66px;
}

.price-wrap {
  position: relative;
}

.price-wrap .currency {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  color: var(--ink-muted);
  font-weight: 500;
  pointer-events: none;
}

.price-wrap input {
  padding-left: 36px;
}

/* LINK */
.field input[type="url"] {
  width: 100%;
}

/* FOTO */
.photo-upload {
  display: flex;
  align-items: center;
  gap: 12px;
}

.photo-preview {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: var(--blush);
  border: 2px dashed var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.2s;
}

.photo-preview:hover {
  border-color: var(--accent);
}

.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-preview .icon {
  font-size: 1.4rem;
}

.photo-upload-btn {
  flex: 1;
  font-size: 0.82rem;
  color: var(--ink-muted);
  cursor: pointer;
}

.photo-upload-btn span {
  color: var(--accent);
  text-decoration: underline;
}

#fileInput {
  display: none;
}

/* PRIORIDAD */
.priority-pills {
  display: flex;
  gap: 8px;
}

.priority-pill {
  flex: 1;
  padding: 8px 4px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: transparent;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.18s;
  color: var(--ink-light);
}

.priority-pill.alta.active  { background: #fee2e2; border-color: #ef4444; color: #dc2626; }
.priority-pill.media.active { background: #fef3c7; border-color: #f59e0b; color: #d97706; }
.priority-pill.baja.active  { background: #dcfce7; border-color: #22c55e; color: #16a34a; }
.priority-pill:hover        { border-color: var(--accent); }

.btn-add {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.12s;
  letter-spacing: 0.02em;
  margin-top: 4px;
}

.btn-add:hover  { background: var(--accent-dark); transform: translateY(-1px); }
.btn-add:active { transform: translateY(0); }

/* PANEL DERECHO */
.panel-right {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.summary-strip {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.cat-card {
  background: var(--warm-white);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 14px 18px;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
  min-width: 110px;
}

.cat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--shadow-md);
}

.cat-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 119, 58, 0.15);
}

.cat-card .cat-emoji  { font-size: 1.4rem; display: block; margin-bottom: 4px; }
.cat-card .cat-name   { font-size: 0.75rem; font-weight: 600; color: var(--ink-light); display: block; }
.cat-card .cat-total  { font-size: 0.82rem; font-weight: 700; color: var(--accent); display: block; }
.cat-card .cat-count  { font-size: 0.7rem; color: var(--ink-muted); }

.cat-all              { background: var(--ink); border-color: var(--ink); }
.cat-all .cat-name    { color: rgba(255, 255, 255, 0.8); }
.cat-all .cat-total   { color: var(--gold); }
.cat-all .cat-count   { color: rgba(255, 255, 255, 0.5); }

.total-strip {
  background: var(--ink);
  border-radius: 14px;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.total-strip .label   { font-size: 0.8rem; color: rgba(255,255,255,0.55); text-transform: uppercase; letter-spacing: 0.07em; }
.total-strip .amount  { font-family: 'Playfair Display', serif; font-size: 1.6rem; color: var(--gold); }
.total-strip .amount small { font-size: 0.85rem; font-family: 'DM Sans', sans-serif; color: rgba(255,255,255,0.4); }
.total-strip .filtered-note { font-size: 0.78rem; color: rgba(255,255,255,0.45); font-style: italic; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.4rem;
  flex: 1;
}

.toolbar-title span {
  color: var(--accent);
  font-style: italic;
}

.search-box {
  position: relative;
}

.search-box input {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  padding: 9px 14px 9px 36px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--warm-white);
  color: var(--ink);
  outline: none;
  width: 200px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 119, 58, 0.1);
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

.sort-select {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--warm-white);
  color: var(--ink-light);
  outline: none;
  cursor: pointer;
}

/* GRID */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.product-card {
  background: var(--warm-white);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.22s;
  position: relative;
  animation: cardIn 0.3s ease both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.product-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px var(--shadow-md);
  border-color: rgba(201, 119, 58, 0.3);
}

.product-card.comprado { opacity: 0.6; }
.product-card.comprado .product-name { text-decoration: line-through; }

.product-img {
  width: 100%;
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.8rem;
}

.product-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-body {
  padding: 14px 16px;
}

.product-cat-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 7px;
}

.product-name  { font-family: 'Playfair Display', serif; font-size: 0.98rem; line-height: 1.3; margin-bottom: 6px; color: var(--ink); }
.product-price { font-size: 1.1rem; font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.product-price .currency-sm { font-size: 0.72rem; font-weight: 500; color: var(--ink-muted); }

.product-note {
  font-size: 0.75rem;
  color: var(--ink-muted);
  line-height: 1.4;
  margin-bottom: 10px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
}

.priority-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
}

.priority-badge.alta  { background: #fee2e2; color: #dc2626; }
.priority-badge.media { background: #fef3c7; color: #d97706; }
.priority-badge.baja  { background: #dcfce7; color: #16a34a; }

.product-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  gap: 6px;
}

.product-date { font-size: 0.68rem; color: var(--ink-muted); }

.product-actions {
  display: flex;
  gap: 6px;
}

.action-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  transition: all 0.16s;
}

.action-btn:hover      { border-color: var(--accent); background: var(--blush); }
.action-btn.buy:hover  { border-color: #22c55e; background: #dcfce7; }
.action-btn.del:hover  { border-color: #ef4444; background: #fee2e2; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 64px 20px;
  color: var(--ink-muted);
}

.empty-state .emoji { font-size: 3.5rem; margin-bottom: 16px; display: block; }
.empty-state h3     { font-family: 'Playfair Display', serif; font-size: 1.3rem; color: var(--ink-light); margin-bottom: 8px; }
.empty-state p      { font-size: 0.88rem; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: var(--ink);
  color: #fff;
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 999;
  max-width: 300px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 20, 16, 0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--warm-white);
  border-radius: 20px;
  max-width: 440px;
  width: 100%;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
  animation: modalIn 0.25s ease;
  position: relative;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.94) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-img {
  width: 100%;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
}

.modal-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-body    { padding: 24px 28px 28px; }
.modal-cat     { font-size: 0.75rem; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 8px; }
.modal-name    { font-family: 'Playfair Display', serif; font-size: 1.5rem; margin-bottom: 10px; }
.modal-price   { font-size: 1.8rem; font-weight: 700; color: var(--accent); margin-bottom: 16px; }
.modal-note    { font-size: 0.9rem; color: var(--ink-light); line-height: 1.6; margin-bottom: 20px; }
.modal-meta    { font-size: 0.78rem; color: var(--ink-muted); margin-bottom: 20px; }

.modal-actions { display: flex; gap: 10px; }

.modal-btn {
  flex: 1;
  padding: 11px;
  border-radius: 10px;
  border: none;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
}

.modal-btn.primary   { background: var(--accent); color: #fff; }
.modal-btn.primary:hover { background: var(--accent-dark); }
.modal-btn.secondary { background: var(--blush); color: var(--accent-dark); }
.modal-btn.secondary:hover { background: var(--accent-light); }
.modal-btn.danger    { background: #fee2e2; color: #dc2626; }
.modal-btn.danger:hover { background: #fecaca; }

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* MODAL CONFIRMAR */
.confirm-modal {
  max-width: 340px;
  text-align: center;
  padding: 36px 28px 28px;
}

.confirm-icon {
  font-size: 2.8rem;
  margin-bottom: 12px;
}

.confirm-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  color: var(--ink);
  margin-bottom: 8px;
}

.confirm-desc {
  font-size: 0.88rem;
  color: var(--ink-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

/* RESPONSIVE */
@media (max-width: 900px) {
  .app          { grid-template-columns: 1fr; padding: 20px; }
  .panel-form   { position: static; }
  header        { padding: 0 20px; }
  .header-stats { gap: 18px; }
}

@media (max-width: 500px) {
  .products-grid { grid-template-columns: 1fr 1fr; }
}