/* ═══════════════════════════════════════
   ComfyUI Mobile - 原生 APP 体验
   ═══════════════════════════════════════ */

/* ── Reset & Variables ─────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --card-hover: #222244;
  --card2: #16213e;
  --tab-bg: #12122a;
  --tab-border: #2a2a4a;
  --accent: #4361ee;
  --accent2: #7209b7;
  --accent-gradient: linear-gradient(135deg, #4361ee, #7209b7);
  --text: #e8e8f0;
  --text2: #8888aa;
  --text3: #555577;
  --border: #2a2a4a;
  --success: #06d6a0;
  --error: #ef476f;
  --warning: #ffd166;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: all 0.2s ease;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

/* ── Bottom Tab Bar ────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900;
  background: var(--tab-bg);
  border-top: 1px solid var(--tab-border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 0 4px;
  color: var(--text3);
  font-size: 0.65rem;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.tab-item:active {
  transform: scale(0.92);
}

.tab-item.active {
  color: var(--accent);
}

.tab-item .tab-icon {
  font-size: 1.4rem;
  margin-bottom: 1px;
  line-height: 1;
}

.tab-item .tab-label {
  font-size: 0.6rem;
  font-weight: 500;
  line-height: 1;
}

/* ── Page Container ────────────────── */
.page {
  padding: 12px 16px;
  padding-bottom: 80px;
  min-height: 100vh;
  animation: fadeIn 0.2s ease;
}

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

.page-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

/* ── Card ──────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

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

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

/* ── Workflow Grid ─────────────────── */
.wf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.wf-card-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.wf-card-item:active {
  transform: scale(0.96);
  background: var(--card-hover);
}

.wf-card-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.25);
}

.wf-card-img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: var(--card2);
  display: block;
}

.wf-card-img-placeholder {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--card2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--text3);
}

.wf-card-info {
  padding: 10px 12px;
}

.wf-card-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wf-card-meta {
  font-size: 0.65rem;
  color: var(--text3);
  margin-top: 2px;
}

/* ── Form Elements ─────────────────── */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-label .label-icon {
  font-size: 0.9rem;
}

input[type="text"],
input[type="number"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.15);
}

textarea { resize: none; min-height: 80px; }
select { cursor: pointer; }

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

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

/* ── Buttons ───────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 16px rgba(67, 97, 238, 0.3);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 24px rgba(67, 97, 238, 0.4);
}

.btn-success {
  background: linear-gradient(135deg, #06d6a0, #00b894);
  color: white;
}

.btn-danger {
  background: linear-gradient(135deg, #ef476f, #d63031);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1.5px solid var(--border);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.8rem;
  border-radius: 6px;
  width: auto;
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}

/* ── Progress Bar ──────────────────── */
.progress-container {
  margin: 16px 0;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text2);
  margin-top: 6px;
}

/* ── Result Image ──────────────────── */
.result-container {
  margin-top: 16px;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

.result-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
  cursor: pointer;
}

.result-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* ── History ───────────────────────── */
.history-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.history-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

.history-img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.history-img-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: var(--card2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text3);
  font-size: 0.7rem;
}

.history-img-placeholder .icon {
  font-size: 1.5rem;
}

.history-info {
  padding: 8px 10px;
}

.history-prompt {
  font-size: 0.7rem;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.history-meta {
  font-size: 0.6rem;
  color: var(--text3);
}

.history-actions-overlay {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.history-item:hover .history-actions-overlay,
.history-item:active .history-actions-overlay {
  opacity: 1;
}

.history-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: white;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-action-btn.delete {
  background: rgba(239, 71, 111, 0.8);
}

/* ── Pagination ────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
  font-size: 0.8rem;
  color: var(--text2);
}

.pagination button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Fullscreen Image Viewer ───────── */
.img-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.img-viewer-close {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.img-viewer-nav {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 20px;
  z-index: 1000;
}

.img-viewer-download {
  padding: 10px 24px;
  border-radius: 24px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Login Screen ──────────────────── */
.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: var(--bg);
}

.login-logo {
  font-size: 3rem;
  margin-bottom: 8px;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--text2);
  margin-bottom: 32px;
}

.login-form {
  width: 100%;
  max-width: 320px;
}

.login-form .form-group {
  margin-bottom: 16px;
}

.login-error {
  background: rgba(239, 71, 111, 0.12);
  color: var(--error);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
  text-align: center;
}

/* ── Settings ──────────────────────── */
.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text);
}

.settings-label .icon {
  font-size: 1.1rem;
}

.settings-value {
  font-size: 0.85rem;
  color: var(--text2);
}

.settings-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 20px 0 10px;
}

/* ── Loading / Empty States ────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text3);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

.spinner-sm {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text3);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 12px;
  display: block;
}

.empty-state .text {
  font-size: 0.9rem;
  color: var(--text2);
}

/* ── Prompt Input Area ─────────────── */
.prompt-section {
  margin-bottom: 16px;
}

.prompt-section .form-label {
  font-size: 0.85rem;
  font-weight: 600;
}

textarea.prompt-input {
  min-height: 80px;
  line-height: 1.4;
}

textarea.prompt-input.neg {
  min-height: 56px;
  opacity: 0.8;
}

/* ── Workflow Info Bar ─────────────── */
.wf-info-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(67, 97, 238, 0.08);
  border: 1px solid rgba(67, 97, 238, 0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.wf-info-bar .icon {
  font-size: 1.2rem;
}

.wf-info-bar .name {
  font-size: 0.9rem;
  font-weight: 600;
  flex: 1;
}

.wf-info-bar .change-btn {
  font-size: 0.75rem;
  color: var(--accent);
  cursor: pointer;
  border: none;
  background: none;
  padding: 4px 8px;
}

/* ── WebSocket Status Badge ────────── */
.ws-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.6rem;
  font-weight: 500;
}

.ws-badge.connected {
  background: rgba(6, 214, 160, 0.12);
  color: var(--success);
}

.ws-badge.disconnected {
  background: rgba(239, 71, 111, 0.12);
  color: var(--error);
}

/* ── Toast / Notification ──────────── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  z-index: 9999;
  animation: toastIn 0.3s ease;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.toast.info {
  background: rgba(67, 97, 238, 0.9);
  color: white;
}

.toast.error {
  background: rgba(239, 71, 111, 0.9);
  color: white;
}

.toast.success {
  background: rgba(6, 214, 160, 0.9);
  color: white;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Miscellaneous ─────────────────── */
.seed-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.seed-row input {
  flex: 1;
}

.seed-row .random-btn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text2);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.6rem;
  font-weight: 500;
}

.tag-success { background: rgba(6, 214, 160, 0.15); color: var(--success); }
.tag-error { background: rgba(239, 71, 111, 0.15); color: var(--error); }
.tag-pending { background: rgba(255, 209, 102, 0.15); color: var(--warning); }

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

/* ── Responsive ────────────────────── */
@media (min-width: 480px) {
  .wf-grid, .history-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (min-width: 768px) {
  .page {
    max-width: 600px;
    margin: 0 auto;
  }
}

/* ── Status Badge in History ───────── */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.6rem;
  font-weight: 500;
  margin-left: 4px;
}

.status-badge.done { background: rgba(6, 214, 160, 0.15); color: var(--success); }
.status-badge.running { background: rgba(67, 97, 238, 0.15); color: var(--accent); animation: pulse 1.5s ease infinite; }
.status-badge.error { background: rgba(239, 71, 111, 0.15); color: var(--error); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
