:root {
  color-scheme: light;
  --bg: #f6f8f8;
  --surface: #ffffff;
  --text: #172024;
  --muted: #66757c;
  --line: #dbe3e6;
  --accent: #047f86;
  --accent-dark: #02656b;
  --soft: #e7f5f5;
  --warn: #b35412;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(100%, 860px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--surface);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 12px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.topbar h1 {
  grid-column: 2;
  margin: 0;
  text-align: center;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 760;
}

.icon-button,
.mic-button {
  display: grid;
  place-items: center;
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 40px;
  height: 40px;
  background: transparent;
  color: var(--muted);
  font-size: 32px;
  line-height: 1;
}

.nav-icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}

.nav-icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-icon-button:hover,
.nav-icon-button:focus-visible {
  background: var(--soft);
}

.search-panel {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.search-box {
  display: grid;
  grid-template-columns: 30px 1fr 52px auto;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 8px 10px 8px 16px;
  border: 1px solid #cbd6da;
  border-radius: 8px;
  background: #fff;
}

.search-box > svg,
.mic-button svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search-box > svg {
  color: #1e292e;
}

.search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 18px;
}

.search-box input::placeholder {
  color: #9aa5aa;
}

.mic-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}

.mic-button.is-listening {
  background: var(--warn);
}

.mic-button.is-unavailable {
  background: #829197;
}

.clear-search {
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: #eef3f4;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 18px;
  left: 16px;
  z-index: 20;
  max-width: 560px;
  margin: 0 auto;
  padding: 13px 16px;
  border-radius: 8px;
  background: #172024;
  color: #fff;
  font-size: 15px;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 14px 36px rgba(23, 32, 36, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 16px;
  border-bottom: 1px solid var(--line);
}

.wide-action {
  width: 100%;
  min-height: 44px;
  margin-top: 14px;
  border: 1px solid #c7d8be;
  border-radius: 8px;
  background: #f4faef;
  color: #4f6f18;
  font-size: 16px;
  font-weight: 760;
  cursor: pointer;
}

.tab {
  position: relative;
  min-height: 46px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}

.tab.is-active {
  color: var(--accent);
}

.tab.is-active::after {
  content: "";
  position: absolute;
  right: 18px;
  bottom: -1px;
  left: 18px;
  height: 3px;
  background: var(--accent);
}

.result-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.result-summary strong {
  color: var(--accent);
}

.result-summary select {
  max-width: 45%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 15px;
}

.results {
  display: grid;
}

.result-row {
  display: grid;
  grid-template-columns: 74px 62px minmax(0, 1fr);
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  align-items: start;
  cursor: pointer;
}

.result-row.is-out {
  background: #f2f4f5;
  color: #78858b;
}

.result-row.is-out .cabinet,
.result-row.is-out .level,
.result-row.is-out .item-name {
  color: #758187;
}

.location {
  display: grid;
  gap: 5px;
}

.cabinet {
  color: var(--accent);
  font-size: 16px;
  font-weight: 760;
}

.level {
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.item-name {
  margin: 0 0 6px;
  font-size: 18px;
  line-height: 1.35;
  font-weight: 720;
}

.item-code {
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.stock-state {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 760;
}

.stock-state.is-available {
  color: #4f6f18;
}

.stock-state.is-empty {
  color: #9a4a1a;
}

.open-hint {
  display: inline-block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.take-button,
.put-button {
  margin-top: 10px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--accent);
  font-size: 15px;
  font-weight: 760;
  cursor: pointer;
}

.put-button {
  margin-left: 6px;
  color: #4f6f18;
}

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

.empty strong {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 20px;
}

mark {
  padding: 0 2px;
  border-radius: 3px;
  background: var(--soft);
  color: var(--accent-dark);
}

.admin-dialog,
.take-dialog {
  width: min(920px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 24px 70px rgba(23, 32, 36, 0.28);
}

.admin-dialog::backdrop,
.take-dialog::backdrop {
  background: rgba(23, 32, 36, 0.42);
}

.admin-card,
.take-card {
  display: grid;
  max-height: calc(100vh - 24px);
}

.admin-head {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.admin-head h2 {
  grid-column: 2;
  margin: 0;
  text-align: center;
  font-size: 22px;
}

.admin-head .icon-button {
  grid-column: 3;
}

.login-panel,
.editor-panel {
  padding: 16px;
}

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

.login-panel input,
.editor-grid input,
.editor-grid select,
.admin-search {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid #cbd6da;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: 0;
}

.editor-grid {
  display: grid;
  grid-template-columns: 120px 140px 1fr 1.4fr;
  gap: 12px;
}

.editor-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 6px;
  font-weight: 760;
  cursor: pointer;
}

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

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.danger-button {
  border: 1px solid #d7a08a;
  background: #fff6f1;
  color: #a43f14;
}

.danger-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.admin-search {
  margin-bottom: 12px;
}

.admin-list {
  display: grid;
  max-height: min(48vh, 440px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 120px;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.admin-row:last-child {
  border-bottom: 0;
}

.admin-row.is-selected {
  background: var(--soft);
}

.admin-row span,
.admin-row small {
  color: var(--muted);
}

.admin-row strong,
.admin-row small {
  overflow-wrap: anywhere;
}

.records-title {
  margin: 18px 0 10px;
  font-size: 18px;
}

.record-list {
  display: grid;
  max-height: min(44vh, 420px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.record-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.record-row:last-child {
  border-bottom: 0;
}

.record-row.is-returned {
  background: #f7fafa;
  color: var(--muted);
}

.record-line {
  min-width: 0;
  overflow: hidden;
}

.record-row span,
.empty-record {
  color: var(--muted);
  font-size: 13px;
}

.record-line span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

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

.record-row .return-button {
  min-height: 30px;
  padding: 0 8px;
  font-size: 13px;
}

.take-dialog {
  width: min(480px, calc(100vw - 24px));
}

.item-dialog {
  width: min(720px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 24px 70px rgba(23, 32, 36, 0.28);
}

.item-dialog::backdrop {
  background: rgba(23, 32, 36, 0.42);
}

.item-detail-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.item-detail-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.item-detail-meta div,
.item-detail-stock {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.item-detail-meta span,
.item-detail-stock span {
  color: var(--muted);
  font-size: 13px;
}

.item-detail-stock.is-available {
  border-color: #c7d8be;
  background: #f4faef;
  color: #4f6f18;
}

.item-detail-stock.is-empty {
  border-color: #e0b08f;
  background: #fff6f1;
  color: #9a4a1a;
}

.item-detail-actions {
  display: flex;
  gap: 10px;
}

.item-record-list {
  max-height: min(42vh, 360px);
}

.take-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.take-item {
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent-dark);
  font-weight: 760;
}

.take-body label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.take-body input,
.take-body select {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid #cbd6da;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

@media (max-width: 520px) {
  .topbar {
    padding-top: 14px;
  }

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

  .result-row {
    grid-template-columns: 68px 52px minmax(0, 1fr);
    gap: 10px;
    padding: 15px 14px;
  }

  .search-panel,
  .result-summary {
    padding-right: 14px;
    padding-left: 14px;
  }

  .item-name {
    font-size: 17px;
  }

  .search-box {
    grid-template-columns: 30px 1fr 48px;
  }

  .clear-search {
    grid-column: 2 / 4;
  }

  .editor-grid {
    grid-template-columns: 1fr 1fr;
  }

  .editor-grid label:nth-child(5) {
    grid-column: 1 / -1;
  }

  .item-detail-meta {
    grid-template-columns: 1fr;
  }

  .admin-row {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .admin-row small {
    grid-column: 2;
  }

  .record-row {
    grid-template-columns: minmax(0, 1fr) 64px;
  }

  .record-row .return-button {
    grid-column: 2;
  }
}
