:root {
  --bg: #0f1220;
  --card: #1a1f36;
  --card-2: #232a49;
  --text: #eef1fb;
  --muted: #9aa3c4;
  --primary: #5b8cff;
  --primary-2: #3f6fe0;
  --success: #35c78a;
  --warn: #ffb020;
  --error: #ff5c6c;
  --border: #2c3560;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Vazirmatn", "Segoe UI", Tahoma, system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1b2350 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 18, 32, 0.6);
  backdrop-filter: blur(8px);
}
.brand { font-size: 18px; font-weight: 700; }
.user-box { display: flex; align-items: center; gap: 12px; }
.balance {
  background: var(--card-2);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
}
.username { color: var(--muted); font-size: 14px; }

/* Layout */
.container {
  width: 100%;
  max-width: 700px;
  margin: 0 auto;
  padding: 28px 16px 56px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* The cards live inside #app-view, so it needs its own column gap - the
   .container gap only spaces the top-level views (loading/login/app). */
#app-view {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.card {
  background: linear-gradient(155deg, #1d2340 0%, #171c30 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 26px 28px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .28), inset 0 1px 0 rgba(255, 255, 255, .04);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.card:hover {
  transform: translateY(-2px);
  border-color: #3a4680;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .36), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.card h1 { font-size: 24px; margin: 0 0 12px; }
.card h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -.2px;
}
/* Gradient accent bar before each section title (sits on the right in RTL). */
.card h2::before {
  content: "";
  flex: none;
  width: 4px;
  height: 20px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--primary), var(--success));
}

.row { display: flex; gap: 10px; margin-top: 16px; }
.row.wrap { flex-wrap: wrap; }

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .05s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, #5b8cff, #6c6cff);
  color: #fff;
  box-shadow: 0 4px 14px rgba(91, 140, 255, .35);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #4f7dfa, #5a5af0);
  box-shadow: 0 6px 18px rgba(91, 140, 255, .45);
}
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); }
.btn-outline { background: var(--card-2); color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); }

/* Dropzone */
.dropzone {
  display: block;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 34px 18px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--card-2); }
.dropzone-inner { text-align: center; }
.dz-icon { font-size: 40px; margin-bottom: 8px; }

/* Key-value table */
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 9px 4px; border-bottom: 1px solid var(--border); font-size: 15px; }
.kv td:first-child { color: var(--muted); width: 45%; }
.kv tr:last-child td { border-bottom: none; }

/* Progress */
.progress {
  height: 12px;
  background: var(--card-2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  transition: width .4s ease;
}

/* Messages */
.error { color: var(--error); margin-top: 12px; font-size: 14px; }
.warn {
  color: var(--warn);
  background: rgba(255, 176, 32, .1);
  border: 1px solid rgba(255, 176, 32, .3);
  padding: 10px 14px;
  border-radius: 10px;
  margin-top: 14px;
  font-size: 14px;
}

/* History */
.history { list-style: none; padding: 0; margin: 0; }
.history li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.history li:last-child { border-bottom: none; }
.history .h-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 8px; min-width: 0; }
.history .h-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.src-tag { flex: none; font-size: 11px; color: var(--muted); background: var(--card-2); padding: 2px 8px; border-radius: 999px; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; }
.badge.completed { background: rgba(53,199,138,.15); color: var(--success); }
.badge.processing { background: rgba(91,140,255,.15); color: var(--primary); }
.badge.failed { background: rgba(255,92,108,.15); color: var(--error); }
.badge.init { background: var(--card-2); color: var(--muted); }

/* History pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
}
.page-btn { padding: 6px 16px; font-size: 14px; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-label { font-size: 13px; color: var(--muted); min-width: 90px; text-align: center; }

/* Admin panel */
.admin-row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.admin-input {
  flex: 1;
  min-width: 160px;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}
.admin-input:focus { outline: none; border-color: var(--primary); }
.admin-info {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--card-2);
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.9;
}
.admin-result { margin-top: 12px; font-size: 14px; min-height: 1em; }

/* Login widget */
.tg-login { display: flex; justify-content: center; margin: 18px 0; min-height: 46px; }

/* Spinner */
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 10px auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  max-width: 90%;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 1000;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--error); color: #ffd0d5; }
.toast.success { border-color: var(--success); color: #bff0d8; }

.foot { text-align: center; padding: 20px; }

code {
  background: var(--card-2);
  padding: 1px 6px;
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  direction: ltr;
  display: inline-block;
}
