:root {
  --navy: #14213d;
  --navy-2: #213154;
  --blue: #2d6cff;
  --cyan: #24b8c7;
  --green: #16a36a;
  --orange: #e89132;
  --red: #d94b5a;
  --paper: #f3f6fa;
  --card: rgba(255, 255, 255, 0.94);
  --text: #1a2436;
  --muted: #768296;
  --line: #e2e8f1;
  --shadow: 0 20px 55px rgba(31, 47, 78, 0.11);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 87% 5%, rgba(45, 108, 255, 0.1), transparent 26%),
    linear-gradient(135deg, #fafbfc 0%, var(--paper) 55%, #edf2f8 100%);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, sans-serif;
}

body.drawer-open { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.62; }
[hidden] { display: none !important; }
.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; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px 1fr; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 5;
  width: 248px;
  padding: 30px 22px;
  color: white;
  background:
    linear-gradient(160deg, rgba(45, 108, 255, 0.17), transparent 35%),
    linear-gradient(180deg, #111c34, #172643 55%, #101a30);
  overflow: hidden;
}
.sidebar::after {
  content: "";
  position: absolute;
  left: -110px;
  bottom: -95px;
  width: 270px;
  height: 270px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 50%;
  box-shadow: 0 0 0 46px rgba(255,255,255,.025), 0 0 0 92px rgba(255,255,255,.018);
}
.brand { display: flex; align-items: center; gap: 12px; margin: 0 6px 46px; color: white; text-decoration: none; }
.brand-mark, .modal-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  color: white;
  background: linear-gradient(145deg, #3f7cff, #17bfc6);
  box-shadow: 0 9px 28px rgba(45,108,255,.4);
  font-weight: 850;
}
.brand strong { display: block; font-size: 20px; letter-spacing: .4px; }
.brand small { display: block; margin-top: 2px; color: #94a3bd; font-size: 10px; letter-spacing: 1.5px; }
.nav { position: relative; z-index: 1; display: grid; gap: 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  border-radius: 12px;
  color: #9eabc1;
  background: transparent;
  text-align: left;
  transition: .2s ease;
}
.nav-item span { width: 20px; text-align: center; }
.nav-item:hover, .nav-item.active { color: white; background: rgba(255,255,255,.095); }
.nav-item.active { box-shadow: inset 3px 0 #3c7cff; }
.sidebar-foot { position: absolute; z-index: 1; left: 30px; bottom: 29px; display: flex; align-items: center; gap: 8px; color: #8795ad; font-size: 12px; }
.connection-dot { width: 7px; height: 7px; border-radius: 50%; background: #34c889; box-shadow: 0 0 0 4px rgba(52,200,137,.12); }

main { grid-column: 2; min-width: 0; padding: 28px 38px 38px; }
.mobile-brand { display: none; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 5px; color: var(--blue); font-size: 11px; font-weight: 800; letter-spacing: 1.6px; text-transform: uppercase; }
h1 { margin: 0; font-size: 25px; letter-spacing: -.5px; }
.subtitle { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.header-actions { display: flex; gap: 10px; }
.button {
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--navy);
  background: rgba(255,255,255,.9);
  box-shadow: 0 5px 16px rgba(31,47,78,.05);
  font-size: 13px;
  font-weight: 700;
}
.button:hover { transform: translateY(-1px); }
.button.primary { border-color: transparent; color: white; background: linear-gradient(135deg, var(--blue), #4f7cff); box-shadow: 0 10px 24px rgba(45,108,255,.24); }
.button.secondary { background: rgba(255,255,255,.78); }
.button.danger { border-color: #f2cdd2; color: #b73344; background: #fff7f8; }
.button.full-width { width: 100%; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 15px; margin-bottom: 18px; }
.stat-card {
  --tone: var(--blue);
  position: relative;
  overflow: hidden;
  min-height: 101px;
  padding: 18px 19px;
  border: 1px solid rgba(224,229,238,.82);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 9px 26px rgba(31,47,78,.055);
}
.stat-card::after { content: ""; position: absolute; right: -22px; bottom: -42px; width: 100px; height: 100px; border-radius: 50%; background: var(--tone); opacity: .075; }
.stat-card > span { display: block; margin-bottom: 9px; color: var(--muted); font-size: 12px; }
.stat-card strong { display: flex; align-items: flex-end; gap: 7px; font-size: 27px; letter-spacing: -.6px; }
.stat-card small { padding-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 500; }
.tone-orange { --tone: var(--orange); }
.tone-cyan { --tone: var(--cyan); }
.tone-green { --tone: var(--green); }

.records-panel { overflow: hidden; border: 1px solid rgba(222,228,238,.92); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.filters { display: grid; grid-template-columns: minmax(220px,1fr) 150px 150px auto; gap: 11px; padding: 17px 18px; border-bottom: 1px solid var(--line); }
.filters input, .filters select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #dfe5ee;
  border-radius: 10px;
  outline: 0;
  color: var(--text);
  background: #fbfcfe;
}
.filters input:focus, .filters select:focus, .editor-form input:focus, .editor-form textarea:focus, .editor-form select:focus, .modal input:focus { border-color: #91aeff; box-shadow: 0 0 0 3px rgba(45,108,255,.09); }
.record-count { display: flex; align-items: center; justify-content: flex-end; color: var(--muted); font-size: 12px; white-space: nowrap; }
.loading-state, .empty-state { min-height: 330px; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.loading-state { grid-auto-flow: column; gap: 10px; }
.spinner { width: 18px; height: 18px; border: 2px solid #d9e1ef; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 40px 20px; }
.empty-icon { width: 58px; height: 58px; display: grid; place-items: center; margin-bottom: 15px; border-radius: 18px; color: var(--blue); background: #edf3ff; font-size: 27px; }
.empty-state h2 { margin: 0; color: var(--navy); font-size: 17px; }
.empty-state p { margin: 8px 0 18px; font-size: 13px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 940px; border-collapse: collapse; }
th { padding: 12px 16px; color: #8791a2; background: #f9fafc; text-align: left; font-size: 10px; letter-spacing: .45px; font-weight: 800; }
td { padding: 15px 16px; border-top: 1px solid #edf0f5; vertical-align: middle; font-size: 13px; }
tbody tr { transition: .18s; }
tbody tr:hover { background: #f8faff; }
.record-code { color: var(--blue); font-weight: 750; white-space: nowrap; }
.machine-cell strong { display: block; font-size: 13px; }
.machine-cell small, .cell-subtitle { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; }
.issue-cell { max-width: 270px; font-weight: 650; line-height: 1.45; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 20px; font-size: 10px; font-weight: 750; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-investigating { color: #bd6b17; background: #fff2df; }
.status-temporary { color: #2760d6; background: #eaf0ff; }
.status-resolved { color: #16865a; background: #e6f7ef; }
.thumbnail-stack { display: flex; align-items: center; min-width: 70px; }
.thumbnail-stack img, .thumbnail-placeholder, .thumbnail-more { width: 32px; height: 32px; margin-left: -7px; border: 2px solid white; border-radius: 8px; object-fit: cover; box-shadow: 0 2px 8px rgba(20,33,61,.14); }
.thumbnail-stack > :first-child { margin-left: 0; }
.thumbnail-placeholder { background: linear-gradient(145deg, #25395c, #8196b2); }
.thumbnail-more { display: grid; place-items: center; color: white; background: #2d3950; font-size: 9px; }
.view-button { padding: 7px; border: 0; color: var(--blue); background: transparent; font-weight: 750; white-space: nowrap; }
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.pagination > div { display: flex; align-items: center; gap: 10px; }
.page-button { padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--navy); background: white; }
.site-footer { margin-top: 22px; color: #99a3b3; text-align: center; font-size: 10px; letter-spacing: .5px; }
.mobile-cards { display: none; }

.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(8,15,29,.43); backdrop-filter: blur(4px); opacity: 0; transition: opacity .24s; }
.backdrop.visible { opacity: 1; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 21;
  width: min(680px, 96vw);
  height: 100%;
  overflow-y: auto;
  background: #f7f9fc;
  box-shadow: -25px 0 60px rgba(8,15,29,.2);
  transform: translateX(102%);
  transition: transform .32s cubic-bezier(.2,.8,.2,1);
}
.drawer.editor-drawer { width: min(760px, 97vw); }
.drawer.open { transform: translateX(0); }
.drawer-header { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 20px; min-height: 72px; padding: 15px 24px; border-bottom: 1px solid var(--line); background: rgba(247,249,252,.92); backdrop-filter: blur(16px); }
.drawer-header > div:first-child { display: grid; }
.drawer-kicker { margin-bottom: 3px; color: var(--blue); font-size: 9px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase; }
.drawer-header strong { font-size: 15px; }
.drawer-actions { display: flex !important; grid-auto-flow: column; align-items: center; gap: 7px; }
.icon-button, .close-button { height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; color: #657188; background: white; font-size: 11px; font-weight: 700; }
.close-button { width: 34px; padding: 0; font-size: 20px; font-weight: 400; }
.drawer-content { padding: 24px; }
.report-cover { padding: 23px; border-radius: 17px; color: white; background: linear-gradient(145deg, #152442, #253d67); box-shadow: 0 17px 38px rgba(20,33,61,.2); }
.cover-topline { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: #aebbd0; font-size: 10px; }
.report-cover h2 { margin: 12px 0 21px; font-size: 22px; line-height: 1.4; }
.report-meta { display: grid; grid-template-columns: repeat(3,1fr); gap: 9px; }
.report-meta div { padding: 11px; border-radius: 10px; background: rgba(255,255,255,.08); font-size: 11px; }
.report-meta span { display: block; margin-bottom: 4px; color: #9fadc4; font-size: 9px; }
.report-section { margin-top: 14px; padding: 19px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.report-section h3 { margin: 0 0 11px; color: var(--navy); font-size: 12px; }
.report-section p { margin: 0; color: #566276; white-space: pre-wrap; font-size: 12px; line-height: 1.78; }
.report-section .no-content { color: #9aa4b5; font-style: italic; }
.gallery { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; }
.gallery-button { overflow: hidden; aspect-ratio: 4/3; padding: 0; border: 0; border-radius: 10px; background: #e7ebf1; }
.gallery-button img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s; }
.gallery-button:hover img { transform: scale(1.035); }
.detail-footer { display: flex; justify-content: space-between; margin-top: 14px; padding: 14px 4px; color: #8c97a8; font-size: 10px; }

.editor-form { padding: 23px; }
.form-section { margin-bottom: 14px; padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.section-heading { display: flex; align-items: center; gap: 11px; margin-bottom: 18px; }
.section-heading > span { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; color: var(--blue); background: #edf3ff; font-size: 10px; font-weight: 850; }
.section-heading h2 { margin: 0; color: var(--navy); font-size: 14px; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 10px; }
.form-grid { display: grid; gap: 13px; }
.two-columns { grid-template-columns: repeat(2, minmax(0,1fr)); }
.editor-form label, .modal label { display: grid; gap: 7px; margin-top: 13px; color: #4d596b; font-size: 11px; font-weight: 700; }
.editor-form label:first-of-type { margin-top: 0; }
.editor-form label b { color: var(--red); }
.editor-form input, .editor-form textarea, .editor-form select, .modal input {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid #dfe5ee;
  border-radius: 9px;
  outline: none;
  color: var(--text);
  background: #fbfcfe;
  font-size: 12px;
  font-weight: 450;
}
.editor-form textarea { resize: vertical; line-height: 1.65; }
.upload-zone { min-height: 135px; place-content: center; justify-items: center; margin: 0 !important; border: 1.5px dashed #bdc9dc; border-radius: 12px; color: #69768a !important; background: #f9fbfe; text-align: center; transition: .2s; }
.upload-zone.dragging { border-color: var(--blue); background: #f0f5ff; }
.upload-zone input { display: none; }
.upload-symbol { width: 35px; height: 35px; display: grid; place-items: center; border-radius: 10px; color: white; background: linear-gradient(145deg, #477eff, #20b8c7); font-size: 21px; font-weight: 400; }
.upload-zone strong { margin-top: 7px; color: var(--navy); font-size: 12px; }
.upload-zone small { color: var(--muted); font-size: 10px; font-weight: 450; }
.photo-preview { display: grid; grid-template-columns: repeat(4,1fr); gap: 9px; margin-top: 12px; }
.preview-item { position: relative; overflow: hidden; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; background: #e9edf3; }
.preview-item img { width: 100%; height: 100%; object-fit: cover; }
.preview-remove { position: absolute; top: 5px; right: 5px; width: 25px; height: 25px; padding: 0; border: 0; border-radius: 50%; color: white; background: rgba(13,23,42,.72); font-size: 15px; }
.preview-new::after { content: "待上传"; position: absolute; left: 5px; bottom: 5px; padding: 3px 5px; border-radius: 5px; color: white; background: rgba(45,108,255,.85); font-size: 8px; }
.form-footer { position: sticky; bottom: -23px; z-index: 2; display: flex; align-items: center; gap: 9px; margin: 0 -23px -23px; padding: 15px 23px; border-top: 1px solid var(--line); background: rgba(247,249,252,.95); backdrop-filter: blur(14px); }
.form-spacer { flex: 1; }

.modal { width: min(410px, calc(100vw - 30px)); padding: 0; border: 0; border-radius: 18px; color: var(--text); box-shadow: 0 30px 90px rgba(8,15,29,.3); }
.modal::backdrop, .lightbox::backdrop { background: rgba(8,15,29,.56); backdrop-filter: blur(5px); }
.modal form { position: relative; padding: 31px; }
.modal-close { position: absolute; top: 14px; right: 14px; width: 31px; height: 31px; border: 0; border-radius: 8px; color: #778296; background: #f1f4f8; font-size: 19px; }
.modal-mark { margin-bottom: 20px; }
.modal h2 { margin: 3px 0 7px; font-size: 20px; }
.modal form > p:not(.eyebrow):not(.form-error) { margin: 0 0 21px; color: var(--muted); font-size: 11px; }
.modal .button { margin-top: 18px; }
.form-error { margin: 8px 0 0; color: var(--red); font-size: 11px; }
.lightbox { max-width: min(1100px, 94vw); max-height: 92vh; padding: 15px; border: 0; border-radius: 15px; background: #0c1424; color: white; }
.lightbox img { display: block; max-width: 100%; max-height: 78vh; margin: auto; border-radius: 9px; }
.lightbox p { margin: 11px 40px 0; color: #aab5c7; text-align: center; font-size: 11px; }
.lightbox-close { position: absolute; top: 10px; right: 10px; z-index: 1; width: 34px; height: 34px; border: 0; border-radius: 9px; color: white; background: rgba(0,0,0,.5); font-size: 22px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: 360px; padding: 12px 16px; border-radius: 10px; color: white; background: #1d2b45; box-shadow: 0 14px 35px rgba(10,20,39,.22); opacity: 0; pointer-events: none; transform: translateY(10px); transition: .22s; font-size: 12px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #ad3746; }

@media (max-width: 980px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  main { padding: 20px 16px 34px; }
  .mobile-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 22px; }
  .mobile-brand .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
  .stats { grid-template-columns: repeat(2,1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .search-field { grid-column: 1 / -1; }
}

@media (max-width: 660px) {
  main { padding: 16px 12px 30px; }
  .topbar { align-items: flex-end; }
  h1 { font-size: 20px; }
  .subtitle { display: none; }
  .button { min-height: 38px; padding: 8px 11px; font-size: 11px; }
  .header-actions { flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  .stats { gap: 9px; }
  .stat-card { min-height: 91px; padding: 14px; }
  .stat-card strong { font-size: 23px; }
  .filters { padding: 13px; }
  .record-count { justify-content: flex-end; }
  .table-wrap { display: none !important; }
  .mobile-cards { display: grid; gap: 10px; padding: 11px; }
  .record-card { padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: white; }
  .record-card-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
  .record-card h3 { margin: 4px 0 0; font-size: 13px; }
  .record-card p { margin: 0 0 12px; color: #556176; font-size: 12px; line-height: 1.55; }
  .record-card-footer { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; border-top: 1px solid #edf0f5; }
  .pagination { font-size: 10px; }
  .page-button { padding: 6px; font-size: 10px; }
  .drawer { width: 100vw !important; }
  .drawer-header { min-height: 65px; padding: 12px 15px; }
  .drawer-content, .editor-form { padding: 14px; }
  .report-cover { padding: 18px; }
  .report-cover h2 { font-size: 18px; }
  .report-meta { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: repeat(2,1fr); }
  .form-section { padding: 16px; }
  .two-columns { grid-template-columns: 1fr; }
  .photo-preview { grid-template-columns: repeat(3,1fr); }
  .form-footer { bottom: -14px; margin: 0 -14px -14px; padding: 12px 14px; }
  .form-footer .button.secondary { display: none; }
  .toast { right: 12px; bottom: 12px; left: 12px; max-width: none; }
}

@media print {
  body * { visibility: hidden; }
  #detailDrawer, #detailDrawer * { visibility: visible; }
  #detailDrawer { position: absolute; inset: 0; width: 100%; height: auto; overflow: visible; transform: none; box-shadow: none; background: white; }
  .drawer-header, .backdrop { display: none !important; }
  .drawer-content { padding: 0; }
  .report-cover { color: black; border: 1px solid #aaa; background: white; box-shadow: none; }
  .report-cover span, .report-meta span, .cover-topline { color: #555; }
  .report-meta div { border: 1px solid #ddd; background: white; }
  .report-section { break-inside: avoid; }
}
