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

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --error: #dc2626;
  --error-light: #fee2e2;
  --processing: #6366f1;
  --processing-light: #e0e7ff;
  --radius: 12px;
  --radius-sm: 8px;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }

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

.header {
  background: #0f172a; color: #fff;
  height: 56px; padding: 0 24px;
  display: flex; align-items: center;
  position: sticky; top: 0; z-index: 50;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.header-inner {
  max-width: 720px; width: 100%; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 22px; height: 22px; color: #60a5fa; }
.brand h1 { font-size: 16px; font-weight: 600; color: #fff; }

.ws-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; padding: 4px 12px; border-radius: 20px;
  background: rgba(251,191,36,0.15); color: #fbbf24;
  transition: all 0.3s;
}
.ws-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #fbbf24; animation: pulse 2s infinite;
}
.ws-connected { background: rgba(74,222,128,0.15); color: #4ade80; }
.ws-connected .ws-dot { background: #4ade80; }
.ws-disconnected { background: rgba(248,113,113,0.15); color: #f87171; }
.ws-disconnected .ws-dot { background: #f87171; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.progress-bar-wrap {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  position: sticky; top: 56px; z-index: 40;
}
.progress-bar {
  max-width: 720px; margin: 0 auto;
  display: flex; gap: 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.progress-bar::-webkit-scrollbar { display: none; }
.progress-step {
  flex: 1; min-width: 60px;
  text-align: center;
  font-size: 12px; font-weight: 500;
  color: var(--text-light);
  padding: 6px 4px;
  border-bottom: 2px solid var(--border);
  transition: all 0.2s;
  white-space: nowrap;
}
.progress-step.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.progress-step.done {
  color: var(--success);
  border-bottom-color: var(--success);
}
.progress-step.processing {
  color: var(--processing);
  border-bottom-color: var(--processing);
}
.progress-step.error {
  color: var(--error);
  border-bottom-color: var(--error);
}

.network-info-bar {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 12px;
  font-size: 13px;
}
.net-info-item {
  display: flex; align-items: center; gap: 6px;
}
.net-label {
  color: var(--text-muted); font-size: 12px;
  padding: 2px 6px; background: var(--bg);
  border-radius: 4px;
}
.net-link {
  color: var(--primary); text-decoration: none; font-weight: 500;
  font-family: 'SF Mono', Consolas, monospace; font-size: 12px;
}
.net-link:hover { text-decoration: underline; }
.net-hint {
  color: var(--warning); font-size: 11px; margin-left: 4px;
}

.main {
  flex: 1; max-width: 720px; width: 100%;
  margin: 0 auto; padding: 24px 16px 48px;
  display: flex; flex-direction: column; gap: 16px;
}

.step-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: border-color 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.step-card[data-state="locked"] { opacity: 0.45; }
.step-card[data-state="active"] { border-color: #93c5fd; box-shadow: 0 0 0 1px #93c5fd; }
.step-card[data-state="processing"] { border-color: #a5b4fc; }
.step-card[data-state="done"] { border-color: #86efac; }
.step-card[data-state="error"] { border-color: #fca5a5; box-shadow: 0 0 0 1px #fca5a5; }

.step-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.step-num {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  background: #f1f5f9; color: var(--text-muted);
  flex-shrink: 0; transition: all 0.2s;
}
[data-state="active"] .step-num { background: var(--primary); color: #fff; }
[data-state="processing"] .step-num { background: var(--processing); color: #fff; }
[data-state="done"] .step-num { background: var(--success); color: #fff; font-size: 0; }
[data-state="done"] .step-num::before { content: '\2713'; font-size: 15px; }
[data-state="error"] .step-num { background: var(--error); color: #fff; }

.step-title { font-size: 15px; font-weight: 600; flex: 1; }

.step-badge {
  padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.badge-locked { background: #f1f5f9; color: var(--text-muted); }
.badge-active { background: var(--primary-light); color: var(--primary); }
.badge-processing { background: var(--processing-light); color: var(--processing); }
.badge-done { background: var(--success-light); color: var(--success); }
.badge-error { background: var(--error-light); color: var(--error); }

.drop-zone {
  border: 2px dashed #cbd5e1; border-radius: var(--radius);
  padding: 40px 20px; text-align: center; cursor: pointer;
  transition: all 0.2s;
}
.drop-zone:hover { border-color: var(--primary); background: var(--primary-light); }
.drop-zone.drag-active { border-color: var(--primary); background: var(--primary-light); }
.drop-icon { width: 44px; height: 44px; color: var(--text-light); margin: 0 auto 12px; display: block; }
.drop-text { font-size: 14px; color: #475569; }
.link { color: var(--primary); cursor: pointer; text-decoration: underline; }
.drop-hint { font-size: 12px; color: var(--text-light); margin-top: 6px; }

.preview { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.preview-img { max-width: 100%; max-height: 200px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

.field-row { display: flex; flex-direction: column; gap: 6px; }
.field-row label { font-size: 13px; font-weight: 500; color: var(--text-muted); }

.card-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.card-info-grid .field-row { gap: 4px; }
@media (max-width: 600px) { .card-info-grid { grid-template-columns: 1fr; } }

.input-group { display: flex; gap: 8px; align-items: stretch; }
.input {
  flex: 1; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 16px; font-family: inherit;
  outline: none; transition: border-color 0.2s;
  background: #fff;
  -webkit-appearance: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.input:disabled { background: #f8fafc; color: var(--text-muted); cursor: not-allowed; }

.value-display {
  font-size: 16px; font-weight: 600; color: var(--text);
  min-height: 24px; line-height: 24px; word-break: break-all;
}
.value-display.status-normal { color: var(--success); }
.value-display.status-warning { color: var(--warning); }
.value-display.status-error { color: var(--error); }

.summary-box {
  margin-top: 16px; padding: 12px 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg);
}
.summary-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.summary-title { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.summary-text {
  width: 100%; min-height: 80px;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: #fff;
  font-family: var(--font-mono); font-size: 14px;
  color: var(--text); resize: vertical; outline: none;
  line-height: 1.6;
}
.summary-text:focus { border-color: var(--primary); }

.detail-screenshot {
  margin-top: 16px; padding: 12px 16px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg);
}
.screenshot-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.screenshot-title { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.screenshot-hint { font-size: 12px; color: var(--text-light); }
.screenshot-img {
  width: 100%; max-height: none; object-fit: contain;
  border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border); background: #fff;
  transition: opacity 0.2s, transform 0.2s;
}
.screenshot-img:hover { opacity: 0.85; }

.recharge-prompt {
  margin-top: 16px; padding: 16px 20px;
  border: 2px solid var(--primary); border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(102,126,234,0.05), rgba(118,75,162,0.05));
  text-align: center;
}
.prompt-text { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.year-select-wrap { margin-bottom: 16px; }
.year-label { display: block; font-size: 14px; color: var(--text-muted); margin-bottom: 8px; font-weight: 500; }
.year-options { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.year-opt {
  padding: 8px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  min-width: 60px;
}
.year-opt:hover { border-color: var(--primary); color: var(--primary); }
.year-opt.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}
.prompt-buttons { display: flex; gap: 12px; justify-content: center; }

.step-progress {
  display: flex; align-items: center; gap: 8px;
  margin-top: 12px; font-size: 13px; color: var(--text-muted);
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border); border-top-color: var(--processing);
  border-radius: 50%; animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn {
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; font-family: inherit;
  border: none; cursor: pointer; transition: all 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #f1f5f9; color: #475569; border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-text { background: transparent; color: var(--primary); padding: 4px 8px; }
.btn-text:hover { text-decoration: underline; }
.btn-sm { font-size: 12px; padding: 4px 10px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; text-align: center; }

.log-area {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.log-head {
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  display: flex; justify-content: space-between; align-items: center;
}
.log-content { max-height: 200px; overflow-y: auto; padding: 4px 0; }
.log-entry {
  padding: 3px 16px; font-size: 12px; color: var(--text-muted);
  border-bottom: 1px solid #f8fafc; display: flex; gap: 8px;
}
.log-time { color: var(--text-light); flex-shrink: 0; font-family: var(--font-mono); }
.log-entry.log-success { color: var(--success); }
.log-entry.log-error { color: var(--error); }
.log-entry.log-warning { color: var(--warning); }

.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content {
  position: relative; background: var(--surface);
  border-radius: 16px; padding: 32px; max-width: 380px; width: 90%;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-close {
  position: absolute; top: 12px; right: 16px;
  font-size: 24px; line-height: 1; background: none; border: none;
  cursor: pointer; color: var(--text-light); padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-title { text-align: center; font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.qr-container { text-align: center; margin: 12px 0; min-height: 200px; display: flex; align-items: center; justify-content: center; }
.qr-img { max-width: 280px; width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.qr-hint { text-align: center; color: var(--text-muted); font-size: 14px; }
.qr-hint.success { color: var(--success); font-weight: 600; font-size: 16px; }

.image-viewer-content {
  max-width: 100vw; max-height: 100vh; width: 100vw; height: 100vh;
  padding: 0; background: rgba(0,0,0,0.9); border: none;
  box-shadow: none; border-radius: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.image-viewer-toolbar {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 16px; flex-shrink: 0;
  background: rgba(0,0,0,0.3);
}
.zoom-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.15); border: none;
  color: #fff; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.zoom-btn:hover { background: rgba(255,255,255,0.3); }
.zoom-level { color: rgba(255,255,255,0.8); font-size: 14px; min-width: 50px; text-align: center; }
.image-viewer-scroll {
  flex: 1; overflow: auto;
  display: flex;
  padding: 16px;
  cursor: grab;
}
.image-viewer-scroll.grabbing { cursor: grabbing; }
.image-viewer-img {
  max-width: none; max-height: none;
  object-fit: contain; border-radius: var(--radius-sm);
  display: block;
  margin: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.success-icon {
  width: 80px; height: 80px; margin: 0 auto 16px;
  border-radius: 50%; background: var(--success-light); color: var(--success);
  display: flex; align-items: center; justify-content: center;
  animation: bounceIn 0.5s ease;
}
@keyframes bounceIn { 0% { transform: scale(0); } 60% { transform: scale(1.1); } 100% { transform: scale(1); } }
.success-icon svg { width: 40px; height: 40px; }

.toast-container {
  position: fixed; top: 72px; right: 16px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-size: 14px; color: #fff; font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: toastIn 0.3s ease; transition: opacity 0.3s;
  pointer-events: auto; max-width: 360px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--error); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--primary); }
@keyframes toastIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.record-form { margin-bottom: 16px; }
.record-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px; margin-bottom: 12px;
}
.record-grid .field-row { gap: 4px; }
.record-grid .field-row label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.record-grid .input { padding: 8px 10px; font-size: 14px; }
.record-grid .input:read-only { background: #f5f7fa; color: var(--text-muted); }
.record-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.records-table-wrap {
  overflow-x: auto; border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-top: 12px;
}
.records-table {
  width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap;
}
.records-table th {
  background: var(--bg); padding: 8px 10px; text-align: left;
  font-weight: 600; color: var(--text-muted); border-bottom: 2px solid var(--border);
  position: sticky; top: 0;
}
.records-table td {
  padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--text);
}
.records-table tr:hover td { background: var(--bg); }
.records-table .del-btn {
  color: var(--error); background: none; border: none; cursor: pointer;
  font-size: 13px; padding: 2px 6px;
}
.records-table .del-btn:hover { text-decoration: underline; }
.records-table .empty-row td { text-align: center; color: var(--text-light); padding: 24px; }

@media (max-width: 640px) {
  .main { padding: 16px 12px 48px; }
  .input-group { flex-direction: column; }
  .input-group .btn { width: 100%; }
  .step-card { padding: 16px; }
  .toast-container { right: 8px; left: 8px; }
  .toast { max-width: none; }
  .input { font-size: 16px; }
  .progress-step { min-width: 50px; font-size: 11px; }
  .header { padding: 0 16px; }
  .brand h1 { font-size: 14px; }
}
