/* Kraft surfaces for both layouts. Keep texture off data, barcode and print surfaces. */
@media screen {
  :root, .theme-refined {
    --ink: var(--tone-35291f, #35291f); --muted: var(--tone-6d5b49, #6d5b49); --line: var(--tone-d5c4ab, #d5c4ab); --border: var(--line);
    --green: var(--tone-705039, #705039); --paper: var(--tone-f7f2e9, #f7f2e9); --kraft: var(--tone-bc966f, #bc966f); --grain: url("textures/kraft.svg");
    --ease: cubic-bezier(.22, 1, .36, 1);
    --lift: 0 2px 3px var(--tone-52371b08, #52371b08), 0 12px 32px var(--tone-52371b0b, #52371b0b);
  }
  body, body.theme-refined {
    background-color: var(--tone-e4d7c6, #e4d7c6);
    background-image: var(--grain), radial-gradient(ellipse at 15% 0%, var(--tone-eee6da, #eee6da) 0%, transparent 65%);
    color: var(--ink); -webkit-font-smoothing: antialiased;
  }
  a, .theme-refined a { color: var(--tone-6f492f, #6f492f); }
  a { text-decoration-thickness: 1px; text-underline-offset: 4px; }
  h1, h2, h3 { color: var(--ink); }
  h1 { font-weight: 700; letter-spacing: -.045em; }
  h2 { letter-spacing: -.025em; }
  .eyebrow { color: var(--tone-715333, #715333); letter-spacing: .14em; font-size: 11px; }
  .app-header, .theme-refined .app-header {
    position: relative; background-color: var(--tone-bc966f, #bc966f);
    background-image: var(--grain), linear-gradient(115deg, var(--tone-d0b28f, #d0b28f), var(--tone-b7916c, #b7916c));
    color: var(--ink); border-bottom: 1px solid var(--tone-ad8659, #ad8659);
    box-shadow: inset 0 1px var(--tone-fff5dfb3, #fff5dfb3), 0 3px 12px var(--tone-51351c0c, #51351c0c);
    padding-block: 16px;
  }
  .app-header::after {
    content: ""; position: absolute; bottom: 3px; left: 0; right: 0;
    border-bottom: 1px dashed var(--tone-805d3538, #805d3538); pointer-events: none;
  }
  .brand, .theme-refined .brand, .account a, .theme-refined .account a { color: var(--ink); }
  .brand crate-logo { --crate-cap: var(--tone-35291f, #35291f); --crate-rest: var(--tone-35291f, #35291f); --crate-accent: linear-gradient(90deg, var(--tone-755139, #755139), var(--tone-8c6240, #8c6240)); }
  .brand crate-logo::part(character) { filter: drop-shadow(0 1px 1px var(--tone-fff7e270, #fff7e270)); }
  .account small, .theme-refined .account small { color: var(--tone-493725, #493725); }
  .account { gap: 18px; }
  .account .quiet, .theme-refined .quiet { color: var(--tone-35291f, #35291f); border-color: var(--tone-94734f, #94734f); background: var(--tone-fff5df40, #fff5df40); box-shadow: none; }
  .account .quiet:hover, .theme-refined .quiet:hover { background: var(--tone-e8dac8, #e8dac8); color: var(--tone-35291f, #35291f); border-color: var(--tone-94734f, #94734f); }
  .header-search { border: 1px solid var(--tone-b79770, #b79770); border-radius: 10px; background: var(--tone-f7f2e9, #f7f2e9); box-shadow: inset 0 1px 3px var(--tone-51351c0c, #51351c0c); }
  .header-search input[type=search] { background: transparent; color: var(--ink); }
  .header-search button { background: transparent; color: var(--tone-493725, #493725); box-shadow: none; }
  .header-search button:hover { background: var(--tone-efe1cb, #efe1cb); }
  .main-nav { background: var(--tone-ceb291, #ceb291); background-image: var(--grain); border-color: var(--tone-c6a77f, #c6a77f); }
  .main-nav a, .nav-group summary { color: var(--tone-58432e, #58432e); }
  .nav-group summary { border-radius: 8px; }
  .nav-group summary:hover, .main-nav a:hover { background: var(--tone-e8dac8, #e8dac8); color: var(--tone-35291f, #35291f); }
  .main-nav a[aria-current] { color: var(--tone-4d3422, #4d3422); border-bottom-color: var(--tone-8c6240, #8c6240); }
  .nav-children { background: var(--tone-f4ede2, #f4ede2); border-color: var(--tone-c6a77f, #c6a77f); border-radius: 0 0 12px 12px; box-shadow: 0 14px 30px var(--tone-51351c20, #51351c20), inset 0 1px var(--tone-fffdf7, #fffdf7); transform-origin: top; }
  .theme-refined .main-nav {
    background-color: var(--tone-c2a180, #c2a180); background-image: var(--grain), linear-gradient(110deg, var(--tone-ceb08e, #ceb08e), var(--tone-bd9a76, #bd9a76));
    border-right: 1px solid var(--tone-bfa079, #bfa079); border-radius: 0;
    box-shadow: inset -4px 0 0 var(--tone-fff3db24, #fff3db24); scrollbar-color: var(--tone-a98962, #a98962) var(--tone-c2a180, #c2a180);
  }
  .theme-refined .main-nav a, .theme-refined .nav-group summary { color: var(--tone-493725, #493725); }
  .theme-refined .nav-group summary:hover, .theme-refined .nav-group[open] summary,
  .theme-refined .main-nav a:hover { color: var(--tone-35291f, #35291f); background: var(--tone-ecdfce8c, #ecdfce8c); }
  .theme-refined .nav-children { background: transparent; border-left: 1px solid var(--tone-ac8a604d, #ac8a604d); margin: 3px 0 5px 23px; padding-left: 7px; border-radius: 0; box-shadow: none; }
  .theme-refined .main-nav a[aria-current] { color: var(--tone-4d3422, #4d3422); background: var(--tone-f4ede2, #f4ede2); box-shadow: 0 2px 5px var(--tone-52371b12, #52371b12), inset 3px 0 var(--tone-8c6240, #8c6240); }
  .panel, .theme-refined .panel {
    background: var(--tone-f7f2e9, #f7f2e9); background-image: var(--grain);
    border: 1px solid var(--line); border-radius: 14px;
    box-shadow: var(--lift), inset 0 1px 0 #ffffffc9;
  }
  .panel > h2:first-child { margin-top: 0; }
  .auth-panel { border-top: 5px solid var(--tone-bd9360, #bd9360); padding-top: 30px; }
  .form-panel { background-color: var(--tone-f8f4ed, #f8f4ed); }
  .panel.table-wrap, .theme-refined .panel.table-wrap { background-image: none; }
  .report-grid .metric, .section-card { position: relative; border-top: 3px solid var(--tone-bca077, #bca077); }
  .metric strong, .quantity { font-variant-numeric: tabular-nums; color: var(--tone-35291f, #35291f); }
  .report-grid .metric:hover, .section-card:hover { border-color: var(--tone-a5895c, #a5895c); box-shadow: 0 5px 8px var(--tone-52371b08, #52371b08), 0 16px 35px var(--tone-52371b14, #52371b14); }
  button, .button { border-radius: 9px; background: var(--tone-705039, #705039); border-color: var(--tone-705039, #705039); box-shadow: inset 0 1px #ffffff1f, 0 2px 3px var(--tone-35291f0c, #35291f0c); }
  button:hover, .button:hover { filter: none; background: var(--tone-583d2c, #583d2c); border-color: var(--tone-583d2c, #583d2c); }
  .button.secondary, button.secondary, .theme-refined .button.secondary, .theme-refined button.secondary {
    background: var(--tone-eee2d3, #eee2d3); border-color: var(--tone-c3aa87, #c3aa87); color: var(--tone-58432e, #58432e);
  }
  .button.secondary:hover, button.secondary:hover { background: var(--tone-deccb5, #deccb5); }
  .button.danger, button.danger { background: #953d2f; border-color: #953d2f; color: white; }
  .button.danger:hover, button.danger:hover { background: #7b3025; border-color: #7b3025; }
  input:not([type=checkbox]):not([type=hidden]), select, textarea {
    border-color: var(--tone-b8a386, #b8a386); border-radius: 8px; background-color: var(--tone-fcfaf6, #fcfaf6); color: var(--ink);
    box-shadow: inset 0 1px 2px var(--tone-52371b08, #52371b08);
  }
  input::placeholder, textarea::placeholder { color: var(--tone-81705c, #81705c); }
  input:focus, select:focus, textarea:focus { border-color: var(--tone-875b38, #875b38); }
  :focus-visible { outline: 3px solid var(--tone-875b38, #875b38); outline-offset: 3px; }
  .header-search:focus-within { outline: 3px solid var(--tone-875b38, #875b38); outline-offset: 2px; }
  .header-search input[type=search] { border: 0; box-shadow: none; }
  .invalid input, .invalid select, .invalid textarea, [aria-invalid=true] { border-color: #a13e31; }
  .error, .errorlist { color: #8c3429; }
  .notice { background: #eef0de; border-color: #bac39b; border-left: 4px solid #78864d; border-radius: 10px; color: #3f4e2d; }
  .notice[data-mascot-tags~="error"] { color: #842f26; background: #fff0e8; border-color: #d4a298; border-left-color: #a13e31; }
  thead, .theme-refined thead { background: var(--tone-dfcbb3, #dfcbb3); }
  thead th, .theme-refined thead th { color: var(--tone-645039, #645039); font-size: 11px; letter-spacing: .07em; }
  main table > tbody > tr:nth-child(odd) { background: var(--tone-faf6ef, #faf6ef); }
  main table > tbody > tr:nth-child(even) { background: var(--tone-eee4d6, #eee4d6); }
  main table > tbody > tr:hover, .theme-refined main table > tbody > tr:hover { background: var(--tone-e1d0ba, #e1d0ba); }
  main th, main td { border-bottom-color: var(--tone-dfd1ba, #dfd1ba); }
  .badge, .theme-refined .badge:not(.low):not(.good) { color: #644b32; background: #e5d6c2; border-radius: 5px; }
  .badge.low { color: #7b4d0c; background: #fae6b3; }
  .badge.good { color: #38532d; background: #e4ebd0; }
  .scan-status { color: var(--tone-58432e, #58432e); background: var(--tone-e5d6c2, #e5d6c2); }
  .scan-status.scan-good { color: #30552f; background: #e2edda; }
  .scan-status.scan-bad { color: #842f26; background: #ffe8dd; }
  summary { color: var(--tone-6f492f, #6f492f); }
  #po-line-forms .po-line-form:nth-child(even) { background: var(--tone-e9ddcd, #e9ddcd); }
  .layout-preview { background: var(--tone-e4d7c6, #e4d7c6); border-color: var(--tone-c3aa87, #c3aa87); }
  .layout-preview > div, .preview-refined > div, .preview-refined > aside { background: var(--tone-bc966f, #bc966f); background-image: var(--grain); }
  .layout-preview > aside { background-color: var(--tone-ceb291, #ceb291); }
  .layout-preview i { background: var(--tone-f7f2e9, #f7f2e9); border-color: var(--tone-d5c4ab, #d5c4ab); }
  footer { color: var(--tone-77624b, #77624b); font-size: 12px; letter-spacing: .025em; }
  .nav-chevron { transition: transform 220ms var(--ease); }
  .nav-group summary[aria-expanded=false] .nav-chevron { transform: rotate(0); }
  button, .button, .main-nav a, summary, input, select, textarea, .section-card, .metric {
    transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 220ms ease;
  }
  @media (prefers-reduced-motion: no-preference) {
    .panel { animation: paper-arrive 280ms var(--ease) both; }
    .table-wrap, .scanner, .po-line-form, .panel .panel { animation: none; }
    button:not(:disabled):active, .button:active { transform: translateY(1px); }
    @keyframes paper-arrive { from { opacity: .65; transform: translateY(5px); } to { opacity: 1; transform: none; } }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  }
  @media (forced-colors: active) {
    body, .panel, .app-header, .main-nav { background-image: none !important; }
    .brand crate-logo { --crate-cap: CanvasText; --crate-rest: CanvasText; }
  }
}

/* Torn kraft header, account controls and sign-in composition. */
@media screen {
  .app-header::after, .theme-classic.has-navigation .main-nav::after {
    content: ""; position: absolute; left: 0; right: 0; pointer-events: none;
    bottom: -9px; height: 12px; border: 0; z-index: 2;
    background-color: var(--tone-b7916c, #b7916c); background-image: var(--grain);
    clip-path: polygon(0 0,100% 0,100% 60%,98% 77%,96% 46%,94% 88%,91% 64%,89% 96%,86% 58%,83% 79%,80% 48%,77% 85%,74% 65%,71% 92%,68% 52%,65% 81%,62% 59%,59% 96%,56% 64%,53% 84%,50% 49%,47% 88%,44% 64%,41% 92%,38% 55%,35% 82%,32% 62%,29% 94%,26% 51%,23% 81%,20% 59%,17% 94%,14% 65%,11% 85%,8% 48%,5% 88%,2% 62%,0 78%);
  }
  .theme-classic.has-navigation .app-header::after { display: none; }
  .theme-classic.has-navigation .main-nav { position: relative; border-bottom: 0; }
  .theme-classic.has-navigation .main-nav::after { background-color: var(--tone-ceb291, #ceb291); }
  .app-header, .theme-refined .app-header { border-bottom: 0; padding-bottom: 20px; }
  .account { font-family: 'CRATE Sans', system-ui, sans-serif; gap: 10px; letter-spacing: .01em; }
  .account-identity { display: grid; gap: 1px; padding-right: 14px; border-right: 1px solid var(--tone-6c4c3040, #6c4c3040); }
  .account-identity strong { font-size: 15px; font-weight: 600; }
  .account-identity small { font-family: system-ui, sans-serif; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
  .account > a { padding: 0 12px; font-size: 13px; text-decoration: none; border-radius: 8px; }
  .account > a:hover { background: var(--tone-f4ede270, #f4ede270); }
  .account .quiet { min-height: 40px; font-size: 13px; }
  .account-panel { margin-inline: auto; }
  .account-panel h1 { font-size: 30px; }
  .background-preview { display: block; width: 100%; max-height: 240px; object-fit: cover; border-radius: 9px; }
  .appearance-form input[type=file] { padding: 12px; }
  body.is-login { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; isolation: isolate; }
  .is-login .app-header { justify-content: center; flex: 0 0 auto; padding-block: 22px; }
  .is-login .brand { margin-inline: auto; }
  .is-login .brand crate-logo { font-size: clamp(26px, 4vw, 34px); }
  .is-login .brand crate-logo::part(bot) { width: 72px; height: 72px; }
  .is-login main { display: flex; flex-direction: column; justify-content: center; width: 100%; flex: 1 0 auto; margin: 0 auto; padding-block: 40px; }
  .is-login .auth-panel { width: min(100%, 440px); margin: 0 auto; padding: 32px; border-top: 1px solid var(--tone-d5c4ab, #d5c4ab); background: var(--tone-faf6efed, #faf6efed); box-shadow: 0 18px 60px var(--tone-30211326, #30211326), inset 0 1px #ffffffc9; }
  .login-heading { text-align: center; margin-bottom: 28px; }
  .login-heading h1 { font: 400 clamp(42px, 8vw, 54px)/1.1 'CRATE Stencil', system-ui, sans-serif; letter-spacing: .045em; margin: 0 0 10px; }
  .login-heading p { font: 500 15px/1.5 'CRATE Sans', system-ui, sans-serif; margin: 0; color: var(--tone-66503d, #66503d); }
  .is-login .auth-panel button[type=submit] { width: 100%; }
  .is-login .auth-panel > .muted { font-size: 12px; text-align: center; margin-top: 22px; }
  .is-login footer { flex: 0 0 auto; margin-top: auto; text-align: center; padding: 20px; color: var(--tone-493725, #493725); }
  .login-backdrop { position: fixed; inset: 0; z-index: -2; width: 100%; height: 100%; object-fit: cover; }
  .is-login.has-login-photo::before { content: ''; position: fixed; inset: 0; z-index: -1; background: linear-gradient(var(--tone-26190e14, #26190e14), var(--tone-26190e45, #26190e45)); pointer-events: none; }
  .is-login.has-login-photo footer { background: var(--tone-f0e6d8eb, #f0e6d8eb); border-top: 1px solid var(--tone-d1bba1, #d1bba1); }
  @media (max-width: 600px) {
    .account { width: 100%; flex-wrap: wrap; gap: 6px; }
    .account-identity { margin-right: auto; padding-right: 10px; }
    .account > a { padding: 0 8px; }
    .is-login .auth-panel { padding: 25px; }
    .is-login main { padding-block: 28px; }
    .is-login .brand crate-logo::part(bot) { width: 60px; height: 60px; }
  }
}
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  .brand { view-transition-name: crate-brand; }
  ::view-transition-group(crate-brand) { animation-duration: 550ms; animation-timing-function: cubic-bezier(.22,1,.36,1); }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}

.room-heading th { background: var(--tone-e3c49a, #e3c49a); color: var(--tone-392619, #392619); padding-block: .65rem; text-align: left; }

@media screen {
  body { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
  body > main { flex: 1 0 auto; width: 100%; margin: 0 auto; min-width: 0; }
  body > header, body > nav, body > footer { flex-shrink: 0; }
  body > footer { margin-top: auto; }
  .theme-refined.has-navigation { display: grid; }
  #project-edit-form .po-filters { grid-template-columns: minmax(6rem, 9rem) minmax(12rem, 1fr) 7rem 5rem; align-items: start; }
  .project-part-picker button { width: 100%; text-align: left; overflow-wrap: anywhere; }
  #part-picker { width: min(640px, calc(100vw - 32px)); max-height: 88dvh; overflow: auto; background: var(--tone-faf4e9, #faf4e9); color: var(--tone-392619, #392619); border: 1px solid var(--tone-9b7953, #9b7953); border-radius: 12px; padding: 24px; }
  #part-picker::backdrop { background: var(--tone-21170eb3, #21170eb3); }
  #part-picker-results { display: grid; gap: 6px; margin-block: 12px; }
  #part-picker-errors { white-space: pre-line; }
  #part-picker-create { border-top: 1px solid var(--tone-c5aa84, #c5aa84); margin-top: 16px; padding-top: 12px; }
  @media (max-width: 719px) {
    body.theme-refined.has-navigation { display: flex; }
    #project-edit-form .po-filters { grid-template-columns: minmax(0, 1fr) 6rem; }
    #project-edit-form .project-field-room { max-width: 12rem; }
    #project-edit-form .project-field-part { grid-column: 1 / -1; grid-row: 2; }
  }
}

/* Shared searchable choices: the popup escapes scrolling table containers. */
.search-select-native { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; clip-path: inset(50%); overflow: hidden; opacity: 0; }
.search-select-trigger, [data-part-target] { width: 100%; min-width: 0; text-align: left; display: flex; align-items: center; justify-content: space-between; gap: .7rem; }
.search-select-trigger::after, [data-part-target]::after { content: '⌄'; margin-left: auto; }
.search-select-popup { position: fixed; z-index: 2000; box-sizing: border-box; display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px solid var(--tone-a6845b, #a6845b); border-radius: 10px; background: var(--tone-faf4e9, #faf4e9); color: var(--tone-392619, #392619); box-shadow: 0 12px 32px var(--tone-38271940, #38271940); overflow: auto; }
.search-select-popup input { width: 100%; min-height: 42px; flex-shrink: 0; }
.search-select-options { max-height: 216px; overflow-y: auto; min-height: 0; flex: 0 1 auto; overscroll-behavior: contain; }
.search-select-option { padding: 10px 12px; min-height: 42px; box-sizing: border-box; cursor: pointer; border-radius: 5px; overflow-wrap: anywhere; }
.search-select-option:hover, .search-select-option.is-active { background: var(--tone-ead7b9, #ead7b9); }
.search-select-option[aria-selected=true] { background: var(--tone-dfc297, #dfc297); font-weight: 700; }
.search-select-status { font-size: .8rem; color: var(--tone-695239, #695239); }
.search-select-status:empty { display: none; }
.search-select-add { flex-shrink: 0; text-align: left; border-top: 1px solid var(--tone-c5aa84, #c5aa84); }
@media (prefers-reduced-motion: no-preference) { .search-select-popup { animation: choice-appear 120ms ease-out; } @keyframes choice-appear { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: translateY(0); } } }

.project-back { display: inline-block; margin-bottom: 12px; }
.project-print { position: relative; }
.project-print > summary { padding: 10px 18px; border: 1px solid var(--tone-ae895b, #ae895b); border-radius: 8px; cursor: pointer; }
.project-print-options { position: absolute; right: 0; z-index: 20; min-width: 180px; padding: 12px; display: grid; gap: 12px; background: var(--tone-fff8ed, #fff8ed); border: 1px solid var(--tone-ae895b, #ae895b); border-radius: 8px; box-shadow: 0 8px 20px var(--tone-39261930, #39261930); }
.project-readiness { border-left: 5px solid; }
.readiness-ready { border-left-color: #427342; }
.readiness-pending { border-left-color: var(--tone-b17a1d, #b17a1d); }
.readiness-missing { border-left-color: #af4534; }
.readiness-counts { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.status-ready, .status-pending, .status-missing, .status-incoming { display: inline-block; border-radius: 5px; padding: 4px 8px; font-weight: 600; }
.status-ready { background: #e4efdf; color: #28532d; }
.status-pending { background: #f7e9cb; color: #754d09; }
.status-missing { background: #f7e1db; color: #873b2b; }
.status-incoming { background: #e1eaf0; color: #305a73; }
.project-stock-action { display: grid; gap: 5px; margin-top: 8px; min-width: 110px; }
.project-stock-action input { width: 6rem; }
.project-delete { margin-top: 32px; padding-top: 18px; border-top: 1px solid var(--tone-c5aa84, #c5aa84); }

/* Project allocation and receiving hierarchy. */
.project-supply-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.project-supply-heading > a { font-weight: 650; }
.project-supply-heading > span { font-size: 12px; color: var(--tone-705435, #705435); }
.project-received { display: inline-flex; align-items: baseline; gap: 5px; margin: 5px 0; padding: 3px 8px; border: 1px solid var(--tone-c5aa84, #c5aa84); border-radius: 6px; background: var(--tone-eddfcc, #eddfcc); color: var(--tone-49321f, #49321f); font-size: 12px; }
.project-received strong { font-size: 18px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.2; }
.project-table .supply-summary + .supply-summary { margin-top: 10px; padding-top: 10px; }
