/* =====================================================
   Buy Back Pros — Platform Styles
   Brand: Black #000000 | White #FFFFFF | Green #639E54
   Font: Barlow (Neue Haas Grotesk equivalent, Google Fonts)
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700;800&display=swap');

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

:root {
  --black:        #000000;
  --white:        #FFFFFF;
  --green:        #639E54;
  --green-dark:   #4a7a3d;
  --green-light:  #edf5ea;
  --green-mid:    #d0e8c9;
  --gray-50:      #f9f9f9;
  --gray-100:     #f2f2f2;
  --gray-200:     #e5e5e5;
  --gray-300:     #d0d0d0;
  --gray-400:     #a0a0a0;
  --gray-500:     #717171;
  --gray-600:     #4a4a4a;
  --gray-700:     #2e2e2e;
  --red:          #d94040;
  --red-light:    #fdf0f0;
  --amber:        #c97b1a;
  --amber-light:  #fdf6ec;
  --radius-sm:    4px;
  --radius:       8px;
  --radius-lg:    12px;
  --radius-xl:    16px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,0.08);
  --shadow:       0 2px 8px rgba(0,0,0,0.10);
  --shadow-lg:    0 4px 20px rgba(0,0,0,0.12);
  --sidebar-w:    240px;
  --topbar-h:     60px;
  --font:         'Barlow', sans-serif;
  --tracking-tight: -0.025em;
}

html { font-size: 16px; }
body { font-family: var(--font); background: var(--gray-50); color: var(--black); line-height: 1.6; }
a { color: inherit; text-decoration: none; }
button { font-family: var(--font); cursor: pointer; }
input, select, textarea { font-family: var(--font); }

/* ---- AUTH PAGES ---- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--black); }
.auth-card { background: var(--white); border-radius: var(--radius-xl); padding: 48px 40px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); }
.auth-logo { margin-bottom: 32px; }
.auth-logo .logo-mark { width: 44px; height: 44px; border-radius: var(--radius); background: var(--black); display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.auth-logo .logo-mark svg { width: 26px; height: 26px; }
.auth-logo h1 { font-size: 22px; font-weight: 800; letter-spacing: var(--tracking-tight); color: var(--black); }
.auth-logo p { font-size: 14px; color: var(--gray-500); margin-top: 2px; }
.auth-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 6px; letter-spacing: var(--tracking-tight); }
.auth-card .subtitle { font-size: 14px; color: var(--gray-500); margin-bottom: 28px; }

/* ---- LAYOUT ---- */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--black);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo .logo-icon {
  width: 34px; height: 34px;
  background: var(--green);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo .logo-icon svg { width: 20px; height: 20px; }
.sidebar-logo span { font-size: 15px; font-weight: 800; letter-spacing: var(--tracking-tight); }

.sidebar-nav { padding: 16px 12px; flex: 1; }
.nav-section-label { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; color: rgba(255,255,255,0.3); text-transform: uppercase; padding: 0 8px; margin: 16px 0 6px; }
.nav-section-label:first-child { margin-top: 0; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  font-size: 14px; font-weight: 500;
  color: rgba(255,255,255,0.65);
  margin-bottom: 2px;
  transition: all 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: var(--white); }
.nav-item.active { background: var(--green); color: var(--white); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.8; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  transition: background 0.15s;
}
.sidebar-user:hover { background: rgba(255,255,255,0.07); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--green);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--white);
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-info .name { font-size: 13px; font-weight: 600; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: 11px; color: rgba(255,255,255,0.4); }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 17px; font-weight: 700; letter-spacing: var(--tracking-tight); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.page-body { padding: 28px; flex: 1; }

/* ---- FORMS ---- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--gray-600); margin-bottom: 6px; }
.form-label .optional { font-weight: 400; text-transform: none; color: var(--gray-400); letter-spacing: 0; }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--black);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}
.form-control:hover { border-color: var(--gray-300); }
.form-control:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(99,158,84,0.12); }
textarea.form-control { resize: vertical; min-height: 90px; line-height: 1.5; }
.form-hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  border: 1.5px solid transparent;
  transition: all 0.15s;
  line-height: 1;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--black); color: var(--white); border-color: var(--black); }
.btn-primary:hover:not(:disabled) { background: var(--gray-700); border-color: var(--gray-700); }

.btn-green { background: var(--green); color: var(--white); border-color: var(--green); }
.btn-green:hover:not(:disabled) { background: var(--green-dark); border-color: var(--green-dark); }

.btn-outline { background: var(--white); color: var(--black); border-color: var(--gray-200); }
.btn-outline:hover:not(:disabled) { border-color: var(--black); background: var(--gray-50); }

.btn-ghost { background: transparent; color: var(--gray-600); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); color: var(--black); }

.btn-danger { background: var(--white); color: var(--red); border-color: var(--red); }
.btn-danger:hover:not(:disabled) { background: var(--red-light); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 13px 24px; font-size: 15px; }
.btn-full { width: 100%; }
.btn-icon { padding: 8px; }

/* ---- CARDS ---- */
.card { background: var(--white); border-radius: var(--radius-lg); border: 1px solid var(--gray-200); }
.card-header { padding: 18px 20px 0; }
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--gray-100); display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.card-title { font-size: 15px; font-weight: 700; letter-spacing: var(--tracking-tight); }
.card-subtitle { font-size: 13px; color: var(--gray-500); margin-top: 2px; }

/* ---- STAT CARDS ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--white); border: 1px solid var(--gray-200); border-radius: var(--radius-lg); padding: 20px; }
.stat-card .stat-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--gray-400); margin-bottom: 8px; }
.stat-card .stat-value { font-size: 28px; font-weight: 800; letter-spacing: var(--tracking-tight); color: var(--black); }
.stat-card .stat-sub { font-size: 12px; color: var(--gray-400); margin-top: 4px; }
.stat-card.green-accent { border-left: 3px solid var(--green); }

/* ---- CONDITION PILLS ---- */
.condition-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.cond-pill {
  padding: 7px 16px; border-radius: 30px;
  font-size: 13px; font-weight: 600;
  border: 1.5px solid var(--gray-200);
  background: var(--white); color: var(--gray-600);
  cursor: pointer; transition: all 0.12s;
}
.cond-pill:hover { border-color: var(--green); color: var(--green); }
.cond-pill.active { background: var(--black); border-color: var(--black); color: var(--white); }

/* ---- FLAW TAGS ---- */
.flaw-grid { display: flex; flex-wrap: wrap; gap: 7px; }
.flaw-tag {
  padding: 5px 12px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500;
  border: 1px solid var(--gray-200);
  background: var(--white); color: var(--gray-600);
  cursor: pointer; transition: all 0.12s;
}
.flaw-tag:hover { border-color: var(--red); color: var(--red); }
.flaw-tag.active { background: #fdf0f0; border-color: var(--red); color: var(--red); }

/* ---- TABS ---- */
.tabs { display: flex; border-bottom: 1px solid var(--gray-200); gap: 0; margin-bottom: 24px; }
.tab-btn {
  padding: 10px 18px; font-size: 14px; font-weight: 600;
  color: var(--gray-500); background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  cursor: pointer; transition: all 0.12s;
}
.tab-btn:hover { color: var(--black); }
.tab-btn.active { color: var(--black); border-bottom-color: var(--green); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- BADGES ---- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-green { background: var(--green-light); color: var(--green-dark); }
.badge-black { background: var(--black); color: var(--white); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-amber { background: var(--amber-light); color: var(--amber); }

/* ---- TABLE ---- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gray-400); padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
.data-table td { padding: 13px 16px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }

/* ---- IMAGE UPLOAD ---- */
.upload-zone {
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--gray-50);
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--green); background: var(--green-light); }
.upload-zone .upload-icon { width: 40px; height: 40px; color: var(--gray-300); margin: 0 auto 10px; }
.upload-zone p { font-size: 14px; color: var(--gray-500); }
.upload-zone strong { color: var(--green); }
.image-previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-top: 12px; }
.image-preview { position: relative; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--gray-200); }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview .remove-img { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,0.6); color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 12px; }

/* ---- OUTPUT SECTION ---- */
.output-section { margin-top: 24px; border: 1px solid var(--gray-200); border-radius: var(--radius-lg); overflow: hidden; }
.output-header { background: var(--black); padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; }
.output-header h3 { font-size: 14px; font-weight: 700; color: var(--white); letter-spacing: var(--tracking-tight); }

.listing-field { margin-bottom: 20px; }
.listing-field .lf-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--gray-400); margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between; }
.listing-field .lf-value { font-size: 14px; color: var(--black); line-height: 1.65; }
.listing-field .lf-value.title-text { font-size: 16px; font-weight: 700; letter-spacing: var(--tracking-tight); }
.char-counter { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 12px; }
.char-ok { background: var(--green-light); color: var(--green-dark); }
.char-warn { background: var(--amber-light); color: var(--amber); }

.specifics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.spec-item { background: var(--gray-50); border-radius: var(--radius); padding: 10px 12px; border: 1px solid var(--gray-100); }
.spec-key { font-size: 11px; color: var(--gray-400); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 2px; }
.spec-val { font-size: 13px; font-weight: 600; color: var(--black); }

.price-bar { display: grid; grid-template-columns: 1fr 1fr 1fr; background: var(--black); border-radius: var(--radius-lg); overflow: hidden; }
.price-col { padding: 18px 16px; text-align: center; }
.price-col + .price-col { border-left: 1px solid rgba(255,255,255,0.1); }
.price-col .pc-label { font-size: 11px; color: rgba(255,255,255,0.5); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.price-col .pc-val { font-size: 24px; font-weight: 800; color: var(--white); letter-spacing: var(--tracking-tight); }
.price-col.suggested .pc-val { color: var(--green); }
.price-col .pc-sub { font-size: 11px; color: rgba(255,255,255,0.35); margin-top: 3px; }

.compliance-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--gray-100); font-size: 14px; }
.compliance-item:last-child { border-bottom: none; }
.compliance-item svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.compliance-ok svg { color: var(--green); }
.compliance-warn svg { color: var(--amber); }

/* ---- KEYWORD TAGS ---- */
.keyword-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.keyword-tag { background: var(--green-light); color: var(--green-dark); padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }

/* ---- ALERTS ---- */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 14px; margin-bottom: 16px; display: flex; align-items: flex-start; gap: 10px; }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-error { background: var(--red-light); color: var(--red); border: 1px solid #f5c0c0; }
.alert-success { background: var(--green-light); color: var(--green-dark); border: 1px solid var(--green-mid); }
.alert-info { background: #f0f5ff; color: #2e5aab; border: 1px solid #c5d5f7; }

/* ---- LOADING ---- */
.loading-dots { display: inline-flex; gap: 4px; align-items: center; }
.loading-dots span { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: ldot 1.2s ease-in-out infinite; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ldot { 0%,80%,100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ---- MODAL ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal { background: var(--white); border-radius: var(--radius-xl); padding: 28px; width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; transform: translateY(8px); transition: transform 0.2s; }
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-title { font-size: 18px; font-weight: 700; letter-spacing: var(--tracking-tight); }

/* ---- EMPTY STATE ---- */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state svg { width: 48px; height: 48px; color: var(--gray-300); margin: 0 auto 16px; }
.empty-state h3 { font-size: 16px; font-weight: 700; color: var(--gray-600); margin-bottom: 6px; }
.empty-state p { font-size: 14px; color: var(--gray-400); margin-bottom: 20px; }

/* ---- TOAST ---- */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--black); color: var(--white); padding: 12px 18px; border-radius: var(--radius-lg); font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; animation: toast-in 0.25s ease; max-width: 320px; }
.toast.success .toast-icon { color: var(--green); }
.toast.error .toast-icon { color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---- SEARCH & FILTER BAR ---- */
.filter-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.search-input-wrap { position: relative; flex: 1; min-width: 200px; }
.search-input-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--gray-400); pointer-events: none; }
.search-input-wrap input { padding-left: 34px; }

/* ---- TEMPLATE CARD ---- */
.template-card { background: var(--white); border: 1.5px solid var(--gray-200); border-radius: var(--radius-lg); padding: 18px 20px; transition: border-color 0.15s; }
.template-card:hover { border-color: var(--gray-300); }
.template-card.default-template { border-color: var(--green); }
.template-card .tc-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 10px; }
.template-card .tc-name { font-size: 15px; font-weight: 700; letter-spacing: var(--tracking-tight); }
.template-card .tc-desc { font-size: 13px; color: var(--gray-500); margin-bottom: 12px; }
.template-card .tc-meta { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- MISC ---- */
.divider { border: none; border-top: 1px solid var(--gray-200); margin: 20px 0; }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 13px; }
.font-bold { font-weight: 700; }
.section-heading { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gray-400); margin: 24px 0 12px; }
.copy-btn-sm { background: none; border: 1px solid var(--gray-200); border-radius: var(--radius-sm); padding: 3px 9px; font-size: 12px; font-weight: 500; color: var(--gray-500); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; transition: all 0.12s; }
.copy-btn-sm:hover { border-color: var(--green); color: var(--green); }
.copy-btn-sm svg { width: 12px; height: 12px; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
}

/* ---- V2 ADDITIONS ---- */
kbd { font-family: var(--font-mono, monospace); font-size: 11px; background: var(--gray-100); border: 1px solid var(--gray-200); padding: 2px 6px; border-radius: 4px; }
.session-warning { display: none; }
#session-warning { display: none; }
.price-bar { display: grid; grid-template-columns: 1fr 1fr 1fr; background: var(--black); border-radius: var(--radius-lg); overflow: hidden; }
.price-col { padding: 18px 16px; text-align: center; }
.price-col + .price-col { border-left: 1px solid rgba(255,255,255,0.1); }
.price-col .pc-label { font-size: 11px; color: rgba(255,255,255,0.5); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.price-col .pc-val { font-size: 24px; font-weight: 800; color: var(--white); letter-spacing: var(--tracking-tight); }
.price-col.suggested .pc-val { color: var(--green); }

/* ---- V3 PATCH ---- */
.char-amber { background: var(--amber-light); color: var(--amber); }
.price-bar { display:grid;grid-template-columns:1fr 1fr 1fr;background:var(--black);border-radius:var(--radius-lg);overflow:hidden; }
.price-col { padding:16px;text-align:center; }
.price-col+.price-col { border-left:1px solid rgba(255,255,255,.1); }
.price-col .pc-label { font-size:11px;color:rgba(255,255,255,.5);font-weight:600;text-transform:uppercase;letter-spacing:.06em;margin-bottom:5px; }
.price-col .pc-val { font-size:22px;font-weight:800;color:var(--white);letter-spacing:var(--tracking-tight); }
.price-col.suggested .pc-val { color:var(--green); }
