:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #f8fafc;
  --line: #dbe3ea;
  --line-strong: #c8d3dd;
  --text: #17202a;
  --muted: #64748b;
  --primary: #176b87;
  --primary-dark: #0f536b;
  --primary-soft: #e5f3f7;
  --secondary: #2f6f4e;
  --secondary-soft: #e7f4ec;
  --warning: #b77928;
  --warning-soft: #fff4df;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --purple: #6d4aff;
  --purple-soft: #f0edff;
  --shadow: 0 18px 55px rgba(15, 35, 52, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.login-mode {
  display: block;
}

.boot-screen,
.login-layout {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.boot-screen {
  color: var(--muted);
  gap: 14px;
}

.boot-mark,
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.brand-mark.large {
  width: 54px;
  height: 54px;
  font-size: 20px;
}

.login-layout {
  background:
    linear-gradient(180deg, rgba(23, 107, 135, 0.08), rgba(47, 111, 78, 0.04)),
    var(--bg);
}

.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.login-brand h1 {
  margin: 0;
  font-size: 24px;
}

.login-brand p {
  margin: 4px 0 0;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 16px;
}

.login-form label,
.field {
  display: grid;
  gap: 7px;
}

.login-form label.checkbox-field,
.checkbox-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #334155;
  font-weight: 650;
  justify-self: start;
}

.checkbox-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
  padding: 0;
  border-radius: 4px;
  box-shadow: none;
}

.checkbox-field span {
  margin: 0;
}

.login-form label span,
.field span {
  color: #334155;
  font-weight: 650;
}

.field em {
  color: var(--danger);
  font-style: normal;
  margin-left: 3px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14);
}

.form-hint,
.detail-muted {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.sidebar {
  min-height: 100vh;
  background: #102536;
  color: #dbeafe;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px;
}

.brand strong {
  display: block;
  color: #fff;
  font-size: 17px;
}

.brand span {
  display: block;
  color: #b8c9d9;
  font-size: 12px;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 5px;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 11px 12px;
  background: transparent;
  color: #dbeafe;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.main-area {
  min-width: 0;
  padding: 24px;
}

.topbar {
  min-height: 76px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

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

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-chip {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.toolbar-surface,
.table-surface {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toolbar-surface {
  padding: 16px;
  margin-bottom: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.filter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
}

.filter-grid .field {
  flex: 0 1 210px;
  width: 210px;
}

.filter-actions,
.table-actions,
.pager-controls,
.action-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.table-actions {
  justify-content: flex-end;
  align-self: end;
}

.filter-actions {
  flex: 0 0 auto;
}

.filter-actions .button,
.table-actions .button {
  min-height: 38px;
}

.table-surface {
  overflow: hidden;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: #475569;
  font-size: 12px;
  font-weight: 750;
  background: var(--surface-strong);
}

tbody tr:hover {
  background: #fbfdff;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.actions-cell {
  min-width: 150px;
  text-align: right;
  white-space: nowrap;
}

.action-buttons {
  justify-content: flex-end;
}

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 700;
  color: var(--text);
  background: #fff;
  transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(15, 35, 52, 0.1);
}

.button:disabled {
  opacity: 0.52;
}

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

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

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

.button-ghost {
  border-color: var(--line-strong);
  color: #334155;
}

.button-warning {
  color: #8a4f12;
  border-color: #e8c279;
  background: var(--warning-soft);
}

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

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

.full-width {
  width: 100%;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.tag {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.tag-green {
  color: #1e6b3b;
  background: var(--secondary-soft);
}

.tag-red {
  color: var(--danger);
  background: var(--danger-soft);
}

.tag-blue {
  color: #176b87;
  background: var(--primary-soft);
}

.tag-gold {
  color: #8a4f12;
  background: var(--warning-soft);
}

.tag-purple {
  color: var(--purple);
  background: var(--purple-soft);
}

.tag-slate {
  color: #475569;
  background: #eef2f7;
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
}

.truncate {
  max-width: 240px;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.stacked {
  display: grid;
  gap: 4px;
}

.stacked small {
  color: var(--muted);
}

.thumb {
  width: 56px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  display: grid;
  place-items: center;
  background: #edf7f7;
  color: var(--primary);
  font-weight: 800;
  overflow: hidden;
}

.thumb-clickable {
  cursor: pointer;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-fallback {
  width: 100%;
  height: 100%;
  display: none;
  place-items: center;
  font-size: 12px;
}

.image-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 132px;
}

.upload-control {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.upload-button {
  position: relative;
  min-height: 38px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--primary);
  font-weight: 700;
  cursor: pointer;
}

.upload-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.image-upload-preview {
  min-height: 116px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #f8fafc;
  color: var(--muted);
}

.image-upload-preview img {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  display: block;
}

.image-preview-modal {
  width: min(900px, 100%);
}

.image-preview-body {
  padding: 18px;
  display: grid;
  place-items: center;
  background: #f8fafc;
}

.image-preview-body img {
  max-width: 100%;
  max-height: min(72vh, 720px);
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.method-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 6px;
  padding: 2px 8px;
  background: #17202a;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.number-positive {
  color: #1e6b3b;
  font-weight: 800;
}

.number-negative {
  color: #a05a13;
  font-weight: 800;
}

.state-box {
  min-height: 240px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

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

.loader {
  width: 30px;
  height: 30px;
  border: 3px solid #dce7ee;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.pagination {
  min-height: 58px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.pager-controls select {
  width: auto;
  min-width: 98px;
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  min-width: 180px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-weight: 750;
}

.toast-success {
  background: #ecfdf3;
  color: #17663a;
  border: 1px solid #b8e5c8;
}

.toast-error {
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #f4b8b2;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.48);
}

.modal {
  width: min(760px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  overflow: auto;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-form {
  padding: 18px 20px 20px;
}

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

.field-wide {
  grid-column: 1 / -1;
}

.form-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px 20px;
}

.detail-grid {
  padding: 18px 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-item {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-strong);
}

.detail-item > span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.table-link {
  font-weight: 750;
}

@media (max-width: 1080px) {
  .toolbar-surface {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    min-height: auto;
    padding: 14px;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav-item {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .main-area {
    padding: 16px;
  }

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

  .topbar-actions,
  .table-actions,
  .pager-controls {
    justify-content: flex-start;
  }

  .toolbar-surface,
  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .filter-grid {
    align-items: stretch;
  }

  .filter-grid .field {
    width: 100%;
    flex: 1 1 100%;
  }

  .filter-actions {
    width: 100%;
  }

  .modal-backdrop {
    padding: 12px;
  }
}

@media (max-width: 560px) {
  .login-panel {
    padding: 24px;
  }

  .toolbar-surface,
  .table-surface {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    margin-left: -16px;
    margin-right: -16px;
  }

  .toolbar-surface {
    padding: 14px 16px;
  }

  .button {
    width: 100%;
  }

  .actions-cell .button,
  .pager-controls .button,
  .topbar-actions .button,
  .table-actions .button,
  .modal-footer .button {
    width: auto;
  }
}
