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

:root {
  --bg: #0d0d10;
  --surface: #16161c;
  --surface2: #1e1e26;
  --border: #2c2c38;
  --text: #e2e2ec;
  --muted: #6a6a82;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 10px;
}

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

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

/* ── Layout ── */
.page-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.topbar-actions { display: flex; gap: 12px; align-items: center; }

.content { flex: 1; padding: 28px; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

/* ── Login ── */
.login-card {
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-card p {
  color: var(--muted);
  margin-bottom: 24px;
  font-size: 13px;
}

/* ── Form elements ── */
label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="password"],
input[type="url"],
select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

input:focus, select:focus {
  border-color: var(--accent);
}

select option { background: var(--surface2); }

.form-group { margin-bottom: 16px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; }

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

.btn-success {
  background: var(--success);
  color: #fff;
  font-size: 15px;
  padding: 11px 22px;
}
.btn-success:hover { opacity: .9; }

.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Upload page ── */
.upload-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  height: calc(100vh - 65px - 56px);
}

.client-rail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  padding: 12px 8px;
}

.rail-header {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 4px 8px 10px;
}

.client-target {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 7px;
  cursor: default;
  transition: background .12s;
  border: 2px solid transparent;
}

.client-target:hover { background: var(--surface2); }
.client-target.drag-over {
  background: rgba(99,102,241,.15);
  border-color: var(--accent);
}

.client-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.client-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.client-tag {
  font-size: 11px;
  color: var(--muted);
  margin-left: auto;
  flex-shrink: 0;
}

/* ── Drop zone ── */
.upload-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  background: var(--surface);
  flex-shrink: 0;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(99,102,241,.08);
}

.drop-zone-icon { font-size: 32px; margin-bottom: 10px; }

.drop-zone h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.drop-zone p { font-size: 13px; color: var(--muted); }

#file-input { display: none; }

/* ── Queue ── */
.queue {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.queue-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  color: var(--muted);
  font-size: 13px;
}

.queue-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  grid-template-columns: 52px 1fr auto auto auto;
  gap: 12px;
  align-items: center;
}

.queue-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 5px;
  background: var(--surface2);
  border: 1px solid var(--border);
}

.queue-name input {
  font-size: 13px;
  padding: 7px 10px;
}

.queue-client select,
.queue-type select {
  font-size: 13px;
  padding: 7px 10px;
  width: auto;
}

.queue-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px;
  transition: color .12s;
}
.queue-remove:hover { color: var(--error); }

/* ── Upload footer ── */
.upload-footer {
  padding: 14px 28px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}

.queue-count { font-size: 13px; color: var(--muted); }

/* ── Links & Review ── */
.campaign-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.campaign-block-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.campaign-block-title { font-size: 15px; font-weight: 600; }
.campaign-block-meta { font-size: 12px; color: var(--muted); }

.section-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 14px;
  align-items: start;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.section-thumb {
  width: 90px;
  border-radius: 5px;
  border: 1px solid var(--border);
}

.section-info { display: flex; flex-direction: column; gap: 8px; }
.section-label { font-size: 12px; color: var(--muted); }

/* ── Results ── */
.result-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.result-icon { font-size: 22px; flex-shrink: 0; }

.result-info { flex: 1; }
.result-name { font-size: 15px; font-weight: 600; }
.result-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.result-error {
  border-color: var(--error);
}

.result-error .result-icon { color: var(--error); }

/* ── Error alert ── */
.alert-error {
  background: rgba(239,68,68,.1);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: 7px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Client grid ── */
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 4px;
}

.client-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  text-align: left;
  cursor: pointer;
  transition: all .15s;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.client-card:hover {
  border-color: var(--accent);
  background: rgba(99,102,241,.07);
}

.client-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.client-card-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(99,102,241,.12);
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: .04em;
}

/* ── Topbar client label ── */
.topbar-client {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Upload page (simplified) ── */
.queue-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 52px 1fr 1fr auto;
  gap: 12px;
  align-items: center;
}

.queue-link input { font-size: 13px; padding: 7px 10px; }

/* ── Same-link suggestion ── */
.same-link-suggestion {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.same-link-suggestion button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
}

.same-link-suggestion button:hover { opacity: .85; }

/* ── Recent link chips ── */
.link-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

.link-chip:hover { border-color: var(--accent); color: var(--text); }

/* ── Progress cards ── */
.progress-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 12px;
  transition: border-color .2s;
}

.progress-card.card-done    { border-color: var(--success); }
.progress-card.card-error   { border-color: var(--error); }
.progress-card.card-needs-links { border-color: #f59e0b; }

.error-debug {
  font-family: monospace;
  font-size: 11px;
  color: #f87171;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-break: break-all;
  cursor: pointer;
  user-select: all;
  width: 100%;
  box-sizing: border-box;
}
.error-debug:hover { background: rgba(239,68,68,0.14); }
.error-debug.copied::after { content: ' ✓ Copied'; color: #4ade80; }

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

.progress-card-name { font-size: 15px; font-weight: 600; }

.progress-card-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: .03em;
}

.progress-card-badge.queued      { background: var(--surface2); color: var(--muted); }
.progress-card-badge.active      { background: rgba(99,102,241,.15); color: var(--accent); }
.progress-card-badge.done        { background: rgba(34,197,94,.15); color: var(--success); }
.progress-card-badge.error       { background: rgba(239,68,68,.15); color: var(--error); }
.progress-card-badge.needs-links { background: rgba(245,158,11,.15); color: #f59e0b; }

.progress-bar-wrap { margin-bottom: 10px; }

.progress-bar-track {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .3s ease;
}

.progress-card-msg {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.progress-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Links form (inline in progress card) ── */
.links-form {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.links-form-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

.links-section { margin-bottom: 16px; }

.links-section-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 8px;
}

.links-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.links-cell {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 160px;
}

.links-thumb {
  width: 100%;
  max-width: 200px;
  border-radius: 5px;
  border: 1px solid var(--border);
}

.links-input { font-size: 13px; padding: 7px 10px; }

/* ── History table ── */
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 4px;
}

.history-table th {
  text-align: left;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 0 12px 10px 0;
  border-bottom: 1px solid var(--border);
}

.history-table td {
  padding: 12px 12px 12px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.history-table tr:last-child td { border-bottom: none; }

/* ── Misc ── */
.text-muted { color: var(--muted); }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

.page-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.page-sub { font-size: 13px; color: var(--muted); margin-bottom: 24px; }
