:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a1d26;
  --muted: #5c6475;
  --border: #e2e6ef;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --sidebar: #0f172a;
  --sidebar-text: #e2e8f0;
  --success: #059669;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

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

.auth-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: linear-gradient(145deg, #eef2ff 0%, #f8fafc 45%, #f1f5f9 100%);
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 2.25rem;
  border: 1px solid var(--border);
}

.auth-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-card .sub {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

input[type="email"],
input[type="password"] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  margin-bottom: 1rem;
  background: #fafbfc;
}
input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--accent);
  background: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--bg);
  color: var(--text);
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: -0.5rem 0 1rem;
  min-height: 1.25rem;
}

.auth-footer {
  margin-top: 1.25rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

/* App shell */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.sidebar .logo {
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  padding: 0 0.5rem;
}
.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.sidebar nav a {
  color: #94a3b8;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-weight: 500;
  text-decoration: none;
}
.sidebar nav a:hover,
.sidebar nav a.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.credit-pill {
  background: #ecfdf5;
  color: var(--success);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
}

.content {
  padding: 1.5rem 1.75rem 2.5rem;
  flex: 1;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.panel h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th,
td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tr:last-child td {
  border-bottom: none;
}
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-pending {
  background: #fef3c7;
  color: #b45309;
}
.badge-running {
  background: #dbeafe;
  color: #1d4ed8;
}
.badge-done {
  background: #d1fae5;
  color: #047857;
}
.badge-error {
  background: #fee2e2;
  color: #b91c1c;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0.75rem 0 0.35rem;
}

.textarea,
.select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  padding: 0.65rem 0.75rem;
  background: #fafbfc;
}
.textarea:focus,
.select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.25);
  border-color: var(--accent);
  background: #fff;
}

.subheading {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.messages-panel {
  margin-top: 1.25rem;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: 320px;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.msg {
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  font-size: 0.9rem;
  white-space: pre-wrap;
  border: 1px solid var(--border);
}
.msg-user {
  background: #eff6ff;
  align-self: flex-end;
  max-width: 92%;
}
.msg-assistant {
  background: #f8fafc;
  align-self: flex-start;
  max-width: 100%;
}
.msg-meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.estimate-card {
  margin: 0.75rem 0;
  padding: 0.85rem 1rem;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: #f8fafc;
}
.estimate-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.9rem;
  padding: 0.2rem 0;
  color: var(--muted);
}
.estimate-row strong {
  color: var(--text);
}

tbody tr.job-row {
  cursor: pointer;
}
tbody tr.job-row:hover {
  background: #f8fafc;
}
tbody tr.job-row.row-selected {
  background: #eff6ff;
}

.monitor-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.demo-link {
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-all;
}

.log-pre {
  margin: 0;
  padding: 0.85rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  font-size: 0.78rem;
  line-height: 1.45;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
}

.panel-monitor {
  border-left: 3px solid var(--accent);
}

.monitor-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.status-line {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.status-label {
  letter-spacing: -0.02em;
}

.monitor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.monitor-actions[hidden] {
  display: none !important;
}

.btn-inline {
  width: auto;
  padding: 0.5rem 1rem;
  font-size: 0.88rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.monitor-hint {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.25rem;
}

.preview-embed-wrap {
  margin: 0 0 1.25rem;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: var(--shadow);
}

.preview-iframe {
  display: block;
  width: 100%;
  min-height: 280px;
  height: 42vh;
  max-height: 520px;
  border: none;
}

.retry-hint {
  margin-top: 1rem;
  font-size: 0.8rem;
  opacity: 0.85;
}

.panel-billing {
  border-left: 3px solid #059669;
}

.billing-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.billing-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}

.billing-card-title {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.billing-card-value {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.billing-card-meta {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.billing-actions {
  margin-bottom: 1rem;
}

.billing-plans {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
}

.plan-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.plan-card h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.plan-card .price {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.plan-card .credits-line {
  font-size: 0.88rem;
  color: var(--muted);
}

.plan-card .btn {
  margin-top: auto;
  width: 100%;
}

tbody tr.job-row td:first-child {
  white-space: nowrap;
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .sidebar nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
}
