:root {
  color-scheme: light;
  --ink: #142238;
  --muted: #68768a;
  --line: #dbe3ed;
  --soft-line: #edf1f6;
  --canvas: #f4f7fb;
  --paper: #ffffff;
  --nav: #10243d;
  --nav-active: #1f4266;
  --blue: #1967b3;
  --blue-soft: #eaf3fc;
  --teal: #138a86;
  --teal-soft: #e8f7f5;
  --amber: #b66b08;
  --amber-soft: #fff5df;
  --red: #b42318;
  --red-soft: #fff0ee;
  --green: #18794e;
  --green-soft: #eaf7f0;
  --shadow: 0 12px 32px rgba(23, 44, 73, .07);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; touch-action: pan-x pan-y; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.5 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 25px; line-height: 1.25; letter-spacing: 0; }
h2 { font-size: 17px; line-height: 1.3; letter-spacing: 0; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px 16px;
  background: var(--nav);
  color: #f6fbff;
}
.brand-block {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}
.brand-block strong, .brand-block span {
  display: block;
  white-space: nowrap;
}
.brand-block strong { font-size: 16px; }
.brand-block span { margin-top: 2px; color: #aebfd2; font-size: 12px; }
.brand-mark {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: block;
  border-radius: 50%;
  object-fit: contain;
}
.nav-list { display: grid; gap: 5px; }
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 0;
  border-radius: 7px;
  padding: 11px 12px;
  background: transparent;
  color: #c8d6e6;
  text-align: left;
}
.nav-item:hover, .nav-item.active { background: var(--nav-active); color: #fff; }
.nav-icon { width: 18px; color: #9cc6e7; text-align: center; font-size: 17px; }
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding-top: 15px;
  border-top: 1px solid rgba(255,255,255,.15);
}
.avatar {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #e7b65e;
  color: #10243d;
  font-weight: 800;
}
.user-meta { min-width: 0; flex: 1; }
.user-meta strong, .user-meta span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta span { color: #aebfd2; font-size: 12px; }
.main-content { min-width: 0; padding: 28px; }
.mobile-header { display: none; }
.mobile-bottom-nav { display: none; }
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}
.page-header p { margin-top: 7px; color: var(--muted); }
.panel {
  min-width: 0;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.metric-card {
  min-height: 108px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.metric-card span { color: var(--muted); }
.metric-card strong { font-size: 30px; line-height: 1; }
.metric-card.accent { border-color: #a9d7d4; background: var(--teal-soft); }
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.section-heading span { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }
.form-grid, .filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}
.filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label, .field-label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(25,103,179,.12); }
.field-wide { grid-column: 1 / -1; }
.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin-top: 4px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
}
.check-row input { width: 16px; min-height: 16px; margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; }
.form-stack { display: grid; gap: 15px; }
.button, .icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
}
.button:hover, .icon-button:hover { border-color: #aab8c8; background: #f7f9fc; }
.button.primary { border-color: var(--blue); background: var(--blue); color: #fff; }
.button.secondary { border-color: #a6c5df; background: var(--blue-soft); color: #15568d; }
.button.ghost { border-color: transparent; background: transparent; color: var(--blue); }
.button.danger { border-color: #edb4ad; background: var(--red-soft); color: var(--red); }
.button.tiny { min-height: 31px; padding: 5px 9px; font-size: 12px; }
.button.full { width: 100%; }
.icon-button { width: 36px; min-width: 36px; height: 36px; min-height: 36px; padding: 0; }
.sidebar .icon-button { border-color: transparent; background: transparent; color: #c8d6e6; }
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 11px 10px; border-bottom: 1px solid var(--soft-line); text-align: left; vertical-align: middle; }
.data-table th { color: var(--muted); font-weight: 600; white-space: nowrap; background: #f8fafc; }
.data-table td { white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }
.actions-cell { display: flex; flex-wrap: wrap; gap: 7px; }
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}
.status-QUEUED, .status-WAITING_PACKAGE { border-color: #cbd9ea; background: #edf3fa; color: #385674; }
.status-CLAIMED, .status-RUNNING { border-color: #eed4a7; background: var(--amber-soft); color: var(--amber); }
.status-COMPLETED, .status-PUBLISHED, .status-GENERATED { border-color: #b9dfc9; background: var(--green-soft); color: var(--green); }
.status-FAILED, .status-MISSING, .status-DISABLED { border-color: #edb4ad; background: var(--red-soft); color: var(--red); }
.progress-line { width: 86px; height: 7px; overflow: hidden; display: inline-block; margin-right: 6px; border-radius: 99px; background: #e6edf4; vertical-align: middle; }
.progress-line span { display: block; height: 100%; border-radius: inherit; background: var(--teal); }
.task-progress { display: grid; gap: 4px; min-width: 138px; }
.task-progress > div { display: flex; align-items: center; }
.estimate { color: var(--muted); font-size: 11px; white-space: nowrap; }
.empty-state, .empty-folder, .archive-loading { padding: 34px 16px; color: var(--muted); text-align: center; }
.empty-folder { display: grid; justify-items: center; gap: 12px; }
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 15px;
  border: 1px solid #315477;
  border-radius: 7px;
  background: #142b47;
  color: #fff;
  box-shadow: var(--shadow);
}
.toast.error { border-color: #934138; background: #71291f; }
.archive-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 17px; }
.archive-toolbar-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; min-width: 0; }
.crumb { padding: 3px 4px; border: 0; background: transparent; color: var(--blue); }
.crumb.current { color: var(--ink); font-weight: 700; }
.crumb-separator { color: #a3afbd; }
.archive-hint { color: var(--muted); font-size: 12px; }
.archive-root-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.archive-root-card {
  display: grid;
  justify-items: start;
  gap: 7px;
  min-height: 145px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}
.archive-root-card:hover { border-color: #a4bdd7; background: #f8fbfe; }
.archive-root-card span:last-child { color: var(--muted); font-size: 12px; }
.root-icon { color: var(--blue); font-size: 32px; }
.file-list { display: grid; gap: 5px; }
.file-row {
  min-width: 0;
  display: grid;
  grid-template-columns: 34px minmax(180px, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 11px 9px;
  border-bottom: 1px solid var(--soft-line);
}
.file-row:last-child { border-bottom: 0; }
.file-row:hover { background: #fafcfe; }
.file-row.has-selection { grid-template-columns: 22px 30px minmax(180px, 1fr) auto; }
.archive-file-select { display: grid; place-items: center; }
.archive-file-select input { width: 17px; min-height: 17px; margin: 0; }
.file-icon { color: var(--blue); font-size: 21px; text-align: center; }
.file-name { min-width: 0; }
.file-name strong, .file-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-name span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.manual-upload-tag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  margin-left: 7px;
  padding: 1px 6px;
  border: 1px solid #bed9d7;
  border-radius: 99px;
  background: var(--teal-soft);
  color: #116b68;
  font-size: 11px;
  font-weight: 600;
  vertical-align: 1px;
}
.folder-name-button {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.folder-name-button strong, .folder-name-button span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-name-button strong { color: var(--blue); }
.folder-name-button .folder-meta { display: flex; align-items: center; gap: 7px; margin-top: 2px; color: var(--muted); font-size: 12px; }
.folder-name-button:hover strong { text-decoration: underline; }
.archive-missing { font-style: normal; color: var(--red); }
.archive-generation {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--amber);
  font-size: 12px;
}
.folder-name-button .folder-meta .archive-generation { display: inline-flex; }
.archive-generation-label { color: var(--amber); }
.archive-generation .progress-line { width: 70px; margin: 0; }
.archive-generation small { color: var(--muted); }
.archive-generation.failed { color: var(--red); }
.archive-generation.failed span:last-child { color: var(--red); }
.file-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
.section-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.grant-list { display: grid; gap: 7px; }
.grant-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.grant-row input { width: 17px; min-height: 17px; }
.grant-row strong, .grant-row small { display: block; }
.grant-row small { color: var(--muted); font-size: 12px; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--canvas); }
.login-card { width: min(420px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.login-brand { margin-bottom: 28px; }
.login-brand .brand-mark { width: 46px; height: 46px; }
.login-card h1 { font-size: 23px; }
.login-subtitle { margin: 8px 0 20px; color: var(--muted); }
.form-error { min-height: 20px; color: var(--red); font-size: 13px; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(13, 28, 48, .48);
}
.modal {
  width: min(640px, 100%);
  max-height: calc(100vh - 48px);
  overflow: hidden;
  border: 1px solid #b9c8d8;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(10, 28, 49, .26);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-header strong, .modal-header span { display: block; }
.modal-header strong { font-size: 15px; }
.modal-header span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.modal-actions { display: flex; align-items: center; gap: 7px; }
.preview-modal {
  width: min(1280px, 100%);
  height: min(860px, calc(100vh - 48px));
  position: relative;
  display: flex;
  flex-direction: column;
}
.preview-floating-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  gap: 7px;
}
.preview-floating-actions .icon-button {
  border-color: #b9c8d8;
  background: rgba(255,255,255,.94);
  box-shadow: 0 4px 14px rgba(21,40,65,.12);
}
.preview-frame-wrap { min-height: 0; flex: 1; background: #f3f6fa; }
.report-preview-frame { display: block; width: 100%; height: 100%; border: 0; background: #fff; touch-action: pan-x pan-y; }
.modal-form { padding: 16px; overflow: auto; }
.modal-note { color: var(--muted); font-size: 13px; line-height: 1.55; }
.batch-download-modal { width: min(480px, 100%); }
.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.segment {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 8px 10px;
  color: var(--muted);
  cursor: pointer;
}
.segment + .segment { border-left: 1px solid var(--line); }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment.selected { background: var(--blue-soft); color: #15568d; font-weight: 700; }
.task-confirm-group {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}
.task-confirm-group strong { font-size: 13px; }
.task-confirm-group span { color: var(--muted); font-size: 13px; }
.tool-list {
  display: grid;
  gap: 8px;
  max-width: 720px;
}
.tool-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 11px;
  min-height: 58px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
}
.tool-row:hover { border-color: #aac1d6; background: #f9fbfd; }
.tool-icon { color: var(--blue); font-size: 20px; text-align: center; }
.tool-arrow { color: var(--muted); font-size: 22px; text-align: right; }
.profile-panel { max-width: 760px; }

@media (max-width: 1080px) {
  .main-content { padding: 22px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .file-row { grid-template-columns: 30px minmax(150px, 1fr) auto; }
  .file-row.has-selection { grid-template-columns: 22px 27px minmax(140px, 1fr) auto; }
}

@media (max-width: 760px) {
  .app-shell { display: block; min-height: 100dvh; }
  .sidebar { display: none; }
  .main-content { min-height: 100dvh; padding: 12px 12px 84px; }
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 40px;
    margin: 0 0 8px;
  }
  .mobile-brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .mobile-brand-logo { flex: 0 0 auto; width: 32px; height: 32px; display: block; border-radius: 50%; object-fit: contain; }
  .mobile-brand-text { min-width: 0; display: grid; gap: 0; }
  .mobile-brand strong { font-size: 15px; line-height: 1.18; }
  .mobile-brand span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-bottom-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    min-height: 66px;
    padding: 6px max(10px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.97);
    box-shadow: 0 -5px 18px rgba(26,46,74,.08);
  }
  .mobile-nav-item {
    display: grid;
    place-items: center;
    gap: 1px;
    min-width: 0;
    min-height: 52px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
  }
  .mobile-nav-item span { font-size: 19px; line-height: 1; }
  .mobile-nav-item small { font-size: 11px; }
  .mobile-nav-item.active { background: var(--blue-soft); color: #15568d; font-weight: 700; }
  .page-header { align-items: center; gap: 10px; margin-bottom: 12px; }
  .page-header > div { min-width: 0; }
  .page-header p, .archive-hint { display: none; }
  .page-header .button { flex: 0 0 auto; min-height: 36px; padding: 7px 11px; }
  h1 { font-size: 22px; }
  .metric-grid { display: none; }
  .form-grid, .filter-grid, .archive-root-grid { grid-template-columns: 1fr; }
  .panel { padding: 14px; margin-bottom: 12px; }
  .section-heading { display: grid; gap: 10px; }
  .section-actions { justify-content: stretch; }
  .section-actions .button { flex: 1 1 130px; }
  .form-actions { justify-content: stretch; }
  .form-actions .button { width: 100%; }
  .archive-toolbar { display: grid; gap: 9px; }
  .archive-toolbar-actions { justify-content: stretch; }
  .archive-toolbar-actions .button { flex: 1 1 135px; }
  .file-row { grid-template-columns: 27px minmax(0, 1fr) auto; gap: 8px; padding: 12px 3px; }
  .file-row.has-selection { grid-template-columns: 22px 25px minmax(0, 1fr) auto; }
  .file-name strong, .folder-name-button strong { white-space: normal; overflow: visible; }
  .file-actions { grid-column: 3; grid-row: 1; }
  .file-row.has-selection .file-actions { grid-column: 4; }
  .file-actions .button { min-height: 30px; }
  .manual-upload-tag { margin-left: 4px; }
  .archive-generation .progress-line { width: 58px; }
  .data-table, .data-table thead, .data-table tbody, .data-table tr, .data-table th, .data-table td { display: block; }
  .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .data-table tr { margin-bottom: 10px; padding: 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
  .data-table tr:last-child { margin-bottom: 0; }
  .data-table td { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; align-items: start; min-height: 34px; padding: 6px 0; border-bottom: 1px solid var(--soft-line); white-space: normal; }
  .data-table td:last-child { border-bottom: 0; }
  .data-table td::before { content: attr(data-label); color: var(--muted); }
  .data-table .actions-cell { display: flex; justify-content: flex-end; }
  .data-table .actions-cell::before { margin-right: auto; }
  .toast { right: 12px; bottom: 78px; }
  .modal-backdrop { padding: 8px; }
  .modal { max-height: calc(100vh - 16px); }
  .preview-modal { height: calc(100dvh - 16px); }
  .modal-header { min-height: 52px; padding: 8px 10px; }
  .modal-form { padding: 12px; }
  .preview-floating-actions { top: 8px; right: 8px; }
  .preview-floating-actions .icon-button { width: 34px; min-width: 34px; height: 34px; min-height: 34px; }
  .tool-list { gap: 7px; }
  .tool-row { min-height: 56px; box-shadow: none; }
  .task-progress { min-width: 0; }
  .task-progress .estimate { white-space: normal; }
}
