:root {
  --bg: #f3f6f4;
  --bg-elevated: #ffffff;
  --bg-input: #f7faf8;
  --line: #d5e0d9;
  --text: #15241c;
  --muted: #5f7268;
  --accent: #0d7a4f;
  --accent-soft: #e5f5ed;
  --danger: #c0392b;
  --warn: #9a6b00;
  --warn-soft: #fff3d6;
  --radius: 12px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(13, 122, 79, 0.06), transparent 220px),
    repeating-linear-gradient(
      -12deg,
      transparent,
      transparent 18px,
      rgba(21, 36, 28, 0.015) 18px,
      rgba(21, 36, 28, 0.015) 19px
    ),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  min-height: 100vh;
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 12px;
  height: 44px;
  border-radius: 3px;
  background: var(--accent);
}

h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats {
  display: flex;
  gap: 12px;
}

.stat {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  text-align: right;
  min-width: 88px;
}

.stat-value {
  display: block;
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--accent);
  line-height: 1.1;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.main {
  display: grid;
  gap: 18px;
}

.scan-panel,
.list-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 1px 0 rgba(21, 36, 28, 0.03);
}

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.scan-input {
  width: 100%;
  padding: 16px 18px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--mono);
  font-size: 1.05rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.scan-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 122, 79, 0.15);
}

.scan-input.flash-ok {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.scan-input.flash-dup {
  border-color: var(--warn);
  background: var(--warn-soft);
}

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

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 18px;
}

.control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.control input[type="number"] {
  width: 72px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-input);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.95rem;
}

.control.check {
  user-select: none;
  cursor: pointer;
}

.control.check input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  margin-left: auto;
}

.btn.primary:hover:not(:disabled) {
  background: #0a6541;
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.btn.ghost:hover:not(:disabled) {
  border-color: var(--muted);
  background: var(--bg);
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 0;
}

.file-btn.is-busy {
  opacity: 0.55;
  pointer-events: none;
}

.btn.icon {
  padding: 4px 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
}

.btn.icon:hover {
  color: var(--danger);
}

.toast {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid #b7e2cb;
  color: var(--accent);
  font-size: 0.9rem;
}

.toast.warn {
  background: var(--warn-soft);
  border-color: #edd9a3;
  color: var(--warn);
}

.toast.error {
  background: #fdecea;
  border-color: #f3c0bb;
  color: var(--danger);
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.list-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.muted {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
}

.table-wrap {
  overflow: auto;
  max-height: min(52vh, 520px);
  border: 1px solid var(--line);
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th {
  position: sticky;
  top: 0;
  background: #eef4f0;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
}

td {
  font-family: var(--mono);
  word-break: break-all;
}

th.num,
td.num {
  width: 48px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

th.actions,
td.actions {
  width: 44px;
  text-align: right;
}

.empty-row td {
  text-align: center;
  color: var(--muted);
  font-family: var(--font);
  padding: 28px 12px;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr.new {
  animation: row-in 0.4s ease;
}

@keyframes row-in {
  from {
    background: var(--accent-soft);
  }
  to {
    background: transparent;
  }
}

@media (max-width: 640px) {
  .header {
    flex-direction: column;
  }

  .btn.primary {
    margin-left: 0;
    width: 100%;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .muted {
    max-width: 100%;
  }
}
