:root {
  --red: #E3350D;
  --red-dark: #b8290a;
  --yellow: #FFCB05;
  --blue: #3B4CCA;
  --bg: #f5f5f5;
  --white: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-light: #666;
  --text-muted: #999;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.14);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── HEADER ─────────────────────────── */
header {
  background: var(--white);
  border-bottom: 2px solid var(--red);
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
}
.logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 22px; font-weight: 800;
  color: var(--red); white-space: nowrap;
}
.logo span { color: var(--yellow); font-size: 26px; }
.search-bar {
  flex: 1; display: flex; gap: 0; max-width: 500px;
}
.search-bar input {
  flex: 1; padding: 9px 14px; border: 2px solid var(--border);
  border-right: none; border-radius: var(--radius) 0 0 var(--radius);
  font-size: 14px; outline: none;
  transition: border-color .2s;
}
.search-bar input:focus { border-color: var(--red); }
.search-bar button {
  background: var(--red); color: #fff; border: none;
  padding: 9px 16px; border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 15px;
}
.header-nav { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius); font-size: 14px; font-weight: 600; border: none; transition: all .2s; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-outline { background: transparent; color: var(--red); border: 2px solid var(--red); }
.btn-outline:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-success { background: #22c55e; color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-gray { background: #e5e7eb; color: #374151; }

#user-menu { position: relative; }
#user-btn {
  background: none; border: 2px solid var(--border); border-radius: var(--radius);
  padding: 7px 14px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 6px; cursor: pointer;
}
.notif-badge {
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 50%; width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.dropdown {
  position: absolute; right: 0; top: 110%; min-width: 200px;
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-hover);
  overflow: hidden; display: none; z-index: 200;
}
.dropdown.open { display: block; }
.dropdown a, .dropdown button {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; font-size: 14px; width: 100%;
  background: none; border: none; text-align: left; color: var(--text);
}
.dropdown a:hover, .dropdown button:hover { background: #f9f9f9; }
.dropdown hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── LAYOUT ─────────────────────────── */
.page { max-width: 1200px; margin: 0 auto; padding: 24px 20px; }
.page-wide { max-width: 1400px; margin: 0 auto; padding: 24px 20px; }

/* ── FILTERS ─────────────────────────── */
.filters-bar {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  margin-bottom: 20px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.filter-group select, .filter-group input {
  padding: 7px 10px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 13px; min-width: 120px; background: #fff; outline: none;
}
.filter-group select:focus, .filter-group input:focus { border-color: var(--red); }

/* ── GRID ANNONCES ─────────────────────── */
.listings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}
.listing-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  cursor: pointer; transition: all .2s;
}
.listing-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.listing-card.featured { border: 2px solid var(--yellow); }
.card-photo {
  width: 100%; aspect-ratio: 3/4; object-fit: cover;
  background: #f0f0f0; display: block;
}
.card-photo-placeholder {
  width: 100%; aspect-ratio: 3/4; background: linear-gradient(135deg,#f0f0f0,#e0e0e0);
  display: flex; align-items: center; justify-content: center; font-size: 40px;
}
.card-body { padding: 10px 12px; }
.card-name { font-weight: 700; font-size: 14px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-edition { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }
.badge {
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 20px;
  background: #f0f0f0; color: #555;
}
.badge-NM  { background: #dcfce7; color: #166534; }
.badge-EX  { background: #dbeafe; color: #1e40af; }
.badge-GD  { background: #fef9c3; color: #854d0e; }
.badge-LP  { background: #ffe4e6; color: #9f1239; }
.badge-PO  { background: #f3f4f6; color: #374151; }
.badge-FR  { background: #dbeafe; color: #1e3a8a; }
.badge-EN  { background: #f0fdf4; color: #14532d; }
.badge-JP  { background: #fef3c7; color: #92400e; }
.card-price { font-size: 18px; font-weight: 800; color: var(--red); }
.card-price small { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.card-seller { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── DETAIL PAGE ─────────────────────── */
.listing-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: start; }
@media (max-width: 768px) { .listing-detail { grid-template-columns: 1fr; } }
.photos-grid { display: grid; grid-template-columns: 60px 1fr; gap: 8px; }
.photos-thumbs { display: flex; flex-direction: column; gap: 6px; }
.thumb { width: 60px; height: 80px; object-fit: cover; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.thumb.active { border-color: var(--red); }
.main-photo { width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.listing-info-box { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.listing-title { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.listing-price { font-size: 32px; font-weight: 800; color: var(--red); margin: 12px 0; }
.listing-price span { font-size: 14px; color: var(--text-muted); font-weight: 400; }
.info-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.info-row:last-child { border: none; }
.info-label { color: var(--text-muted); }
.info-value { font-weight: 600; }
.seller-box { background: #f9f9f9; border-radius: 8px; padding: 14px; margin: 16px 0; display: flex; align-items: center; gap: 12px; }
.seller-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--red); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 18px; }
.stars { color: #f59e0b; font-size: 14px; }
.insurance-box { background: #fff7ed; border: 1.5px solid #fed7aa; border-radius: 8px; padding: 14px; margin: 12px 0; }
.insurance-box label { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }

/* ── FORMS ─────────────────────────── */
.form-box { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; max-width: 600px; }
.form-box h2 { margin-bottom: 20px; font-size: 20px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text-light); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none; transition: border .2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--red); }
.form-group textarea { resize: vertical; min-height: 100px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-error { background: #fee2e2; border: 1px solid #fca5a5; border-radius: 8px; padding: 10px 14px; color: #dc2626; font-size: 13px; margin-bottom: 14px; }
.form-success { background: #dcfce7; border: 1px solid #86efac; border-radius: 8px; padding: 10px 14px; color: #16a34a; font-size: 13px; margin-bottom: 14px; }

/* ── PHOTO UPLOAD ─────────────────────── */
.photo-upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 20px; text-align: center; cursor: pointer; transition: border .2s;
  background: #fafafa;
}
.photo-upload-zone:hover { border-color: var(--red); }
.photo-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.photo-preview-item { position: relative; }
.photo-preview-item img { width: 80px; height: 100px; object-fit: cover; border-radius: 6px; }
.photo-remove { position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; display: flex; align-items: center; justify-content: center; cursor: pointer; }

/* ── TABS ─────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab { padding: 10px 20px; font-size: 14px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; cursor: pointer; }
.tab.active { color: var(--red); border-bottom-color: var(--red); }

/* ── MODAL ─────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal { background: var(--white); border-radius: 14px; padding: 28px; max-width: 480px; width: 100%; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-bottom: 16px; font-size: 18px; }
.modal-close { float: right; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); margin-top: -4px; }

/* ── DASHBOARD ─────────────────────── */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-card .stat-num { font-size: 28px; font-weight: 800; color: var(--red); }
.stat-card .stat-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── TABLE ─────────────────────────── */
.table-wrap { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { background: #f9f9f9; padding: 11px 14px; text-align: left; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--border); }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:last-child td { border: none; }
tr:hover td { background: #fafafa; }

/* ── PAGINATION ─────────────────────── */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 24px; }
.pagination button { padding: 7px 13px; border: 1.5px solid var(--border); border-radius: 8px; background: #fff; font-size: 13px; cursor: pointer; }
.pagination button.active { background: var(--red); color: #fff; border-color: var(--red); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

/* ── EMPTY STATE ─────────────────────── */
.empty { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty h3 { font-size: 16px; margin-bottom: 6px; color: var(--text-light); }

/* ── TOAST ─────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1a1a1a; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px; max-width: 320px; animation: slideIn .3s ease; display: flex; align-items: center; gap: 10px; }
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
@keyframes slideIn { from { transform: translateX(100px); opacity:0; } to { transform: translateX(0); opacity:1; } }

/* ── RESPONSIVE ─────────────────────── */
@media (max-width: 600px) {
  .header-inner { flex-wrap: wrap; }
  .search-bar { order: 3; width: 100%; max-width: 100%; }
  .filters-bar { flex-direction: column; }
  .listings-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}

/* ── CHAT WIDGET ───────────────────── */

/* ── TCHAT GENERAL */
#pm-tchat-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 4000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
#pm-tchat-btn {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  border: none;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(59,76,202,0.4);
  position: relative;
  transition: transform .2s;
}
#pm-tchat-btn:hover { transform: scale(1.08); }
.pm-tchat-notif {
  position: absolute; top: -3px; right: -3px;
  background: var(--red); color: #fff;
  font-size: 10px; font-weight: 800;
  border-radius: 50%; width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
}
#pm-tchat-panel {
  width: 340px;
  height: 480px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#pm-tchat-header {
  background: var(--blue);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
#pm-tchat-header button {
  background: none; border: none; color: #fff;
  font-size: 20px; cursor: pointer; opacity: .8; padding: 2px 6px;
}
#pm-tchat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f7f8fc;
}
.pm-tchat-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 30px 16px;
  line-height: 1.6;
}
.pm-tchat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 90%;
}
.pm-tchat-msg-me {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.pm-tchat-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.pm-tchat-bubble-wrap { display: flex; flex-direction: column; gap: 2px; max-width: 100%; }
.pm-tchat-pseudo {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding-left: 4px;
}
.pm-tchat-pseudo a { color: inherit; text-decoration: none; }
.pm-tchat-pseudo a:hover { color: var(--blue); }
.pm-tchat-admin { color: var(--red) !important; }
.pm-tchat-bubble {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 4px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}
.pm-tchat-msg-me .pm-tchat-bubble {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  border-radius: 14px 14px 4px 14px;
}
.pm-tchat-time {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.pm-tchat-msg-me .pm-tchat-time { justify-content: flex-end; }
.pm-tchat-del {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 12px; padding: 0 2px;
  opacity: 0;
  transition: opacity .15s;
}
.pm-tchat-msg:hover .pm-tchat-del { opacity: 1; }
.pm-tchat-del:hover { color: var(--red); }
#pm-tchat-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: #fff;
  flex-shrink: 0;
}
#pm-tchat-footer input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  outline: none;
}
#pm-tchat-footer input:focus { border-color: var(--blue); }
#pm-tchat-footer button {
  background: var(--blue); color: #fff;
  border: none; border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  #pm-tchat-panel { width: calc(100vw - 32px); height: 420px; }
  #pm-tchat-wrap { right: 16px; bottom: 80px; }
}


@media (max-width: 600px) {
  #pm-chat-widget { right: 12px; bottom: 12px; }
  #pm-chat-panel { width: calc(100vw - 24px); height: calc(100vh - 120px); }
}
