:root {
  color-scheme: light;
  --text: #172033;
  --muted: #68758a;
  --line: rgba(255, 255, 255, 0.48);
  --line-dark: rgba(23, 36, 62, 0.1);
  --glass: rgba(255, 255, 255, 0.66);
  --glass-strong: rgba(255, 255, 255, 0.82);
  --primary: #1677ff;
  --primary-dark: #0b4fb3;
  --soft: rgba(225, 239, 255, 0.78);
  --danger: #b7352a;
  --warning: #b67914;
  --ok: #1d8cff;
  --shadow: 0 20px 60px rgba(22, 65, 125, 0.16);
  --shadow-soft: 0 12px 36px rgba(22, 65, 125, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 18% -10%, rgba(87, 160, 255, 0.58), transparent 34%),
    radial-gradient(circle at 88% 10%, rgba(156, 210, 255, 0.62), transparent 28%),
    radial-gradient(circle at 50% 100%, rgba(255, 255, 255, 0.9), transparent 38%),
    linear-gradient(145deg, #eef6ff 0%, #f3f7fb 48%, #f9fbff 100%);
  background-attachment: fixed;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1040px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  padding: 22px;
}

.topbar,
.dialog-header,
.database-toolbar,
.scan-actions,
.input-row,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar,
.dialog-header {
  justify-content: space-between;
}

.topbar {
  padding: 2px 2px 0;
}

.eyebrow,
.section-label {
  margin: 0 0 5px;
  color: rgba(22, 119, 255, 0.82);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.04;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(32px, 7vw, 56px);
}

h2 {
  font-size: 23px;
}

.subtitle {
  max-width: 600px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.status-strip,
.scanner-panel,
.dialog-card {
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: var(--shadow-soft);
  -webkit-backdrop-filter: blur(24px) saturate(1.45);
  backdrop-filter: blur(24px) saturate(1.45);
}

.status-strip {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: 18px;
}

.status-strip div {
  display: flex;
  align-items: center;
  gap: 9px;
}

.status-strip span:last-child {
  color: var(--muted);
  text-align: right;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--warning);
  box-shadow: 0 0 0 5px rgba(182, 121, 20, 0.14);
}

.status-dot.ready {
  background: var(--ok);
  box-shadow: 0 0 0 5px rgba(29, 140, 255, 0.14);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 5px rgba(183, 53, 42, 0.14);
}

.scanner-panel {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding: 12px;
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.scanner-frame {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: min(68vh, 760px);
  min-height: 430px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 24px;
  background: #0b1728;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

#scannerVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 28px;
  color: #f8fff9;
  text-align: center;
  background:
    radial-gradient(circle at 50% 28%, rgba(72, 150, 255, 0.28), transparent 30%),
    linear-gradient(145deg, rgba(8, 18, 34, 0.96), rgba(18, 45, 82, 0.94));
}

.scanner-placeholder strong {
  font-size: 25px;
  letter-spacing: -0.02em;
}

.scanner-placeholder.hidden {
  display: none;
}

.scan-reticle {
  position: absolute;
  width: min(72%, 540px);
  height: 122px;
  border: 1.5px solid rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  box-shadow:
    0 0 0 999px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.25),
    0 18px 50px rgba(0, 0, 0, 0.18);
}

.scan-reticle::before,
.scan-reticle::after {
  content: "";
  position: absolute;
}

.scan-reticle::before {
  inset: -1px;
  border-radius: inherit;
  background:
    linear-gradient(90deg, #61a8ff 34px, transparent 34px calc(100% - 34px), #61a8ff calc(100% - 34px)) top / 100% 3px no-repeat,
    linear-gradient(90deg, #61a8ff 34px, transparent 34px calc(100% - 34px), #61a8ff calc(100% - 34px)) bottom / 100% 3px no-repeat,
    linear-gradient(#61a8ff 34px, transparent 34px calc(100% - 34px), #61a8ff calc(100% - 34px)) left / 3px 100% no-repeat,
    linear-gradient(#61a8ff 34px, transparent 34px calc(100% - 34px), #61a8ff calc(100% - 34px)) right / 3px 100% no-repeat;
}

.scan-reticle::after {
  left: 10%;
  right: 10%;
  top: 50%;
  height: 2px;
  background: #74b7ff;
  box-shadow: 0 0 18px rgba(116, 183, 255, 0.9);
}

.scan-actions {
  margin-top: 0;
}

.scan-actions .secondary-button {
  width: 100%;
}

.primary-button,
.secondary-button,
.icon-button,
.input-row button {
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 16px;
  padding: 0 17px;
  font-weight: 780;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary-button {
  flex: 1;
  color: #fff;
  background: linear-gradient(180deg, #4da3ff, var(--primary));
  box-shadow: 0 14px 28px rgba(22, 119, 255, 0.22);
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover,
.input-row button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: default;
  background: #7994b8;
}

.secondary-button,
.input-row button {
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 10px 24px rgba(22, 65, 125, 0.08);
}

.icon-button {
  min-width: 46px;
  padding: 0 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  font-size: 22px;
  box-shadow: var(--shadow-soft);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.manual-search {
  display: grid;
  gap: 8px;
  margin-top: 0;
}

label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 760;
}

input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(23, 36, 62, 0.09);
  border-radius: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

input {
  min-height: 46px;
  padding: 0 13px;
}

input:focus,
textarea:focus {
  outline: 3px solid rgba(22, 119, 255, 0.18);
  border-color: rgba(22, 119, 255, 0.38);
}

.input-row input {
  flex: 1;
}

.source-preview {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(22, 119, 255, 0.12);
  border-radius: 18px;
  padding: 12px 14px;
  background: rgba(225, 239, 255, 0.62);
  color: var(--primary-dark);
}

.source-preview span {
  color: #304a70;
  font-size: 13px;
}

.empty-state {
  color: var(--muted);
}

.product-result {
  display: grid;
  gap: 10px;
}

.price {
  color: var(--primary);
  font-size: clamp(34px, 8vw, 64px);
  font-weight: 900;
  letter-spacing: -0.05em;
}

dialog {
  width: min(760px, calc(100% - 24px));
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(8, 18, 34, 0.34);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.dialog-card {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 24px);
  min-width: 0;
  overflow: auto;
  padding: 20px;
  border-radius: 26px;
}

.database-dialog {
  width: min(1100px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
}

.script-dialog {
  width: min(860px, calc(100vw - 24px));
}

.script-code {
  min-height: 420px;
  resize: vertical;
  padding: 14px;
  background: rgba(8, 18, 34, 0.92);
  color: #f5f9ff;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
}

#databaseDialog {
  width: min(1100px, calc(100% - 24px));
}

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

.form-status {
  margin: 2px 0 0;
  border: 1px solid rgba(22, 119, 255, 0.22);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(22, 119, 255, 0.08);
  color: var(--primary);
  font-weight: 800;
}

.form-status[data-variant="error"] {
  border-color: rgba(190, 46, 46, 0.26);
  background: rgba(190, 46, 46, 0.09);
  color: #a62a2a;
}

.tutorial-box {
  border: 1px solid rgba(23, 36, 62, 0.08);
  border-radius: 18px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.5);
  overflow-wrap: anywhere;
}

.tutorial-box summary {
  color: var(--primary);
  cursor: pointer;
  font-weight: 850;
}

.tutorial-box ol {
  margin: 12px 0;
  padding-left: 22px;
}

.tutorial-box li + li {
  margin-top: 8px;
}

.tutorial-box p {
  margin: 10px 0 0;
  color: var(--muted);
}

.inline-action {
  width: 100%;
  margin-top: 12px;
}

code {
  white-space: normal;
  border-radius: 8px;
  padding: 2px 6px;
  background: rgba(230, 239, 252, 0.9);
  color: var(--text);
  font-size: 0.92em;
}

.result-toast {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 2;
  display: grid;
  gap: 8px;
  max-height: calc(100% - 32px);
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 22px 62px rgba(0, 0, 0, 0.2);
  -webkit-backdrop-filter: blur(26px) saturate(1.5);
  backdrop-filter: blur(26px) saturate(1.5);
}

.result-toast[hidden] {
  display: none;
}

.result-toast strong {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: clamp(21px, 5vw, 32px);
  letter-spacing: -0.03em;
}

.result-label {
  color: var(--primary);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.result-toast p {
  margin: 0;
}

.result-toast.error {
  border-color: rgba(183, 53, 42, 0.24);
  background: rgba(255, 246, 244, 0.82);
}

.result-toast.error strong,
.result-toast.error p {
  color: var(--danger);
}

.table-wrap {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid rgba(23, 36, 62, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.42);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  min-width: 120px;
  padding: 11px;
  border-bottom: 1px solid rgba(23, 36, 62, 0.08);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(246, 249, 255, 0.92);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

td:last-child,
th:last-child {
  min-width: 92px;
  text-align: right;
}

.edit-fields {
  display: grid;
  gap: 10px;
}

.status {
  color: var(--muted);
  font-size: 14px;
}

.not-found {
  color: var(--danger);
  font-weight: 850;
}

@media (max-width: 620px) {
  .app-shell {
    padding: 14px;
  }

  dialog {
    width: calc(100% - 16px);
  }

  .dialog-card {
    padding: 15px;
    border-radius: 22px;
  }

  .dialog-header h2 {
    font-size: 20px;
  }

  .scan-actions,
  .database-toolbar,
  .input-row {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .scanner-panel {
    border-radius: 24px;
  }

  .scanner-frame {
    height: 62vh;
    min-height: 420px;
    border-radius: 20px;
  }

  .topbar {
    align-items: flex-start;
  }

  .status-strip {
    align-items: flex-start;
    flex-direction: column;
    border-radius: 18px;
  }

  .status-strip span:last-child {
    text-align: left;
  }
}
