:root {
  --ink: #143d38;
  --ink-soft: #5f7773;
  --pine: #075e54;
  --jade: #009b80;
  --mint: #dff2ec;
  --paper: #f3f7f5;
  --surface: #ffffff;
  --line: #d7e4df;
  --line-strong: #b9cec7;
  --shadow: 0 18px 55px rgba(19, 61, 56, 0.12);
  --radius: 16px;
  --font-display: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-body: Inter, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); font-family: var(--font-body); }
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(0, 155, 128, .25); outline-offset: 2px; }
.is-hidden { display: none !important; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { height: 76px; display: flex; align-items: center; justify-content: space-between; padding: 0 26px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); backdrop-filter: blur(18px); position: sticky; top: 0; z-index: 20; }
.brand-lockup { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 34px; }
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
h1, h2 { font-family: var(--font-display); letter-spacing: -.035em; }
h1 { font-size: 21px; margin: 0; }
h2 { font-size: 24px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.version-switch { height: 34px; padding: 0 10px; display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 9px; background: #f6faf8; color: var(--ink); white-space: nowrap; font-size: 12px; font-weight: 750; }
.version-switch:hover { border-color: var(--line-strong); background: var(--mint); }
.version-switch:disabled { cursor: not-allowed; opacity: .5; }
.version-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: var(--jade); }
.version-switch[aria-pressed="true"] .version-dot { background: #e88a2e; }
.button { min-height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 750; }
.icon-button { width: 38px; height: 38px; min-height: 38px; padding: 0; display: inline-grid; place-items: center; flex: 0 0 38px; }
.icon-button svg { width: 19px; height: 19px; }
.export-badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; border: 2px solid white; border-radius: 99px; background: #d94b45; color: white; font-size: 9px; font-weight: 850; line-height: 1; box-shadow: 0 3px 8px rgba(126, 40, 35, .22); }
#exportButton { position: relative; }
.button-primary { border-color: var(--jade); background: var(--jade); color: white; box-shadow: 0 7px 18px rgba(0,155,128,.18); }
.button-primary:hover { background: #008b73; }
body.has-archive #openButton { border-color: var(--line-strong); background: var(--surface); color: var(--ink); box-shadow: none; }
body.has-archive #openButton:hover { background: #f1f7f4; }
.button:disabled { cursor: not-allowed; opacity: .45; box-shadow: none; }
.button-quiet { background: transparent; }
.button-large { min-height: 46px; padding: 0 24px; }

.workspace { display: grid; grid-template-columns: 186px minmax(0, 1fr); flex: 1; min-height: 0; }
.rail { padding: 20px 12px 14px; border-right: 1px solid var(--line); background: #eef4f1; display: flex; flex-direction: column; gap: 5px; }
.rail-item { position: relative; width: 100%; min-height: 42px; display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; padding: 0 11px; border: 0; border-radius: 10px; background: transparent; color: var(--ink-soft); text-align: left; font-size: 13px; font-weight: 700; }
.rail-item:hover { background: rgba(255,255,255,.68); color: var(--ink); }
.rail-item.is-active { color: var(--pine); background: white; box-shadow: 0 5px 16px rgba(20,61,56,.07); }
.rail-item.is-active::before { content: ""; position: absolute; left: 0; width: 3px; height: 20px; border-radius: 0 4px 4px 0; background: var(--jade); }
.rail-icon { display: block; width: 28px; height: 28px; object-fit: contain; object-position: center; background: transparent; }
.rail-item small { color: #95a7a3; font-size: 9px; }
.rail-divider { height: 1px; margin: 8px 10px; background: var(--line); }
.rail-footer { margin-top: auto; padding: 12px; display: flex; flex-direction: column; gap: 3px; color: #8ca19c; font-size: 9px; letter-spacing: .12em; }
.rail-footer strong { color: var(--ink-soft); font-size: 11px; }

.content-stage { min-width: 0; padding: 22px; }
.empty-state, .loading-state, .error-state { min-height: calc(100vh - 120px); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-state h2 { margin: 9px 0 24px; font-size: clamp(30px, 4vw, 48px); }
.welcome-illustration, .loading-illustration, .error-illustration { position: relative; width: 192px; height: 178px; display: flex; justify-content: center; align-items: flex-start; }
.welcome-illustration { margin-bottom: 14px; }
.welcome-sprite, .loading-sprite, .error-sprite { position: relative; z-index: 1; width: 144px; height: 156px; background-image: url("./animation/piko/spritesheet.webp"); background-size: 1152px 1404px; background-repeat: no-repeat; }
.welcome-sprite { background-position: 0 -468px; animation: piko-greet 3.2s steps(1) infinite; }
.sprite-ground { position: absolute; bottom: 9px; left: 25px; right: 25px; height: 6px; border-radius: 50%; background: rgba(7, 94, 84, .12); filter: blur(3px); }
@keyframes piko-greet {
  0%, 10%, 42%, 100% { background-position: 0 -468px; }
  12%, 20% { background-position: -144px -468px; }
  22%, 30% { background-position: -288px -468px; }
  32%, 40% { background-position: -432px -468px; }
}

.loading-state h2 { margin: 14px 0 0; }
.loading-sprite { background-position: 0 -156px; animation: piko-run .88s steps(8) infinite; }
@keyframes piko-run { to { background-position: -1152px -156px; } }
.loading-activity { height: 27px; margin-top: 15px; display: flex; align-items: flex-end; justify-content: center; gap: 5px; }
.loading-activity span { width: 4px; height: 24px; border-radius: 99px; background: var(--jade); transform: scaleY(.28); transform-origin: center bottom; opacity: .35; animation: activity-wave 1.05s ease-in-out infinite; }
.loading-activity span:nth-child(2) { animation-delay: .11s; }
.loading-activity span:nth-child(3) { animation-delay: .22s; }
.loading-activity span:nth-child(4) { animation-delay: .33s; }
.loading-activity span:nth-child(5) { animation-delay: .44s; }
.loading-activity span:nth-child(6) { animation-delay: .55s; }
.loading-activity span:nth-child(7) { animation-delay: .66s; }
@keyframes activity-wave { 0%, 65%, 100% { transform: scaleY(.28); opacity: .35; } 30% { transform: scaleY(1); opacity: 1; } }
.error-sprite { background-position: 0 -780px; animation: piko-sad 2.2s steps(8) infinite; }
@keyframes piko-sad { to { background-position: -1152px -780px; } }
.error-state h2 { margin: 12px 0 4px; }
.error-state p { max-width: 520px; margin: 0 16px 22px; color: var(--ink-soft); font-size: 13px; line-height: 1.6; overflow-wrap: anywhere; }
.error-actions { display: flex; align-items: center; justify-content: center; gap: 9px; }

.app-state { max-width: 1560px; margin: 0 auto; }
.view-panel { padding-top: 2px; }
.panel-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 15px; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: #eaf1ee; }
.segmented button { min-height: 30px; padding: 0 13px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-soft); font-size: 11px; font-weight: 750; }
.segmented button.is-active { background: white; color: var(--pine); box-shadow: 0 3px 10px rgba(20,61,56,.09); }
.option-strip { min-height: 46px; margin: -5px 0 12px; padding: 9px 12px; display: flex; align-items: center; gap: 22px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.72); color: var(--ink-soft); font-size: 11px; }
.option-strip label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.option-strip input { accent-color: var(--jade); }
.mapping-grid { display: grid; grid-template-columns: minmax(0,1fr) 74px minmax(0,1fr); align-items: stretch; }
.data-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.86); box-shadow: 0 10px 30px rgba(20,61,56,.055); }
.card-toolbar { min-height: 59px; padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.card-toolbar > div { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.step-index { color: var(--jade); font-size: 10px; font-weight: 900; letter-spacing: .1em; }
.search-input { width: min(270px, 58%); height: 34px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; background: #f8fbfa; color: var(--ink); font-size: 12px; }
.search-input::placeholder { color: #94a6a2; }
.search-wide { width: 330px; }
.filter-controls { min-width: 0; flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 7px; }
.filter-controls .search-input { width: min(210px, 58%); }
.filter-select { width: 112px; height: 34px; padding: 0 28px 0 10px; border: 1px solid var(--line); border-radius: 9px; background-color: #f8fbfa; color: var(--ink); font-size: 11px; font-weight: 700; cursor: pointer; }
.filter-select:hover { border-color: var(--line-strong); }
.table-wrap { height: 386px; overflow: auto; scrollbar-width: none; }
.table-wrap::-webkit-scrollbar { display: none; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; }
th { position: sticky; top: 0; z-index: 2; padding: 9px 12px; color: #718783; background: #f5f9f7; border-bottom: 1px solid var(--line); text-align: left; font-size: 10px; letter-spacing: .04em; }
td { padding: 9px 12px; border-bottom: 1px solid #edf2f0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tbody tr { cursor: pointer; transition: background .12s ease; }
tbody tr:hover { background: #f2faf7; }
tbody tr.is-selected { background: var(--mint); color: var(--pine); }
th:nth-child(2), td:nth-child(2), th:nth-child(3), td:nth-child(3) { width: 92px; }
.pager { min-height: 44px; padding: 7px 12px; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 11px; }
.pager div { display: flex; gap: 5px; }
.pager button { padding: 5px 9px; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--ink-soft); font-size: 10px; }
.pager button:disabled { opacity: .35; cursor: not-allowed; }
.mapping-action { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--ink-soft); font-size: 10px; }
.mapping-action button { width: 50px; height: 38px; border: 0; border-radius: 11px; background: var(--jade); color: white; font-size: 20px; box-shadow: 0 9px 20px rgba(0,155,128,.18); }
.mapping-action button:disabled { background: #bed1cc; box-shadow: none; cursor: not-allowed; }

.skill-card .skill-table-wrap { height: 510px; }
.skill-card th:nth-child(1) { width: 34%; }
.skill-card th:nth-child(2) { width: 90px; }
.skill-card th:nth-child(3) { width: 23%; }
.skill-card th:nth-child(4), .skill-card th:nth-child(5) { width: 86px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.metric { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.metric span { display: block; color: var(--ink-soft); font-size: 11px; }
.metric strong { display: block; margin-top: 8px; font: 750 28px var(--font-display); letter-spacing: -.04em; }

body.has-modal { overflow: hidden; }
.pending-dialog { position: fixed; inset: 0; z-index: 60; padding: 20px; display: grid; place-items: center; background: rgba(18, 42, 39, .34); backdrop-filter: blur(3px); }
.pending-dialog-shell { width: min(720px, calc(100vw - 32px)); min-height: 280px; max-height: min(680px, calc(100vh - 40px)); overflow: hidden; display: flex; flex-direction: column; border: 1px solid var(--line-strong); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 28px 80px rgba(17, 48, 44, .24); }
.pending-dialog-header { min-height: 64px; padding: 14px 16px 13px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.pending-dialog-header > div { display: flex; align-items: center; gap: 10px; }
.pending-dialog-header h2 { font-size: 18px; }
.dialog-close { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--ink-soft); font-size: 23px; font-weight: 400; line-height: 1; }
.dialog-close:hover { background: var(--paper); color: var(--ink); }
.pending-dialog-body { min-height: 140px; overflow: hidden; display: flex; flex-direction: column; }
.pending-count { min-width: 24px; height: 24px; padding: 0 7px; display: grid; place-items: center; border-radius: 99px; background: var(--mint); color: var(--pine); font-size: 11px; font-weight: 800; }
.text-button { border: 0; background: transparent; color: var(--jade); font-size: 11px; font-weight: 750; }
.text-button:disabled { color: #aebdb9; cursor: not-allowed; }
.pending-empty { margin: auto; padding: 42px 15px; color: #8ba09b; font-size: 12px; text-align: center; }
.pending-list { max-height: min(440px, calc(100vh - 210px)); overflow: auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.pending-item { padding: 10px 12px; display: grid; grid-template-columns: 76px minmax(0,1fr) auto minmax(0,1fr) auto; gap: 12px; align-items: center; border-top: 1px solid #edf2f0; font-size: 12px; }
.pending-item:first-child { border-top: 0; }
.pending-item small { color: var(--ink-soft); }
.pending-item.is-option { grid-template-columns: 76px minmax(0,1fr); }
.change-kind { width: max-content; padding: 4px 7px; border-radius: 6px; background: var(--mint); color: var(--pine); font-size: 9px; font-weight: 800; }
.pending-arrow { color: var(--jade); font-weight: 900; }
.pending-item button { border: 0; background: transparent; color: #a45c55; }
.pending-dialog-footer { min-height: 66px; margin-top: auto; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); background: #f8fbfa; }
.pending-dialog-footer .button { min-width: 112px; }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: 390px; padding: 12px 15px; color: white; background: var(--ink); border-radius: 10px; box-shadow: var(--shadow); font-size: 12px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; z-index: 50; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 68px minmax(0,1fr); }
  .rail-item { grid-template-columns: 1fr; justify-items: center; padding: 7px; }
  .rail-item span:not(.rail-icon), .rail-item small, .rail-footer span { display: none; }
  .rail-footer { align-items: center; padding: 8px 0; }
  .mapping-grid { grid-template-columns: 1fr; gap: 10px; }
  .mapping-action { flex-direction: row; padding: 2px 0; }
  .mapping-action button { transform: rotate(90deg); }
  .table-wrap { height: 310px; }
  .metric-grid { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 680px) {
  .topbar { height: auto; padding: 12px; align-items: flex-start; flex-direction: column; gap: 10px; }
  .brand-lockup { min-width: 0; }
  .brand-lockup h1 { font-size: 18px; white-space: nowrap; }
  .topbar-actions { width: 100%; margin-left: 0; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
  .topbar-actions #openButton { display: none; }
  body.has-archive .topbar-actions #openButton { display: inline-grid; }
  .version-switch { position: absolute; top: 15px; right: 12px; height: 34px; font-size: 11px; }
  .topbar-actions .button.icon-button { padding: 0; }
  .workspace { display: block; }
  .rail { position: relative; top: auto; z-index: 10; padding: 7px; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  body:not(.has-archive) .topbar { gap: 0; }
  .rail-item { min-width: 48px; width: auto; }
  .rail-divider, .rail-footer, .rail-item.is-muted { display: none; }
  .content-stage { padding: 12px; }
  .empty-state h2 { max-width: 100%; padding: 0 8px; font-size: 30px; line-height: 1.22; word-break: break-all; }
  .empty-copy { max-width: 100%; padding: 0 7px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
  .option-strip { align-items: flex-start; flex-direction: column; gap: 8px; }
  .search-wide { width: 100%; }
  .card-toolbar { align-items: flex-start; flex-direction: column; }
  .card-toolbar .search-input { width: 100%; }
  .filter-controls { width: 100%; }
  .filter-controls .search-input { width: 100%; }
  .filter-select { width: 116px; flex: 0 0 116px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .pending-item { grid-template-columns: 1fr auto; }
  .pending-item .change-kind { grid-column: 1 / -1; }
  .pending-item .pending-arrow { display: none; }
  .pending-item.is-option { grid-template-columns: 1fr; }
  .pending-dialog { padding: 10px; }
  .pending-dialog-shell { width: 100%; max-height: calc(100vh - 20px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
  .welcome-sprite { animation: none !important; background-position: 0 -468px; }
  .loading-sprite { animation: none !important; background-position: 0 -156px; }
  .error-sprite { animation: none !important; background-position: -432px -780px; }
  .loading-activity span { animation: none !important; transform: scaleY(.58); opacity: .65; }
}
