:root {
  color-scheme: light;
  --bg: #f5f8fc;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --line: #dfe7f1;
  --line-strong: #cbd7e6;
  --text: #142033;
  --muted: #66758a;
  --subtle: #94a1b2;
  --blue: #1463df;
  --blue-dark: #0d4eb7;
  --blue-soft: #eaf2ff;
  --green: #15835d;
  --green-soft: #e8f7f0;
  --danger: #c83c4d;
  --danger-soft: #fff0f2;
  --shadow: 0 14px 45px rgba(35, 59, 94, 0.1);
  --sidebar-width: 248px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image:
    linear-gradient(#e9eef6 1px, transparent 1px),
    linear-gradient(90deg, #e9eef6 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--text);
}

button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(20, 99, 223, 0.2);
  outline-offset: 2px;
}

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  padding: 30px 20px 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 30px;
}

.brand-mark, .dialog-icon, .inventory-icon, .stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--blue);
  color: white;
  box-shadow: 0 8px 20px rgba(20, 99, 223, 0.23);
}

.brand-mark svg { width: 21px; }
.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-size: 17px; letter-spacing: 0; }
.brand-copy small { color: var(--muted); font-size: 12px; }

.main-nav { display: grid; gap: 7px; }

.nav-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 11px;
  min-height: 46px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: 160ms ease;
}

.nav-item svg { width: 19px; }
.nav-item:hover { background: var(--surface-muted); color: var(--text); }
.nav-item.active { background: var(--blue-soft); color: var(--blue-dark); font-weight: 650; }
.primary-nav { margin-bottom: 16px; border-color: #cbdcf6; color: var(--blue-dark); }
.primary-nav kbd {
  display: inline-flex;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border: 1px solid #c3d4ec;
  border-radius: 5px;
  background: white;
  color: var(--blue);
  font: 600 16px/1 system-ui;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 15px 10px 0;
  border-top: 1px solid var(--line);
}

.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #1ca46f; box-shadow: 0 0 0 4px #e1f6ed; }
.sidebar-footer div:last-child { display: grid; gap: 2px; }
.sidebar-footer strong { font-size: 12px; }
.sidebar-footer span { color: var(--muted); font-size: 11px; }

.workspace {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  padding: 0 clamp(28px, 5vw, 72px) 56px;
}

.topbar {
  display: flex;
  min-height: 126px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.eyebrow { margin: 0 0 5px; color: var(--blue); font-size: 11px; font-weight: 750; letter-spacing: 0.12em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 27px; line-height: 1.2; letter-spacing: 0; }
h2 { margin-bottom: 7px; font-size: 18px; letter-spacing: 0; }

.inventory { display: flex; align-items: center; gap: 11px; }
.inventory-icon { width: 38px; height: 38px; border-radius: 7px; background: var(--surface); color: var(--blue); border: 1px solid var(--line); }
.inventory-icon svg { width: 18px; }
.inventory > span:last-child { display: grid; gap: 1px; }
.inventory small { color: var(--muted); font-size: 11px; }
.inventory strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.mobile-import { display: none !important; }

.view { max-width: 1180px; margin: 0 auto; padding-top: 34px; }
.view[hidden] { display: none; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); background: var(--surface); box-shadow: 0 8px 28px rgba(35, 59, 94, 0.06); }
.stat-block { display: flex; align-items: center; gap: 14px; min-height: 104px; padding: 20px 24px; }
.stat-block + .stat-block { border-left: 1px solid var(--line); }
.stat-icon { width: 40px; height: 40px; border-radius: 7px; }
.stat-icon svg { width: 19px; }
.stat-icon.blue { color: var(--blue); background: var(--blue-soft); }
.stat-icon.green { color: var(--green); background: var(--green-soft); }
.stat-icon.gray { color: #6b778a; background: #eef1f5; }
.stat-block div { display: grid; gap: 4px; }
.stat-block small { color: var(--muted); font-size: 12px; }
.stat-block strong { font-size: 24px; line-height: 1; font-variant-numeric: tabular-nums; }

.section-heading { display: flex; align-items: flex-end; justify-content: space-between; margin: 38px 0 15px; }
.section-heading p { margin-bottom: 0; color: var(--muted); font-size: 13px; }

.extract-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 19px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.number-field { display: grid; flex: 1; max-width: 290px; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 650; }
.input-shell { display: flex; height: 44px; align-items: center; border: 1px solid var(--line-strong); background: white; transition: 160ms ease; }
.input-shell:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20, 99, 223, 0.1); }
.input-shell input { width: 100%; min-width: 0; height: 100%; padding: 0 14px; border: 0; outline: 0; color: var(--text); font-weight: 700; }
.input-shell small { padding-right: 14px; color: var(--muted); font-weight: 500; }

.button, .text-button, .icon-button, .segment {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  cursor: pointer;
  transition: 160ms ease;
}

.button { min-height: 44px; padding: 0 17px; border-radius: 6px; font-size: 13px; font-weight: 700; }
.button svg, .text-button svg { width: 17px; }
.button-primary { background: var(--blue); color: white; box-shadow: 0 7px 18px rgba(20, 99, 223, 0.2); }
.button-primary:hover { background: var(--blue-dark); transform: translateY(-1px); }
.button-secondary { border: 1px solid var(--line-strong); background: white; color: #3e4d62; }
.button-secondary:hover { border-color: #aabbd1; background: var(--surface-muted); }
.button:disabled, .text-button:disabled { cursor: not-allowed; opacity: 0.45; transform: none; }

.output-panel, .editor-panel { border: 1px solid var(--line); background: var(--surface); }
.output-panel { margin-top: 16px; }
.panel-toolbar { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 16px; padding: 0 15px 0 18px; border-bottom: 1px solid var(--line); }
.panel-toolbar > div { display: flex; align-items: center; gap: 9px; min-width: 0; }
.panel-title { font-size: 13px; font-weight: 750; }
.result-count { padding-left: 9px; border-left: 1px solid var(--line); color: var(--subtle); font-size: 11px; white-space: nowrap; }
.output-panel textarea { display: block; width: 100%; min-height: 290px; resize: vertical; padding: 20px; border: 0; outline: 0; background: #fbfcfe; color: #26364c; font: 13px/1.75 "Cascadia Code", Consolas, monospace; }
textarea::placeholder { color: #a6b2c2; }

.converter-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.segmented-control { display: inline-flex; padding: 4px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.segment { min-height: 38px; padding: 0 14px; border-radius: 5px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 650; }
.segment svg { width: 16px; }
.segment:hover { color: var(--text); }
.segment.active { background: var(--blue-soft); color: var(--blue-dark); }

.converter-grid { display: grid; grid-template-columns: minmax(0, 1fr) 38px minmax(0, 1fr); align-items: stretch; }
.editor-panel { min-width: 0; }
.editor-panel textarea { display: block; width: 100%; height: 430px; resize: vertical; padding: 18px; border: 0; outline: 0; color: #26364c; font: 12px/1.75 "Cascadia Code", Consolas, monospace; }
.output-editor textarea { background: #fbfcfe; }
.flow-indicator { display: flex; align-items: center; justify-content: center; color: var(--blue); }
.flow-indicator svg { width: 18px; }
.text-button { padding: 8px; background: transparent; color: var(--blue); font-size: 12px; font-weight: 700; }
.text-button:hover { background: var(--blue-soft); }
.format-hint { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.format-hint svg { width: 15px; color: var(--blue); }
.format-hint code { padding: 2px 5px; border: 1px solid var(--line); background: white; color: var(--text); }

.icon-button { width: 38px; height: 38px; border-radius: 6px; background: transparent; color: var(--muted); }
.icon-button:hover { background: var(--surface-muted); color: var(--text); }
.icon-button svg { width: 19px; }

.import-dialog { width: min(720px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 8px; background: transparent; box-shadow: var(--shadow); }
.import-dialog::backdrop { background: rgba(18, 30, 49, 0.48); backdrop-filter: blur(3px); }
.dialog-shell { background: var(--surface); }
.dialog-header { display: grid; grid-template-columns: 42px 1fr 38px; align-items: center; gap: 12px; padding: 22px 24px 18px; border-bottom: 1px solid var(--line); }
.dialog-icon { width: 42px; height: 42px; border-radius: 7px; background: var(--blue-soft); color: var(--blue); }
.dialog-icon svg { width: 20px; }
.dialog-header h2 { margin-bottom: 4px; }
.dialog-header p { margin: 0; color: var(--muted); font-size: 12px; }
.format-example { display: flex; align-items: center; gap: 12px; margin: 18px 24px 12px; padding: 11px 13px; border: 1px solid #cfe0f9; background: #f3f7fe; color: var(--muted); font-size: 11px; overflow: auto; }
.format-example span { flex: 0 0 auto; font-weight: 700; color: var(--blue-dark); }
.format-example code { color: #344760; white-space: nowrap; }
.dialog-editor { display: block; margin: 0 24px; border: 1px solid var(--line-strong); }
.dialog-editor:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20, 99, 223, 0.1); }
.dialog-editor textarea { display: block; width: 100%; height: 260px; resize: vertical; padding: 16px; border: 0; outline: 0; color: #26364c; font: 12px/1.7 "Cascadia Code", Consolas, monospace; }
.dialog-meta { display: flex; justify-content: space-between; padding: 9px 24px 18px; color: var(--subtle); font-size: 11px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--line); background: var(--surface-muted); }

.toast-region { position: fixed; z-index: 100; right: 24px; bottom: 24px; display: grid; width: min(380px, calc(100vw - 32px)); gap: 10px; }
.toast { display: grid; grid-template-columns: 20px 1fr auto; align-items: start; gap: 10px; padding: 14px 15px; border: 1px solid var(--line); border-left: 3px solid var(--green); border-radius: 6px; background: white; box-shadow: var(--shadow); animation: toast-in 180ms ease-out; }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: #ca7a13; }
.toast svg { width: 18px; color: var(--green); }
.toast.error svg { color: var(--danger); }
.toast.warning svg { color: #ca7a13; }
.toast span { font-size: 12px; line-height: 1.5; }
.toast button { border: 0; background: transparent; color: var(--subtle); cursor: pointer; }

.loading { pointer-events: none; opacity: 0.7; }
.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; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 820px) {
  :root { --sidebar-width: 0px; }
  body { background-size: 24px 24px; }
  .sidebar { inset: auto 0 0; width: 100%; height: 68px; padding: 8px 12px; border-top: 1px solid var(--line); border-right: 0; }
  .brand, .sidebar-footer { display: none; }
  .main-nav { grid-template-columns: 1fr 1fr; height: 100%; gap: 8px; }
  .nav-item { display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: 0; padding: 0; text-align: center; font-size: 11px; }
  .nav-item.primary-nav { display: none; }
  .nav-item svg { width: 18px; height: 18px; }
  .workspace { margin-left: 0; padding: 0 18px 98px; }
  .topbar { min-height: 96px; }
  .topbar h1 { font-size: 23px; }
  .inventory { display: none; }
  .mobile-import { display: inline-flex !important; margin-left: auto; border: 1px solid var(--line); background: white; color: var(--blue); }
  .view { padding-top: 22px; }
  .stats-grid { grid-template-columns: 1fr; }
  .stat-block { min-height: 78px; }
  .stat-block + .stat-block { border-left: 0; border-top: 1px solid var(--line); }
  .section-heading { margin-top: 28px; }
  .extract-controls { align-items: stretch; flex-direction: column; }
  .number-field { max-width: none; }
  .converter-toolbar { align-items: stretch; flex-direction: column; }
  .segmented-control { display: grid; grid-template-columns: 1fr 1fr; }
  .converter-grid { grid-template-columns: 1fr; gap: 12px; }
  .flow-indicator { height: 20px; transform: rotate(90deg); }
  .editor-panel textarea { height: 300px; }
  .dialog-header { padding: 18px; }
  .format-example, .dialog-editor { margin-left: 18px; margin-right: 18px; }
  .dialog-meta { padding-left: 18px; padding-right: 18px; }
  .dialog-actions { padding: 14px 18px; }
  .toast-region { right: 16px; bottom: 84px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-block { justify-content: center; min-height: 90px; padding: 13px 7px; text-align: center; }
  .stat-icon { display: none; }
  .stat-block small { font-size: 10px; }
  .stat-block strong { font-size: 20px; }
  .stat-block + .stat-block { border-top: 0; border-left: 1px solid var(--line); }
  .panel-toolbar { padding-left: 13px; }
  .output-panel .button span { display: none; }
  .output-panel .button { width: 40px; padding: 0; }
  .segment { padding: 0 8px; font-size: 11px; }
  .dialog-header { grid-template-columns: 38px 1fr 34px; gap: 9px; }
  .dialog-icon { width: 38px; height: 38px; }
  .dialog-meta { gap: 12px; }
}
