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

:root {
  --bg: #f0f4f8;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 14px rgba(0,0,0,.1);
  --radius: 12px;
  --radius-sm: 8px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ============ HEADER ============ */
header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: #fff;
  padding: 32px 0 28px;
  text-align: center;
}
header h1 { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; justify-content: center; gap: 12px; }
.header-logo { width: 28px; height: 28px; vertical-align: middle; filter: drop-shadow(0 2px 4px rgba(0,0,0,.2)); }
.subtitle { margin-top: 6px; font-size: 0.95rem; opacity: 0.85; font-weight: 400; }

/* ============ STEP CARDS ============ */
.step-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-top: 24px;
}
.step-header { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.step-num {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-weight: 700; font-size: 0.95rem; flex-shrink: 0;
}
.step-header h2 { font-size: 1.15rem; font-weight: 700; }

/* ============ TYPE TOGGLE ============ */
.type-toggle, .table-toggle {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.toggle-btn {
  padding: 10px 22px; border-radius: var(--radius-sm);
  border: 2px solid var(--border); background: var(--card);
  cursor: pointer; font-weight: 600; font-size: 0.9rem;
  transition: all .15s ease; color: var(--text);
  font-family: inherit;
}
.toggle-btn:hover { border-color: var(--primary); color: var(--primary); }
.toggle-btn.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}

/* ============ SEARCH ============ */
.search-box { margin-bottom: 16px; }
.search-box input {
  width: 100%; padding: 12px 16px; border: 2px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.95rem;
  outline: none; transition: border-color .15s; font-family: inherit;
}
.search-box input:focus { border-color: var(--primary); }

/* ============ CATEGORY FILTERS ============ */
.category-filters {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px;
}
.cat-btn {
  padding: 5px 12px; border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--card); cursor: pointer; font-size: 0.75rem;
  font-weight: 600; font-family: inherit; transition: all .15s;
  color: var(--text-muted); white-space: nowrap;
}
.cat-btn:hover { border-color: var(--primary); color: var(--primary); }
.cat-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============ PRESET GRID ============ */
.preset-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px; max-height: 340px; overflow-y: auto;
  padding-right: 4px;
}
.preset-card {
  padding: 12px 14px; border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: all .15s ease; text-align: center;
}
.preset-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.preset-card.active { border-color: var(--primary); background: #eff6ff; }
.preset-card .preset-title { font-weight: 600; font-size: 0.85rem; }
.preset-card .preset-dim { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; }
.preset-card .preset-tag {
  display: inline-block; margin-top: 5px; font-size: 0.65rem;
  padding: 2px 8px; border-radius: 999px; font-weight: 600;
  background: #dbeafe; color: var(--primary);
}

/* ============ PRESET INFO ============ */
.preset-info {
  margin-top: 16px; padding: 16px; background: #f8fafc;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.preset-info h3 { font-size: 1rem; margin-bottom: 12px; color: var(--primary); }
.specs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 10px; }
.spec { display: flex; flex-direction: column; }
.spec-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.spec-value { font-size: 0.95rem; font-weight: 600; margin-top: 2px; }

/* ============ UPLOAD ZONE ============ */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 48px 24px; text-align: center; cursor: pointer;
  transition: all .2s ease; position: relative;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary); background: #eff6ff;
}
.upload-icon { font-size: 2.5rem; margin-bottom: 10px; }
.upload-sub { font-size: 0.82rem; color: var(--text-muted); margin-top: 4px; }

/* ============ CROP EDITOR ============ */
.crop-hint { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 14px; }
.editor-layout { display: flex; gap: 20px; flex-wrap: wrap; }
.crop-container {
  position: relative; width: 400px; height: 400px; max-width: 100%;
  background: #1e293b; border-radius: var(--radius-sm); overflow: hidden;
  cursor: grab; touch-action: none;
}
.crop-container:active { cursor: grabbing; }
#cropCanvas { display: block; }
.crop-overlay {
  position: absolute; border: 2px solid rgba(255,255,255,.85);
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
  pointer-events: none; border-radius: 2px;
}
.editor-controls {
  display: flex; flex-direction: column; gap: 12px; min-width: 160px;
}
.editor-controls label { font-weight: 600; font-size: 0.85rem; }
#zoomSlider { width: 100%; accent-color: var(--primary); }

/* ============ BUTTONS ============ */
.btn {
  padding: 12px 24px; border: none; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.9rem; cursor: pointer;
  transition: all .15s ease; font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 2px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

/* ============ OUTPUT ============ */
.output-layout { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.preview-box {
  padding: 16px; background: repeating-conic-gradient(#e5e7eb 0% 25%, transparent 0% 50%) 50%/16px 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  min-width: 200px; min-height: 200px;
}
#previewCanvas { max-width: 280px; max-height: 320px; border-radius: 2px; display: block; }
.output-info { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 10px; }
.output-stat {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.output-stat span { color: var(--text-muted); }
.status-row strong.pass { color: var(--success); }
.status-row strong.fail { color: var(--danger); }
#btnDownload { margin-top: 8px; width: 100%; font-size: 1rem; padding: 14px; }
#btnRestart { width: 100%; }

/* ============ REFERENCE TABLE ============ */
.table-toggle { margin-bottom: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); position: sticky; top: 0; }
tr:hover td { background: #f8fafc; }

/* ============ FOOTER ============ */
footer {
  margin-top: 40px; padding: 28px 0; text-align: center;
  font-size: 0.85rem; color: var(--text-muted);
}
.footer-note { margin-top: 6px; font-size: 0.78rem; }
.visitor-counter { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 10px 0; font-size: 0.85rem; }
.counter-badge { height: 20px; vertical-align: middle; }

/* ============ SEO CONTENT ============ */
.seo-content {
  text-align: left; max-width: 800px; margin: 0 auto 32px;
  padding: 24px; background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); font-size: 0.88rem; line-height: 1.7;
}
.seo-content h2 { font-size: 1.15rem; margin-bottom: 12px; color: var(--text); }
.seo-content h3 { font-size: 0.95rem; margin: 16px 0 8px; color: var(--text); }
.seo-content p { margin-bottom: 10px; color: var(--text-muted); }
.seo-content ul { margin: 0 0 12px 20px; color: var(--text-muted); }
.seo-content li { margin-bottom: 4px; }
.seo-content strong { color: var(--text); }

/* ============ UTILITY ============ */
.hidden { display: none !important; }

/* ============ FETCH BAR ============ */
.fetch-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; margin-bottom: 14px;
  background: #f0fdf4; border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm); font-size: 0.82rem;
  color: var(--text-muted); transition: all .2s;
}
.fetch-bar.error { background: #fef2f2; border-color: #fecaca; }
.fetch-bar.loading { background: #eff6ff; border-color: #bfdbfe; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  font-size: 1rem; padding: 4px 6px; border-radius: 4px;
  transition: background .15s;
}
.btn-icon:hover { background: rgba(0,0,0,.06); }

/* ============ CUSTOM SIZE ============ */
.custom-size-toggle { margin-top: 12px; }
.custom-size-panel {
  margin-top: 14px; padding: 20px;
  background: #f8fafc; border: 2px solid var(--border);
  border-radius: var(--radius-sm);
}
.custom-size-panel h3 { font-size: 0.95rem; margin-bottom: 14px; color: var(--primary); }
.custom-fields {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-group label {
  font-size: 0.75rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .03em;
}
.field-group input, .field-group select {
  padding: 8px 10px; border: 2px solid var(--border);
  border-radius: 6px; font-size: 0.9rem; font-family: inherit;
  outline: none; transition: border-color .15s;
}
.field-group input:focus, .field-group select:focus { border-color: var(--primary); }
#btnApplyCustom { width: 100%; }

/* ============ PRESET SOURCE TAG ============ */
.preset-card .preset-source {
  display: inline-block; margin-top: 3px; font-size: 0.6rem;
  padding: 1px 6px; border-radius: 999px; font-weight: 600;
  background: #dcfce7; color: #166534;
}
.preset-card .preset-source.local { background: #f1f5f9; color: var(--text-muted); }
.preset-card .preset-date { font-size: 0.68rem; color: var(--text-muted); margin-top: 3px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 640px) {
  header h1 { font-size: 1.35rem; }
  .header-logo { width: 22px; height: 22px; }
  .subtitle { font-size: 0.82rem; }
  .step-card { padding: 16px; }
  .preset-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); max-height: 260px; }
  .crop-container { width: 100%; height: 280px; }
  .editor-layout { flex-direction: column; }
  .output-layout { flex-direction: column; }
  #previewCanvas { max-width: 100%; }
  .category-filters { gap: 4px; }
  .cat-btn { padding: 4px 8px; font-size: 0.68rem; }
  .custom-fields { grid-template-columns: 1fr 1fr; }
  .custom-size-toggle { display: flex; gap: 8px; flex-wrap: wrap; }
  .custom-size-toggle .btn { font-size: 0.8rem; padding: 8px 14px; flex: 1; }
  .specs-grid { grid-template-columns: 1fr 1fr; }
  .type-toggle { flex-wrap: wrap; }
  .toggle-btn { flex: 1; text-align: center; padding: 8px 14px; font-size: 0.82rem; }
  .table-wrap { font-size: 0.75rem; }
  th, td { padding: 6px 8px; }
  .seo-content { padding: 16px; font-size: 0.82rem; }
  .seo-content h2 { font-size: 1rem; }
  .fetch-bar { font-size: 0.75rem; padding: 6px 10px; }
  #pdfUploadZone { padding: 20px 12px; }
}
