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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: #f0f2f5;
  color: #333;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container { max-width: 900px; margin: 0 auto; padding: 0 20px; }

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  color: #fff;
  padding: 28px 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}
.header-inner { text-align: center; }
.header-inner h1 { font-size: 26px; font-weight: 700; }
.subtitle { margin-top: 6px; font-size: 14px; color: #aab; }

/* ===== Cards ===== */
.card {
  background: #fff;
  border-radius: 10px;
  padding: 22px 28px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  margin-top: 18px;
}
.card h2 { font-size: 18px; margin-bottom: 12px; }
.card h3 { font-size: 16px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ===== Stage 1: Search ===== */
.search-row { display: flex; gap: 10px; }
.search-row input {
  flex: 1;
  padding: 11px 16px;
  font-size: 15px;
  border: 2px solid #d9d9d9;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
}
.search-row input:focus { border-color: #0f3460; box-shadow: 0 0 0 3px rgba(15,52,96,0.12); }
.search-row button {
  padding: 11px 26px;
  font-size: 15px;
  font-weight: 600;
  background: linear-gradient(135deg, #0f3460, #1a5276);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.search-row button:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(15,52,96,0.3); }
.search-hint { margin-top: 10px; font-size: 13px; color: #888; }
#mcuList { color: #0f3460; font-weight: 500; }

/* ===== Loading ===== */
#stageLoading { text-align: center; padding: 50px 20px; }
.spinner {
  width: 44px; height: 44px;
  border: 4px solid #e0e0e0;
  border-top-color: #0f3460;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 16px; color: #555; }
.loading-sub { font-size: 13px; color: #999; margin-top: 6px; }
.loading-bar {
  width: 260px; height: 5px;
  background: #e0e0e0;
  border-radius: 3px;
  margin: 16px auto 0;
  overflow: hidden;
}
.loading-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #0f3460, #4a90d9);
  animation: loadProgress 2s ease-in-out infinite;
}
@keyframes loadProgress {
  0% { width: 0%; margin-left: 0; }
  50% { width: 60%; margin-left: 0; }
  100% { width: 0%; margin-left: 100%; }
}

/* ===== Source Bar ===== */
.source-bar {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 0;
}
.source-database { background: #d0f0c0; color: #2d5a1e; }
.source-cache    { background: #cce5ff; color: #004085; }
.source-ai       { background: #e8d0ff; color: #5a2d8a; }
.source-fallback { background: #fff3cd; color: #856404; }

/* ===== Config Header ===== */
.config-header { margin-top: 10px; }
.clock-note { font-size: 14px; color: #666; margin-top: -8px; }

/* ===== Timer Table ===== */
.table-wrap { overflow-x: auto; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-wrap th, .table-wrap td {
  padding: 8px 12px;
  border: 1px solid #e0e0e0;
  text-align: left;
}
.table-wrap th { background: #f5f7fa; font-weight: 600; font-size: 13px; }
.table-wrap tr:hover { background: #f8f9ff; }
.timer-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
}
.timer-bits16 { background: #e3f2fd; color: #1565c0; }
.timer-bits32 { background: #fce4ec; color: #c62828; }
.timer-bits64 { background: #f3e5f5; color: #6a1b9a; }

/* ===== Rules ===== */
.rules-box {
  background: #1e1e2e;
  color: #c9d1d9;
  padding: 14px 16px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== Form ===== */
.form-fields { display: flex; flex-direction: column; gap: 14px; }
.form-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.form-row label {
  min-width: 130px;
  font-size: 14px;
  font-weight: 500;
  color: #444;
}
.form-row input, .form-row select {
  flex: 1;
  min-width: 180px;
  padding: 8px 12px;
  font-size: 14px;
  border: 2px solid #d9d9d9;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
}
.form-row input:focus, .form-row select:focus {
  border-color: #0f3460;
  box-shadow: 0 0 0 3px rgba(15,52,96,0.1);
}
.form-row .calc-result {
  font-size: 13px;
  color: #666;
  background: #f5f5f5;
  padding: 4px 10px;
  border-radius: 4px;
  white-space: nowrap;
}
.badge-form {
  font-size: 11px;
  font-weight: 400;
  background: #e8f5e9;
  color: #2e7d32;
  padding: 2px 10px;
  border-radius: 10px;
}

/* ===== Generate Button ===== */
.btn-generate {
  margin-top: 16px;
  padding: 12px 36px;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, #0f3460, #1a5276);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  width: 100%;
}
.btn-generate:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(15,52,96,0.3); }

/* ===== Code Output ===== */
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.code-actions { display: flex; gap: 8px; }
.btn-small {
  padding: 5px 14px;
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-small:hover { background: #f0f0f0; }
.code-output {
  background: #1e1e2e;
  color: #c9d1d9;
  padding: 16px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  max-height: 500px;
  overflow-y: auto;
  white-space: pre;
  tab-size: 4;
}
.params-summary {
  margin-top: 12px;
  padding: 10px 14px;
  background: #f5f7fa;
  border-radius: 6px;
  font-size: 13px;
  color: #555;
  line-height: 1.6;
}

/* ===== Error ===== */
#stageError { text-align: center; padding: 40px 20px; }
.error-box {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #fff2f0;
  border: 1px solid #ffccc7;
  border-radius: 8px;
  padding: 16px 24px;
  font-size: 15px;
  color: #a8071a;
}

/* ===== Copied toast ===== */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 999;
}
.toast.show { opacity: 1; }

/* ===== Footer ===== */
footer { margin-top: auto; text-align: center; padding: 20px 0; font-size: 13px; color: #999; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .search-row { flex-direction: column; }
  .form-row { flex-direction: column; align-items: stretch; }
  .form-row label { min-width: auto; }
  .card { padding: 16px; }
  header { padding: 20px 0; }
  .header-inner h1 { font-size: 20px; }
}
