:root {
  --bg: #101418;
  --card: #1a2027;
  --border: #2b333d;
  --text: #e8edf2;
  --muted: #8b98a5;
  --accent: #35c26b;
  --accent-press: #2aa257;
  --danger: #e5534b;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
}

h1 { font-size: 1.2rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 10px; }

main {
  padding: 0 14px 40px;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.row { display: flex; gap: 10px; align-items: center; }
.row.spread { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.row input { flex: 1; min-width: 0; }

.muted { color: var(--muted); font-size: 0.85rem; }
.hidden { display: none !important; }
.req { color: var(--danger); }

button {
  font: inherit;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  color: var(--text);
}

button.primary { background: var(--accent); color: #06130b; font-weight: 600; }
button.primary:active { background: var(--accent-press); }
button.secondary { background: #2b333d; }
button.big { width: 100%; padding: 16px; font-size: 1.05rem; margin-top: 12px; }

.icon-btn {
  background: transparent;
  font-size: 1.4rem;
  padding: 6px 10px;
  line-height: 1;
}

.scan-state {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
}

.scan-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.scan-state[data-state="scanning"] .scan-dot {
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}

.scan-state[data-state="error"] .scan-dot { background: var(--danger); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(53, 194, 107, 0.55); }
  50% { box-shadow: 0 0 0 9px rgba(53, 194, 107, 0); }
}

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

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 12px 0 4px;
}

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #12181e;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

input[readonly] { color: var(--muted); }
textarea { resize: vertical; }

/* status badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.badge.new { background: rgba(77, 163, 255, 0.16); color: #4da3ff; }
.badge.inuse { background: rgba(53, 194, 107, 0.16); color: var(--accent); }
.badge.retired { background: rgba(229, 83, 75, 0.16); color: var(--danger); }

/* combobox: free-text input + dropdown of existing values */
.combo { position: relative; }

.combo input { padding-right: 40px; }

.combo-toggle {
  position: absolute;
  right: 3px;
  top: 3px;
  bottom: 3px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  border-radius: 6px;
  font-size: 0.9rem;
}

.combo-toggle:active { color: var(--text); }

.combo-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #12181e;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 180px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.combo-list li {
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.combo-list li:hover,
.combo-list li:active { background: #222a33; }

/* manufactured / deployed / end-of-life side by side */
.dates-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0 10px;
}

.dates-grid input[type="date"] {
  min-width: 0;
  padding: 10px 8px;
  font-size: 0.9rem;
}

/* create mode: only ID, version, manufactured, notes */
form.create-mode #personField,
form.create-mode .lifecycle { display: none; }

form.create-mode .dates-grid { grid-template-columns: 1fr; }

.table-wrap { overflow-x: auto; }

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

th, td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th { color: var(--muted); font-weight: 500; }

tbody tr { cursor: pointer; }
tbody tr:active { background: #222a33; }

dialog {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* padding lives on the form so backdrop-click detection (e.target === dialog)
     never fires for clicks inside the visible panel */
  padding: 0;
  width: min(440px, calc(100vw - 32px));
  margin: auto;
}

dialog > form { padding: 20px; }

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #262f39;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.9rem;
  max-width: calc(100vw - 40px);
  z-index: 50;
}

.toast.error { border-color: var(--danger); }
