:root {
  --bg: #0a0a0f;
  --surface: #141422;
  --surface-elevated: #1b1b2e;
  --surface-hover: #222238;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-start: #8b5cf6;
  --accent-end: #ec4899;
  --accent-gradient: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --blue: #38bdf8;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --nav-height: 68px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

/* Prevent iOS Safari / WKWebView auto-zoom on focus */
input,
textarea,
select {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background-color: rgba(10, 10, 15, 0.72);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  width: 100%;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-start);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.22);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-dim);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

textarea {
  resize: vertical;
  min-height: 92px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  line-height: 1.4;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 6px;
  color: #e2e8f0;
}

/* Auth Overlay */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) 18px calc(20px + var(--safe-bottom));
  background:
    radial-gradient(circle at 20% 15%, rgba(139, 92, 246, 0.22), transparent 45%),
    radial-gradient(circle at 80% 85%, rgba(236, 72, 153, 0.18), transparent 45%),
    var(--bg);
}

.glass-card {
  background: rgba(20, 20, 34, 0.92);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  padding: 28px 22px;
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.auth-logo img {
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(139, 92, 246, 0.35);
}

.auth-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.02em;
}

.auth-subtitle {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 13px;
}

/* App Shell */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: var(--safe-top);
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  border-radius: 9px;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.bot-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.bot-pill:active {
  transform: scale(0.97);
}

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

.status-running .status-dot,
.badge-running .status-dot {
  background: var(--green);
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.8);
}

.status-starting .status-dot,
.badge-starting .status-dot {
  background: var(--amber);
}

.status-error .status-dot,
.badge-error .status-dot {
  background: var(--red);
}

/* Main Content */
.app-main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 14px calc(var(--nav-height) + var(--safe-bottom) + 22px);
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
  animation: fadeIn 0.16s ease;
}

.tab-panel.active {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
}

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

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 0;
}

.section-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.helper-banner {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.pill-muted {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Form Layout */
.stack-md {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.field-hint {
  font-size: 12px;
  color: var(--text-dim);
}

.input-action-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.input-action-row input {
  flex: 1;
  min-width: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 420px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* Toggle Switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  cursor: pointer;
}

.toggle-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.toggle-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 46px;
  height: 26px;
  min-width: 46px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.2s ease;
}

.switch:checked {
  background: var(--accent-gradient);
  border-color: transparent;
}

.switch:checked::after {
  transform: translateX(20px);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease, background-color 0.15s ease;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.28);
}

.btn-secondary {
  background: var(--surface-elevated);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-success {
  background: rgba(34, 197, 94, 0.18);
  border-color: rgba(34, 197, 94, 0.4);
  color: #86efac;
}

.btn-danger-outline {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 13px 16px;
  font-size: 15px;
}

.btn-sm {
  padding: 7px 11px;
  font-size: 13px;
}

.btn-icon {
  padding: 10px 12px;
  flex-shrink: 0;
}

.btn-icon-text {
  padding: 10px 13px;
  flex-shrink: 0;
}

.btn-group-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-group-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

@media (max-width: 390px) {
  .btn-group-3 {
    grid-template-columns: 1fr;
  }
}

/* Jobs List */
.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.job-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.job-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
}

.tag-done {
  color: #86efac;
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.35);
}

.tag-working {
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.35);
}

.tag-error {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
}

.tag-platform {
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.14);
  border-color: rgba(139, 92, 246, 0.3);
  text-transform: capitalize;
}

.job-audio {
  width: 100%;
  height: 40px;
  border-radius: 10px;
  filter: invert(0.92) hue-rotate(180deg);
}

.job-error {
  font-size: 12px;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 8px;
  padding: 8px 10px;
  word-break: break-word;
}

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

.job-actions .btn {
  flex: 1;
  min-width: 96px;
}

/* Bot Status Card */
.bot-status-card {
  background:
    radial-gradient(circle at top right, rgba(139, 92, 246, 0.16), transparent 55%),
    var(--surface);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.bot-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
}

.badge-running {
  color: #86efac;
  background: rgba(34, 197, 94, 0.16);
  border-color: rgba(34, 197, 94, 0.35);
}

.badge-starting {
  color: #fcd34d;
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.35);
}

.badge-error {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.35);
}

.bot-name {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.bot-username {
  font-size: 14px;
  color: #c4b5fd;
  margin-top: 2px;
}

.token-current {
  font-size: 12px;
  color: var(--text-muted);
}

.alert-error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 13px;
  word-break: break-word;
}

.test-result {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.test-result.ok {
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #86efac;
}

.test-result.fail {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

/* Cookies Grid */
.cookies-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.cookie-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.cookie-title {
  font-size: 16px;
  font-weight: 700;
}

.cookie-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.file-upload-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.file-input-hidden {
  display: none;
}

/* Logs */
.header-actions {
  display: flex;
  gap: 8px;
}

.logs-container {
  background: #07070c;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  max-height: 62vh;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.log-line {
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.025);
  word-break: break-word;
}

.log-ts {
  color: var(--text-dim);
  margin-right: 6px;
}

.log-lvl {
  font-weight: 700;
  margin-right: 6px;
}

.log-ERROR .log-lvl,
.log-CRITICAL .log-lvl {
  color: var(--red);
}

.log-ERROR,
.log-CRITICAL {
  background: rgba(239, 68, 68, 0.1);
}

.log-WARNING .log-lvl {
  color: var(--amber);
}

.log-WARNING {
  background: rgba(245, 158, 11, 0.08);
}

.log-INFO .log-lvl {
  color: var(--blue);
}

.log-DEBUG .log-lvl {
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--text-muted);
  font-size: 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(14, 14, 24, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(8px + var(--safe-bottom));
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 4px;
  border-radius: 12px;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.nav-item.active {
  color: #e879f9;
  background: rgba(139, 92, 246, 0.14);
}

/* Modal (In-App Update Popup) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(5, 5, 10, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(18px + var(--safe-top)) 16px calc(18px + var(--safe-bottom));
}

.modal-card {
  width: 100%;
  max-width: 440px;
  padding: 22px 20px;
}

.modal-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

#update-version-badge {
  background: var(--accent-gradient);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}

.modal-date {
  font-size: 12px;
  color: var(--text-muted);
}

.modal-title {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 700;
}

.update-list {
  margin: 0 0 18px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #e2e8f0;
  font-size: 14px;
}

/* Toast */
.toast-container {
  position: fixed;
  top: calc(14px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  width: calc(100% - 28px);
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: rgba(27, 27, 46, 0.96);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: toastIn 0.2s ease;
}

.toast-success {
  border-color: rgba(34, 197, 94, 0.45);
  color: #bbf7d0;
}

.toast-error {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
