:root {
  --bg: #ffffff;
  --bg-alt: #f5f7fa;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #ef4444;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --success: #10b981;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-alt: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --warning-bg: #422006;
  --warning-text: #fbbf24;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  position: relative;
}

header h1 { font-size: 1.75rem; font-weight: 700; }
.subtitle { color: var(--text-muted); font-size: 0.95rem; }

.icon-btn {
  position: absolute;
  right: 0;
  top: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

/* Inputs */
.input-section { margin-bottom: 2rem; }

.input-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.input-header label { font-weight: 600; font-size: 0.95rem; }
.input-actions { display: flex; gap: 0.5rem; }

textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
  color: var(--text);
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.875rem;
  resize: vertical;
  transition: border-color 0.15s;
}

textarea:focus { outline: none; border-color: var(--primary); }

.ticker-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.options-row {
  display: flex;
  gap: 1.5rem;
  margin: 1rem 0;
  align-items: end;
}

.option label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 0.875rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-alt);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-secondary { background: var(--bg-alt); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-alt); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-lg { padding: 0.65rem 1.5rem; font-size: 1rem; margin-top: 0.75rem; }

/* Preview section */
.preview-section { margin-bottom: 2rem; }

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.preview-header h2 { font-size: 1.25rem; }
.preview-actions { display: flex; gap: 0.5rem; align-items: center; }

.badge {
  background: var(--primary);
  color: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
}

/* Errors panel */
.errors-panel {
  background: var(--warning-bg);
  color: var(--warning-text);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.errors-panel strong { display: block; margin-bottom: 0.25rem; }
.errors-panel ul { margin: 0; padding-left: 1.25rem; }

/* Table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th, td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--bg-alt);
  font-weight: 600;
  position: sticky;
  top: 0;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-alt); }

.col-check { width: 40px; text-align: center; }
.col-check input { cursor: pointer; }

td a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.8rem;
}

td a:hover { text-decoration: underline; }

/* Progress section */
.progress-section { margin-bottom: 2rem; }
.progress-section h2 { font-size: 1.25rem; margin-bottom: 0.75rem; }

.progress-bar-wrap {
  width: 100%;
  height: 8px;
  background: var(--bg-alt);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s;
}

.progress-text {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.progress-log {
  max-height: 250px;
  overflow-y: auto;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-alt);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.progress-log .log-line { padding: 0.15rem 0; }
.progress-log .log-warning { color: var(--danger); }
.progress-log .log-success { color: var(--success); }

.hidden { display: none !important; }

/* Responsive */
@media (max-width: 640px) {
  .container { padding: 1rem; }
  header h1 { font-size: 1.35rem; }
  .options-row { flex-direction: column; }
}
