:root {
  --ink: #17221e;
  --muted: #69746f;
  --line: #dfe5e1;
  --soft: #f3f6f4;
  --paper: #ffffff;
  --forest: #20382f;
  --green: #2e6b52;
  --green-soft: #e8f2ed;
  --amber: #a05b20;
  --amber-soft: #f9ede1;
  --red: #a33a36;
  --red-soft: #faecea;
  --shadow: 0 16px 42px rgba(25, 45, 37, 0.16);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

* { box-sizing: border-box; }

body { margin: 0; min-width: 320px; background: var(--soft); }

button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.login-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, 520px) minmax(0, 1fr); background: var(--forest); }
.login-panel { min-height: 100vh; padding: 52px clamp(36px, 6vw, 76px); display: flex; flex-direction: column; justify-content: center; background: white; }
.login-brand { position: absolute; top: 34px; display: flex; align-items: center; gap: 12px; }
.login-brand strong, .login-brand span { display: block; }
.login-brand span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.login-panel h1 { font-size: 36px; }
.login-copy { max-width: 360px; margin: 12px 0 28px; color: var(--muted); font-size: 13px; line-height: 1.8; }
.login-panel form { display: grid; gap: 17px; }
.login-submit { width: 100%; margin-top: 4px; }
.server-state { margin-top: 24px; color: var(--muted); }
.server-state .status-dot { background: var(--green); }
.login-art { position: relative; overflow: hidden; display: grid; place-items: center; align-content: center; background: #193027; color: white; }
.login-art::before { content: ""; position: absolute; inset: 0; opacity: .08; background-image: linear-gradient(#fff 1px, transparent 1px), linear-gradient(90deg, #fff 1px, transparent 1px); background-size: 42px 42px; }
.rack-visual { width: min(510px, 65%); position: relative; display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; padding: 14px; border: 2px solid rgba(255,255,255,.25); }
.rack-visual span { aspect-ratio: 1.5; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.08); color: #e3b760; font: 700 14px Georgia, serif; }
.login-art p { margin-top: 28px; color: rgba(255,255,255,.65); font-size: 12px; letter-spacing: 2px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px; display: flex; flex-direction: column; background: var(--forest); color: white; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; background: #e3b760; color: #1b2b25; font-weight: 900; border-radius: 6px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; }
.brand span { margin-top: 3px; font-size: 12px; color: rgba(255,255,255,.62); }
nav { margin-top: 24px; }
.nav-item { width: 100%; border: 0; border-radius: 6px; padding: 12px 14px; display: flex; gap: 11px; align-items: center; color: rgba(255,255,255,.72); background: transparent; text-align: left; }
.nav-item.active { background: rgba(255,255,255,.11); color: white; }
.sidebar-note { margin-top: auto; padding: 14px 8px 2px; font-size: 11px; color: rgba(255,255,255,.58); line-height: 1.5; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #77c49a; box-shadow: 0 0 0 3px rgba(119,196,154,.13); }

main { min-width: 0; padding: 34px 40px 50px; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; max-width: 1480px; margin: 0 auto 28px; }
.eyebrow { margin: 0 0 6px; color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: 1.6px; }
h1 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 34px; font-weight: 700; letter-spacing: 0; }
.subtitle { margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.header-actions { display: flex; gap: 10px; align-items: center; }
.icon-action { width: 42px; height: 42px; border: 1px solid #ccd5d0; border-radius: 6px; background: white; color: var(--green); font-size: 22px; }
.icon-action.spinning { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.user-button { min-height: 42px; padding: 4px 8px 4px 5px; display: flex; align-items: center; gap: 7px; border: 1px solid #ccd5d0; border-radius: 6px; background: white; color: var(--ink); }
.user-button > span { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 4px; background: var(--forest); color: white; font-size: 12px; }
.user-button b { max-width: 80px; overflow: hidden; text-overflow: ellipsis; font-size: 12px; white-space: nowrap; }
.user-button i { color: var(--muted); font-style: normal; }
.user-menu { width: 140px; }
.btn { min-height: 42px; padding: 0 16px; border: 1px solid transparent; border-radius: 6px; font-weight: 700; font-size: 13px; white-space: nowrap; }
.btn.primary { background: var(--green); color: white; }
.btn.primary:hover { background: #245943; }
.btn.secondary { border-color: #ccd5d0; background: white; color: var(--ink); }
.btn.secondary:hover { background: #f8faf9; }
.btn.danger { border-color: #e8bfbb; background: white; color: var(--red); }
.btn.danger.solid { border-color: var(--red); background: var(--red); color: white; }
.menu-wrap { position: relative; }
.data-menu { position: absolute; z-index: 20; top: calc(100% + 7px); right: 0; width: 150px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: white; box-shadow: 0 10px 24px rgba(21,39,32,.12); }
.data-menu button { width: 100%; padding: 10px 11px; border: 0; border-radius: 4px; background: white; color: var(--ink); text-align: left; font-size: 13px; }
.data-menu button:hover { background: var(--soft); }

.stats { max-width: 1480px; margin: 0 auto 20px; display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); border: 1px solid var(--line); background: white; }
.stat { min-height: 112px; padding: 20px 23px; position: relative; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat > span { display: block; color: var(--muted); font-size: 12px; }
.stat strong { display: inline-block; margin-top: 8px; font-family: Georgia, serif; font-size: 32px; line-height: 1; }
.stat small { margin-left: 6px; color: #8a938f; }
.stat::after { content: ""; position: absolute; left: 0; bottom: 0; width: 100%; height: 3px; background: #aebbb4; opacity: .6; }
.stat.accent-green::after { background: #5c9a76; }
.stat.accent-amber::after { background: #d0914f; }

.workspace { max-width: 1480px; min-height: 480px; margin: 0 auto; border: 1px solid var(--line); background: white; }
.toolbar { min-height: 72px; padding: 14px 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.search-box { width: min(430px, 46%); height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid #ccd5d0; border-radius: 5px; color: var(--muted); background: #fbfcfb; }
.search-box:focus-within { border-color: #6d927f; box-shadow: 0 0 0 3px rgba(46,107,82,.10); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; font-size: 13px; }
.filters { display: flex; gap: 9px; }
select, input, textarea { color: var(--ink); }
.filters select { min-width: 130px; height: 42px; padding: 0 32px 0 11px; border: 1px solid #ccd5d0; border-radius: 5px; background: white; font-size: 13px; }
.table-meta { min-height: 43px; display: flex; align-items: center; gap: 12px; padding: 0 18px; color: var(--muted); font-size: 12px; }
.sync-label { padding-left: 12px; border-left: 1px solid var(--line); color: #819089; }
.text-btn { border: 0; padding: 4px; background: transparent; color: var(--green); font-size: 12px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: auto; }
th { height: 42px; padding: 0 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: #74807a; background: #f7f9f8; font-size: 11px; font-weight: 700; text-align: left; white-space: nowrap; }
td { height: 62px; padding: 9px 14px; border-bottom: 1px solid #edf0ee; font-size: 13px; vertical-align: middle; }
tbody tr:hover { background: #fafcfb; }
.cage-number { font-weight: 800; color: #173c2d; }
.main-cell { display: block; font-weight: 650; white-space: nowrap; }
.sub-cell { display: block; max-width: 210px; margin-top: 3px; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.week-age { font-variant-numeric: tabular-nums; font-weight: 700; }
.pill { display: inline-flex; min-width: 54px; justify-content: center; padding: 5px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.pill-在养 { color: #315d49; background: #edf3f0; }
.pill-繁育中 { color: #256044; background: var(--green-soft); }
.pill-实验中 { color: #8b4d16; background: var(--amber-soft); }
.pill-待处理 { color: #963933; background: var(--red-soft); }
.row-actions { text-align: right; white-space: nowrap; }
.edit-btn { width: 34px; height: 34px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--green); font-weight: 800; }
.edit-btn:hover { border-color: #cbd9d1; background: var(--green-soft); }

.empty-state { min-height: 360px; padding: 50px 20px; display: grid; place-items: center; align-content: center; text-align: center; }
.empty-visual { width: 140px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 22px; transform: perspective(280px) rotateX(8deg); }
.empty-visual span { height: 48px; display: grid; place-items: center; border: 1px solid #bdcbc3; background: #eef3f0; color: #547565; font: 700 12px Georgia, serif; }
.empty-state h2 { margin: 0 0 8px; font-size: 18px; }
.empty-state p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }

.modal-backdrop, .confirm-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(15, 27, 22, .52); backdrop-filter: blur(2px); }
.modal { width: min(720px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; border-radius: 7px; background: white; box-shadow: var(--shadow); }
.small-modal { width: min(480px, 100%); }
.modal-header { position: sticky; z-index: 2; top: 0; padding: 22px 24px 18px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--line); background: white; }
.modal-header h2 { margin: 0; font-size: 22px; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 5px; background: var(--soft); color: var(--ink); font-size: 25px; line-height: 1; }
#recordForm { padding: 22px 24px 24px; }
.small-modal form { padding: 22px 24px 24px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px 18px; }
.form-grid.single { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 7px; font-size: 12px; font-weight: 700; }
.field.full { grid-column: 1 / -1; }
.field b { color: var(--red); }
.field input, .field select, .field textarea { width: 100%; border: 1px solid #cbd4cf; border-radius: 5px; outline: 0; background: white; font-size: 13px; font-weight: 400; }
.field input, .field select { height: 42px; padding: 0 11px; }
.field textarea { padding: 10px 11px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: #628c77; box-shadow: 0 0 0 3px rgba(46,107,82,.10); }
.field small { min-height: 15px; color: var(--green); font-size: 11px; font-weight: 400; }
.form-error { margin-top: 16px; padding: 10px 12px; border-left: 3px solid var(--red); background: var(--red-soft); color: #7e2e2a; font-size: 12px; }
.modal-actions { padding-top: 22px; display: flex; gap: 10px; align-items: center; }
.action-spacer { flex: 1; }
.confirm-box { width: min(420px, 100%); padding: 25px; border-radius: 7px; background: white; box-shadow: var(--shadow); }
.confirm-box h2 { margin: 0 0 8px; font-size: 19px; }
.confirm-box p { margin: 0 0 24px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 9px; }
.admin-content { padding: 22px 24px 26px; }
.inline-user-form { display: grid; grid-template-columns: 1fr 1fr 1fr 120px auto; gap: 10px; align-items: end; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.inline-user-form .btn { height: 42px; }
.account-list { margin-top: 8px; }
.account-row { min-height: 66px; display: grid; grid-template-columns: 38px 1fr auto; gap: 11px; align-items: center; border-bottom: 1px solid var(--line); }
.account-avatar { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 4px; background: var(--green-soft); color: var(--green); font-weight: 800; }
.account-row strong, .account-row span { display: block; }
.account-row strong { font-size: 13px; }
.account-row span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.account-toggle:disabled { opacity: .4; cursor: not-allowed; }
.audit-list { max-height: 62vh; overflow-y: auto; padding: 8px 24px 24px; }
.audit-row { display: grid; grid-template-columns: 64px 1fr; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.audit-action { width: 58px; padding: 5px; align-self: start; border-radius: 4px; background: var(--soft); color: var(--green); text-align: center; font-size: 11px; font-weight: 700; }
.audit-row strong { font-size: 13px; }
.audit-row p { margin: 4px 0; color: var(--muted); font-size: 12px; }
.audit-row small { color: #929b97; }
.simple-empty { padding: 48px; color: var(--muted); text-align: center; }
.toast { position: fixed; z-index: 200; right: 24px; bottom: 24px; max-width: min(360px, calc(100vw - 40px)); padding: 12px 16px; border-radius: 5px; background: #182c24; color: white; box-shadow: 0 10px 26px rgba(0,0,0,.2); font-size: 13px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1000px) {
  .login-screen { grid-template-columns: minmax(340px, 50%) 1fr; }
  .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { padding: 24px 11px; }
  .brand { justify-content: center; padding: 0 0 24px; }
  .brand > div:last-child, .nav-item:not(.active) span + *, .sidebar-note { display: none; }
  .nav-item { justify-content: center; padding: 12px; font-size: 0; }
  .nav-item span { font-size: 18px; }
  main { padding: 28px 24px 40px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .inline-user-form { grid-template-columns: 1fr 1fr; }
  .inline-user-form .btn { align-self: end; }
}

@media (max-width: 700px) {
  .login-screen { display: block; background: white; }
  .login-panel { min-height: 100vh; padding: 110px 24px 40px; justify-content: flex-start; }
  .login-brand { top: 28px; }
  .login-panel h1 { font-size: 30px; }
  .login-art { display: none; }
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: 62px; padding: 10px 16px; flex-direction: row; align-items: center; }
  .brand { padding: 0; border: 0; }
  .brand-mark { width: 38px; height: 38px; }
  .brand > div:last-child { display: block; }
  .brand span, .sidebar nav { display: none; }
  main { padding: 22px 14px 32px; }
  .topbar { align-items: flex-start; }
  h1 { font-size: 27px; }
  .subtitle { max-width: 170px; line-height: 1.5; }
  .header-actions { display: grid; grid-template-columns: 40px 1fr; align-items: stretch; }
  .header-actions .btn { min-height: 39px; }
  .header-actions .menu-wrap:first-of-type { display: none; }
  .header-actions > .primary { grid-column: 1 / -1; grid-row: 2; }
  .user-button { width: 100%; }
  .user-button b { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat { min-height: 94px; padding: 16px; }
  .stat strong { font-size: 27px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .search-box { width: 100%; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; }
  .filters select { width: 100%; min-width: 0; }
  .table-scroll { overflow: visible; }
  table, thead, tbody, tr, td { display: block; }
  thead { display: none; }
  tbody { padding: 0 14px 14px; }
  tbody tr { position: relative; padding: 15px 44px 15px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 11px 16px; }
  td { height: auto; padding: 0; border: 0; font-size: 12px; }
  td::before { content: attr(data-label); display: block; margin-bottom: 4px; color: #87908c; font-size: 10px; }
  .row-actions { position: absolute; right: 0; top: 12px; }
  .row-actions::before { display: none; }
  .sub-cell { max-width: 140px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { width: 100%; max-height: 94vh; border-radius: 8px 8px 0 0; }
  .modal-header, #recordForm { padding-left: 18px; padding-right: 18px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .action-spacer { display: none; }
  .modal-actions .btn { flex: 1; }
  .modal-actions .danger { order: 3; flex-basis: 100%; }
  .inline-user-form { grid-template-columns: 1fr; }
  .admin-content { padding: 18px; }
}
