/* ========== Reset & base ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: #1f2937;
  background: #f7f8fa;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: #2563eb; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }

/* ========== Login ========== */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px 36px;
  width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
}
.login-card h1 {
  font-size: 24px; margin-bottom: 8px; color: #1f2937;
}
.login-card .subtitle {
  color: #6b7280; margin-bottom: 28px; font-size: 13px;
}
.login-card .form-row { margin-bottom: 16px; }
.login-card label {
  display: block; margin-bottom: 6px; color: #4b5563; font-size: 13px;
}
.login-card input {
  width: 100%; padding: 10px 14px;
  border: 1px solid #d1d5db; border-radius: 8px;
  font-size: 14px; transition: all .2s;
}
.login-card input:focus {
  outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,.15);
}
.login-card button {
  width: 100%; padding: 12px; margin-top: 8px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 500;
  transition: all .2s;
}
.login-card button:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(102,126,234,.35); }
.login-card button:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.login-error { color: #ef4444; margin-top: 12px; font-size: 13px; text-align: center; }

/* ========== Main layout ========== */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: #1e293b; color: #e2e8f0;
  padding: 20px 12px; flex-shrink: 0;
  display: flex; flex-direction: column;
}
.sidebar .brand { padding: 8px 12px 20px; border-bottom: 1px solid #334155; margin-bottom: 16px; }
.sidebar .brand h2 { font-size: 16px; font-weight: 600; color: #f1f5f9; }
.sidebar .brand p { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 6px;
  color: #cbd5e1; margin-bottom: 4px;
  font-size: 13px; transition: all .15s;
}
.sidebar nav a:hover { background: #334155; color: #f8fafc; }
.sidebar nav a.active { background: #4f46e5; color: #fff; }
.sidebar nav a .icon { font-size: 16px; }
.sidebar .user-info {
  margin-top: auto; padding: 12px 14px; background: #0f172a; border-radius: 8px;
  font-size: 12px; color: #94a3b8;
}
.sidebar .user-info .name { color: #f1f5f9; font-weight: 500; margin-bottom: 4px; }
.sidebar .user-info button {
  width: 100%; margin-top: 8px; padding: 6px;
  background: #334155; color: #e2e8f0; border: none; border-radius: 6px; font-size: 12px;
}
.sidebar .user-info button:hover { background: #475569; }

.main {
  flex: 1; min-width: 0; padding: 24px 32px; overflow-x: hidden;
}
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 20px; font-weight: 600; }
.page-header .subtitle { color: #6b7280; font-size: 13px; margin-top: 2px; }

/* ========== Mode tabs ========== */
.mode-tabs {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px;
}
.mode-tab {
  padding: 10px 16px; border-radius: 8px;
  background: #fff; border: 1px solid #e5e7eb;
  font-size: 13px; color: #4b5563;
  cursor: pointer; transition: all .15s;
  display: flex; align-items: center; gap: 6px;
}
.mode-tab:hover { border-color: #4f46e5; color: #4f46e5; }
.mode-tab.active {
  background: #4f46e5; color: #fff; border-color: #4f46e5;
  box-shadow: 0 4px 12px rgba(79,70,229,.25);
}

/* ========== Card ========== */
.card {
  background: #fff; border-radius: 12px; padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; color: #1f2937; }

/* ========== Drop zone ========== */
.drop-zone {
  border: 2px dashed #cbd5e1; border-radius: 10px;
  padding: 24px; text-align: center;
  background: #fafbfc; cursor: pointer;
  transition: all .2s;
}
.drop-zone.drag-over {
  border-color: #4f46e5; background: #eef2ff;
}
.drop-zone .hint { color: #6b7280; font-size: 13px; }
.drop-zone .hint strong { color: #4f46e5; }
.drop-zone .sub-hint { color: #9ca3af; font-size: 12px; margin-top: 6px; }

.uploaded-list {
  display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px;
}
.uploaded-item {
  position: relative; width: 120px; height: 120px;
  border-radius: 8px; overflow: hidden;
  border: 1px solid #e5e7eb;
  background: #f3f4f6;
}
.uploaded-item img, .uploaded-item video {
  width: 100%; height: 100%; object-fit: cover;
}
.uploaded-item .badge {
  position: absolute; top: 4px; left: 4px;
  background: rgba(0,0,0,.6); color: #fff;
  padding: 2px 6px; border-radius: 4px; font-size: 11px;
}
.uploaded-item .remove-btn {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff;
  border: none; font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.uploaded-item .remove-btn:hover { background: #ef4444; }
.upload-progress {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 3px; background: rgba(0,0,0,.1);
}
.upload-progress-bar {
  height: 100%; background: #4f46e5; transition: width .2s;
}
.role-hint {
  color: #9ca3af; font-size: 11px; margin-top: 4px; text-align: center;
}

/* ========== Form ========== */
.form-row { margin-bottom: 14px; }
.form-row label {
  display: block; color: #4b5563; font-size: 13px; margin-bottom: 6px;
}
.form-row label .required { color: #ef4444; margin-left: 2px; }
.form-row textarea, .form-row input[type=text], .form-row input[type=number], .form-row select {
  width: 100%; padding: 10px 12px;
  border: 1px solid #d1d5db; border-radius: 8px;
  transition: all .15s;
}
.form-row textarea:focus, .form-row input:focus, .form-row select:focus {
  outline: none; border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}
.form-row textarea { resize: vertical; min-height: 72px; }
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px;
}
.form-grid .form-row { margin-bottom: 0; }
.form-inline {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.check-inline {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 8px; background: #f3f4f6;
  cursor: pointer; font-size: 13px; color: #4b5563;
}
.check-inline input[type=checkbox] { cursor: pointer; }
.check-inline:hover { background: #e5e7eb; }

/* ========== Buttons ========== */
.btn {
  padding: 10px 20px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 500;
  cursor: pointer; transition: all .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(79,70,229,.3); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost {
  background: transparent; color: #4b5563; border: 1px solid #d1d5db;
}
.btn-ghost:hover { border-color: #4f46e5; color: #4f46e5; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-danger { background: #fef2f2; color: #ef4444; border: 1px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }

/* ========== Result & history ========== */
.result-card {
  border: 1px solid #e5e7eb; border-radius: 10px; padding: 12px;
  background: #fff; margin-bottom: 12px;
}
.result-row { display: flex; gap: 14px; align-items: flex-start; }
.result-media {
  width: 240px; flex-shrink: 0;
  background: #f3f4f6; border-radius: 8px; overflow: hidden;
  aspect-ratio: 16/9;
}
.result-media img, .result-media video {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.result-info { flex: 1; min-width: 0; }
.result-info .prompt {
  font-size: 13px; color: #1f2937; margin-bottom: 8px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.result-info .meta {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px;
}
.tag {
  padding: 2px 8px; border-radius: 4px; font-size: 11px;
  background: #f3f4f6; color: #4b5563;
}
.tag-client { background: #dbeafe; color: #1e40af; }
.tag-project { background: #d1fae5; color: #065f46; }
.tag-mode { background: #ede9fe; color: #5b21b6; }
.tag-status { background: #fef3c7; color: #92400e; }
.tag-status.done { background: #d1fae5; color: #065f46; }
.tag-status.failed { background: #fee2e2; color: #991b1b; }
.tag-status.running { background: #dbeafe; color: #1e40af; }
.result-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty {
  padding: 40px 20px; text-align: center; color: #9ca3af;
}

/* ========== Toasts ========== */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 10px 16px; border-radius: 8px;
  color: #fff; background: #1f2937;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
  animation: slideIn .2s ease-out;
  font-size: 13px; max-width: 320px;
}
.toast.success { background: #059669; }
.toast.error { background: #dc2626; }
.toast.info { background: #2563eb; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ========== Stats ========== */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.stat-card {
  background: #fff; padding: 20px; border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.stat-card .label { font-size: 12px; color: #6b7280; margin-bottom: 6px; }
.stat-card .value { font-size: 24px; font-weight: 600; color: #1f2937; }
.stat-card .sub { font-size: 11px; color: #9ca3af; margin-top: 4px; }

/* ========== Modal ========== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000; padding: 20px;
}
.modal {
  background: #fff; border-radius: 12px; padding: 24px;
  max-width: 90%; max-height: 90vh; overflow: auto;
}
.modal-media { max-width: min(90vw, 1200px); max-height: 80vh; }
.modal-media img, .modal-media video { max-width: 100%; max-height: 80vh; display: block; border-radius: 8px; }
.modal-close { float: right; cursor: pointer; color: #6b7280; font-size: 22px; line-height: 1; }
.modal-close:hover { color: #ef4444; }

/* ========== Small ========== */
@media (max-width: 768px) {
  .sidebar { width: 60px; padding: 12px 6px; }
  .sidebar .brand h2, .sidebar .brand p, .sidebar nav a span:not(.icon), .sidebar .user-info { display: none; }
  .sidebar nav a { justify-content: center; padding: 10px 6px; }
  .main { padding: 16px; }
  .result-row { flex-direction: column; }
  .result-media { width: 100%; }
}

/* utility */
.text-muted { color: #6b7280; }
.text-sm { font-size: 12px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; }
.hidden { display: none !important; }
