/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --info: #0891b2;
  --info-bg: #ecfeff;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --transition: 150ms ease;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Header === */
header {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}
header a {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
header a:hover { text-decoration: none; color: var(--primary); }
header .logo-icon { display: inline-flex; align-items: center; gap: 10px; }
header button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}
header button:hover { background: var(--bg); border-color: var(--text-muted); }

/* === Main === */
main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* === Typography === */
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
h2 { font-size: 16px; font-weight: 600; color: var(--text); margin: 28px 0 12px; }
p { color: var(--text-secondary); }

/* === Buttons === */
.btn, button[type="submit"], .button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  padding: 9px 18px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover, button[type="submit"]:hover, .button:hover {
  background: var(--primary-hover);
  text-decoration: none;
  box-shadow: var(--shadow);
}
.btn-outline {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); border-color: var(--text-muted); }
.btn-success { background: var(--success); }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); }

/* === Cards === */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

/* === Toolbar === */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

/* === Stats Grid === */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-card .stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.stat-card .stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.stat-card.stat-status .stat-value { font-size: 15px; font-weight: 600; }

/* === Status Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.badge-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.badge-success::before { background: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning-border); }
.badge-warning::before { background: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.badge-danger::before { background: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); border: 1px solid #a5f3fc; }
.badge-info::before { background: var(--info); }
.badge-neutral { background: #f8fafc; color: var(--text-secondary); border: 1px solid var(--border); }
.badge-neutral::before { background: var(--text-muted); }

/* === Tables === */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 24px;
}
table { width: 100%; border-collapse: collapse; }
thead { background: #f8fafc; }
th {
  text-align: left;
  padding: 11px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px 16px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfc; }
td.mono { font-family: "SF Mono", "Fira Code", monospace; font-size: 12.5px; }
td.error-cell {
  color: var(--danger);
  font-size: 12px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td.empty { text-align: center; color: var(--text-muted); padding: 40px; }

/* === Forms === */
.form {
  display: grid;
  gap: 14px;
  max-width: 480px;
}
.form.card { padding: 28px; }
.form label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: -6px;
}
.form input, .form select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form input:focus, .form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form input[type="file"] {
  padding: 10px;
  background: #f8fafc;
  cursor: pointer;
}

/* === Login === */
body.login {
  display: grid;
  min-height: 100vh;
  place-items: center;
  background: linear-gradient(135deg, #f0f2f5 0%, #e2e8f0 100%);
}
.login-panel {
  width: 380px;
  background: var(--surface);
  padding: 40px 36px;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-md);
}
.login-panel h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 22px;
}
.login-panel .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 28px;
}
.login-panel .form { max-width: none; }
.login-panel button[type="submit"] { width: 100%; justify-content: center; padding: 11px; margin-top: 4px; }

/* === Alerts === */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13.5px;
  line-height: 1.5;
}
.alert-danger {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
}
.alert-danger strong { font-weight: 600; }
.alert-info {
  background: var(--info-bg);
  border: 1px solid #a5f3fc;
  color: var(--info);
}
.error { color: var(--danger); font-size: 13px; text-align: center; margin-bottom: 8px; }

/* === Actions & Downloads === */
.actions { margin-bottom: 20px; }
.actions p { font-size: 13.5px; }
.downloads { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }

/* === Processing Indicator === */
.processing {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  color: var(--primary);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 20px;
}
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid #bfdbfe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Review Page === */
.review-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  align-items: start;
}
.review-image {
  position: sticky;
  top: 80px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.review-image img {
  width: 100%;
  display: block;
  cursor: zoom-in;
  transition: transform var(--transition);
}
.review-image img.zoomed {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  background: rgba(0,0,0,0.9);
  z-index: 999;
  border-radius: 0;
  cursor: zoom-out;
}
.review-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
}
.review-form .form { max-width: none; }
@media (max-width: 768px) {
  .review-layout { grid-template-columns: 1fr; }
  .review-image { position: static; }
}

/* === Breadcrumb === */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.breadcrumb a { color: var(--text-secondary); }
.breadcrumb span { color: var(--text-muted); }

/* === Event Log === */
.event-log td:first-child { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.event-log .level-error { color: var(--danger); font-weight: 600; }
.event-log .level-warning { color: var(--warning); font-weight: 600; }
.event-log .level-info { color: var(--info); font-weight: 600; }

/* === Utilities === */
.mb-0 { margin-bottom: 0; }
.mt-sm { margin-top: 8px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
