:root {
  --bg: #0c1120;
  --surface: #131c2e;
  --surface-2: #1a2540;
  --surface-3: #243050;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.12);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --border: #1e293b;
  --border-light: #2d3a52;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Login Modal ─────────────────────────────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-logo .icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.5rem;
}

.login-logo h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.login-logo p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}

.field input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.93rem;
  padding: 0.6rem 0.85rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.field input::placeholder {
  color: var(--text-muted);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0.55rem 1.1rem;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  user-select: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-full { width: 100%; padding: 0.7rem; font-size: 0.95rem; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border-light);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.78rem; }

.btn-generate {
  flex-shrink: 0;
  padding: 0.65rem 1.4rem;
  font-size: 0.95rem;
  white-space: nowrap;
}

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-top: 0.85rem;
}
.alert-error { background: var(--error-bg); color: var(--error); border: 1px solid rgba(239,68,68,0.3); }

/* ── App layout ──────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.card h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.card .hint {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-bottom: 1.1rem;
}

/* ── Generate form ───────────────────────────────────────────────────────── */
.url-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.url-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.93rem;
  padding: 0.65rem 1rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-width: 0;
}

.url-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.url-input::placeholder { color: var(--text-muted); }

/* ── Active job progress ─────────────────────────────────────────────────── */
.job-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.job-title-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.job-url-line {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  word-break: break-all;
}

.log-panel {
  background: #050a14;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.7;
  max-height: 340px;
  overflow-y: auto;
  color: #94a3b8;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-line { display: block; }
.log-success { color: #22c55e; }
.log-ok      { color: #4ade80; }
.log-section { color: #60a5fa; font-weight: 600; }
.log-warn    { color: #fbbf24; }
.log-error   { color: #f87171; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
}

.badge-running  { background: rgba(59,130,246,0.15); color: #60a5fa; }
.badge-success  { background: var(--success-bg);     color: var(--success); }
.badge-error    { background: var(--error-bg);        color: var(--error); }
.badge-pending  { background: rgba(100,116,139,0.15); color: #94a3b8; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(59,130,246,0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result card ─────────────────────────────────────────────────────────── */
.result-card {
  border-color: rgba(34,197,94,0.35);
  background: linear-gradient(135deg, var(--surface) 60%, rgba(34,197,94,0.05));
}

.result-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.result-icon { font-size: 2rem; line-height: 1; }

.result-title {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text);
  direction: rtl;
  text-align: right;
}

.result-subtitle {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.result-links {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.result-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1.1rem;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.result-link:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  transform: translateX(3px);
}

.result-link-icon { font-size: 1.4rem; flex-shrink: 0; }

.result-link-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.result-link-url {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  word-break: break-all;
}

.result-link-arrow {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 1rem;
}

.result-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

/* ── Error card ──────────────────────────────────────────────────────────── */
.error-card {
  border-color: rgba(239,68,68,0.35);
}

.error-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.error-header h2 { font-size: 1rem; color: var(--error); margin: 0; }

.error-body {
  font-size: 0.83rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  word-break: break-word;
}

/* ── History ─────────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-header h2 { margin: 0; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 2rem 0;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  transition: border-color 0.15s;
}

.history-item:hover { border-color: var(--border-light); }
.history-item-running { border-color: rgba(59,130,246,0.4); }

.history-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.history-info { flex: 1; min-width: 0; }

.history-business {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 0.15rem;
  direction: rtl;
  text-align: right;
}

.history-url {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.history-error {
  font-size: 0.73rem;
  color: var(--error);
  margin-top: 0.3rem;
  word-break: break-word;
}

.history-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.history-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(59,130,246,0.1);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: 6px;
  padding: 0.25rem 0.65rem;
  transition: background 0.15s;
}

.history-link:hover { background: rgba(59,130,246,0.2); }

.history-link-btn {
  cursor: pointer;
  font-family: var(--font);
  text-decoration: none;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .url-row { flex-direction: column; }
  .btn-generate { width: 100%; }
  .result-header { flex-direction: column; gap: 0.5rem; }
}

/* ── Sites Database Table ────────────────────────────────────────────────── */
.sites-card { overflow: hidden; }

.sites-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 0.25rem;
}

.sites-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  min-width: 720px;
}

.sites-table thead tr {
  background: var(--surface-3);
  border-bottom: 2px solid var(--border-light);
}

.sites-table th {
  padding: 0.55rem 0.85rem;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}

.sites-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}

.sites-table tbody tr:last-child { border-bottom: none; }

.sites-table tbody tr:hover { background: var(--surface-2); }

.sites-table td {
  padding: 0.6rem 0.85rem;
  color: var(--text);
  vertical-align: middle;
}

.sites-td-name {
  font-weight: 600;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sites-td-mono {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.site-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(59,130,246,0.08);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: 5px;
  padding: 0.2rem 0.5rem;
  transition: background 0.15s;
  white-space: nowrap;
}
.site-link:hover { background: rgba(59,130,246,0.2); }

.badge-info {
  background: rgba(139,92,246,0.15);
  color: #a78bfa;
}

.badge-paid {
  background: rgba(245,158,11,0.15);
  color: #fbbf24;
}

.sites-error {
  font-size: 0.7rem;
  color: var(--error);
  font-family: var(--font-mono);
  display: block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}
