:root {
  color-scheme: light;
  --navy: #174f7b;
  --navy-dark: #153f63;
  --blue-soft: #e9f3ff;
  --ink: #17243a;
  --muted: #66758b;
  --line: #dfe7f0;
  --page: #f3f7fb;
  --green: #15956f;
  --red: #db3b39;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; }
body { margin: 0; color: var(--ink); background: var(--page); font: 14px/1.45 "Segoe UI", Arial, sans-serif; }
img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.app-shell.public-mode { grid-template-columns: minmax(0, 1fr); }
.app-shell.public-mode .sidebar { display: none; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: white; }
.brand { height: 76px; display: flex; align-items: center; gap: 12px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.brand-icon { flex: 0 0 auto; width: 82px; height: 32px; padding: 4px 6px; border: 1px solid #d8e3ec; border-radius: 7px; background: white; object-fit: contain; }
.brand strong, .brand small { display: block; }
.brand strong { color: var(--navy-dark); font-size: 13px; }
.brand small { color: var(--muted); font-size: 10px; }
nav { padding: 14px 9px; }
.nav-section { display: block; margin: 14px 12px 6px; color: #93a3b3; font-size: 8px; font-weight: 800; letter-spacing: .14em; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 0; border-radius: 6px; background: transparent; color: #34475e; text-align: left; }
.nav-item span { width: 17px; color: #57708b; text-align: center; }
.nav-item:hover, .nav-item.active { color: var(--navy); background: #e7f2ff; }
.nav-item.active { font-weight: 600; }
.nav-item.locked::after { content: "🔒"; margin-left: auto; font-size: 9px; opacity: .55; }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; margin: auto 14px 14px; border-radius: 50%; color: white; background: #2d3238; }
.page { min-width: 0; position: relative; }
.topbar { min-height: 92px; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 14px clamp(16px, 2vw, 30px); border-bottom: 1px solid #d9e5f0; background: #f9fcffeb; box-shadow: 0 8px 28px #173c650d; backdrop-filter: blur(16px); }
.topbar-brand { min-width: 0; flex: 1 1 auto; display: flex; align-items: center; gap: 14px; }
.topbar-logo { flex: 0 0 auto; width: 96px; height: 42px; padding: 5px 8px; border: 1px solid #d6e2ed; border-radius: 11px; background: white; box-shadow: 0 6px 18px #174f7b1c; object-fit: contain; }
.topbar-copy { min-width: 0; }
.topbar p { margin: 0 0 3px; color: #58728c; font-size: 9px; font-weight: 700; letter-spacing: .13em; }
.topbar h1 { margin: 0; overflow: hidden; color: #102d49; font-size: clamp(13px, 1.15vw, 17px); line-height: 1.25; letter-spacing: .01em; text-overflow: ellipsis; white-space: nowrap; }
.topbar-copy small { display: block; margin-top: 3px; color: #718399; font-size: 10px; font-weight: 600; letter-spacing: .08em; }
.top-actions { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
.top-search { width: 0; height: 42px; display: grid; grid-template-columns: 20px minmax(0, 1fr) 32px; align-items: center; gap: 7px; padding: 0; overflow: hidden; border: 0 solid #adc9df; border-radius: 10px; color: var(--navy); background: white; opacity: 0; pointer-events: none; box-shadow: 0 5px 16px #174f7b12; transition: width .22s ease, padding .22s ease, border-width .22s ease, opacity .15s ease; }
.top-search.open { width: clamp(280px, 32vw, 540px); padding: 0 6px 0 13px; border-width: 1px; opacity: 1; pointer-events: auto; }
.top-search input { min-width: 0; width: 100%; padding: 9px 0; border: 0; outline: 0; color: var(--ink); background: transparent; }
.top-search button { width: 30px; height: 30px; border: 0; border-radius: 7px; color: #60758a; background: #eef4f9; font-size: 17px; }
.top-action { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 15px; border: 1px solid #d6e2ed; border-radius: 10px; color: #27435e; background: white; box-shadow: 0 4px 12px #173c650b; transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease; }
.top-action:hover { border-color: #8fb7d6; box-shadow: 0 7px 18px #174f7b1b; transform: translateY(-1px); }
.top-action.lookup { border-color: #1c5f91; color: white; background: linear-gradient(145deg, #216b9f, #174f7b); }
.top-action.lookup.active { border-color: #70b4df; box-shadow: 0 0 0 3px #2b80b925, 0 8px 20px #174f7b2b; }
.top-action.admin span { color: var(--navy); }
.top-action.admin strong, .top-action.lookup strong { font-size: 12px; font-weight: 650; }
.top-action.logout { width: 42px; padding: 0; }
.preference-action { width: 42px; padding: 0; font-weight: 800; }
.top-actions button, .secondary-button { min-height: 34px; }
.secondary-button { padding: 0 11px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: white; }
a.secondary-button { display: inline-flex; align-items: center; text-decoration: none; }
main { padding: 20px; }
main:has(> .hierarchy-panel) { padding: 0; }
#searchResults:not(:empty) { padding: 16px clamp(12px, 2vw, 28px) 0; background: #f1f6fb; }
.search-result-row { cursor: pointer; }
.search-result-row:hover { background: #f1f8fe; }
.search-result-path { color: #526b83; font-size: 11px; }
.search-result-open { color: var(--navy); font-weight: 700; white-space: nowrap; }
.panel { border: 1px solid var(--line); border-radius: 8px; background: white; box-shadow: 0 5px 18px #1b416a0a; }
.panel + .panel { margin-top: 16px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; }
.panel-heading h2, .panel-heading h3 { margin: 0; font-size: 16px; }
.panel-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.search-row { padding: 16px; }
.search-box { display: flex; align-items: center; gap: 10px; padding: 0 13px; border: 1px solid var(--line); border-radius: 7px; background: white; box-shadow: 0 4px 14px #173c6510; }
.search-box input { width: 100%; padding: 12px 0; border: 0; outline: 0; }
.hierarchy-panel { width: 100%; min-height: calc(100dvh - 76px); padding: clamp(12px, 2vw, 28px); overflow: auto; background: linear-gradient(180deg, #f8fbfe, #f1f6fb); }
.hierarchy-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.hierarchy-actions { display: flex; gap: 8px; }
.hierarchy-path { min-width: 0; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 9px 12px; overflow-x: auto; border: 1px solid #dfe9f2; border-radius: 8px; color: var(--muted); background: white; white-space: nowrap; }
.hierarchy-path > span { color: #7890a7; }
.hierarchy-crumb { padding: 5px 9px; border: 0; border-radius: 6px; color: var(--navy); background: var(--blue-soft); font-weight: 600; }
.hierarchy-crumb:hover, .hierarchy-crumb:focus-visible { color: white; background: var(--navy); outline: none; }
.hierarchy-step { width: 100%; }
.hierarchy-list { display: grid; gap: 10px; }
.hierarchy-item { width: 100%; min-height: clamp(62px, 7vh, 78px); display: grid; grid-template-columns: 42px minmax(0, 1fr) auto 24px; align-items: center; gap: 14px; padding: 12px 18px; border: 1px solid #d8e4ee; border-radius: 10px; color: var(--ink); background: white; text-align: left; box-shadow: 0 4px 14px #173c650b; transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease; }
.hierarchy-item:hover, .hierarchy-item.selected { color: var(--navy); border-color: #8db9dc; background: #f7fbff; box-shadow: 0 7px 18px #164d7c18; transform: translateY(-1px); }
.hierarchy-item-index { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; color: var(--navy); background: #e7f2fc; font-size: 11px; font-weight: 700; }
.hierarchy-item-name { overflow: hidden; font-size: 14px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.hierarchy-item small { padding: 5px 9px; border-radius: 99px; color: #587087; background: #eef4f9; font-size: 11px; white-space: nowrap; }
.hierarchy-item-arrow { color: #7991a8; font-size: 24px; line-height: 1; text-align: right; }
.hierarchy-empty { padding: 18px 8px; color: var(--muted); font-size: 12px; text-align: center; }
.hierarchy-complete { display: grid; gap: 5px; margin-bottom: 20px; padding: 18px; border: 1px solid #a9d7bb; border-radius: 8px; color: #185c35; background: #effaf3; }
.hierarchy-complete small { color: #417455; }
.hierarchy-details { padding: 0 20px 20px; }
.hierarchy-details h3 { margin: 0 0 10px; }
.hierarchy-details a { color: var(--blue); text-decoration: none; }
.table-note { color: var(--muted); font-size: 11px; }
.factory-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 14px; padding: 0 20px 20px; }
.factory-card { width: 100%; padding: 16px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #f8fbff; text-align: left; }
.factory-card:hover, .metric:hover { border-color: #9fc1df; box-shadow: 0 5px 16px #164d7c12; }
.factory-card > div:first-child { display: flex; justify-content: space-between; align-items: center; color: var(--navy); font-size: 18px; }
.factory-card .building { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 6px; background: var(--blue-soft); }
.factory-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 16px; }
.factory-stats div { padding: 9px; border-radius: 5px; background: #edf6ff; }
.factory-stats small, .metric small { display: block; color: var(--muted); font-size: 10px; }
.factory-stats strong { font-size: 17px; }
.intro { padding: 17px 20px; background: linear-gradient(90deg, #fff, #f5faff); }
.intro h2 { max-width: 620px; margin: 0; color: var(--navy-dark); font-size: 24px; line-height: 1.15; }
.intro p { margin: 9px 0 0; color: var(--muted); }
.metrics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 13px; margin: 16px 0; }
.metric { display: flex; align-items: center; justify-content: space-between; padding: 16px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: white; text-align: left; }
.metric-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 6px; color: var(--navy); background: var(--blue-soft); }
.metric strong { font-size: 22px; }
.charts { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
.chart { padding: 18px; }
.chart h3 { margin: 0; font-size: 14px; }
.chart p { margin: 4px 0 18px; color: var(--muted); font-size: 11px; }
.bars { height: 210px; display: flex; align-items: end; justify-content: space-around; gap: 24px; padding: 12px 22px 0; border-bottom: 1px solid #9aa8b7; background: repeating-linear-gradient(to top, transparent 0 51px, #dbe3eb 52px); }
.bar { width: 25%; min-width: 50px; position: relative; border-radius: 4px 4px 0 0; background: #225985; }
.bar span { position: absolute; top: -22px; width: 100%; text-align: center; font-weight: 700; }
.bar small { position: absolute; bottom: -25px; width: 100%; text-align: center; color: var(--muted); }
.donut { width: 150px; height: 150px; margin: 20px auto; border-radius: 50%; background: conic-gradient(#225985 0 25%, #9bc1d9 25% 43%, #547c97 43% 78%, #08aaa3 78%); position: relative; }
.donut::after { content: ""; position: absolute; inset: 29px; border-radius: 50%; background: white; }
.table-wrap { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 15px; border-top: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: #5b6d83; font-size: 10px; font-weight: 600; text-transform: uppercase; }
td { font-size: 12px; }
td strong { color: #16283e; }
.badge { display: inline-block; padding: 4px 8px; border: 1px solid #b8ead9; border-radius: 99px; color: #0b8463; background: #e9fbf5; font-size: 10px; }
.badge.old, .badge.locked { border-color: #dde5ed; color: #607288; background: #f4f7fa; }
.action-icons { letter-spacing: 8px; }
.primary-button { padding: 9px 15px; border: 0; border-radius: 6px; color: white; background: var(--navy); }
.primary-button:disabled { cursor: not-allowed; opacity: .45; }
.split { display: grid; grid-template-columns: 1fr 1.25fr; gap: 16px; }
.source-panel { margin-bottom: 16px; }
.source-list { display: grid; gap: 10px; padding: 0 20px 20px; }
.source-row { display: grid; grid-template-columns: minmax(210px, .8fr) minmax(280px, 1.6fr) auto; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; background: #f8fbff; }
.source-meta { display: flex; align-items: center; gap: 10px; }
.source-meta strong, .source-meta small { display: block; }
.source-meta small { color: var(--muted); font-size: 10px; }
.source-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 6px; color: var(--navy); background: var(--blue-soft); }
.source-row input { min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: white; }
.disabled-link { pointer-events: none; opacity: .45; }
.workflow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.workflow article { display: grid; grid-template-columns: 34px 1fr; column-gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.workflow span { grid-row: 1 / 3; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: white; background: var(--navy); font-weight: 700; }
.workflow strong, .workflow small { display: block; }
.workflow small { color: var(--muted); }
.upload-box { margin: 0 20px 14px; padding: 38px 20px; border: 1px solid var(--line); border-radius: 7px; background: #f6f9fd; text-align: center; }
.upload-box { display: block; cursor: pointer; }
.upload-box b, .upload-box small { display: block; }
.upload-box b { margin-top: 9px; }
.upload-box small { margin-top: 5px; color: var(--muted); }
.upload-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 20px; }
.danger { padding: 9px 13px; border: 0; border-radius: 6px; color: white; background: var(--red); }
.form-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 20px 20px; }
.form-preview input, .form-preview textarea { padding: 11px; border: 1px solid var(--line); border-radius: 5px; background: #f8fafc; }
.form-preview textarea { grid-column: 1 / -1; min-height: 90px; resize: vertical; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.preview-box { min-height: 170px; margin: 0 20px 12px; padding: 18px; border: 1px dashed #bdcbd9; border-radius: 7px; color: var(--muted); background: #f8fafc; }
.import-summary { display: grid; gap: 8px; color: var(--ink); }
.import-summary span { color: var(--muted); }
.import-message { min-height: 20px; margin: 0 20px 20px; color: var(--green); }
.import-message.error, .form-error { color: var(--red); }
.user-cell { display: flex; align-items: center; gap: 9px; }
.user-initials { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 5px; color: var(--navy); background: var(--blue-soft); font-weight: 700; }
.log-list { display: grid; gap: 10px; padding: 0 16px 16px; }
.log-item { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: #f6f9fd; }
.log-item > span:first-child { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 5px; color: var(--navy); background: var(--blue-soft); }
.log-item div { flex: 1; }
.log-item strong, .log-item small { display: block; }
.log-item small { color: var(--muted); }
.api-status { position: fixed; right: 15px; bottom: 12px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 99px; color: #6f8092; background: #ffffffee; box-shadow: 0 4px 15px #173c6512; font-size: 10px; }
.empty { padding: 35px; color: var(--muted); text-align: center; }
.admin-command { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 24px; overflow: hidden; border: 1px solid #1d628f; border-radius: 14px; color: white; background: linear-gradient(135deg, #123f67, #216b9f); box-shadow: 0 16px 38px #174f7b24; }
.admin-command > div:first-child { max-width: 520px; }
.admin-command > div:first-child > small { color: #bcd8eb; font-size: 9px; font-weight: 800; letter-spacing: .15em; }
.admin-command h2 { margin: 5px 0 4px; font-size: 25px; }
.admin-command p { margin: 0; color: #d9e9f5; }
.admin-command-actions { display: flex; gap: 10px; }
.admin-action { min-width: 165px; min-height: 68px; display: flex; align-items: center; gap: 11px; padding: 12px 14px; border: 1px solid #ffffff38; border-radius: 11px; color: #153f63; background: white; box-shadow: 0 8px 18px #06223a22; text-align: left; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease; }
.admin-action:hover { box-shadow: 0 12px 24px #061d3030; transform: translateY(-2px); }
.admin-action > span { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 9px; color: white; background: var(--navy); font-size: 18px; }
.admin-action div { display: grid; gap: 2px; }
.admin-action strong { font-size: 12px; }
.admin-action small { color: #718599; font-size: 9px; }
.admin-action.manual > span { background: #168765; }
.admin-action.template { min-width: 145px; }
.admin-action.template > span { color: #765515; background: #fff0c8; }
.admin-import-ready { display: flex; align-items: center; gap: 10px; margin-top: 14px; padding: 13px 15px; border: 1px solid #acd6bc; border-radius: 10px; background: #f0faf4; }
.admin-import-ready > div { flex: 1; display: grid; }
.admin-import-ready small { color: #607769; }
.admin-mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 14px 0; }
.admin-mini-stats div { display: grid; gap: 3px; padding: 16px 18px; border: 1px solid #dce7f0; border-radius: 10px; background: white; box-shadow: 0 5px 16px #173c6508; }
.admin-mini-stats strong { color: #123f67; font-size: 22px; }
.admin-mini-stats small { color: var(--muted); }
.admin-records { overflow: hidden; }
.admin-record-search { min-width: min(360px, 40vw); display: flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid #d3e0eb; border-radius: 9px; color: var(--navy); background: #f8fbfd; }
.admin-record-search input { width: 100%; padding: 10px 0; border: 0; outline: 0; background: transparent; }
.admin-record-head, .admin-record { display: grid; grid-template-columns: 1.05fr 1.15fr 1.15fr 1.15fr 60px; align-items: center; gap: 14px; }
.admin-record-head { padding: 9px 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: #788a9c; background: #f7fafc; font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.admin-record-list { max-height: calc(100vh - 430px); min-height: 260px; overflow-y: auto; }
.admin-record { width: 100%; padding: 12px 18px; border: 0; border-bottom: 1px solid #e6edf3; color: var(--ink); background: white; text-align: left; transition: background .15s ease, box-shadow .15s ease; }
.admin-record:hover { position: relative; z-index: 1; background: #f2f8fd; box-shadow: inset 3px 0 var(--navy); }
.admin-record span:not(.admin-record-edit) { min-width: 0; display: grid; gap: 1px; }
.admin-record small { color: #8191a1; font-size: 9px; }
.admin-record strong, .admin-record em { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-record strong { font-size: 12px; }
.admin-record em { color: #6b7e90; font-size: 10px; font-style: normal; }
.admin-record-edit { color: var(--navy); font-size: 11px; font-weight: 700; text-align: right; }
.admin-settings { margin-top: 14px; overflow: hidden; }
.admin-settings summary { display: flex; align-items: center; gap: 12px; padding: 16px 18px; cursor: pointer; list-style: none; }
.admin-settings summary > span { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; color: var(--navy); background: var(--blue-soft); }
.admin-settings summary div { flex: 1; display: grid; }
.admin-settings summary small { color: var(--muted); }
.admin-settings summary > b { color: #8193a5; font-size: 20px; transition: transform .15s ease; }
.admin-settings[open] summary > b { transform: rotate(90deg); }
.admin-settings-body { border-top: 1px solid var(--line); padding-top: 16px; }
.admin-settings-save { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 0 20px 20px; }
.admin-settings-save .import-message { flex: 1; margin: 0; }
dialog:has(.record-form) { width: min(1040px, calc(100% - 28px)); max-height: calc(100dvh - 28px); overflow-y: auto; }
.record-editor-head { padding: 24px 64px 18px 26px; border-bottom: 1px solid var(--line); background: linear-gradient(145deg, #f8fbfe, #edf5fb); }
.record-editor-head small { color: #5b7891; font-size: 9px; font-weight: 800; letter-spacing: .14em; }
.record-editor-head h2 { margin: 4px 0 2px; color: #123f67; }
.record-editor-head p { margin: 0; color: var(--muted); font-size: 11px; }
.record-form { display: grid; gap: 16px; padding: 20px 24px 24px; }
.record-form fieldset { min-width: 0; margin: 0; padding: 16px; border: 1px solid #dce6ef; border-radius: 10px; background: #fbfdff; }
.record-form legend { padding: 0 7px; color: #234d70; font-size: 11px; font-weight: 800; }
.record-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.record-fields label { min-width: 0; display: grid; gap: 6px; }
.record-fields label > span { color: #52677b; font-size: 10px; font-weight: 700; }
.record-fields label > span b { color: var(--red); }
.record-fields input, .record-fields textarea { min-width: 0; width: 100%; padding: 10px 11px; border: 1px solid #cfdce7; border-radius: 8px; outline: 0; color: var(--ink); background: white; resize: vertical; }
.record-fields input:focus, .record-fields textarea:focus { border-color: #4183b1; box-shadow: 0 0 0 3px #2d7daf16; }
.record-form-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.danger-button { min-height: 38px; padding: 0 14px; border: 1px solid #efc4c4; border-radius: 7px; color: #b52929; background: #fff5f5; }
.danger-button:hover { color: white; background: #c73c3c; }

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e7eef6;
  --muted: #91a5b8;
  --line: #2a4053;
  --page: #0d1721;
  --navy: #3e96ca;
  --navy-dark: #dcefff;
  --blue-soft: #17344a;
}
html[data-theme="dark"] body { background: #0d1721; }
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .top-action,
html[data-theme="dark"] .top-search,
html[data-theme="dark"] .hierarchy-item,
html[data-theme="dark"] .hierarchy-path,
html[data-theme="dark"] .admin-mini-stats div,
html[data-theme="dark"] .admin-record,
html[data-theme="dark"] .admin-settings,
html[data-theme="dark"] dialog,
html[data-theme="dark"] .login-dialog,
html[data-theme="dark"] .login-input,
html[data-theme="dark"] .record-fields input,
html[data-theme="dark"] .record-fields textarea,
html[data-theme="dark"] .source-row { color: var(--ink); border-color: var(--line); background: #132330; }
html[data-theme="dark"] .topbar { border-color: #263b4d; background: #101d28ed; box-shadow: 0 8px 28px #00000030; }
html[data-theme="dark"] .brand-icon,
html[data-theme="dark"] .topbar-logo,
html[data-theme="dark"] .login-mark { border-color: #3b5367; background: #f7f9fb; }
html[data-theme="dark"] .topbar h1,
html[data-theme="dark"] .brand strong,
html[data-theme="dark"] .admin-mini-stats strong,
html[data-theme="dark"] .record-editor-head h2,
html[data-theme="dark"] .login-head h2 { color: #dcefff; }
html[data-theme="dark"] .topbar p,
html[data-theme="dark"] .topbar-copy small { color: #8ca2b5; }
html[data-theme="dark"] .top-action.lookup { color: white; background: linear-gradient(145deg, #2879ac, #18557f); }
html[data-theme="dark"] .hierarchy-panel { background: linear-gradient(180deg, #101c27, #0d1721); }
html[data-theme="dark"] .hierarchy-item:hover,
html[data-theme="dark"] .admin-record:hover { color: #e9f6ff; background: #193246; }
html[data-theme="dark"] .hierarchy-item-index,
html[data-theme="dark"] .hierarchy-crumb,
html[data-theme="dark"] .source-icon { color: #b9e1fb; background: #183a52; }
html[data-theme="dark"] .hierarchy-item small,
html[data-theme="dark"] .admin-record-search,
html[data-theme="dark"] .top-search button { color: #a8bbcb; background: #1a2c3a; }
html[data-theme="dark"] .admin-record-head,
html[data-theme="dark"] thead,
html[data-theme="dark"] .preview-box { color: #9cb0c1; border-color: var(--line); background: #10202d; }
html[data-theme="dark"] th,
html[data-theme="dark"] td,
html[data-theme="dark"] .admin-record,
html[data-theme="dark"] .admin-settings-body { border-color: var(--line); }
html[data-theme="dark"] .record-editor-head,
html[data-theme="dark"] .login-head { border-color: var(--line); background: linear-gradient(145deg, #162938, #10202d); }
html[data-theme="dark"] .record-form fieldset { border-color: var(--line); background: #10202d; }
html[data-theme="dark"] .record-fields input:focus,
html[data-theme="dark"] .record-fields textarea:focus,
html[data-theme="dark"] .login-input:focus-within { border-color: #4da3d6; background: #142837; box-shadow: 0 0 0 4px #3e96ca20; }
html[data-theme="dark"] .login-dialog::backdrop,
html[data-theme="dark"] dialog::backdrop { background: #02070bc7; }
html[data-theme="dark"] .api-status { color: #9cafc0; border-color: #2a4053; background: #132330ee; }
html[data-theme="dark"] .nav-item { color: #aec0cf; }
html[data-theme="dark"] .nav-item:hover,
html[data-theme="dark"] .nav-item.active { color: #dff3ff; background: #19384e; }
html[data-theme="dark"] .admin-settings summary,
html[data-theme="dark"] .admin-settings-save { background: #132330; }
html[data-theme="dark"] .form-error { color: #ffaaaa; background: #3a2025; }
html[data-theme="dark"] .log-item,
html[data-theme="dark"] .workflow article,
html[data-theme="dark"] .factory-card,
html[data-theme="dark"] .metric,
html[data-theme="dark"] .upload-box,
html[data-theme="dark"] .preview-box,
html[data-theme="dark"] .detail-grid div,
html[data-theme="dark"] .admin-import-ready { color: var(--ink); border-color: var(--line); background: #10202d; }
html[data-theme="dark"] .log-item > span:first-child,
html[data-theme="dark"] .user-initials { color: #bfe6ff; background: #183a52; }
html[data-theme="dark"] .log-item small,
html[data-theme="dark"] .admin-import-ready small { color: #91a8ba; }
html[data-theme="dark"] .badge,
html[data-theme="dark"] .badge.old,
html[data-theme="dark"] .badge.locked { color: #b9d5e8; border-color: #355168; background: #1a2d3c; }
html[data-theme="dark"] .secondary-button,
html[data-theme="dark"] a.secondary-button { color: #d7e8f4; border-color: #355168; background: #162837; }
html[data-theme="dark"] .secondary-button:hover,
html[data-theme="dark"] a.secondary-button:hover { border-color: #5595bd; background: #1c3548; }
html[data-theme="dark"] #searchResults:not(:empty) { background: #0d1721; }
html[data-theme="dark"] .panel-heading h2,
html[data-theme="dark"] .panel-heading h3,
html[data-theme="dark"] td strong,
html[data-theme="dark"] .detail-grid strong,
html[data-theme="dark"] .admin-record strong { color: #eef6fc; }
html[data-theme="dark"] .panel-heading p,
html[data-theme="dark"] .table-note,
html[data-theme="dark"] .admin-record small,
html[data-theme="dark"] .admin-record em,
html[data-theme="dark"] .record-fields label > span,
html[data-theme="dark"] .login-head p,
html[data-theme="dark"] .login-note { color: #9fb2c3; }
html[data-theme="dark"] th { color: #9eb6c9; }
html[data-theme="dark"] td,
html[data-theme="dark"] .search-result-row { color: #d9e6f0; }
html[data-theme="dark"] .search-result-path { color: #8fb7d3; }
html[data-theme="dark"] .search-result-open,
html[data-theme="dark"] .hierarchy-details a { color: #67c1f3; }
html[data-theme="dark"] .search-result-row:hover { background: #193246; }
html[data-theme="dark"] .top-search input,
html[data-theme="dark"] .admin-record-search input,
html[data-theme="dark"] .login-input input,
html[data-theme="dark"] .record-fields input,
html[data-theme="dark"] .record-fields textarea,
html[data-theme="dark"] .source-row input,
html[data-theme="dark"] .form-preview input,
html[data-theme="dark"] .form-preview textarea,
html[data-theme="dark"] .admin-form input,
html[data-theme="dark"] .admin-form select { color: #edf6fc; caret-color: #70c9f5; }
html[data-theme="dark"] .source-row input,
html[data-theme="dark"] .form-preview input,
html[data-theme="dark"] .form-preview textarea,
html[data-theme="dark"] .admin-form input,
html[data-theme="dark"] .admin-form select { border-color: var(--line); background: #10202d; }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #748da0; opacity: 1; }
html[data-theme="dark"] .factory-stats div { background: #173044; }
html[data-theme="dark"] .donut::after { background: #132330; }
html[data-theme="dark"] .hierarchy-complete { color: #a8e9c0; border-color: #2d6f49; background: #123225; }
html[data-theme="dark"] .hierarchy-complete small { color: #85c69d; }
html[data-theme="dark"] .hierarchy-path > span,
html[data-theme="dark"] .hierarchy-item-arrow { color: #7899b2; }
html[data-theme="dark"] .login-head small,
html[data-theme="dark"] .login-body label > span,
html[data-theme="dark"] .record-form legend { color: #a8c2d5; }
html[data-theme="dark"] .login-close { color: #b8cbd9; border-color: #365066; background: #172b3a; }
html[data-theme="dark"] .login-close:hover { color: white; background: #b83d46; }
html[data-theme="dark"] .danger-button { color: #ffaaaa; border-color: #784348; background: #351f24; }
html[data-theme="dark"] .danger-button:hover { color: white; background: #a9363e; }
html[data-theme="dark"] tbody tr { background: #132330; }
html[data-theme="dark"] tbody tr:hover { background: #193246; }
dialog { width: min(720px, calc(100% - 30px)); padding: 0; border: 0; border-radius: 10px; box-shadow: 0 30px 90px #07162666; }
dialog::backdrop { background: #06152799; }
.dialog-close { position: absolute; top: 11px; right: 12px; width: 32px; height: 32px; border: 0; border-radius: 50%; font-size: 20px; }
.detail-head { padding: 22px; color: white; background: var(--navy); }
.detail-head h2 { margin: 0; }
.detail-body { padding: 20px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 18px; }
.detail-grid div { padding: 10px; border-radius: 6px; background: var(--page); }
.detail-grid small, .detail-grid strong { display: block; }
.detail-grid small { color: var(--muted); }
.login-dialog { width: min(450px, calc(100% - 28px)); overflow: hidden; border: 1px solid #dce7f0; border-radius: 20px; background: white; box-shadow: 0 35px 100px #06152755, 0 10px 30px #06152722; }
.login-dialog::backdrop { background: #0c1b2b9e; backdrop-filter: blur(7px); }
.login-close { position: absolute; z-index: 2; top: 18px; right: 18px; width: 34px; height: 34px; border: 1px solid #dce6ef; border-radius: 10px; color: #5f7387; background: #f6f9fc; font-size: 18px; line-height: 1; transition: color .15s ease, background .15s ease, transform .15s ease; }
.login-close:hover { color: white; background: #d94a4a; transform: rotate(4deg); }
.login-head { display: flex; align-items: center; gap: 15px; padding: 28px 62px 20px 28px; border-bottom: 1px solid #e5edf4; background: linear-gradient(145deg, #ffffff, #f4f9fd); }
.login-mark { flex: 0 0 auto; width: 92px; height: 40px; padding: 5px 7px; border: 1px solid #d6e2ed; border-radius: 10px; background: white; box-shadow: 0 8px 20px #174f7b20; object-fit: contain; }
.login-head div { min-width: 0; }
.login-head small { color: #5c7892; font-size: 9px; font-weight: 800; letter-spacing: .13em; }
.login-head h2 { margin: 3px 0 2px; color: #123553; font-size: 22px; line-height: 1.2; }
.login-head p { margin: 0; color: #718398; font-size: 12px; }
.login-body { display: grid; gap: 16px; padding: 24px 28px 28px; }
.login-body label { display: grid; gap: 7px; }
.login-body label > span { color: #40566d; font-size: 11px; font-weight: 700; }
.login-input { min-height: 50px; display: grid; grid-template-columns: 22px minmax(0, 1fr); align-items: center; gap: 8px; padding: 0 13px; border: 1px solid #cfdae5; border-radius: 11px; color: #7390a8; background: #f9fbfd; transition: border-color .15s ease, background .15s ease, box-shadow .15s ease; }
.login-input:focus-within { border-color: #367eae; background: white; box-shadow: 0 0 0 4px #2d7daf18; }
.login-input b { font-size: 15px; text-align: center; }
.login-input input { min-width: 0; width: 100%; padding: 13px 0; border: 0; outline: 0; color: var(--ink); background: transparent; }
.login-input input::placeholder { color: #9aaaba; }
.login-submit { min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 12px; border: 0; border-radius: 11px; color: white; background: linear-gradient(145deg, #216b9f, #174f7b); box-shadow: 0 10px 24px #174f7b2b; font-weight: 700; transition: box-shadow .15s ease, transform .15s ease; }
.login-submit:hover { box-shadow: 0 13px 28px #174f7b3b; transform: translateY(-1px); }
.login-submit b { font-size: 17px; }
.login-note { color: #8292a2; font-size: 10px; line-height: 1.4; text-align: center; }
.form-error { margin: 0; padding: 9px 11px; border-radius: 8px; background: #fff1f1; font-size: 11px; }
.form-error:empty { display: none; }
.admin-form { display: grid; gap: 14px; padding: 22px; }
.admin-form label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.admin-form input, .admin-form select { padding: 11px 12px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: white; }
.admin-form .primary-button { justify-self: end; }
.toast-region { position: fixed; top: 108px; right: 24px; z-index: 100; width: min(390px, calc(100vw - 32px)); pointer-events: none; }
.toast { position: relative; display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 12px; padding: 14px 16px; overflow: hidden; border: 1px solid #cbd9e6; border-radius: 14px; color: #19324a; background: #fff; box-shadow: 0 18px 50px #102f4d33; animation: toast-in .2s ease-out; }
.toast::after { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: currentColor; }
.toast.success { border-color: #9fd8c5; color: #117252; }
.toast.error { border-color: #efaaa8; color: #b92d2b; }
.toast.warning { border-color: #f0cc83; color: #97600b; }
.toast-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: white; font-size: 17px; font-weight: 800; }
.toast.success .toast-icon { background: #15956f; }
.toast.error .toast-icon { background: #db3b39; }
.toast.warning .toast-icon { background: #c68418; }
.toast-copy { min-width: 0; color: var(--ink); }
.toast-copy strong, .toast-copy small { display: block; }
.toast-copy strong { margin-bottom: 2px; font-size: 13px; }
.toast-copy small { color: var(--muted); font-size: 11px; line-height: 1.45; }
html[data-theme=dark] .toast { border-color: #36536b; background: #122636; box-shadow: 0 18px 50px #0008; }
html[data-theme=dark] .toast.success { border-color: #26775e; }
html[data-theme=dark] .toast.error { border-color: #8e403f; }
html[data-theme=dark] .toast.warning { border-color: #846329; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .brand { justify-content: center; padding: 0; }
  .brand div, .nav-item:not(.active) { font-size: 0; }
  .nav-item { justify-content: center; }
  .nav-item span { font-size: 16px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .charts, .split { grid-template-columns: 1fr; }
  .source-row { grid-template-columns: 1fr; }
  .factory-grid { grid-template-columns: 1fr; }
  .admin-command { align-items: flex-start; flex-direction: column; }
  .admin-command-actions { width: 100%; }
  .admin-action { flex: 1; }
  .admin-record-head, .admin-record { grid-template-columns: 1fr 1fr 1fr 55px; }
  .admin-record-head span:nth-child(4), .admin-record span:nth-child(4) { display: none; }
  .record-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  body { font-size: 13px; overflow-x: hidden; }
  button, a, input, select, textarea { touch-action: manipulation; }
  .toast-region { top: calc(76px + env(safe-area-inset-top)); right: 12px; width: calc(100vw - 24px); }
  .app-shell { display: block; }
  .app-shell:not(.public-mode) .page { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .sidebar { position: fixed; inset: auto 0 0; z-index: 40; width: 100%; height: auto; padding-bottom: env(safe-area-inset-bottom); border: 1px solid var(--line); border-width: 1px 0 0; background: #fffffff2; box-shadow: 0 -8px 28px #173c6517; backdrop-filter: blur(16px); }
  .brand { display: none; }
  nav { min-width: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 6px 8px; overflow: visible; }
  .nav-item, .nav-item:not(.active) { min-width: 0; min-height: 52px; width: 100%; display: grid; justify-items: center; gap: 2px; padding: 5px 4px; font-size: 10px; line-height: 1.15; text-align: center; white-space: normal; }
  .nav-item span { width: auto; font-size: 16px; }
  .nav-item b { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .avatar { display: none; }
  .topbar { min-height: 68px; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px; }
  .topbar-brand { gap: 9px; }
  .topbar-logo { width: 70px; height: 36px; padding: 4px 6px; border-radius: 9px; }
  .topbar p, .topbar-copy small { display: none; }
  .topbar h1 { display: -webkit-box; overflow: hidden; font-size: 11px; line-height: 1.2; white-space: normal; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .top-actions { min-width: 0; gap: 5px; }
  .top-actions button:not(:first-child) { display: inline-flex; }
  .top-action, .preference-action { width: 36px; min-height: 38px; padding: 0; border-radius: 9px; }
  .top-action strong { display: none; }
  .topbar:has(.top-search.open) { flex-wrap: nowrap; }
  .topbar:has(.top-search.open) .top-actions { min-width: 0; width: auto; flex: 1 1 auto; }
  .topbar:has(.top-search.open) .top-action.lookup { display: none; }
  .top-search { height: 40px; }
  .top-search.open { min-width: 0; flex: 1 1 auto; width: auto; }
  main { padding: 10px; }
  #searchResults:not(:empty) { padding: 10px 10px 0; }
  .panel { border-radius: 10px; }
  .panel + .panel { margin-top: 10px; }
  .panel-heading { align-items: flex-start; padding: 14px; }
  .panel-heading h2, .panel-heading h3 { font-size: 15px; }
  .panel-heading p { font-size: 11px; }
  .metrics { grid-template-columns: 1fr; }
  .workflow { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .hierarchy-panel { min-height: calc(100dvh - 68px); padding: 10px; }
  .hierarchy-toolbar { align-items: stretch; flex-direction: column; }
  .hierarchy-path { min-height: 44px; padding: 7px; }
  .hierarchy-crumb { min-height: 34px; }
  .hierarchy-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .hierarchy-actions .secondary-button { min-height: 42px; }
  .hierarchy-item { min-height: 62px; grid-template-columns: 34px minmax(0, 1fr) 20px; gap: 9px; padding: 10px; }
  .hierarchy-item-name { font-size: 13px; white-space: normal; overflow-wrap: anywhere; }
  .hierarchy-item small { display: none; }
  .hierarchy-details { padding: 0 0 12px; }
  .hierarchy-details table { min-width: 760px; }
  .nav-section { display: none; }
  .admin-command { gap: 16px; padding: 16px; border-radius: 12px; }
  .admin-command h2 { font-size: 20px; }
  .admin-command p { font-size: 12px; }
  .admin-command-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .admin-action { min-width: 0; min-height: 64px; padding: 10px; }
  .admin-action.template { grid-column: 1 / -1; }
  .admin-import-ready { align-items: stretch; flex-wrap: wrap; }
  .admin-import-ready > div { flex-basis: 100%; }
  .admin-import-ready .primary-button, .admin-import-ready .secondary-button { min-height: 42px; flex: 1; }
  .admin-mini-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
  .admin-mini-stats div { min-width: 0; padding: 12px; }
  .admin-mini-stats strong { font-size: 19px; }
  .admin-records .panel-heading { align-items: stretch; flex-direction: column; }
  .admin-record-search { min-width: 0; width: 100%; }
  .admin-record-head { display: none; }
  .admin-record-list { max-height: none; }
  .admin-record { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 10px; padding: 14px; }
  .admin-record span:nth-child(2), .admin-record span:nth-child(3), .admin-record span:nth-child(4) { display: grid; }
  .admin-record strong, .admin-record em { white-space: normal; overflow-wrap: anywhere; }
  .admin-record-edit { grid-column: 1 / -1; min-height: 34px; display: flex; align-items: center; justify-content: flex-end; border-top: 1px solid var(--line); }
  .admin-settings summary { align-items: flex-start; padding: 14px; }
  .admin-settings-save { align-items: stretch; flex-direction: column; padding: 0 14px 14px; }
  .admin-settings-save .primary-button { min-height: 44px; }
  .record-fields { grid-template-columns: 1fr; }
  .source-row { grid-template-columns: 1fr; }
  .source-list { padding: 0 14px 14px; }
  .source-row input { width: 100%; min-height: 44px; }
  .source-row .secondary-button { min-height: 42px; justify-content: center; }
  .upload-box, .preview-box { margin-inline: 14px; }
  .upload-box { padding: 28px 14px; }
  .upload-actions { padding: 0 14px 14px; }
  .form-preview { grid-template-columns: 1fr; padding: 0 14px 14px; }
  .form-preview textarea { grid-column: auto; }
  .api-status { right: 10px; bottom: 8px; max-width: calc(100vw - 20px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-shell:not(.public-mode) .api-status { bottom: calc(72px + env(safe-area-inset-bottom)); }
  dialog, dialog:has(.record-form), .login-dialog { width: 100%; max-width: none; max-height: 100dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  dialog:has(.record-form) { height: min(92dvh, 900px); }
  .detail-head { padding: 20px 54px 18px 18px; }
  .detail-body { padding: 14px; overflow-x: hidden; }
  .detail-body .table-wrap { margin-inline: -14px; }
  .detail-body table { min-width: 620px; }
  .login-dialog { width: min(360px, calc(100% - 28px)); height: auto; max-width: 360px; max-height: calc(100dvh - 28px); margin: auto; border-radius: 18px; }
  .login-close { top: 14px; right: 14px; width: 32px; height: 32px; }
  .login-head { gap: 11px; padding: 18px 50px 15px 17px; }
  .login-mark { width: 86px; height: 36px; padding: 4px 6px; border-radius: 9px; }
  .login-head h2 { font-size: 19px; }
  .login-head p { font-size: 11px; }
  .login-body { gap: 12px; padding: 17px; }
  .login-input, .login-submit { min-height: 44px; }
  .record-editor-head { padding: 20px 54px 16px 16px; }
  .record-form { gap: 12px; padding: 14px 14px calc(18px + env(safe-area-inset-bottom)); }
  .record-form fieldset { padding: 12px; }
  .record-fields input, .record-fields textarea { min-height: 44px; font-size: 16px; }
  .record-form-actions { position: sticky; bottom: calc(-14px - env(safe-area-inset-bottom)); z-index: 2; margin: 0 -14px calc(-18px - env(safe-area-inset-bottom)); padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #fffffff2; backdrop-filter: blur(12px); }
  .record-form-actions button { min-height: 44px; }
  html[data-theme="dark"] .sidebar, html[data-theme="dark"] .record-form-actions { background: #132330f2; }
}

@media (max-width: 430px) {
  .topbar-copy { display: none; }
  .topbar-brand { flex: 0 0 auto; }
  .admin-command-actions { grid-template-columns: 1fr; }
  .admin-action.template { grid-column: auto; }
  .admin-record { grid-template-columns: 1fr; }
  .admin-record-edit { grid-column: auto; }
  .record-form-actions { align-items: stretch; flex-direction: column-reverse; }
  .record-form-actions button { width: 100%; }
}

@media (max-width: 350px) {
  .topbar-logo { width: 60px; }
  .top-action, .preference-action { width: 33px; }
  .top-actions { gap: 3px; }
  .admin-mini-stats { grid-template-columns: 1fr; }
}
