/* ════════════════════════════════════════
   Google AI 測試工具 — style.css
   ════════════════════════════════════════ */

:root {
  --blue:        #1a73e8;
  --blue-dark:   #1558b0;
  --blue-light:  #e8f0fe;
  --green:       #1e8e3e;
  --green-light: #e6f4ea;
  --red:         #d93025;
  --red-light:   #fce8e6;
  --gray-50:     #f8f9fa;
  --gray-100:    #f1f3f4;
  --gray-200:    #e8eaed;
  --gray-400:    #bdc1c6;
  --gray-600:    #80868b;
  --gray-800:    #3c4043;
  --gray-900:    #202124;
  --white:       #ffffff;
  --shadow-sm:   0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.06);
  --radius:      12px;
  --radius-sm:   8px;
}

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

body {
  font-family: 'Google Sans', 'Segoe UI', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100vh;
}

/* ── 頂部導覽列 ── */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gray-900);
}
.topbar-brand .logo {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, #4285f4, #34a853, #fbbc04, #ea4335);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 1rem; font-weight: 900;
}
.topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.18s;
}
.topbar-link:hover { background: #d2e3fc; }

/* ── 主體佈局 ── */
.layout {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── 卡片 ── */
.card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── 表單元素 ── */
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
  color: var(--gray-900);
  background: var(--gray-50);
  outline: none;
  font-family: inherit;
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
input[type="password"]:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.12);
  background: var(--white);
}
textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.7;
}
select { cursor: pointer; }

/* ── 輸入欄位 + 清除按鈕的包裝 ── */
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-wrap input[type="password"],
.input-wrap textarea {
  padding-right: 38px;
}
.input-clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 1rem;
  line-height: 1;
  padding: 4px;
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.input-clear-btn:hover {
  color: var(--red);
  background: var(--red-light);
}
/* textarea 的清除鈕靠右上 */
.textarea-wrap { position: relative; }
.textarea-wrap textarea { padding-right: 38px; }
.textarea-wrap .input-clear-btn {
  top: 10px;
  transform: none;
}

/* ── 設定網格 ── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 18px;
}
.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 6px;
  display: block;
}
.field-hint {
  font-size: 0.76rem;
  color: var(--gray-600);
  margin-top: 5px;
  line-height: 1.45;
}

/* 模型徽章 */
.model-badge {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.badge-gemma  { background: var(--green-light); color: var(--green); }
.badge-gemini { background: var(--blue-light);  color: var(--blue); }

/* Temperature slider */
input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
  cursor: pointer;
  margin-top: 8px;
  height: 4px;
}
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--gray-400);
  margin-top: 4px;
}

/* ── 圖片上傳 ── */
.upload-zone {
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--gray-50);
  position: relative;
  outline: none;
}
.upload-zone:hover,
.upload-zone.drag-over,
.upload-zone:focus {
  border-color: var(--blue);
  background: var(--blue-light);
}
/* 隱藏原生 file input，改用 JS 觸發 */
.upload-zone input[type="file"] {
  display: none;
}
.upload-icon { font-size: 2rem; margin-bottom: 6px; }
.upload-text { font-size: 0.84rem; color: var(--gray-600); line-height: 1.5; }
.upload-text strong { color: var(--blue); }
.upload-hint {
  font-size: 0.76rem;
  color: var(--gray-400);
  margin-top: 4px;
}

.preview-wrap {
  display: none;
  align-items: flex-start;
  gap: 14px;
  margin-top: 12px;
  padding: 12px;
  background: var(--gray-50);
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray-200);
}
#imagePreview {
  max-width: 200px;
  max-height: 160px;
  border-radius: 6px;
  object-fit: contain;
  border: 1px solid var(--gray-200);
  background: var(--white);
}
.img-meta { font-size: 0.8rem; color: var(--gray-600); line-height: 1.8; }
.img-meta strong { color: var(--gray-900); }

/* ── 按鈕 ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.18s, transform 0.1s, box-shadow 0.18s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--blue);
  color: var(--white);
  box-shadow: 0 2px 6px rgba(26,115,232,0.3);
}
.btn-primary:hover  { background: var(--blue-dark); box-shadow: 0 3px 10px rgba(26,115,232,0.35); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled {
  background: #a8c7fa;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-ghost {
  background: transparent;
  color: var(--gray-800);
  border: 1.5px solid var(--gray-200);
}
.btn-ghost:hover { background: var(--gray-100); border-color: var(--gray-400); }

.btn-danger-ghost {
  background: transparent;
  color: var(--red);
  border: 1.5px solid #f5c6c3;
  font-size: 0.78rem;
  padding: 5px 12px;
}
.btn-danger-ghost:hover { background: var(--red-light); }

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* ── 狀態標籤 ── */
.status-pill {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-loading { background: #e8f0fe; color: #1967d2; }
.status-success { background: var(--green-light); color: var(--green); }
.status-error   { background: var(--red-light); color: var(--red); }

/* ── 載入動畫（請求中視覺提示）── */
.loading-bar-wrap {
  display: none;
  width: 100%;
  height: 3px;
  background: var(--gray-200);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 12px;
}
.loading-bar-wrap.active { display: block; }
.loading-bar {
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, var(--blue-light), var(--blue), var(--blue-light));
  border-radius: 2px;
  animation: loadingSlide 1.4s ease-in-out infinite;
}
@keyframes loadingSlide {
  0%   { transform: translateX(-150%); }
  100% { transform: translateX(350%); }
}

/* 送出按鈕載入中的脈動效果 */
.btn-primary.loading {
  animation: btnPulse 1.2s ease-in-out infinite;
}
@keyframes btnPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.65; }
}

/* ── 錯誤提示 ── */
.error-box {
  display: none;
  background: var(--red-light);
  border: 1px solid #f5c6c3;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.84rem;
  color: var(--red);
  margin-top: 12px;
  white-space: pre-wrap;
  line-height: 1.55;
}

/* ── 輸出區 ── */
.output-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.output-toolbar .card-title { margin-bottom: 0; }

.output-box {
  background: var(--gray-50);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 18px;
  min-height: 160px;
  font-size: 0.93rem;
  line-height: 1.8;
  color: var(--gray-900);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Consolas', 'Courier New', monospace;
}
.output-box.placeholder {
  color: var(--gray-400);
  font-style: italic;
  font-family: inherit;
}

/* ── Markdown 渲染樣式 ── */
.rendered-box {
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  padding: 20px 22px;
  min-height: 160px;
  font-size: 0.93rem;
  line-height: 1.8;
  color: var(--gray-900);
  display: none;
}
.rendered-box h1,.rendered-box h2,.rendered-box h3,
.rendered-box h4,.rendered-box h5,.rendered-box h6 {
  margin: 1em 0 0.4em;
  color: var(--gray-900);
  font-weight: 700;
}
.rendered-box h1 {
  font-size: 1.4em;
  border-bottom: 2px solid var(--gray-200);
  padding-bottom: 6px;
}
.rendered-box h2 {
  font-size: 1.2em;
  border-bottom: 1px solid var(--gray-200);
  padding-bottom: 4px;
}
.rendered-box p  { margin: 0.6em 0; }
.rendered-box ul,.rendered-box ol { padding-left: 1.6em; margin: 0.5em 0; }
.rendered-box li { margin: 0.25em 0; }
.rendered-box code {
  background: var(--gray-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', monospace;
  font-size: 0.88em;
  color: #c7254e;
}
.rendered-box pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.8em 0;
}
.rendered-box pre code {
  background: none;
  color: inherit;
  padding: 0;
  font-size: 0.87em;
}
.rendered-box blockquote {
  border-left: 4px solid var(--blue);
  padding: 6px 14px;
  margin: 0.6em 0;
  background: var(--blue-light);
  border-radius: 0 6px 6px 0;
  color: var(--gray-800);
}
.rendered-box table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8em 0;
  font-size: 0.9em;
}
.rendered-box th {
  background: var(--gray-100);
  padding: 8px 12px;
  border: 1px solid var(--gray-200);
  font-weight: 700;
  text-align: left;
}
.rendered-box td {
  padding: 7px 12px;
  border: 1px solid var(--gray-200);
}
.rendered-box tr:nth-child(even) td { background: var(--gray-50); }
.rendered-box strong { font-weight: 700; }
.rendered-box em { font-style: italic; color: var(--gray-800); }
.rendered-box a { color: var(--blue); text-decoration: none; }
.rendered-box a:hover { text-decoration: underline; }
.rendered-box hr {
  border: none;
  border-top: 1px solid var(--gray-200);
  margin: 1em 0;
}

/* ── 思考框 ── */
details.thinking-box {
  background: #f0f7ff;
  border: 1px solid #c5d8f8;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 12px;
}
details.thinking-box summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--blue);
  user-select: none;
}
details.thinking-box pre {
  white-space: pre-wrap;
  margin-top: 10px;
  font-size: 0.83rem;
  color: #1e3a5f;
  font-family: inherit;
  line-height: 1.6;
}

/* ── Token 資訊 ── */
.token-info {
  font-size: 0.76rem;
  color: var(--gray-400);
  margin-top: 8px;
  text-align: right;
  display: flex;
  justify-content: flex-end;
  gap: 16px;
}
.token-chip {
  background: var(--gray-100);
  padding: 2px 8px;
  border-radius: 10px;
}

/* ── 複製成功 Toast ── */
.copy-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--gray-900);
  color: var(--white);
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.84rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 999;
}
.copy-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

hr.divider {
  border: none;
  border-top: 1px solid var(--gray-200);
  margin: 14px 0;
}

/* ── API Key 區塊 ── */
.apikey-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.apikey-row input[type="password"] {
  flex: 1;
}
.apikey-hint {
  font-size: 0.76rem;
  color: var(--gray-600);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.apikey-saved-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--green-light);
  color: var(--green);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
}

@media (max-width: 600px) {
  .topbar { padding: 0 16px; }
  .layout { padding: 16px 14px 32px; }
  .card   { padding: 16px; }
  .settings-grid { grid-template-columns: 1fr; }
}
