/* ─────────────────────────────────────────────
   Reset & Base
   ───────────────────────────────────────────── */

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

:root {
  --primary:      #EE4D2D;
  --primary-dark: #C93A1E;
  --primary-light:#FF7337;
  --accent:       #FF9500;
  --bg:           #f5f5f5;
  --bg-card:      #ffffff;
  --text:         #222222;
  --text-sub:     #666666;
  --text-muted:   #999999;
  --border:       #e8e8e8;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.12);
  --transition:   0.18s ease;
}

html { font-size: 14px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─────────────────────────────────────────────
   Layout Shell
   ───────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ─────────────────────────────────────────────
   Header
   ───────────────────────────────────────────── */

.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(238,77,45,0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  font-size: 28px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11.5px;
  opacity: 0.88;
  margin-top: 2px;
}

.brand-sub a { color: #fff; font-weight: 500; }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.account-meta {
  display: flex;
  align-items: center;
  gap: 7px;
}

/* Status dot */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.5);
}
.status-active  { background: #2ecc71; border-color: #27ae60; }
.status-inactive{ background: #e74c3c; border-color: #c0392b; }
.status-unknown { background: #bdc3c7; border-color: #95a5a6; }

.select-account {
  font-size: 13px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.4);
  background: rgba(255,255,255,0.15);
  color: #fff;
  cursor: pointer;
  outline: none;
  max-width: 180px;
  backdrop-filter: blur(4px);
}
.select-account option { background: var(--primary-dark); color: #fff; }
.select-account:focus { border-color: rgba(255,255,255,0.7); }

.icon-btn {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  backdrop-filter: blur(4px);
}
.icon-btn:hover { background: rgba(255,255,255,0.3); }

/* ─────────────────────────────────────────────
   Cards
   ───────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  border: 1px solid var(--border);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.muted { color: var(--text-muted); font-weight: 400; }

/* ─────────────────────────────────────────────
   Settings Panel
   ───────────────────────────────────────────── */

.settings-panel {
  display: none;
  flex-direction: column;
  gap: 16px;
  margin: 16px 20px 0;
  border-top: 3px solid var(--primary);
  animation: slideDown 0.2s ease;
}

.settings-panel.open {
  display: flex;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full-width { grid-column: 1 / -1; }

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-input,
.form-textarea {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13px;
  color: var(--text);
  background: #fafafa;
  outline: none;
  resize: vertical;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

.form-input:focus,
.form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(238,77,45,0.1);
  background: #fff;
}

.cookie-textarea {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 11.5px;
  line-height: 1.6;
}

.help-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--border);
  border: none;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-sub);
  cursor: pointer;
  transition: background var(--transition);
}
.help-badge:hover { background: var(--primary); color: #fff; }

.help-box {
  background: #fffbf0;
  border: 1px solid #ffe58f;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.65;
  color: #595959;
}
.help-box ol { padding-left: 18px; margin: 6px 0; }
.help-box li { margin-bottom: 4px; }
.help-box code {
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
}
.help-box kbd {
  background: #e8e8e8;
  border: 1px solid #ccc;
  border-radius: 3px;
  padding: 0 4px;
  font-size: 11px;
}

.hidden { display: none !important; }

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.confirm-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff5f5;
  border: 1px solid #ffc9c9;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: #c0392b;
  flex-wrap: wrap;
}
.confirm-btns { display: flex; gap: 8px; margin-left: auto; }

/* ─────────────────────────────────────────────
   Main Layout
   ───────────────────────────────────────────── */

.app-main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 18px;
  padding: 18px 20px 24px;
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

.left-col, .right-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ─────────────────────────────────────────────
   Form Elements in Main
   ───────────────────────────────────────────── */

.form-textarea {
  width: 100%;
}

.output-area {
  background: #fafcff;
  color: #1a1a2e;
}

/* ─────────────────────────────────────────────
   SubID
   ───────────────────────────────────────────── */

.subid-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.subid-container {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.subid-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.subid-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 52px;
  flex-shrink: 0;
}

.subid-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  background: #fafafa;
  outline: none;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.subid-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(238,77,45,0.09);
  background: #fff;
}

.subid-remove {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid #e0e0e0;
  background: #f5f5f5;
  color: #999;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
  transition: all var(--transition);
  padding: 0;
}
.subid-remove:hover { background: #ffe5e5; border-color: var(--primary); color: var(--primary); }

/* ─────────────────────────────────────────────
   Action Card (Convert)
   ───────────────────────────────────────────── */

.action-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
}

.convert-btn {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 28px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.2px;
  box-shadow: 0 4px 12px rgba(238,77,45,0.35);
  transition: all var(--transition);
  font-family: inherit;
}
.convert-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(238,77,45,0.4);
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}
.convert-btn:active:not(:disabled) { transform: translateY(0); }
.convert-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}

.status-msg {
  font-size: 13px;
  line-height: 1.4;
  flex: 1;
  word-break: break-word;
}
.status-msg.error   { color: #e74c3c; }
.status-msg.success { color: #27ae60; }

/* ─────────────────────────────────────────────
   Buttons
   ───────────────────────────────────────────── */

.primary-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background var(--transition), box-shadow var(--transition);
}
.primary-btn:hover { background: var(--primary-dark); }
.primary-btn.small { padding: 6px 14px; font-size: 12.5px; }

.ghost-btn {
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-sub);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition);
}
.ghost-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(238,77,45,0.04);
}
.ghost-btn.small { padding: 5px 10px; font-size: 12px; }
.ghost-btn.danger { border-color: #e74c3c; color: #e74c3c; }
.ghost-btn.danger:hover { background: #fff5f5; }
.ghost-btn.sync-ext-btn { border-color: #2ecc71; color: #27ae60; }
.ghost-btn.sync-ext-btn:hover { background: #f0fff4; border-color: #27ae60; }

/* ─────────────────────────────────────────────
   Extension Status Indicator
   ───────────────────────────────────────────── */

.ext-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #27ae60;
  background: #f0fff4;
  border: 1px solid #2ecc71;
  border-radius: 20px;
  padding: 3px 10px;
  font-weight: 600;
}
.ext-status.hidden { display: none; }
.ext-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2ecc71;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1); }
}

/* ─────────────────────────────────────────────
   Product Info Cards
   ───────────────────────────────────────────── */

.product-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.product-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: box-shadow 0.15s, transform 0.15s;
}
.product-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateY(-2px);
}
.product-img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
  background: #f8f8f8;
}
.product-img-placeholder {
  width: 100%;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  background: #f8f8f8;
  color: #ccc;
}
.product-body {
  padding: 10px 12px 12px;
}
.product-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}
.product-shop {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.product-price {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}
.product-link {
  font-size: 11px;
  color: var(--link);
  word-break: break-all;
  text-decoration: none;
}
.product-link:hover { text-decoration: underline; }
.product-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 4px;
}
.product-rating, .product-sales {
  font-size: 11px;
  color: var(--muted);
}
.product-commission {
  font-size: 12px;
  color: #2e7d32;
  background: #e8f5e9;
  border-radius: 4px;
  padding: 3px 7px;
  margin-bottom: 6px;
  display: inline-block;
}
.badge-xtra {
  display: inline-block;
  background: #ff6d00;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 4px;
}

/* ─────────────────────────────────────────────
   History
   ───────────────────────────────────────────── */

.history-card {
  position: sticky;
  top: 70px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  margin-top: 4px;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb { background: #e0e0e0; border-radius: 2px; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 24px 0;
  font-size: 13px;
}

.history-item {
  background: #fafafa;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.history-item:hover {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 2px 8px rgba(238,77,45,0.1);
}

.history-item-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.history-time {
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
}

.history-badge {
  font-size: 10.5px;
  font-weight: 600;
  background: rgba(238,77,45,0.1);
  color: var(--primary);
  padding: 2px 7px;
  border-radius: 999px;
}

.history-del {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #ccc;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  transition: color var(--transition);
}
.history-del:hover { color: var(--primary); }

.history-preview {
  font-size: 11.5px;
  color: var(--text-sub);
  line-height: 1.55;
  word-break: break-all;
}

.history-label {
  font-weight: 600;
  color: var(--text-muted);
}

/* ─────────────────────────────────────────────
   Footer
   ───────────────────────────────────────────── */

.app-footer {
  text-align: center;
  padding: 14px 20px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}
.app-footer .sep { color: var(--border); }

/* ─────────────────────────────────────────────
   Responsive
   ───────────────────────────────────────────── */

@media (max-width: 840px) {
  .app-main {
    grid-template-columns: 1fr;
    padding: 14px 14px 20px;
  }
  .right-col { order: -1; }
  .history-card { position: static; }
  .history-list { max-height: 320px; }
  .settings-panel { margin: 12px 14px 0; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .app-header { padding: 12px 14px; flex-wrap: wrap; }
  .brand-title { font-size: 15px; }
  .brand-sub { font-size: 11px; }
  .action-card { flex-direction: column; align-items: stretch; }
  .convert-btn { width: 100%; }
  .select-account { max-width: 130px; }
}
