:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --blue: #2563eb;
  --amber: #d97706;
  --rose: #e11d48;
  --shadow: 0 20px 45px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

body.locked {
  overflow: hidden;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #121826;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.28);
}

.login-card .brand {
  margin-bottom: 2px;
  color: var(--ink);
}

.login-card .brand p {
  color: var(--muted);
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--rose);
  font-size: 13px;
  font-weight: 700;
}

.admin-only {
  display: none !important;
}

body.role-admin .admin-only {
  display: inline-flex !important;
}

body.role-admin button.admin-only {
  display: inline-grid !important;
}

.logout-button {
  width: fit-content;
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  text-align: left;
}

.logout-button:hover {
  color: #fff;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #121826;
  color: #fff;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: #0f766e;
  font-weight: 800;
}

.brand h1,
.topbar h2,
.section-heading h3,
.panel h3,
.drawer-header h3,
.dialog-header h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p,
.side-panel small {
  margin: 3px 0 0;
  color: rgba(255, 255, 255, 0.64);
}

.drawer-body.empty p {
  margin: 0;
  color: var(--muted);
}

.nav-list {
  display: grid;
  gap: 6px;
  margin-bottom: 28px;
}

.nav-item {
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, 0.72);
  text-align: left;
}

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

.side-panel {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}

.panel-label,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.content {
  min-width: 0;
  padding: 28px;
}

.topbar,
.section-heading,
.panel-header,
.drawer-header,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 24px;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 30px;
}

.topbar-actions,
.filters,
.drawer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 6px;
  transition: 0.18s ease;
}

.primary-button {
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

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

.ghost-button {
  padding: 10px 13px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.ghost-button:hover,
.icon-button:hover {
  border-color: #b7c3d4;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: var(--surface);
  border-color: var(--line);
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.file-trigger {
  position: relative;
  overflow: hidden;
}

.file-trigger input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.section {
  margin-bottom: 26px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

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

.metric span {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(280px, 0.9fr);
  gap: 14px;
}

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

.bar-list,
.location-list,
.legend,
.timeline,
.record-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 92px 1fr 34px;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  background: #e8edf4;
  border-radius: 999px;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}

.location-item,
.record-item {
  display: grid;
  gap: 4px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.record-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.delete-record {
  min-width: 32px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid #ffd0d9;
  border-radius: 6px;
  background: #fff7f9;
  color: var(--rose);
  font-weight: 800;
}

.location-item:last-child,
.record-item:last-child {
  border-bottom: 0;
}

.location-item strong,
.record-item strong {
  font-size: 14px;
}

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

.status-wrap {
  display: grid;
  grid-template-columns: 126px 1fr;
  align-items: center;
  gap: 18px;
}

.donut {
  width: 126px;
  height: 126px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) 0deg 360deg);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 24px;
  border-radius: inherit;
  background: var(--surface);
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 8px;
  border-radius: 50%;
}

.section-heading {
  margin-bottom: 12px;
}

.filters input,
.filters select,
label input,
label select,
label textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.filters input,
.filters select {
  height: 40px;
  padding: 0 12px;
}

.filters input {
  width: 250px;
}

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

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

th {
  background: #eef3f8;
  color: #344054;
  font-size: 12px;
  text-transform: uppercase;
}

tr:hover td {
  background: #f8fafc;
}

.sn-link {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  padding: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e7f7f4;
  color: #0f766e;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.warn {
  background: #fff4df;
  color: var(--amber);
}

.badge.risk {
  background: #ffe8ee;
  color: var(--rose);
}

.detail-drawer {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 22px;
  background: #fbfcfe;
  border-left: 1px solid var(--line);
}

.drawer-header {
  margin-bottom: 14px;
}

.drawer-body.empty {
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.hidden {
  display: none !important;
}

.detail-card,
.movement-form {
  padding: 16px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

dl {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  margin: 0;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  word-break: break-word;
}

.movement-form h4 {
  margin: 0 0 12px;
}

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

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

label input,
label select,
label textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  font-weight: 400;
}

label textarea {
  resize: vertical;
}

.movement-form > label {
  margin: 12px 0;
}

.full {
  width: 100%;
}

dialog {
  width: min(680px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  box-shadow: 0 32px 80px rgba(23, 32, 51, 0.28);
}

dialog::backdrop {
  background: rgba(18, 24, 38, 0.48);
}

.dialog-form {
  display: grid;
  gap: 18px;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
  padding: 0;
}

@media (max-width: 1240px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .detail-drawer {
    grid-column: 1 / -1;
    position: relative;
    height: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .content {
    padding: 18px;
  }

  .topbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .dashboard-grid,
  .form-grid,
  .status-wrap {
    grid-template-columns: 1fr;
  }

  .filters,
  .filters input,
  .filters select,
  .topbar-actions {
    width: 100%;
  }

  .topbar-actions > * {
    flex: 1 1 auto;
  }
}
