:root {
  --ink: #1b2b34;
  --muted: #66757d;
  --line: #d8e0df;
  --paper: #f5f7f5;
  --surface: #ffffff;
  --teal: #0e766e;
  --teal-dark: #075950;
  --teal-soft: #e1f1ed;
  --yellow: #f3bb45;
  --red: #b43c3c;
  --red-soft: #fbe9e7;
  --shadow: 0 12px 34px rgba(27, 43, 52, .09);
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); font: 14px/1.5 "Noto Sans SC", "Microsoft YaHei", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.eyebrow { margin: 0 0 6px; color: var(--teal); font: 500 11px/1 "DM Mono", monospace; letter-spacing: .12em; }
.muted { color: var(--muted); }
.button { border: 1px solid var(--line); border-radius: 5px; padding: 9px 14px; color: var(--ink); background: var(--surface); font-weight: 600; }
.button:hover { border-color: var(--teal); color: var(--teal); }
.button.primary { border-color: var(--teal); color: #fff; background: var(--teal); }
.button.primary:hover { background: var(--teal-dark); color: #fff; }
.button.danger { border-color: #df9290; color: var(--red); background: #fff; }
.button.small { padding: 6px 9px; font-size: 12px; }
.icon-button { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 5px; color: var(--ink); background: #fff; font-size: 18px; }
.icon-button:hover { color: var(--teal); border-color: var(--teal); }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(390px, .8fr); }
.login-brand { display: grid; grid-template-columns: auto 1fr; align-content: center; gap: 16px; padding: clamp(32px, 8vw, 120px); color: #effaf7; background: linear-gradient(135deg, #064e4a, #0a7069); }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border: 1px solid rgba(255,255,255,.55); border-radius: 7px; font: 500 25px "DM Mono", monospace; }
.login-brand .eyebrow { color: #b9e5dc; }
.login-brand h1 { margin: 0; font-size: clamp(32px, 5vw, 58px); letter-spacing: .04em; }
.brand-version { margin-left: .28em; color: #b9e5dc; font-size: .34em; font-weight: 500; letter-spacing: 0; vertical-align: .55em; }
.brand-copy { grid-column: 1 / -1; margin-top: 44px; border-top: 1px solid rgba(255,255,255,.25); padding-top: 16px; }
.brand-copy p { margin: 0 0 4px; font-size: 17px; }
.brand-copy span { color: #b9e5dc; }
.login-panel { align-self: center; width: min(420px, calc(100% - 48px)); margin: auto; }
.login-panel h2 { margin: 0; font-size: 30px; }
.sso-primary-stack { display: grid; gap: 12px; margin-top: 26px; }
.sso-primary-btn { width: 100%; padding: 12px 16px; font-weight: 600; font-size: 15px; }
.login-compat-row { text-align: center; }
.login-compat-toggle { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 4px 8px; }
.login-compat-toggle:hover { color: var(--teal); text-decoration: underline; }
.local-login-wrap[hidden] { display: none; }
.login-divider { display: flex; align-items: center; gap: 10px; margin: 16px 0 14px; color: var(--muted); font-size: 12px; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.local-login-wrap .form-stack { margin-top: 0; }
.form-stack { display: grid; gap: 17px; margin-top: 28px; }
label { display: grid; gap: 7px; font-weight: 600; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 5px; padding: 10px 11px; color: var(--ink); background: #fff; outline: none; }
textarea { min-height: 82px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14,118,110,.12); }
.form-error { margin: -5px 0 0; color: var(--red); }
.demo-accounts { display: grid; gap: 4px; margin-top: 26px; border-left: 3px solid var(--yellow); padding: 9px 12px; color: var(--muted); background: #fff8e9; font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh; padding: 22px 14px; color: #dcefeb; background: #123a3b; }
.app-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 27px; color: #fff; font-weight: 700; font-size: 18px; }
.app-brand .brand-mark { width: 31px; height: 31px; border-radius: 4px; font-size: 17px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { position: relative; display: flex; align-items: center; gap: 11px; width: 100%; border: 0; border-radius: 5px; padding: 10px; color: #cce0dc; background: transparent; text-align: left; }
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.13); }
.nav-icon { display: grid; place-items: center; width: 19px; color: #8ac7bb; }
.nav-icon svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover .nav-icon, .nav-item.active .nav-icon { color: #fff; }
.nav-short, .nav-badge { display: none; }
.user-box { margin-top: auto; border-top: 1px solid rgba(255,255,255,.18); padding: 16px 8px 2px; }
.user-name { color: #fff; font-weight: 600; }
.user-role { color: #9bc7c0; font-size: 12px; }
.logout { margin-top: 10px; border: 0; padding: 0; color: #b8d6d1; background: transparent; font-size: 12px; }
.logout:hover { color: #fff; }
.content { min-width: 0; padding: 32px clamp(18px, 4vw, 56px); }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 25px; }
.page-header h1 { margin: 0; font-size: 28px; }
.page-header p { margin: 6px 0 0; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 146px; padding: 8px 10px; }
.layout-control { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.list-select { position: relative; min-width: 0; }
.list-select select { position: absolute; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.list-select-button { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-width: 146px; border: 1px solid var(--line); border-radius: 5px; padding: 8px 10px; color: var(--ink); background: #fff; font-weight: 500; text-align: left; }
.list-select-button::after { content: ""; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: translateY(-2px) rotate(45deg); }
.list-select-button:hover, .list-select-button:focus-visible { border-color: var(--teal); }
.list-select-menu { position: fixed; z-index: 20; display: grid; overflow: auto; max-height: min(280px, 50vh); border: 1px solid var(--line); border-radius: 5px; background: #fff; box-shadow: var(--shadow); }
.list-select-menu[hidden] { display: none; }
.list-select-option { border: 0; padding: 9px 12px; color: var(--ink); background: transparent; text-align: left; }
.list-select-option:hover, .list-select-option.active { color: var(--teal-dark); background: var(--teal-soft); }
.saved-accounts { display: grid; gap: 8px; }
.saved-accounts-title { margin: 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.saved-account { display: flex; align-items: center; gap: 8px; }
.saved-account-pick { flex: 1; border: 1px solid var(--line); border-radius: 5px; padding: 9px 11px; color: var(--ink); background: #fff; font-weight: 600; text-align: left; }
.saved-account.selected .saved-account-pick { border-color: var(--teal); color: var(--teal-dark); background: var(--teal-soft); }
.saved-account-remove { border: 0; padding: 8px 2px; color: var(--muted); background: transparent; font-size: 12px; }
.saved-account-remove:hover { color: var(--red); }
.remember-account { display: flex; flex-direction: row; align-items: center; gap: 8px; font-weight: 600; }
.remember-account input { width: 16px; height: 16px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { border: 1px solid var(--line); border-radius: 6px; padding: 16px; background: var(--surface); }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { margin-top: 5px; font: 500 28px/1.15 "DM Mono", monospace; }
.stat-note { margin-top: 7px; color: var(--teal); font-size: 12px; }
.dashboard-stock { margin-bottom: 24px; }
.dashboard-stock-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); padding: 16px 18px 13px; }
.dashboard-stock-header h2 { margin: 0; font-size: 16px; }
.dashboard-stock-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.dashboard-stock-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.dashboard-stock-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 12px; min-width: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 13px 18px; }
.dashboard-stock-item > div { min-width: 0; }
.dashboard-stock-item strong { display: block; overflow-wrap: anywhere; line-height: 1.35; }
.dashboard-stock-item .mono { display: block; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-stock-item .dashboard-stock-value { align-self: center; color: var(--teal-dark); font: 600 16px "DM Mono", monospace; white-space: nowrap; }
.lan-access { margin-bottom: 24px; }
.lan-access-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 16px 18px 0; }
.lan-access-header h2 { margin: 0; font-size: 16px; }
.lan-access-header p { margin: 5px 0 0; color: var(--muted); }
.lan-addresses { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 18px; }
.lan-url { border: 1px solid #a6cfca; border-radius: 5px; padding: 6px 9px; color: var(--teal-dark); background: #edf7f5; font: 500 13px "DM Mono", monospace; text-decoration: none; }
.lan-url:hover { border-color: var(--teal); background: var(--teal-soft); }
.service-state { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.service-state.checking { color: var(--muted); background: #f6f8f8; }
.service-state.running { border-color: #91c9ba; color: var(--teal-dark); background: var(--teal-soft); }
.service-state.stopped { border-color: #df9290; color: var(--red); background: var(--red-soft); }
.lan-service-details { margin: 0; border-top: 1px solid var(--line); padding: 10px 18px; color: var(--teal-dark); font: 12px "DM Mono", monospace; }
.lan-access-note { margin: 0; border-top: 1px solid var(--line); padding: 10px 18px; color: var(--muted); font-size: 12px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 28px 0 13px; }
.section-heading h2 { margin: 0; font-size: 17px; }

.material-grid { display: grid; gap: 16px; }
@media (max-width: 860px) {
  .material-grid.columns-3 { gap: 8px; }
  .material-grid.columns-4 { gap: 6px; }
}
.material-grid.columns-1 { grid-template-columns: minmax(0, 1fr); }
.material-grid.columns-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.material-grid.columns-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.material-grid.columns-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.material-card { display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); transition: transform .15s, box-shadow .15s; }
.material-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.material-card.sortable.dragging { cursor: grabbing; opacity: .45; transform: none; }
.material-card.sortable.drag-over-before { box-shadow: inset 0 4px 0 var(--teal); }
.material-card.sortable.drag-over-after { box-shadow: inset 0 -4px 0 var(--teal); }
.material-card.inactive { border-color: #c7cdcf; color: #7b8488; background: #f3f4f4; }
.material-card.inactive:hover { transform: none; box-shadow: none; }
.material-card.sortable.inactive.drag-over-before { box-shadow: inset 0 4px 0 var(--teal); }
.material-card.sortable.inactive.drag-over-after { box-shadow: inset 0 -4px 0 var(--teal); }
.material-card.inactive .material-image img { filter: grayscale(1); }
.material-card.inactive .material-image-button:hover img { transform: none; }
.material-card.inactive .model, .material-card.inactive .stock-unit, .material-card.inactive .location, .material-card.inactive .muted { color: #858d91; }
.material-image { aspect-ratio: 16 / 10; overflow: hidden; background: #e9eeee; }
.material-image-button { display: block; width: 100%; height: 100%; border: 0; padding: 0; background: transparent; }
.material-image-button:focus-visible { outline: 3px solid var(--teal); outline-offset: -3px; }
.material-image img, .material-detail-image img { width: 100%; height: 100%; object-fit: cover; transition: transform .15s; }
.material-image-button:hover img { transform: scale(1.03); }
.material-body { padding: 13px; }
.material-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.material-top > :first-child { flex: 1 1 auto; min-width: 0; }
.material-title-row { display: flex; align-items: flex-start; gap: 7px; }
.material-title { margin: 0; overflow-wrap: anywhere; font-size: 16px; }
.drag-handle { flex: 0 0 auto; width: 25px; height: 25px; border: 1px solid var(--line); border-radius: 4px; padding: 0; color: var(--muted); background: #f7faf9; cursor: grab; font-size: 14px; line-height: 1; }
.drag-handle:hover, .drag-handle:focus-visible { border-color: var(--teal); color: var(--teal-dark); background: var(--teal-soft); }
.drag-handle:active { cursor: grabbing; }
.model { color: var(--muted); font: 12px "DM Mono", monospace; }
.stock-line { display: flex; align-items: baseline; gap: 5px; margin-top: 12px; }
.stock-value { font: 500 25px/1 "DM Mono", monospace; }
.stock-unit { color: var(--muted); font-size: 12px; }
.location { margin: 9px 0 14px; color: var(--muted); font-size: 12px; }
.card-actions { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.card-action-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.badge-group { display: flex; flex: 0 0 auto; align-self: flex-start; flex-wrap: wrap; align-items: flex-start; justify-content: flex-end; gap: 5px; }
.badge { display: inline-flex; flex: 0 0 auto; align-items: center; border-radius: 999px; padding: 3px 8px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.ready, .badge.returned { color: #07665f; background: var(--teal-soft); }
.badge.low, .badge.pending { color: #93620b; background: #fff3d4; }
.badge.out, .badge.danger { color: #a72e2e; background: var(--red-soft); }
.badge.using { color: #215f93; background: #e7f1fa; }
.badge.inactive { color: #687176; background: #e2e5e6; }
.empty { padding: 40px 20px; border: 1px dashed #bbc8c7; border-radius: 6px; color: var(--muted); text-align: center; background: rgba(255,255,255,.55); }
.material-detail { display: grid; grid-template-columns: minmax(280px, .9fr) minmax(0, 1.1fr); overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.material-detail-image { min-height: 300px; background: #e9eeee; }
.material-detail-body { padding: 25px; }
.material-detail-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.material-detail-heading .eyebrow { margin-top: 3px; }
.material-detail-heading h2 { margin: 0; font-size: 24px; }
.detail-stock { display: flex; align-items: baseline; gap: 6px; margin: 24px 0; }
.detail-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; border-top: 1px solid var(--line); }
.detail-list div { min-width: 0; border-bottom: 1px solid var(--line); padding: 12px 0; }
.detail-list div:nth-child(odd) { padding-right: 18px; }
.detail-list div:nth-child(even) { border-left: 1px solid var(--line); padding-left: 18px; }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { margin: 3px 0 0; overflow-wrap: anywhere; }
.detail-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 20px; }

.panel { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.panel-body { padding: 18px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; }
.cart-item { display: grid; grid-template-columns: 50px 1fr 90px auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid #edf0ef; }
.cart-item:last-child { border-bottom: 0; }
.cart-item img { width: 50px; height: 38px; border-radius: 3px; object-fit: cover; }
.cart-item strong { display: block; }
.cart-item span { color: var(--muted); font-size: 12px; }
.cart-item input { padding: 6px 8px; }
.summary-list { display: grid; gap: 9px; margin: 17px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 13px 0; }
.summary-row { display: flex; justify-content: space-between; color: var(--muted); }
.summary-row strong { color: var(--ink); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { border-bottom: 1px solid #e9efed; padding: 12px 14px; text-align: left; font-size: 13px; }
th { color: #4f6165; background: #f7f9f8; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.mono { font-family: "DM Mono", monospace; font-size: 12px; }
.row-actions { vertical-align: middle; }
.row-actions-list { display: flex; flex-wrap: wrap; gap: 6px; }
.modal-backdrop { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 20px; background: rgba(15,31,35,.52); }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; border-radius: 7px; background: #fff; box-shadow: 0 18px 60px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 16px 18px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); padding: 14px 18px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 30; border-radius: 5px; padding: 11px 15px; color: #fff; background: #163f3d; box-shadow: var(--shadow); }
body.is-busy { overflow: hidden; }
.busy-overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; background: rgba(15,31,35,.52); }
.busy-dialog { display: grid; justify-items: center; gap: 16px; width: min(280px, 100%); border-radius: 8px; padding: 28px 24px 24px; text-align: center; background: #fff; box-shadow: 0 18px 60px rgba(0,0,0,.25); }
.busy-spinner { width: 46px; height: 46px; border: 4px solid var(--teal-soft); border-top-color: var(--teal); border-radius: 50%; animation: busy-spin .75s linear infinite; }
.busy-text { margin: 0; font-size: 15px; font-weight: 600; }
@keyframes busy-spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { min-height: 230px; padding: 34px 24px; }
  .brand-copy { margin-top: 18px; }
  .login-panel { width: min(440px, calc(100% - 40px)); padding: 44px 0; }
  .app-shell { display: block; }
  .sidebar { position: sticky; z-index: 5; display: flex; flex-direction: row; align-items: center; width: 100%; height: auto; min-height: 64px; padding: 8px 10px; gap: 8px; }
  .app-brand { flex: 0 0 auto; padding: 0; font-size: 15px; }
  .app-brand .brand-mark { width: 29px; height: 29px; }
  .sidebar nav { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); flex: 1; gap: 2px; margin: 0; padding: 3px; border-radius: 12px; background: rgba(0,0,0,.18); }
  .nav-item { flex-direction: column; justify-content: center; gap: 1px; width: auto; min-width: 0; padding: 5px 0 4px; border-radius: 9px; font-size: 10px; font-weight: 600; line-height: 1.15; text-align: center; }
  .nav-label { display: none; }
  .nav-short { display: block; }
  .nav-icon { width: auto; height: 18px; }
  .nav-item.active { color: #123a3b; background: #fff; }
  .nav-item.active .nav-icon { color: var(--teal); }
  .nav-badge { position: absolute; top: 1px; right: calc(50% - 18px); display: grid; place-items: center; min-width: 15px; height: 15px; border-radius: 99px; padding: 0 3px; color: #123a3b; background: var(--yellow); font: 700 9px/1 "DM Mono", monospace; }
  .nav-item.active .nav-badge { color: #123a3b; background: var(--yellow); }
  .user-box { display: none; }
  .content { padding: 24px 16px 36px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .dashboard-stock-header { align-items: flex-start; }
  .dashboard-stock-list { grid-template-columns: 1fr; }
  .dashboard-stock-item { border-right: 0; }
  .split { grid-template-columns: 1fr; }
  .material-detail { grid-template-columns: 1fr; }
  .material-detail-image { min-height: 0; aspect-ratio: 16 / 9; }
}
@media (max-width: 520px) {
  .page-header { display: block; }
  .page-header .toolbar { margin-top: 15px; }
  .toolbar input, .toolbar select { flex: 1; min-width: 0; }
  .layout-control { flex: 1; }
  .layout-control .list-select, .layout-control .list-select-button { flex: 1; min-width: 0; }
  .material-grid { gap: 10px; }
  .material-body { padding: 10px; }
  .material-title { font-size: 14px; }
  .stock-value { font-size: 21px; }
  .card-actions { align-items: flex-start; flex-direction: column; }
  .card-actions .button { width: 100%; }
  .card-action-buttons { width: 100%; }
  .card-action-buttons .button { flex: 1; }
  .cart-item { grid-template-columns: 42px 1fr 72px; }
  .cart-item .icon-button { grid-column: 3; justify-self: end; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .stats { gap: 9px; }
  .stat { padding: 13px; }
  .stat-value { font-size: 23px; }
  .detail-list { grid-template-columns: 1fr; }
  .detail-list div:nth-child(odd) { padding-right: 0; }
  .detail-list div:nth-child(even) { border-left: 0; padding-left: 0; }
  .material-detail-body { padding: 18px; }
}
