:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #657084;
  --border: #d8dee8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #15803d;
  --warning: #a16207;
  --danger: #c2413b;
  --focus: rgba(37, 99, 235, 0.2);
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.app-header__inner {
  display: flex;
  width: min(100%, 760px);
  min-height: 62px;
  margin: 0 auto;
  padding: 0 18px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.brand__mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  place-items: center;
  border-radius: 8px;
  background: #172033;
  color: #fff;
}

.brand h1 {
  overflow: hidden;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 22px 18px 42px;
}

.workspace {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.workspace__heading {
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border);
}

.workspace__heading h2 {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: 0;
}

.workspace__heading p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-section {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.form-section:last-child { border-bottom: 0; }

.section-title {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.44fr);
  gap: 14px;
}

label {
  display: block;
  margin-bottom: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 650;
}

.required { color: var(--danger); }

input[type="text"],
input[type="password"],
input[type="number"] {
  width: 100%;
  height: 44px;
  border: 1px solid #cbd3df;
  border-radius: 6px;
  outline: 0;
  background: #fff;
  color: var(--text);
  padding: 0 12px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus);
}

input::placeholder { color: #98a2b3; }

.input-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.input-actions--compact { grid-template-columns: minmax(0, 1fr) auto; }

.btn {
  display: inline-flex;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 13px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn svg { width: 17px; height: 17px; stroke-width: 2; }
.btn:disabled { cursor: not-allowed; opacity: 0.58; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn--secondary { border-color: #b9c2d0; background: #fff; }
.btn--secondary:hover:not(:disabled) { background: var(--surface-soft); }
.btn--ghost { min-width: 40px; padding: 8px; color: #475467; }
.btn--ghost:hover { background: #eef2f6; color: var(--text); }
.btn--danger { color: var(--danger); }
.btn--wide { width: 100%; min-height: 48px; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; }

.meta {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.info-strip {
  display: none;
  margin-top: 14px;
  border-left: 3px solid var(--primary);
  background: #eff6ff;
  padding: 11px 13px;
  color: #1e3a5f;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.info-strip.is-visible { display: block; }

.file-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preview {
  display: none;
  width: 100%;
  max-height: 420px;
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: contain;
  background: #f2f4f7;
}

.preview.is-visible { display: block; }

.upload-status {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.upload-status.is-success { color: var(--success); }
.upload-status.is-error { color: var(--danger); }

.toast-stack {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: 18px;
  display: grid;
  width: min(360px, calc(100vw - 36px));
  gap: 8px;
}

.toast {
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
  animation: toast-in 160ms ease-out;
}

.toast__bar { background: var(--primary); }
.toast--success .toast__bar { background: var(--success); }
.toast--warning .toast__bar { background: var(--warning); }
.toast--error .toast__bar { background: var(--danger); }
.toast__message { padding: 13px 10px 13px 12px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.toast__close { border: 0; background: transparent; padding: 8px 11px; color: var(--muted); cursor: pointer; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  background: #fff;
  color: var(--text);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
}

dialog::backdrop { background: rgba(15, 23, 42, 0.58); }

.dialog__header {
  display: flex;
  min-height: 54px;
  padding: 0 14px 0 18px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
}

.dialog__header h3 { margin: 0; font-size: 16px; letter-spacing: 0; }
.dialog__body { padding: 18px; color: #475467; font-size: 14px; line-height: 1.65; white-space: pre-wrap; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 18px; }

.scanner-video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #0b1020;
  object-fit: cover;
}

.scanner-status { min-height: 44px; padding: 12px 16px; color: var(--muted); font-size: 13px; }

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 410px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.09);
  padding: 28px;
}

.login-panel .brand { margin-bottom: 26px; }
.login-panel h1 { font-size: 19px; }
.login-panel__message { min-height: 22px; margin: 12px 0 0; color: var(--danger); font-size: 13px; text-align: center; }

.export-options { display: grid; gap: 14px; }
.export-actions { display: flex; flex-wrap: wrap; gap: 8px; }

@media (max-width: 600px) {
  .app-header__inner { min-height: 58px; padding: 0 12px; }
  .page-shell { padding: 12px 10px 28px; }
  .workspace__heading, .form-section { padding-left: 15px; padding-right: 15px; }
  .field-row { grid-template-columns: 1fr; }
  .input-actions { grid-template-columns: minmax(0, 1fr) auto; }
  .input-actions .btn--query { grid-column: 1 / -1; }
  .file-picker { grid-template-columns: 1fr; }
  .header-actions .btn span { display: none; }
  .header-actions .btn { min-width: 40px; padding: 8px; }
  .toast-stack { right: 10px; bottom: 10px; width: calc(100vw - 20px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
