:root {
  --bg: #0a0a0f;
  --surface: #13131a;
  --surface-2: #1c1c26;
  --surface-3: #252532;
  --border: #2a2a3a;
  --border-strong: #3a3a4d;
  --text: #f1f1f7;
  --text-2: #a1a1b0;
  --text-3: #71718a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow: 0 8px 30px rgba(0,0,0,0.35);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.45);
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --grad-2: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro SC", "SF Pro Text", "PingFang SC", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-container { display: flex; height: 100vh; }

/* ========== Top Header ========== */
.top-header {
  position: fixed;
  top: 0;
  left: 264px;
  right: 0;
  height: 64px;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 28px;
  z-index: 100;
}

.top-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-right: auto;
}

.top-header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}

.top-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ========== Sidebar ========== */
.sidebar {
  width: 264px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 0 16px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px 20px;
}

.brand-logo {
  width: 42px; height: 42px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
  flex-shrink: 0;
}
.brand-logo svg { width: 42px; height: 42px; }

.brand-name-row { display: flex; align-items: center; gap: 8px; }
.brand-name { font-size: 17px; font-weight: 700; color: var(--text); letter-spacing: -0.2px; }
.brand-badge {
  font-size: 9.5px; font-weight: 600;
  color: var(--accent-hover);
  background: var(--accent-soft);
  padding: 2px 6px;
  border-radius: 999px;
  letter-spacing: 0.2px;
}
.brand-tag { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }

.lang-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 12px 7px 10px;
  font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: transform .15s, background .18s, border-color .18s;
}
.lang-toggle:hover { background: var(--surface-3); border-color: var(--border-strong); transform: translateY(-1px); }
.lang-toggle:active { transform: scale(0.97); }
.lang-globe { font-size: 14px; line-height: 1; }
.lang-code { letter-spacing: 0.5px; min-width: 22px; text-align: center; }

.nav-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 8px 22px 6px;
}

.tab-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 12px;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-2);
  padding: 11px 12px;
  text-align: left;
  cursor: pointer;
  font-size: 14.5px;
  font-family: inherit;
  border-radius: var(--radius-sm);
  transition: background 0.18s, color 0.18s;
  display: flex;
  align-items: center;
  gap: 11px;
}

.tab-btn:hover { background: var(--surface-2); color: var(--text); }

.tab-btn.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-weight: 500;
}

.tab-icon { width: 20px; height: 20px; display: inline-flex; }
.tab-icon svg { width: 20px; height: 20px; }

/* ========== Main Content ========== */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 92px 48px 60px;
}

.tab-panel { display: none; max-width: 760px; margin: 0 auto; animation: fadeUp 0.35s ease; }
.tab-panel.active { display: block; }

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

.panel-head { margin-bottom: 22px; }
.panel-head h2 { font-size: 28px; font-weight: 600; color: var(--text); letter-spacing: -0.4px; }
.subtitle { color: var(--text-2); font-size: 15px; margin-top: 6px; }

/* ========== Card ========== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

/* ========== Example Prompts ========== */
.example-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 18px;
}

.example-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.18s;
  line-height: 1.4;
}
.example-chip:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* ========== Form Elements ========== */
.form-group { margin-bottom: 18px; }
.form-group:last-child { margin-bottom: 0; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 8px;
}

textarea, input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  resize: vertical;
  transition: border-color 0.18s, box-shadow 0.18s;
}

textarea:focus, input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
  background: var(--surface-3);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2371718a' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 34px;
  cursor: pointer;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 0; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row .form-group { margin-bottom: 0; }
.card > .form-group + .form-row { margin-top: 18px; }
.card > .form-row + .advanced-section,
.card > .form-row + button { margin-top: 20px; }

.rate-limit-hint {
  display: none;
  font-size: 12px;
  color: #fbbf24;
  margin-top: 7px;
  line-height: 1.4;
}
.rate-limit-hint.visible { display: block; }

select.warning {
  border-color: #f59e0b;
  background-color: rgba(245, 158, 11, 0.08);
}
select.warning:focus {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15);
}

option.option-warn { color: #fbbf24; }

/* ========== Prompt with Inline Optimize ========== */
.prompt-with-icon { position: relative; }
.prompt-with-icon textarea { padding-bottom: 44px; min-height: 90px; }

.inline-optimize-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--accent-hover);
  padding: 6px 12px;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s;
}
.inline-optimize-btn:hover { background: rgba(99, 102, 241, 0.22); }
.inline-optimize-btn:disabled { opacity: 0.6; cursor: default; }

/* ========== Upload Area ========== */
.upload-area {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
  position: relative;
  min-height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
}
.upload-area:hover { border-color: var(--accent); background: var(--accent-soft); }

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-3);
  font-size: 13.5px;
}
.upload-placeholder svg { width: 28px; height: 28px; }

.upload-preview {
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  object-fit: contain;
}

/* ========== Buttons ========== */
.btn-primary {
  width: 100%;
  background: var(--grad);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  padding: 13px 24px;
  font-size: 15.5px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s, transform 0.08s, box-shadow 0.18s;
  margin-top: 20px;
  box-shadow: 0 4px 18px rgba(99, 102, 241, 0.28);
}
.btn-primary:hover { background: linear-gradient(135deg, #818cf8 0%, #a78bfa 100%); box-shadow: 0 6px 24px rgba(99, 102, 241, 0.38); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { background: var(--border-strong); color: var(--text-3); cursor: not-allowed; box-shadow: none; }

.btn-download {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 22px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
}
.btn-download:hover { background: var(--surface-3); border-color: var(--border-strong); }

/* ========== Result Area ========== */
.result-area {
  margin-top: 22px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.result-placeholder {
  color: var(--text-3);
  font-size: 14px;
  padding: 40px 0;
}

.result-image, .result-video {
  max-width: 100%;
  max-height: 520px;
  border-radius: var(--radius-sm);
  object-fit: contain;
}
.result-video { background: #000; width: 100%; }

.result-info {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--text-2);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  text-align: left;
}

.result-actions { margin-top: 16px; }

/* ========== Spinner ========== */
.spinner {
  display: inline-block;
  width: 17px; height: 17px;
  border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 8px;
  vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Advanced Section ========== */
.advanced-section {
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.advanced-section summary {
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-2);
  padding: 12px 14px;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.advanced-section summary::-webkit-details-marker { display: none; }
.advanced-section summary::before {
  content: "›";
  font-size: 17px;
  transition: transform 0.2s;
  display: inline-block;
}
.advanced-section[open] summary::before { transform: rotate(90deg); }
.advanced-section summary:hover { color: var(--text); }

.advanced-controls {
  padding: 4px 14px 14px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  padding: 6px 0;
}
.checkbox-label input[type="checkbox"] {
  width: 17px; height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ========== Range Slider ========== */
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 34px;
}
.range-val {
  display: inline-block;
  min-width: 28px;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30,30,40,0.96);
  color: #fff;
  padding: 12px 22px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 9999;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  animation: toastIn 0.28s ease;
  border: 1px solid var(--border);
}
.toast.error { background: rgba(239, 68, 68, 0.96); }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ========== File protocol warning ========== */
.file-protocol-warning {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.file-protocol-card {
  background: var(--surface);
  max-width: 520px; width: 100%;
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.file-protocol-card h3 { font-size: 20px; margin-bottom: 14px; color: var(--danger); }
.file-protocol-card p { margin-bottom: 12px; line-height: 1.6; color: var(--text-2); }
.file-protocol-card ol { margin: 14px 0 0 20px; color: var(--text); }
.file-protocol-card li { margin-bottom: 8px; line-height: 1.5; }
.file-protocol-card code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--accent-hover);
}

/* ========== Sidebar Buy Card ========== */
.site-info-panel {
  margin-top: auto;
  padding: 18px 22px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.buy-card {
  margin: auto 16px 16px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border-radius: 16px;
  padding: 18px;
  color: #fff;
  box-shadow: 0 10px 30px rgba(99, 102, 241, 0.3);
}
.buy-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; opacity: 0.95; }
.buy-price { font-size: 36px; font-weight: 700; letter-spacing: -1px; line-height: 1; }
.buy-price small { font-size: 14px; font-weight: 500; opacity: 0.85; margin-left: 2px; }
.buy-desc { font-size: 13px; opacity: 0.9; margin-top: 12px; line-height: 1.5; }
.buy-contacts { display: flex; gap: 8px; flex-wrap: wrap; }
.buy-contact {
  flex: 1 1 auto;
  text-align: center;
  padding: 8px 10px;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.18s;
}
.buy-contact:hover { background: rgba(255,255,255,0.28); }

/* ========== API Key Panel ========== */
.api-key-panel {
  position: fixed;
  bottom: 0;
  left: 256px;
  right: 0;
  z-index: 1000;
  padding: 12px 24px;
  background: rgba(17, 17, 24, 0.98);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.api-key-card {
  max-width: 600px;
  margin: 0 auto;
}

.api-key-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.api-key-icon {
  font-size: 20px;
}

.api-key-title {
  flex: 1;
  color: var(--text-primary);
  font-weight: 600;
}

.api-key-toggle {
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.api-key-toggle:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.api-key-body {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.api-key-body .form-group {
  flex: 1;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.api-key-body input[type="password"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-primary);
  font-size: 13px;
}

.btn-sm {
  padding: 8px 20px;
  font-size: 13px;
  white-space: nowrap;
}

/* ========== Admin Login Button ========== */
.admin-login-area {
  padding: 16px;
  border-top: 1px solid var(--border);
}

.btn-admin-login {
  width: 100%;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-admin-login:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ========== Admin Modal ========== */
.admin-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.admin-modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 400px;
}

.admin-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.admin-modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-secondary);
  cursor: pointer;
}

/* ========== Admin Panel ========== */
.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.admin-tab {
  padding: 8px 16px;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.admin-tab:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.admin-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.admin-section {
  display: none;
}

.admin-section.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-item {
  text-align: center;
  padding: 20px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.stat-number {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.key-health-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 8px;
}

.key-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
}

.key-status-dot.invalid {
  background: var(--danger);
}

.key-status-dot.limited {
  background: #f59e0b;
}

.banned-ip-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
  margin-bottom: 8px;
}

.btn-danger {
  padding: 8px 16px;
  font-size: 13px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-danger:hover {
  opacity: 0.9;
}

/* ========== Responsive ========== */
@media (max-width: 720px) {
  .sidebar { width: 76px; }
  .brand-text, .nav-label, .tab-btn span:not(.tab-icon), .site-info-panel { display: none; }
  .tab-btn { justify-content: center; }
  .top-header { left: 76px; padding: 0 16px; }
  .main-content { padding: 80px 20px 40px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
