:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #657086;
  --line: #dfe4ef;
  --primary: #1266f1;
  --primary-dark: #0f55c8;
  --danger: #c92a2a;
  --ok: #0f7b4f;
  --warn: #9a5b00;
}

* { box-sizing: border-box; }

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

body.image-fullscreen-open {
  overflow: hidden;
  background: #05070d;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255,255,255,.96);
  border-bottom: 1px solid var(--line);
}

.brand {
  grid-column: 2;
  justify-self: center;
  max-width: 100%;
  color: var(--text);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  overflow-wrap: anywhere;
}

nav {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

a { color: var(--primary); }

.page {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.narrow {
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

h1, h2, h3 {
  margin: 0 0 12px;
  line-height: 1.25;
}

h1 { font-size: 24px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

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

.form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 650;
}

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

.checkbox-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
  font-weight: 650;
}

.checkbox-row input[type="checkbox"] {
  width: 20px;
  min-height: 20px;
  height: 20px;
  padding: 0;
}

button, .button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button.primary, .button.primary, .primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

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

.danger-button {
  border-color: #ffd0d0;
  color: var(--danger);
}

.small-button {
  min-height: 32px;
  padding: 5px 9px;
  font-size: 13px;
}

.link-button {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 500;
}

.inline { display: inline; }

.visually-hidden {
  position: fixed;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  left: -9999px;
  top: 0;
}

.notice {
  padding: 11px 12px;
  margin-bottom: 14px;
  border-radius: 8px;
  background: #eaf3ff;
  color: #0b4aa2;
}

.notice.danger, .danger-text {
  color: var(--danger);
  font-weight: 700;
}

.notice.danger {
  background: #fff1f1;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 23, 42, .34);
}

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

.modal-panel {
  width: min(100%, 720px);
  max-height: calc(100vh - 32px);
  overflow: auto;
  margin: 0;
}

.modal-block {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.compact-cards {
  grid-template-columns: 1fr;
}

.upload-menu {
  display: grid;
  gap: 10px;
}

.user-tabs-panel {
  display: grid;
  gap: 16px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1f5fb;
}

.tab-button {
  width: 100%;
  border-color: transparent;
  background: transparent;
}

.tab-button.active {
  border-color: var(--primary);
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(18, 102, 241, .14);
}

.tab-content {
  display: grid;
  gap: 12px;
}

.tab-content[hidden] {
  display: none;
}

.admin-tabs-panel {
  padding: 10px;
}

.admin-tab-content[hidden] {
  display: none;
}

.admin-contact-name {
  color: var(--text);
  font-style: italic;
  font-weight: 700;
}

.progress-banner {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stats div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.stats strong {
  display: block;
  font-size: 24px;
}

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

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

.storage-planning-row {
  margin-bottom: 14px;
}

.storage-summary div {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.storage-summary strong {
  display: block;
  font-size: 20px;
  overflow-wrap: anywhere;
}

.storage-summary span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.storage-summary small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.storage-edit-card {
  cursor: text;
}

.storage-edit-card input {
  margin-top: 8px;
}

.storage-edit-card.editing strong,
.storage-edit-card.editing small {
  display: none;
}

.storage-edit-card input[hidden] {
  display: none;
}

.storage-plan-form {
  max-width: none;
}

.storage-plan-form > label,
.storage-estimate-note,
.storage-submit,
.storage-submit-note {
  width: 100%;
}

.storage-submit {
  display: flex;
}

.storage-submit-note,
.storage-estimate-note {
  margin: 0;
}

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

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.card.compact p {
  margin: 4px 0 0;
}

.card-head, .split {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.countdown {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

.countdown.expired {
  color: var(--danger);
  background: #fff1f1;
}

.compact-form {
  max-width: 360px;
}

.search-form {
  margin-bottom: 14px;
}

.search-inline {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.search-inline label {
  font-weight: 700;
}

.search-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
  width: 100%;
}

.search-row input {
  flex: 1 1 auto;
  min-width: 0;
}

.search-row button {
  flex: 0 0 auto;
  min-width: 86px;
}

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

  .brand,
  nav {
    grid-column: 1;
    justify-self: center;
  }
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.admin-primary-actions {
  margin-top: 0;
  justify-content: flex-end;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

.status-uploaded, .status-issued { color: var(--warn); background: #fff7e6; }
.status-claimed, .status-result_uploaded { color: #175cd3; background: #eaf3ff; }
.status-completed, .status-received_deleted, .status-sent { color: var(--ok); background: #e9f8f0; }
.status-failed { color: var(--danger); background: #fff1f1; }

.collab-body {
  margin: 0;
  overflow: hidden;
  background: #05070d;
  color: #fff;
  min-height: 100dvh;
}

.collab-stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: #05070d;
}

.collab-track {
  display: flex;
  width: max-content;
  height: 100%;
  transition: transform .24s ease;
  touch-action: pan-y;
}

.collab-slide {
  flex: 0 0 100vw;
  width: 100vw;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: 0;
}

.collab-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.collab-badge {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  z-index: 3;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .76);
  color: #fff;
  font-weight: 800;
  opacity: 0;
  transition: opacity .18s ease;
}

.collab-badge.visible {
  opacity: 1;
}

.collab-back {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  z-index: 3;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  background: rgba(15, 23, 42, .64);
  border-radius: 999px;
  padding: 7px 12px;
  opacity: 0;
  transition: opacity .18s ease;
  pointer-events: none;
}

.collab-back.visible {
  opacity: 1;
  pointer-events: auto;
}

.collab-upload-slide {
  align-items: stretch;
}

.collab-upload-panel {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  background: #05070d;
}

.collab-image-pane {
  min-height: 0;
  display: grid;
  place-items: center;
}

.collab-image-pane img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.collab-upload-controls {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: #fff;
  color: var(--text);
}

.collab-upload-controls h1 {
  margin-bottom: 0;
}

.preview {
  display: block;
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f1f5f9;
}

.zoomable-preview {
  cursor: zoom-in;
}

.zoomable-preview.image-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100vw;
  height: 100dvh;
  max-height: none;
  object-fit: contain;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  border: 0;
  border-radius: 0;
  background: #05070d;
  cursor: zoom-out;
}

.compare {
  display: grid;
  gap: 16px;
}

.credential {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.credential p {
  margin: 0;
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
}

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

.credential strong {
  font-size: 28px;
  overflow-wrap: anywhere;
}

.confirm-box {
  margin-top: 14px;
}

@media (min-width: 720px) {
  .page { padding: 24px; }
  .stats { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .storage-primary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .storage-planning-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compare { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .collab-upload-panel {
    grid-template-columns: minmax(0, 1fr) clamp(360px, 30vw, 460px);
    grid-template-rows: 1fr;
  }
  .collab-image-pane {
    padding: 24px;
  }
  .collab-image-pane img {
    max-width: 100%;
    max-height: calc(100vh - 48px);
    border-radius: 8px;
    background: #0f172a;
  }
  .collab-upload-controls {
    align-content: center;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow-y: auto;
    padding: 32px;
    box-shadow: -1px 0 0 rgba(255,255,255,.08), -18px 0 38px rgba(0,0,0,.22);
  }
  .collab-upload-controls .upload-menu form,
  .collab-upload-controls .upload-menu button,
  .collab-upload-controls .confirm-box button {
    width: 100%;
  }
  h1 { font-size: 30px; }
}
