:root {
  --bg: #f4f7f6;
  --text: #17211f;
  --muted: #60716d;
  --line: #d8e1de;
  --panel: #ffffff;
  --primary: #0f7a6a;
  --primary-dark: #075e53;
  --accent: #bf6b21;
  --danger: #b72d42;
  --shadow: 0 10px 32px rgba(23, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-view,
.shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
}

.login-view {
  min-height: 100vh;
  display: grid;
  align-content: center;
  gap: 24px;
  padding: 40px 0;
}

.brand-block h1,
.topbar h1 {
  margin: 0;
  font-size: clamp(30px, 5vw, 54px);
  line-height: 1.05;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 30px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.subtitle {
  max-width: 620px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 18px;
}

.panel-heading span {
  color: var(--muted);
  font-size: 13px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-grid,
.cabinet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.user-card,
.cabinet-card,
.tab,
.identity {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  color: var(--text);
}

.user-card,
.cabinet-card {
  min-height: 84px;
  padding: 14px;
  text-align: left;
}

.user-card strong,
.cabinet-card strong {
  display: block;
  font-size: 17px;
  margin-bottom: 6px;
}

.user-card span,
.cabinet-card span {
  color: var(--muted);
  font-size: 13px;
}

.user-card:hover,
.cabinet-card:hover,
.cabinet-card.selected {
  border-color: var(--primary);
  outline: 3px solid rgba(15, 122, 106, 0.12);
}

.shell {
  padding: 24px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.identity {
  min-height: 44px;
  padding: 8px 12px;
  color: var(--primary-dark);
  font-weight: 700;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  min-height: 44px;
  font-weight: 700;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.workflow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  gap: 16px;
  margin-bottom: 16px;
}

.photo-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.photo-action {
  min-height: 150px;
  border: 2px dashed #a9b9b5;
  border-radius: 8px;
  background: #f8fbfa;
  display: grid;
  place-content: center;
  gap: 8px;
  text-align: center;
  padding: 18px;
  cursor: pointer;
}

.photo-action.camera {
  border-color: rgba(15, 122, 106, 0.55);
  background: #f2faf8;
}

.photo-action.gallery {
  border-color: rgba(191, 107, 33, 0.55);
  background: #fff8f1;
}

.photo-action.qr {
  border-color: rgba(15, 82, 122, 0.55);
  background: #f1f8fc;
}

.photo-action.label-scan,
.photo-action.label-album {
  min-height: 190px;
}

.photo-action.label-scan {
  border-color: rgba(15, 122, 106, 0.58);
  background: #f4fbf9;
}

.photo-action.label-album {
  border-color: rgba(191, 107, 33, 0.55);
  background: #fff8f1;
}

.photo-action input {
  display: none;
}

.qr-import {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.qr-import details {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.qr-import summary {
  color: var(--primary-dark);
  cursor: pointer;
  font-weight: 800;
  margin-bottom: 12px;
}

.scanner {
  display: grid;
  gap: 10px;
}

.scanner video {
  width: 100%;
  max-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101816;
  object-fit: cover;
}

.url-import {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: 10px;
}

.photo-cta {
  color: var(--primary-dark);
  font-weight: 800;
}

.photo-hint,
.notice {
  color: var(--muted);
  font-size: 13px;
}

.photo-preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 12px 0;
  background: #fff;
}

.photo-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.photo-thumb {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  object-fit: cover;
  width: 100%;
}

.photo-thumb-wrap {
  position: relative;
}

.photo-remove {
  position: absolute;
  right: 6px;
  top: 6px;
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  background: rgba(183, 45, 66, 0.92);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 9px;
}

.primary {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.secondary {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--primary-dark);
  font-weight: 800;
}

.field-button {
  align-self: end;
  width: 100%;
}

.required-field {
  color: var(--primary-dark);
}

.secondary.compact {
  min-height: 34px;
  padding: 0 12px;
  white-space: nowrap;
}

.strong-notice {
  margin-top: -4px;
  margin-bottom: 14px;
}

.primary:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.wide,
.full {
  width: 100%;
}

.reagent-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 122, 106, 0.12);
}

textarea {
  resize: vertical;
}

.full {
  grid-column: 1 / -1;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 12px;
}

.result-list,
.ranking-list {
  display: grid;
  gap: 10px;
}

.result-card {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--primary);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 8px 20px rgba(23, 33, 31, 0.05);
}

.result-main {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.result-card h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 10px;
}

.location-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #e7f2ef;
  color: var(--primary-dark);
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.low {
  background: #fff3e8;
  color: var(--accent);
}

.status-badge.empty {
  background: #fdecef;
  color: var(--danger);
}

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

.status-select {
  width: auto;
  min-width: 96px;
  min-height: 34px;
  padding: 4px 30px 4px 10px;
  border-radius: 8px;
  background: #eaf5f2;
  color: var(--primary-dark);
  font-weight: 700;
}

.status-select.low {
  background: #fff3e8;
  color: var(--accent);
}

.status-select.empty {
  background: #fdecef;
  color: var(--danger);
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.danger-button {
  min-height: 38px;
  border: 1px solid #f2b8c1;
  border-radius: 8px;
  background: #fff5f7;
  color: var(--danger);
  font-weight: 800;
  padding: 6px 12px;
}

.danger-button:disabled {
  opacity: 0.55;
}

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

.rank-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.rank-index {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #edf4f2;
  color: var(--primary-dark);
  font-weight: 900;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: min(420px, calc(100vw - 32px));
  border-radius: 8px;
  background: #17211f;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.success-banner {
  position: fixed;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  z-index: 20;
  width: min(420px, calc(100vw - 32px));
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  padding: 14px 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  .workflow,
  .reagent-form,
  .search-row,
  .photo-actions,
  .url-import {
    grid-template-columns: 1fr;
  }

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

  .tabs {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg);
    padding: 8px 0;
  }
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 24, 24, 0.42);
}

.modal-backdrop.hidden {
  display: none;
}

.success-dialog {
  width: min(420px, 100%);
  padding: 28px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(16, 24, 24, 0.26);
  text-align: center;
}

.success-dialog h2 {
  margin: 0 0 10px;
  font-size: 28px;
  color: #0f3d35;
}

.success-dialog p {
  margin: 0 0 24px;
  color: #5e706b;
  font-size: 17px;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.dialog-actions button {
  min-height: 48px;
}

@media (max-width: 520px) {
  .success-dialog {
    padding: 24px 20px;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }
}
