/* ============================================================
   AAT Common CSS
   공통 스타일 — 모든 도구 페이지에서 공유
   ============================================================ */

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

/* --- Design Tokens --- */
:root {
  /* Brand */
  --aat-dark: #1a1a2e;
  --aat-dark-hover: #2d2d4e;
  --aat-blue: #4a6cf7;

  /* Surfaces — warm neutrals */
  --aat-bg: #f6f5f4;
  --aat-card: #ffffff;
  --aat-warm-light: #f0efee;

  /* Text — near-black, warm grays */
  --aat-text: rgba(0,0,0,0.8);
  --aat-text-secondary: #615d59;
  --aat-text-muted: #a39e98;
  --aat-text-placeholder: #a39e98;

  /* Border & Shadow — whisper style */
  --aat-border-color: rgba(0,0,0,0.1);
  --aat-border-light: rgba(0,0,0,0.05);
  --aat-border: 1px solid var(--aat-border-color);
  --aat-shadow-card: 0 1px 4px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
  --aat-shadow-deep: 0 4px 12px rgba(0,0,0,0.06), 0 12px 28px rgba(0,0,0,0.04);

  /* Semantic */
  --aat-success: #2e7d32;
  --aat-success-bg: #e8f5e9;
  --aat-warning: #e65100;
  --aat-warning-bg: #fff3e0;
  --aat-error: #c62828;
  --aat-error-bg: #ffebee;
  --aat-info: #1565c0;
  --aat-info-bg: #e3f2fd;

  /* Interactive */
  --aat-hover: #f0efee;
  --aat-active-bg: #f0f0ff;
}

/* --- Body --- */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--aat-bg);
  color: var(--aat-text);
  min-height: 100vh;
}

/* --- Typography --- */
a { color: inherit; text-decoration: none; }


/* ============================================================
   Header
   ============================================================ */
.header {
  background: var(--aat-dark);
  color: #fff;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header h1 {
  font-size: 20px;
  font-weight: 700;
}
.header h1 a {
  color: #fff;
  text-decoration: none;
}
.header h1 .sep {
  font-size: 13px;
  color: rgba(255,255,255,0.5);
  margin: 0 8px;
}
.header a {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 13px;
}

/* Header Right */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-right span {
  font-size: 12px;
  color: rgba(255,255,255,0.6);
}

/* Header Button (작동방식, 이력 조회 등) */
.header-btn {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.header-btn:hover {
  background: rgba(255,255,255,0.2);
}

/* Header Nav (탭 형태 네비게이션) */
.header-nav {
  display: flex;
  gap: 8px;
}
.header-nav button {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.header-nav button:hover {
  background: rgba(255,255,255,0.25);
}
.header-nav button.active {
  background: var(--aat-blue);
}

/* 관리자 전용 헤더 (product_competition_admin) */
.header-admin {
  background: #8b0000;
}
.header-admin .main-tab.active {
  background: #8b0000;
}
.header-admin .loading {
  border-top-color: #8b0000;
}
.header-admin .btn-primary {
  background: #8b0000;
}
.header-admin .btn-primary:hover {
  background: #a00000;
}


/* ============================================================
   Container
   ============================================================ */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
}


/* ============================================================
   Card
   ============================================================ */
.card {
  background: var(--aat-card);
  border-radius: 12px;
  box-shadow: var(--aat-shadow-card);
  padding: 24px;
  margin-bottom: 16px;
}
.card h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--aat-dark);
}
.card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--aat-dark);
}


/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--aat-dark);
  color: #fff;
}
.btn-primary:hover {
  background: var(--aat-dark-hover);
}
.btn-primary:disabled {
  background: #ccc;
  color: #999;
  cursor: not-allowed;
}
.btn-secondary {
  background: #e8e8e8;
  color: #333;
}
.btn-secondary:hover {
  background: #ddd;
}
.btn-danger {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ffcdd2;
}
.btn-danger:hover {
  background: #ffcdd2;
}
.btn-success {
  background: #2e7d32;
  color: #fff;
}
.btn-success:hover {
  background: #388e3c;
}
.btn-outline {
  background: #fff;
  color: #666;
  border: 1px solid #ddd;
}
.btn-outline:hover {
  background: #f5f5f5;
}
.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}
.btn-copy {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #c8e6c9;
  padding: 6px 12px;
  font-size: 12px;
}
.btn-copy:hover {
  background: #c8e6c9;
}
.btn-copy.copied {
  background: #2e7d32;
  color: #fff;
}


/* ============================================================
   Badge
   ============================================================ */
.badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  line-height: 1.6;
  white-space: nowrap;
}
.badge-best {
  background: #fff3e0;
  color: #e65100;
}
.badge-regular {
  background: #e3f2fd;
  color: #1565c0;
}
.badge-active {
  background: #e8f5e9;
  color: #2e7d32;
}
.badge-soon {
  background: #f5f5f5;
  color: #999;
}
.badge-env {
  background: #e3f2fd;
  color: #1565c0;
  margin-left: 6px;
}
.badge-gpu {
  background: #fce4ec;
  color: #c62828;
  margin-left: 6px;
}
.badge-deal {
  background: #fff3e0;
  color: #e65100;
}
.badge-nbest {
  background: #ff6f00;
  color: #fff;
}


/* ============================================================
   Form Elements
   ============================================================ */
label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #555;
  margin-bottom: 3px;
  margin-top: 10px;
}
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
}
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--aat-blue);
}
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, monospace;
  resize: vertical;
  line-height: 1.5;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  margin: 0;
}
.form-group input,
.form-group select {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--aat-dark);
}

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  align-items: end;
  flex-wrap: wrap;
}
.row {
  display: flex;
  gap: 10px;
}
.row > div {
  flex: 1;
}


/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}
.modal-overlay.visible,
.modal-overlay.show {
  display: flex;
}
.modal {
  background: var(--aat-card);
  border-radius: 12px;
  max-width: 800px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
}
.modal h2 {
  font-size: 16px;
  margin-bottom: 16px;
}
.modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #888;
}
.modal-close:hover {
  color: #333;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Modal (작동방식 등 컨텐츠형 모달) */
.modal-content {
  background: #fff;
  max-width: 800px;
  margin: 40px auto;
  border-radius: 12px;
  padding: 32px;
  position: relative;
}
.modal-content h2 {
  font-size: 20px;
  margin-bottom: 20px;
}
.modal-content h3 {
  font-size: 15px;
  color: var(--aat-dark);
  margin: 20px 0 10px;
}
.modal-content p,
.modal-content li {
  font-size: 13px;
  line-height: 1.7;
  color: #555;
}
.modal-content ul {
  padding-left: 20px;
}
.modal-content pre {
  background: #f5f5f5;
  padding: 14px;
  border-radius: 8px;
  font-size: 12px;
  overflow-x: auto;
  margin: 10px 0;
}


/* ============================================================
   Tabs
   ============================================================ */

/* 필 탭 (배경색 전환 방식) */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: #fff;
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.tab,
.main-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  transition: all 0.2s;
}
.tab.active,
.main-tab.active {
  background: var(--aat-dark);
  color: #fff;
}
.tab:hover:not(.active),
.main-tab:hover:not(.active) {
  background: #f0f0f0;
}
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* 서브 탭 */
.sub-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  background: #e8e8e8;
  border-radius: 8px;
  padding: 3px;
}
.sub-tab {
  padding: 8px 14px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  transition: all 0.2s;
}
.sub-tab.active {
  background: var(--aat-card);
  color: var(--aat-dark);
  box-shadow: var(--aat-shadow-card);
}
.sub-tab:hover:not(.active):not(:disabled) {
  background: rgba(255,255,255,0.5);
}
.sub-tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 모드 탭 (토글 방식) */
.mode-tabs {
  display: flex;
  gap: 0;
  margin-top: 8px;
}
.mode-tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #ddd;
  cursor: pointer;
  background: #f9f9f9;
  color: #888;
}
.mode-tab:first-child {
  border-radius: 6px 0 0 6px;
}
.mode-tab:last-child {
  border-radius: 0 6px 6px 0;
}
.mode-tab.active {
  background: var(--aat-blue);
  color: #fff;
  border-color: var(--aat-blue);
}
.mode-panel {
  display: none;
}
.mode-panel.active {
  display: block;
}
.mode-desc {
  font-size: 11px;
  color: #888;
  margin-top: 3px;
}


/* ============================================================
   Table
   ============================================================ */
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.result-table th {
  background: var(--aat-warm-light);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--aat-text-secondary);
  border-bottom: 2px solid #eee;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
.result-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.result-table tr:hover {
  background: #fafafa;
}


/* ============================================================
   Status Messages
   ============================================================ */
.error {
  background: #ffebee;
  color: #c62828;
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
}
.status-success {
  background: var(--aat-success-bg);
  color: var(--aat-success);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
}
.status-warn {
  background: var(--aat-warning-bg);
  color: var(--aat-warning);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
}
.status-info {
  background: var(--aat-info-bg);
  color: var(--aat-info);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
}
.status-error {
  background: var(--aat-error-bg);
  color: var(--aat-error);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
}
.warnings {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 12px;
}
.warnings h3 {
  font-size: 13px;
  color: #f57f17;
  margin-bottom: 6px;
}
.warnings ul {
  padding-left: 18px;
  font-size: 12px;
  color: #6d4c00;
  line-height: 1.7;
}


/* ============================================================
   Spinner
   ============================================================ */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.loading {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--aat-border-color);
  border-top-color: var(--aat-dark);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}


/* ============================================================
   History
   ============================================================ */
.history-item {
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 12px;
}
.history-item:hover {
  background: #f0f4ff;
}
.history-item:last-child {
  border-bottom: none;
}
.history-item .h-name {
  font-weight: 600;
  color: var(--aat-dark);
}
.history-item .h-meta {
  color: #888;
  font-size: 11px;
  margin-top: 2px;
}
.history-empty {
  color: #aaa;
  font-size: 13px;
  text-align: center;
  padding: 40px;
}


/* ============================================================
   Prompt Box
   ============================================================ */
.prompt-box {
  background: #fafafa;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  margin-top: 6px;
}
.prompt-box pre {
  padding: 12px;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, monospace;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
  line-height: 1.5;
}
.prompt-box .actions {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  border-top: 1px solid #e0e0e0;
  background: #f5f5f5;
  border-radius: 0 0 6px 6px;
}


/* ============================================================
   Stats
   ============================================================ */
.stats {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.stat {
  background: #f0f4ff;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--aat-blue);
  font-weight: 500;
}
.stat strong {
  font-size: 16px;
  display: block;
  color: var(--aat-dark);
}
.stat-grid {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.stat-box {
  padding: 16px 24px;
  background: #f8f8f8;
  border-radius: 8px;
  text-align: center;
  min-width: 100px;
}
.stat-num {
  font-size: 24px;
  font-weight: 700;
}
.stat-label {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
}


/* ============================================================
   Model Selection
   ============================================================ */
.model-radio {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-right: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.model-radio:hover {
  border-color: var(--aat-dark);
}
.model-radio.checked {
  border-color: var(--aat-dark);
  background: var(--aat-active-bg);
}
.model-radio input {
  cursor: pointer;
}
.provider-label {
  font-size: 12px;
  font-weight: 600;
  color: #888;
  margin-bottom: 6px;
}

/* --- 통합 모델 선택 UI --- */
.model-select-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.model-provider-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.model-provider-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 8px;
  font-weight: 600;
  white-space: nowrap;
}
.model-provider-badge.openai {
  background: #e8f5e9;
  color: #2e7d32;
}
.model-provider-badge.google {
  background: #e3f2fd;
  color: #1565c0;
}
.model-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid #ddd;
  border-radius: 20px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
  background: #fff;
  white-space: nowrap;
}
.model-item:hover {
  border-color: var(--aat-dark);
}
.model-item.active {
  border-color: var(--aat-dark);
  background: var(--aat-active-bg);
  font-weight: 600;
}
.model-item input {
  display: none;
}
.model-item .model-price {
  font-size: 10px;
  color: #999;
}
.model-item .model-tag {
  font-size: 9px;
  color: #fff;
  background: #1a73e8;
  padding: 1px 5px;
  border-radius: 6px;
  margin-left: 2px;
}
.model-no-key {
  font-size: 12px;
  color: #aaa;
  padding: 4px 0;
}
.model-no-key a {
  color: #4a6cf7;
  text-decoration: underline;
}
.model-select-all {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #888;
  cursor: pointer;
  padding: 4px 8px;
  border: 1px dashed #ccc;
  border-radius: 12px;
  background: transparent;
}
.model-select-all input {
  margin: 0;
  cursor: pointer;
}
.model-select-all:hover {
  border-color: #999;
}


/* ============================================================
   Filter Bar
   ============================================================ */
.filter-bar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 16px;
}


/* ============================================================
   Pagination
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
  font-size: 13px;
}
.pagination button {
  padding: 6px 14px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}
.pagination button:hover:not(:disabled) {
  background: #f0f0f0;
}
.pagination button:disabled {
  opacity: 0.4;
  cursor: default;
}
.pagination .page-info {
  color: #888;
}


/* ============================================================
   Tier Badge (scoring)
   ============================================================ */
.tier {
  display: inline-block;
  width: 28px;
  height: 28px;
  line-height: 28px;
  text-align: center;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
  border: 1px solid transparent;
}
.tier-S { background: #ffd54f; color: #e65100; border-color: #ffca28; font-weight: 900; }
.tier-A { background: #c8e6c9; color: #1b5e20; border-color: #a5d6a7; }
.tier-B { background: #bbdefb; color: #0d47a1; border-color: #90caf9; }
.tier-C { background: #ffe0b2; color: #e65100; border-color: #ffcc80; }
.tier-D { background: #f8bbd0; color: #880e4f; border-color: #f48fb1; }


/* ============================================================
   Ranking Badge
   ============================================================ */
.rank-badge {
  display: inline-block;
  width: 24px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
}
.rank-1 { background: #ffd700; color: #333; }
.rank-2 { background: #c0c0c0; color: #333; }
.rank-3 { background: #cd7f32; color: #fff; }
.rank-n { background: #f0f0f0; color: #888; }


/* ============================================================
   Price
   ============================================================ */
.price-discount { color: #c62828; font-weight: 600; }
.price-original { color: #aaa; font-size: 11px; text-decoration: line-through; }
.discount-badge { background: #c62828; color: #fff; font-size: 10px; padding: 1px 5px; border-radius: 3px; font-weight: 700; }


/* ============================================================
   Product Image (table)
   ============================================================ */
.product-img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  background: #f0f0f0;
}


/* ============================================================
   Trend
   ============================================================ */
.trend-up { color: #2e7d32; }
.trend-down { color: #c62828; }


/* ============================================================
   Scroll Area
   ============================================================ */
.scroll-area {
  max-height: 55vh;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 8px;
  resize: vertical;
  min-height: 120px;
}


/* ============================================================
   Utility
   ============================================================ */
.hidden {
  display: none !important;
}
.text-muted {
  color: #888;
  font-size: 11px;
}
.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--aat-blue);
  margin-top: 16px;
  margin-bottom: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--aat-border-light);
}
.page {
  display: none;
}
.page.active {
  display: block;
}
.result-section {
  display: none;
}
.result-section.visible {
  display: block;
}
.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}


/* ============================================================
   How-to Modal Steps
   ============================================================ */
.how-step {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.how-step-num {
  width: 28px;
  height: 28px;
  background: var(--aat-dark);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.how-step-text h4 {
  font-size: 14px;
  margin-bottom: 4px;
}
.how-step-text p {
  font-size: 13px;
  color: #666;
  line-height: 1.5;
}


/* ============================================================
   Message
   ============================================================ */
.msg {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  display: none;
}
.msg-success {
  background: var(--aat-success-bg);
  color: var(--aat-success);
}
.msg-error {
  background: var(--aat-error-bg);
  color: var(--aat-error);
}


/* ============================================================
   Responsive — Tablet (max-width: 1024px)
   ============================================================ */
@media (max-width: 1024px) {
  .container {
    padding: 20px 16px;
  }
  .stat-grid {
    gap: 12px;
  }
}


/* ============================================================
   Responsive — Mobile (max-width: 640px)
   ============================================================ */
@media (max-width: 640px) {
  /* Header */
  .header {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .header h1 {
    font-size: 17px;
  }
  .header-right {
    gap: 6px;
  }
  .header-btn {
    padding: 5px 10px;
    font-size: 11px;
  }
  .header-nav {
    flex-wrap: wrap;
  }

  /* Container */
  .container {
    padding: 16px 12px;
  }

  /* Card */
  .card {
    padding: 16px;
    border-radius: 10px;
  }

  /* Tabs */
  .tabs {
    flex-wrap: wrap;
  }
  .tab,
  .main-tab {
    padding: 8px 12px;
    font-size: 12px;
  }
  .sub-tabs {
    flex-wrap: wrap;
  }
  .sub-tab {
    padding: 6px 10px;
    font-size: 11px;
  }

  /* Table — horizontal scroll */
  .result-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Forms */
  .form-row {
    flex-direction: column;
    gap: 8px;
  }
  .row {
    flex-direction: column;
  }
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  /* Modal */
  .modal {
    width: 95%;
    padding: 16px;
  }
  .modal-content {
    padding: 20px;
    margin: 20px auto;
  }

  /* Stats */
  .stat-grid {
    flex-direction: column;
    gap: 8px;
  }
  .stat-box {
    min-width: auto;
  }
  .stats {
    flex-direction: column;
    gap: 6px;
  }

  /* Buttons */
  .btn {
    padding: 8px 16px;
    font-size: 12px;
  }

  /* Model Selection */
  .model-provider-group {
    flex-direction: column;
    align-items: flex-start;
  }
  .model-item {
    font-size: 11px;
    padding: 5px 10px;
  }

  /* Mode Tabs */
  .mode-tabs {
    flex-wrap: wrap;
  }
  .mode-tab {
    font-size: 11px;
  }
  .mode-tab:first-child {
    border-radius: 6px 6px 0 0;
  }
  .mode-tab:last-child {
    border-radius: 0 0 6px 6px;
  }

  /* Pagination */
  .pagination {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Scroll Area */
  .scroll-area {
    max-height: 40vh;
  }

  /* Prompt Box */
  .prompt-box pre {
    font-size: 11px;
    max-height: 300px;
  }
}
