/* ===== Reset & Base ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #eef1f6;
  --bg-hover: #e3e8f0;
  --border: #dce1ea;
  --border-light: #e8ecf2;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent: #4f6ef7;
  --accent-light: #7c8ff9;
  --accent-bg: #e8edff;
  --accent-glow: rgba(79, 110, 247, 0.15);
  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --purple: #8b5cf6;
  --purple-bg: #ede9fe;
  --pink: #ec4899;
  --pink-bg: #fce7f3;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.10);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ===== Header ===== */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 60px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.logo {
  font-size: 20px; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.header-right { display: flex; align-items: center; gap: 12px; }
.badge {
  background: var(--accent-bg); color: var(--accent);
  padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); box-shadow: 0 0 8px var(--success);
}

/* ===== Main Layout ===== */
.main-layout { display: flex; flex: 1; overflow: hidden; }

/* ===== Control Panel ===== */
.control-panel {
  width: 380px; min-width: 380px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto; padding: 20px;
}
.panel-section { display: flex; flex-direction: column; gap: 16px; }
.section-title {
  font-size: 13px; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px;
}

/* ===== Form Elements ===== */
.form-group { display: flex; flex-direction: column; gap: 8px; position: relative; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.hint { font-size: 11px; font-weight: 400; color: var(--text-muted); }

.textarea-wrapper {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; transition: border-color 0.2s;
}
.textarea-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-textarea {
  width: 100%; border: none; padding: 12px;
  background: var(--bg-secondary); color: var(--text-primary);
  font-size: 14px; line-height: 1.6; resize: vertical; min-height: 120px;
  font-family: inherit;
}
.form-textarea:focus { outline: none; }
.textarea-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; background: var(--bg-tertiary); border-top: 1px solid var(--border-light);
}
.char-count { font-size: 11px; color: var(--text-muted); }
.enhance-group { display: flex; align-items: center; gap: 8px; }
.enhance-duration { font-size: 11px; color: var(--success); font-weight: 600; }

/* ===== Buttons ===== */
.btn-small {
  padding: 5px 12px; border: none; border-radius: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.2s;
  font-family: inherit;
}
.btn-enhance { background: var(--purple-bg); color: var(--purple); }
.btn-enhance:hover { background: var(--purple); color: white; }
.btn-enhance:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-undo { background: var(--bg-hover); color: var(--text-secondary); }
.btn-undo:hover { background: var(--text-secondary); color: white; }

.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-toggle {
  padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-secondary); color: var(--text-secondary);
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.2s;
  font-family: inherit;
}
.btn-toggle:hover { border-color: var(--accent); color: var(--accent); }
.btn-toggle.active {
  background: var(--accent); color: white; border-color: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-generate {
  width: 100%; padding: 14px; border: none; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--purple));
  color: white; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: all 0.2s; font-family: inherit;
  box-shadow: 0 4px 12px var(--accent-glow);
}
.btn-generate:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--accent-glow); }
.btn-generate:active { transform: translateY(0); }
.btn-generate:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ===== Info Box ===== */
.info-box {
  background: var(--bg-tertiary); border-radius: var(--radius-sm); padding: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.info-row {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text-secondary);
}
.info-row span:last-child { font-weight: 600; color: var(--text-primary); }

/* ===== Result Panel ===== */
.result-panel { flex: 1; overflow-y: auto; padding: 20px; }
.result-section { margin-bottom: 24px; }
.result-area {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); min-height: 300px; padding: 16px;
  display: flex; align-items: center; justify-content: center;
}

/* ===== Empty State ===== */
.empty-state { text-align: center; color: var(--text-muted); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== Progress ===== */
.progress-container { width: 100%; max-width: 400px; text-align: center; }
.progress-info { display: flex; justify-content: space-between; margin-bottom: 8px; }
.progress-status { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.progress-percent { font-size: 14px; font-weight: 700; color: var(--accent); }
.progress-bar { height: 8px; background: var(--bg-tertiary); border-radius: 4px; overflow: hidden; }
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--purple));
  border-radius: 4px; transition: width 0.5s ease;
}
.progress-detail { margin-top: 8px; font-size: 12px; color: var(--text-muted); }

/* ===== Image Grid ===== */
.image-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px; width: 100%;
}
.image-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: all 0.2s;
  background: var(--bg-secondary);
}
.image-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.image-card img { width: 100%; display: block; }
.image-card-info { padding: 8px 12px; font-size: 11px; color: var(--text-muted); }

/* ===== History ===== */
.history-section { margin-top: 24px; }
.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-empty { text-align: center; color: var(--text-muted); padding: 20px; font-size: 13px; }
.history-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer; transition: all 0.2s;
}
.history-item:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.history-thumb { font-size: 20px; flex-shrink: 0; }
.history-info { flex: 1; min-width: 0; }
.history-prompt {
  font-size: 13px; color: var(--text-primary); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.history-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.history-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 12px; font-weight: 600; flex-shrink: 0;
}
.history-badge.success { background: var(--success-bg); color: var(--success); }
.history-badge.failed { background: var(--error-bg); color: var(--error); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  padding: 12px 24px; border-radius: var(--radius); font-size: 14px; font-weight: 600;
  background: var(--text-primary); color: white; box-shadow: var(--shadow-lg);
  opacity: 0; transition: all 0.3s; z-index: 1000; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--error); }
.toast.success { background: var(--success); }

/* ===== Image Modal ===== */
.image-modal {
  position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center;
}
.modal-content { max-width: 90%; max-height: 90%; border-radius: var(--radius); }
.modal-close {
  position: absolute; top: 20px; right: 30px; color: white; font-size: 36px;
  font-weight: bold; cursor: pointer; user-select: none;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  body { overflow: auto; height: auto; }
  #app { height: auto; min-height: 100vh; }
  .header { padding: 0 12px; height: 50px; }
  .logo { font-size: 16px; }
  .badge { font-size: 10px; padding: 3px 8px; }
  .main-layout { flex-direction: column; overflow: visible; }
  .control-panel {
    width: 100%; min-width: 100%; max-height: none;
    border-right: none; border-bottom: 1px solid var(--border);
    padding: 12px; overflow: visible;
  }
  .result-panel { overflow: visible; padding: 12px; }
  .result-area { min-height: 200px; padding: 12px; }
  .btn-group { flex-wrap: wrap; }
  .btn-toggle { font-size: 12px; padding: 6px 10px; }
  .btn-generate { font-size: 14px; padding: 12px; }
  .form-textarea { min-height: 80px; font-size: 13px; }
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
  .empty-icon { font-size: 40px; }
  .modal-close { top: 10px; right: 15px; font-size: 28px; }
  .toast { font-size: 13px; padding: 10px 18px; bottom: 16px; }
  .textarea-footer { flex-wrap: wrap; gap: 4px; }
  .info-box { padding: 8px; }
  .info-row { font-size: 11px; }
  .panel-section { gap: 12px; }
  .section-title { font-size: 12px; }
  .form-label { font-size: 12px; }
}

@media (max-width: 480px) {
  .header { padding: 0 8px; }
  .logo { font-size: 14px; }
  .control-panel { padding: 10px; }
  .result-panel { padding: 10px; }
  .btn-toggle { font-size: 10px; padding: 5px 6px; }
  .btn-group { gap: 4px; }
  .form-textarea { font-size: 12px; min-height: 70px; }
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
  .toast { font-size: 12px; padding: 8px 14px; }
  .modal-content { max-width: 95%; max-height: 95%; }
}
