:root {
  color-scheme: light;
  --bg: #eef3ef;
  --surface: #ffffff;
  --surface-soft: #f7faf8;
  --ink: #15211a;
  --muted: #68786e;
  --line: #d7e0da;
  --accent: #176d58;
  --accent-dark: #0d5744;
  --accent-soft: #e3f1eb;
  --danger: #b23d43;
  --danger-soft: #fff0f1;
  --amber: #a9681c;
  --shadow: 0 20px 55px rgba(20, 37, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(238, 243, 239, 0.86)),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  transition:
    transform 140ms ease,
    box-shadow 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 440px);
  gap: 24px;
  min-height: 100vh;
  padding: 26px;
}

.workspace,
.registry {
  min-width: 0;
}

.topbar,
.registry-header,
.panel-header,
.brand-block,
.registry-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.topbar {
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: 0 12px 28px rgba(21, 33, 26, 0.2);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.16rem;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 0;
  font-size: 1.65rem;
  line-height: 1.08;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.summary-strip div {
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.summary-strip span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.summary-strip strong {
  display: block;
  overflow-wrap: anywhere;
}

.panel,
.registry {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(215, 224, 218, 0.95);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.panel-header p {
  margin-bottom: 0;
  color: var(--muted);
}

.status-pill,
.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill {
  padding: 0 14px;
}

.status-pill.online {
  border-color: #a5d0bf;
  background: #effaf5;
  color: var(--accent-dark);
}

.status-pill.error {
  border-color: #e8b8bd;
  background: var(--danger-soft);
  color: var(--danger);
}

.count-badge {
  min-width: 42px;
  padding: 0 12px;
}

.ghost-button,
.primary-button,
.danger-button,
.small-danger-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 850;
}

.ghost-button {
  background: var(--surface-soft);
  border-color: var(--line);
  color: var(--ink);
}

.primary-button {
  width: 100%;
  min-height: 50px;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 14px 26px rgba(23, 109, 88, 0.22);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.primary-button:disabled,
.danger-button:disabled {
  cursor: wait;
  opacity: 0.7;
  transform: none;
}

.danger-button,
.small-danger-button {
  background: var(--danger-soft);
  border-color: #efc5c9;
  color: var(--danger);
}

.small-danger-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.dropzone {
  display: grid;
  gap: 16px;
  margin-top: 18px;
}

.dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.mode-tab {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

.mode-tab.active {
  background: var(--surface);
  color: var(--accent-dark);
  box-shadow: 0 8px 18px rgba(20, 37, 28, 0.1);
}

.slides {
  display: grid;
}

.input-slide {
  display: none;
}

.input-slide.active {
  display: block;
}

.drop-label {
  display: grid;
  place-items: center;
  min-height: 285px;
  border: 1.5px dashed #adc1b6;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(240, 247, 243, 0.92)),
    var(--surface-soft);
  cursor: pointer;
  text-align: center;
  padding: 32px;
}

.drop-label:hover {
  border-color: var(--accent);
  background: #f5fbf8;
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin-bottom: 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 2rem;
  font-weight: 600;
  line-height: 1;
  box-shadow: 0 14px 28px rgba(23, 109, 88, 0.2);
}

.drop-title {
  display: block;
  font-size: 1.25rem;
  font-weight: 900;
}

.drop-copy {
  display: block;
  max-width: 100%;
  margin-top: 8px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.camera-panel {
  display: grid;
  gap: 12px;
}

.camera-panel video {
  width: 100%;
  background: #121a16;
  border: 1px solid var(--line);
  border-radius: 8px;
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

.camera-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.capture-button {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  border: 4px solid #ffffff;
  border-radius: 999px;
  background: var(--accent);
  box-shadow:
    0 0 0 1px var(--line),
    0 16px 28px rgba(23, 109, 88, 0.22);
  cursor: pointer;
  padding: 0;
}

.capture-button span {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: #ffffff;
}

.camera-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

.camera-open {
  overflow: hidden;
}

.camera-open #cameraSlide.input-slide.active {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  padding: 0;
  background: #050807;
}

.camera-open .camera-panel {
  min-height: 100vh;
  min-height: 100dvh;
}

.camera-open .camera-panel video {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border: 0;
  border-radius: 0;
  aspect-ratio: auto;
  object-fit: cover;
}

.camera-open .camera-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 9002;
  padding: 0 18px;
}

.camera-open .capture-button {
  width: 86px;
  height: 86px;
  border-width: 5px;
  background: rgba(255, 255, 255, 0.22);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.32),
    0 20px 48px rgba(0, 0, 0, 0.42);
}

.camera-open .capture-button span {
  width: 54px;
  height: 54px;
}

.camera-open #closeCameraButton {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  right: 18px;
  z-index: 9003;
  min-height: 46px;
  background: rgba(255, 255, 255, 0.9);
  border-color: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.28);
}

.camera-open .camera-note {
  position: fixed;
  left: 18px;
  right: 18px;
  top: max(20px, env(safe-area-inset-top));
  z-index: 9001;
  max-width: calc(100vw - 120px);
  margin: 0;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 850;
  text-align: left;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

.preview-section {
  display: grid;
  gap: 8px;
}

.preview-heading {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.preview-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121a16;
  aspect-ratio: 16 / 9;
}

.preview-wrap img,
.preview-wrap video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.preview-wrap img:not([hidden]) + video:not([hidden]) {
  position: absolute;
  inset: 0;
  background: transparent;
}

.preview-message {
  position: absolute;
  inset: auto 14px 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(18, 26, 22, 0.82);
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 750;
}

.result-panel {
  display: grid;
  gap: 18px;
  margin-top: 18px;
  padding: 18px;
  border-radius: 8px;
  background: #edf8f3;
  border: 1px solid #bfdbd0;
}

.result-panel.new {
  background: #fff8ed;
  border-color: #ebd1aa;
}

.result-panel.error {
  background: var(--danger-soft);
  border-color: #efc5c9;
}

.result-label {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.result-grid div {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

dt {
  color: var(--muted);
  font-size: 0.73rem;
  font-weight: 850;
  text-transform: uppercase;
}

dd {
  margin: 5px 0 0;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.registry {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 52px);
  padding: 18px;
}

.search-row {
  margin: 16px 0 10px;
}

.search-row input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  background: var(--surface-soft);
  color: var(--ink);
}

.search-row input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(23, 109, 88, 0.12);
}

.db-path {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.cow-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 4px;
}

.cow-card {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 102px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-soft);
}

.cow-card:hover {
  border-color: #b5c8bd;
  background: #ffffff;
}

.cow-thumb {
  display: grid;
  place-items: center;
  width: 82px;
  height: 78px;
  overflow: hidden;
  border-radius: 8px;
  background: #e9f0ec;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.cow-thumb img,
.cow-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cow-meta {
  min-width: 0;
}

.cow-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.cow-id {
  margin-bottom: 8px;
  font-size: 1.08rem;
  font-weight: 950;
  overflow-wrap: anywhere;
}

.cow-detail {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.empty-state {
  margin: 28px 0 0;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 48px));
  padding: 14px 16px;
  border-radius: 8px;
  background: #15211a;
  color: #ffffff;
  box-shadow: var(--shadow);
  font-weight: 750;
}

.modal-open {
  overflow: hidden;
}

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

.result-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 22px;
  width: 100vw;
  height: 100vh;
  min-height: 100vh;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 17, 13, 0.48);
  backdrop-filter: blur(3px);
}

.modal-card {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  width: min(520px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 26px 80px rgba(9, 17, 13, 0.28);
}

.result-modal.new .modal-card {
  border-color: #ebd1aa;
}

.result-modal.existing .modal-card {
  border-color: #efb4ba;
}

.result-modal.warning .modal-card {
  border-color: #eac18f;
}

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

.modal-header h2 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 2.65rem);
  line-height: 1.04;
}

.modal-kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 900;
  text-transform: uppercase;
}

.result-modal.new .modal-kicker {
  color: var(--amber);
}

.result-modal.warning .modal-kicker {
  color: var(--amber);
}

.result-modal.existing .modal-kicker,
.result-modal.existing .modal-header h2,
.result-modal.existing .modal-id-block strong {
  color: var(--danger);
}

.result-modal.existing .modal-id-block {
  background: var(--danger-soft);
}

.modal-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  font-size: 2rem;
  line-height: 1;
}

.modal-id-block {
  display: grid;
  gap: 8px;
  padding: 22px;
  border-radius: 8px;
  background: var(--accent-soft);
}

.modal-id-block[hidden] {
  display: none;
}

.result-modal.new .modal-id-block {
  background: #fff7ea;
}

.modal-id-block span {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 900;
  text-transform: uppercase;
}

.modal-id-block strong {
  font-size: clamp(2.4rem, 8vw, 4rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

@media (max-width: 960px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .registry {
    max-height: none;
  }
}

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

  .topbar,
  .registry-header,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-strip,
  .camera-actions,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .panel,
  .registry {
    padding: 16px;
  }

  .brand-block {
    align-items: flex-start;
  }
}
