/* tw-zaico UI — TOEI EC Design System skin
   依存: tokens.css を先に読み込むこと */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.icon-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.ds-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* ── Body ── */
body {
    font-family: var(--font-body);
    font-size: 18px;
    background: var(--bg-grad);
    color: var(--ink);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    padding-left: var(--nav-width);
}

/* ── Typography ── */
h1, h2 {
    font-family: var(--font-display);
}
h1 { font-size: 24px; margin: 0 0 16px; font-weight: 900; }
h2 { font-size: 20px; margin: 0 0 12px; font-weight: 700; }

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}
.page-header h1 {
    margin: 0;
    flex-shrink: 0;
}
.page-title-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}
.page-header .toolbar {
    margin-bottom: 0;
    justify-content: flex-end;
}

/* ── Sidebar nav ── */
.ds-sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: var(--nav-width);
    background: var(--nav-bg);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    z-index: 300;
    overflow: hidden;
}

.ds-brand {
    display: flex; align-items: center; gap: 10px;
    margin: 18px 14px 12px; padding: 12px;
    border-radius: 10px; text-decoration: none;
    color: var(--ink); font-weight: 700; font-size: 16px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.66);
    white-space: nowrap; overflow: hidden;
}
.ds-brand .logo {
    width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(13, 107, 93, 0.12); color: var(--accent);
    font-size: 17px; line-height: 1;
}
.ds-brand .brand-name {
    font-family: var(--font-display);
    font-size: 17px; font-weight: 700; color: var(--ink);
}

.ds-nav-section {
    padding: 6px 10px; overflow-y: auto; flex: 1; min-height: 0;
}

.ds-nav-link {
    text-decoration: none; color: var(--muted);
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px; border-radius: 9px;
    font-size: 15px; font-weight: 600;
    border: 1px solid transparent; white-space: nowrap;
    transition: background 0.13s, color 0.13s, border-color 0.13s;
}
.ds-nav-link:hover {
    background: rgba(13, 107, 93, 0.08);
    border-color: rgba(13, 107, 93, 0.16);
    color: var(--accent);
}
.ds-nav-link.active {
    color: var(--accent);
    background: rgba(13, 107, 93, 0.12);
    border-color: rgba(13, 107, 93, 0.20);
}
.ds-nav-link .ds-icon { opacity: 0.75; }
.ds-nav-link.active .ds-icon { opacity: 1; }
.ds-nav-link.has-submenu-toggle::after {
    content: "▾";
    margin-left: auto;
    color: var(--accent);
    font-size: 13px;
    line-height: 1;
}
.ds-nav-link.has-submenu-toggle[aria-expanded="false"]::after {
    content: "▸";
}

.inventory-submenu {
    margin: 0;
}
.inventory-submenu-summary {
    display: none;
}
.inventory-submenu-summary::-webkit-details-marker {
    display: none;
}
.inventory-nav-filter {
    margin: 4px 0 12px 18px;
    padding-left: 8px;
    border: 0;
    border-left: 2px solid rgba(13, 107, 93, 0.18);
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    position: static;
    overflow: visible;
}
.inventory-nav-filter .detail-search-head {
    padding: 7px 2px 8px 8px;
    border-bottom: 0;
    font-size: 14px;
}
.inventory-nav-filter .condition-mode {
    padding: 8px 2px 10px 8px;
    border-bottom: 0;
    gap: 6px;
    font-size: 13px;
}
.inventory-nav-filter .detail-field {
    padding: 8px 2px 8px 8px;
    font-size: 13px;
}
.inventory-nav-filter .filter-group {
    border-top: 1px solid rgba(45, 58, 52, 0.08);
}
.inventory-nav-filter .filter-group summary {
    padding: 8px 2px 8px 8px;
    font-size: 14px;
}
.inventory-nav-filter .check-list {
    max-height: 210px;
    padding: 2px 2px 12px 8px;
    font-size: 13px;
    gap: 8px;
}
.inventory-nav-filter .range-row {
    padding: 2px 2px 12px 8px;
}
.inventory-nav-filter .detail-field input[type=text],
.inventory-nav-filter .detail-field select,
.inventory-nav-filter .range-row input[type=text] {
    font-size: 14px;
    padding: 6px 8px;
}
.ds-nav-footer {
    padding: 10px 10px 14px;
    border-top: 1px solid var(--line);
}
.ds-user-email {
    font-size: 13px; color: var(--muted); padding: 4px 2px 8px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ds-logout-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%; text-decoration: none; border-radius: 9px;
    padding: 8px 10px; font-size: 14px; font-weight: 700;
    color: #8d5e52; border: 1px solid rgba(141, 94, 82, 0.20);
    background: rgba(255, 255, 255, 0.70);
    cursor: pointer; font-family: var(--font-body);
    transition: background 0.13s, color 0.13s;
}
.ds-logout-btn:hover { background: rgba(163, 48, 48, 0.08); color: var(--danger); }

/* ── Responsive: ≤980px collapse to top bar ── */
@media (max-width: 980px) {
    body { padding-left: 0; padding-top: 56px; }

    /* On mobile the sidebar becomes a top bar, so the bulk action bar
       spans full width instead of starting after the (now absent) sidebar. */
    #bulk-stock-bar { left: 0 !important; }

    .ds-sidebar {
        position: fixed; top: 0; left: 0; right: 0; bottom: auto;
        width: 100% !important; height: 56px;
        flex-direction: row; align-items: center;
        border-right: none; border-bottom: 1px solid var(--line);
        overflow-x: auto; overflow-y: hidden;
        z-index: 300;
    }
    .ds-brand {
        margin: 0 8px; padding: 6px 10px; border: none;
        background: transparent; flex-shrink: 0;
    }
    .ds-nav-section {
        display: flex; flex-direction: row; overflow-x: auto; overflow-y: hidden;
        padding: 0 4px; gap: 2px; flex: 1; align-items: center;
        scrollbar-width: none;
    }
    .ds-nav-section::-webkit-scrollbar { display: none; }
    .ds-nav-link { padding: 6px 10px; white-space: nowrap; flex-shrink: 0; }
    .ds-nav-link .ds-icon { display: none; }
    .inventory-submenu { flex-shrink: 0; }
    .inventory-submenu .inventory-nav-filter { display: none; }
    .inventory-submenu[open] .inventory-nav-filter {
        display: block;
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        margin: 0;
        padding: 8px 14px 24px;
        border-left: 0;
        border-top: 1px solid var(--line);
        background: var(--panel);
        box-shadow: 0 8px 18px rgba(30, 44, 38, 0.16);
        overflow-y: auto;
        z-index: 299;
    }
    .ds-nav-footer {
        display: flex; flex-direction: row; align-items: center;
        padding: 0 8px; gap: 6px; border-top: none; border-left: 1px solid var(--line);
        flex-shrink: 0;
    }
    .ds-user-email { display: none; }
    .ds-logout-btn { padding: 5px 10px; white-space: nowrap; font-size: 13px; }
}

/* ── Banner ── */
.banner-readonly {
    background: var(--warn-s);
    border-bottom: 1px solid rgba(184, 95, 46, 0.30);
    color: var(--warn);
    padding: 6px 16px;
    font-size: 17px;
    text-align: center;
}

/* ── Main content ── */
.content {
    max-width: none;
    margin: 0;
    padding: 24px 24px;
}

/* ── Settings page ── */
.settings-page {
    min-width: 0;
}
.settings-layout {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    gap: 28px;
    align-items: start;
}
.settings-subnav {
    position: sticky;
    top: 24px;
    min-height: calc(100vh - 48px);
    padding: 12px 16px 18px 0;
    border-right: 1px solid var(--line);
    color: var(--muted);
}
.settings-subnav-title {
    margin: 4px 0 22px;
    color: var(--ink);
    font-size: 18px;
    font-weight: 700;
}
.settings-subnav-group {
    margin: 20px 0 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}
.settings-subnav-link {
    display: block;
    padding: 7px 0 7px 24px;
    color: var(--ink);
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
}
.settings-subnav-link:hover,
.settings-subnav-link.active {
    color: #d86d00;
}
.settings-subnav-link.disabled {
    color: var(--muted);
    cursor: default;
    opacity: 0.58;
}
.settings-workspace {
    min-width: 0;
}
.settings-category-panel {
    margin-bottom: 24px;
}
.settings-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}
.settings-page-head h1 {
    margin: 0;
    font-family: var(--font-body);
    font-size: 30px;
    font-weight: 700;
    line-height: 1.25;
}
.settings-legacy-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}
.settings-add-form {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}
.settings-add-form input[type=text] {
    width: 240px;
    max-width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-size: 15px;
}
.settings-new-category-btn {
    background: #d86d00;
    border-color: #d86d00;
    white-space: nowrap;
}
.settings-new-category-btn:hover {
    background: #bd5f00;
}
.settings-tabs {
    display: flex;
    gap: 32px;
    margin: 0 0 16px;
    border-bottom: 1px solid var(--line-2);
}
.settings-tab {
    padding: 8px 0 12px;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    font-size: 15px;
    font-weight: 700;
    text-decoration: none;
}
.settings-tab.active {
    color: #d86d00;
    border-bottom-color: #d86d00;
}
.settings-tab.disabled {
    cursor: default;
    opacity: 0.55;
}
.settings-info-panel {
    padding: 14px 18px;
    margin-bottom: 24px;
    border-left: 8px solid #7db8ea;
    border-radius: 4px;
    background: #dcecf9;
    color: #2170b7;
    font-size: 16px;
}
.settings-info-panel ul {
    margin: 0;
    padding-left: 24px;
}
.settings-category-list {
    width: min(980px, 100%);
    margin: 28px auto 0;
}
.settings-category-row {
    position: relative;
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) 96px;
    align-items: center;
    min-height: 62px;
    gap: 12px;
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.42);
}
.settings-category-row:hover {
    background: rgba(13, 107, 93, 0.035);
}
.settings-category-row.is-dragging {
    opacity: 0.58;
    background: rgba(45, 58, 52, 0.06);
}
.settings-category-row.inventory-only {
    background: rgba(255, 255, 255, 0.24);
}
.settings-row-handle,
.settings-row-actions {
    display: flex;
    align-items: center;
}
.settings-row-handle {
    justify-content: center;
}
.settings-row-main {
    min-width: 0;
}
.settings-category-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink);
    font-size: 16px;
    font-weight: 700;
}
.settings-row-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
}
.settings-promote-form,
.settings-row-actions form {
    margin: 0;
}
.settings-row-actions {
    justify-content: flex-end;
    gap: 10px;
}
.settings-action-svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}
.settings-drag-handle,
.settings-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-family: var(--font-body);
    cursor: pointer;
}
.settings-drag-handle,
.settings-icon-btn {
    width: 34px;
    height: 34px;
    border: 0;
    background: transparent;
    color: #d86d00;
}
.settings-drag-handle:hover:not(:disabled),
.settings-icon-btn:hover:not(:disabled) {
    background: rgba(216, 109, 0, 0.10);
}
.settings-drag-handle:disabled,
.settings-icon-btn:disabled {
    cursor: not-allowed;
    opacity: 0.35;
}
.settings-drag-handle,
.category-drag-handle {
    touch-action: none;
    user-select: none;
}
.settings-delete-icon {
    color: #d86d00;
}
.settings-badge-muted {
    background: rgba(107, 117, 112, 0.12);
    color: var(--muted);
}
.settings-row-edit {
    position: relative;
}
.settings-row-edit summary {
    list-style: none;
}
.settings-row-edit summary::-webkit-details-marker {
    display: none;
}
.settings-row-edit[open] summary {
    background: rgba(216, 109, 0, 0.10);
}
.settings-row-edit-form {
    position: absolute;
    top: 42px;
    right: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(420px, calc(100vw - var(--nav-width) - 80px));
    padding: 10px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--panel);
    box-shadow: var(--shadow-2);
}
.settings-row-edit-form input[type=text] {
    flex: 1;
    min-width: 0;
    padding: 7px 9px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-size: 15px;
}

@media (max-width: 980px) {
    .settings-layout {
        grid-template-columns: 1fr;
        gap: 18px;
    }
    .settings-subnav {
        position: static;
        min-height: 0;
        display: flex;
        align-items: center;
        gap: 16px;
        overflow-x: auto;
        padding: 0 0 10px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
    .settings-subnav-title,
    .settings-subnav-group {
        margin: 0;
        flex-shrink: 0;
    }
    .settings-subnav-link {
        flex-shrink: 0;
        padding: 4px 0;
    }
    .settings-page-head {
        flex-direction: column;
        align-items: stretch;
    }
    .settings-add-form {
        justify-content: flex-start;
    }
    .settings-add-form input[type=text] {
        flex: 1;
        min-width: 180px;
    }
    .settings-row-edit-form {
        width: min(420px, calc(100vw - 48px));
    }
}

@media (max-width: 640px) {
    .settings-page-head h1 {
        font-size: 26px;
    }
    .settings-tabs {
        gap: 20px;
        overflow-x: auto;
    }
    .settings-info-panel {
        font-size: 15px;
    }
    .settings-category-row {
        grid-template-columns: 42px minmax(0, 1fr) 84px;
        gap: 8px;
        padding: 10px 8px;
    }
    .settings-row-actions {
        grid-column: 3 / 4;
        grid-row: 1 / 2;
    }
    .settings-row-edit-form {
        position: fixed;
        left: 16px;
        right: 16px;
        top: auto;
        bottom: 16px;
        width: auto;
        flex-wrap: wrap;
    }
    .settings-row-edit-form input[type=text] {
        flex-basis: 100%;
    }
}

/* ── Toolbar / filter row ── */
.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    align-items: flex-end;
}
.toolbar label {
    font-size: 16px; color: var(--muted);
    display: flex; flex-direction: column; gap: 2px;
    line-height: 1.2;
}
.toolbar input[type=text],
.toolbar input[type=date],
.toolbar select {
    height: 42px;
    padding: 5px 8px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    font-size: 17px;
    line-height: 1.2;
    min-width: 140px;
    background: var(--panel);
    color: var(--ink);
    font-family: var(--font-body);
}

.inventory-search-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}
.inventory-detail-search {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    overflow: hidden;
    position: sticky;
    top: 16px;
}
.detail-search-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    font-size: 15px;
    font-weight: 700;
}
.detail-search-head a {
    color: var(--warn);
    text-decoration: none;
}
.condition-mode {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    font-size: 15px;
}
.condition-mode label,
.check-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.35;
}
.detail-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 14px;
    font-size: 14px;
    color: var(--muted);
    font-weight: 700;
}
.detail-field input[type=text],
.detail-field select,
.range-row input[type=text] {
    width: 100%;
    min-width: 0;
    padding: 7px 9px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 16px;
}
.filter-group {
    border-top: 1px solid var(--line);
}
.filter-group summary {
    cursor: pointer;
    padding: 10px 14px;
    font-size: 15px;
    font-weight: 700;
    color: var(--ink);
}
.check-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 260px;
    overflow: auto;
    padding: 4px 14px 14px;
    font-size: 15px;
}
.category-check-list {
    gap: 8px;
}
.category-filter-row {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: start;
    gap: 6px;
}
.category-filter-row.is-dragging {
    opacity: 0.58;
}
.category-filter-row.inventory-only {
    opacity: 0.82;
}
.category-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--accent);
    cursor: grab;
}
.category-drag-handle:hover:not(:disabled) {
    background: var(--soft);
}
.category-drag-handle:active:not(:disabled) {
    cursor: grabbing;
}
.category-drag-handle:disabled {
    cursor: not-allowed;
    opacity: 0.28;
}
.category-drag-icon {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}
.category-filter-label {
    min-width: 0;
}
.category-filter-label span {
    min-width: 0;
    overflow-wrap: anywhere;
}
.range-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    padding: 4px 14px 14px;
}
.inventory-list-panel {
    min-width: 0;
    overflow: hidden;
}
.inventory-actions {
    display: flex;
    justify-content: flex-end;
}
.boss-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.3;
}

@media (max-width: 980px) {
    .page-header {
        align-items: flex-start;
        flex-direction: column;
    }
    .page-header .toolbar {
        justify-content: flex-start;
        width: 100%;
    }
    .inventory-search-layout {
        grid-template-columns: 1fr;
    }
    .inventory-detail-search {
        position: static;
    }
    .inventory-actions {
        justify-content: flex-start;
    }
    .list-table-wrap {
        max-height: calc(100vh - 180px);
    }
}

/* ── Buttons ── */
.toolbar button, .btn {
    padding: 7px 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 17px;
    text-decoration: none;
    display: inline-block;
    font-weight: 700;
    font-family: var(--font-body);
    transition: background 0.13s;
}
.toolbar button:hover, .btn:hover { background: var(--accent-h); }

.toolbar > button,
.toolbar > .btn {
    height: 42px;
    padding-top: 0;
    padding-bottom: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    white-space: nowrap;
    flex: 0 0 auto;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-h); }

.btn-secondary {
    background: rgba(255, 255, 255, 0.80);
    color: var(--accent);
    border: 1px solid var(--line-2);
}
.btn-secondary:hover {
    background: var(--soft);
    border-color: rgba(13, 107, 93, 0.22);
}

.btn-sm { padding: 4px 10px; font-size: 15px; }

.file-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.file-picker input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    clip-path: inset(50%);
}
.file-picker input[type="file"]:disabled + label {
    opacity: 0.55;
    cursor: not-allowed;
}
.file-picker-name {
    color: var(--muted);
    font-size: 15px;
}
.file-picker-help {
    flex-basis: 100%;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.5;
}

.btn-danger {
    background: var(--danger);
    border: none;
    color: #fff;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 17px;
    font-weight: 700;
    font-family: var(--font-body);
    transition: background 0.13s;
}
.btn-danger:hover { background: #8a2020; }

.btn-outline-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}
.btn-outline-danger:hover { background: var(--danger); color: #fff; }

.btn-in  { background: var(--ok); color: #fff; }
.btn-in:hover  { background: #1f6140; }
.btn-out { background: var(--danger); color: #fff; }
.btn-out:hover { background: #8a2020; }

.btn-google-login {
    background: #fff;
    color: #444;
    border: 1px solid var(--line-2);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.13s;
}
.btn-google-login:hover { background: var(--soft); }

/* ── Focus ring ── */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
.list-table-wrap {
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - 220px);
    overflow: auto;
    scrollbar-gutter: stable;
}
.list-table-wrap table {
    min-width: 980px;
}
.list-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-2);
    font-size: 16px;
}
thead th {
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line-2);
    background: rgba(255, 255, 255, 0.50);
    white-space: nowrap;
}
tbody td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--line);
    font-size: 16px;
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}
.cell-clip {
    position: relative;
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
}
.cell-clip > .clip-pop {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cell-clip:hover,
.cell-clip:focus-within {
    overflow: visible;
    z-index: 40;
}
.cell-clip:hover > .clip-pop,
.cell-clip:focus-within > .clip-pop {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: max-content;
    min-width: calc(100% - 16px);
    max-width: min(720px, calc(100vw - var(--nav-width) - 72px));
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
    line-height: 1.45;
    padding: 8px 10px;
    color: var(--ink);
    background: var(--panel);
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-2);
}
.cell-clip:hover > .clip-pop a,
.cell-clip:focus-within > .clip-pop a {
    color: var(--accent);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(13, 107, 93, 0.03); }

/* ── Quantity state warnings ── */
.qty-current {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    max-width: 100%;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.qty-current.qty-negative {
    color: var(--danger);
    font-weight: 800;
}
.qty-current.qty-low {
    color: var(--warn);
    font-weight: 700;
}
.qty-unit {
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
}
.qty-negative .qty-unit {
    color: var(--danger);
}
.qty-alert-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    line-height: 1;
    font-weight: 800;
    flex: 0 0 18px;
}
.qty-negative-alert {
    background: rgba(163, 48, 48, 0.12);
    color: var(--danger);
    border: 1px solid rgba(163, 48, 48, 0.34);
}
.qty-low-alert {
    background: var(--warn-s);
    color: var(--warn);
    border: 1px solid rgba(184, 95, 46, 0.30);
}
.qty-negative-cell {
    color: var(--danger);
}
.qty-alert-text {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    margin-left: 8px;
    font-size: 14px;
    font-weight: 700;
}
.qty-low-text {
    color: var(--warn);
}
.badge-negative {
    background: rgba(163, 48, 48, 0.10);
    color: var(--danger);
    margin-left: 8px;
}

/* ── Pagination ── */
.pagination {
    display: flex;
    gap: 4px;
    margin-top: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 4px 10px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--ink);
    font-size: 16px;
}
.pagination a:hover { background: var(--soft); border-color: rgba(13, 107, 93, 0.22); }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Detail card ── */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    padding: 20px;
    margin-bottom: 18px;
}
.detail-grid {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr) 160px minmax(0, 1fr);
    gap: 8px 28px;
    font-size: 17px;
}
.detail-grid dt { color: var(--muted); font-weight: normal; }
.detail-grid dd { margin: 0; }
.detail-grid .field-wide { grid-column: 1 / -1; }

.movement-memo-cell {
    min-width: 220px;
}
.movement-memo-display {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.movement-memo-text {
    flex: 1;
    min-width: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.movement-memo-edit-btn {
    flex-shrink: 0;
}
.movement-memo-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 220px;
}
.movement-memo-input {
    width: 100%;
    min-width: 0;
    resize: vertical;
    padding: 6px 8px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 15px;
    color: var(--ink);
    background: #fff;
}
.movement-memo-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* ── Forms ── */
.form-grid {
    display: grid;
    grid-template-columns: 160px minmax(0, 1fr) 160px minmax(0, 1fr);
    gap: 12px 28px;
    align-items: start;
    max-width: none;
}
.form-grid label { font-size: 17px; text-align: right; color: var(--muted); padding-top: 8px; }
.form-grid label.field-wide { text-align: left; padding-top: 4px; }
.form-grid .field-wide { grid-column: 1 / -1; }
.form-grid input[type=text],
.form-grid input[type=number],
.form-grid input[type=date],
.form-grid select,
.form-grid textarea {
    padding: 6px 10px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    font-size: 17px;
    width: 100%;
    background: var(--panel);
    color: var(--ink);
    font-family: var(--font-body);
}
.form-grid input[readonly] { background: rgba(107, 117, 112, 0.08); color: var(--muted); }
.form-actions { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.purchase-edit-table {
    table-layout: fixed;
    box-shadow: none;
    border: 1px solid var(--line);
}
.purchase-edit-table .pe-col-title { width: auto; }
.purchase-edit-table .pe-col-qty { width: 120px; }
.purchase-edit-table .pe-col-price { width: 150px; }
.purchase-edit-table .pe-col-amount { width: 92px; }
.purchase-edit-table .pe-col-date { width: 118px; }
.purchase-edit-table .pe-col-delete { width: 76px; }
.purchase-edit-table th,
.purchase-edit-table td {
    padding: 10px 12px;
}
.purchase-edit-table .num-cell {
    text-align: right;
}
.purchase-edit-table .delete-cell {
    text-align: center;
}
.purchase-edit-table td:first-child {
    line-height: 1.45;
}
.line-number-input {
    width: 100%;
    height: 34px;
    padding: 5px 8px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    background: var(--panel);
    color: var(--ink);
    font: inherit;
    font-size: 16px;
    text-align: right;
}
.line-number-input:focus {
    border-color: rgba(13, 107, 93, 0.45);
}
.amount-cell,
.line-date-cell {
    color: var(--ink);
    white-space: nowrap;
}
.line-date-cell {
    font-size: 15px;
}
.line-delete-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    white-space: nowrap;
    color: var(--muted);
    font-size: 15px;
}
.line-delete-control input {
    width: 15px;
    height: 15px;
    margin: 0;
    accent-color: var(--accent);
}

@media (max-width: 860px) {
    .form-grid,
    .detail-grid { grid-template-columns: 160px minmax(0, 1fr); }
}

/* ── Login page ── */
.login-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
}
.login-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-2);
    padding: 32px 40px;
    min-width: 320px;
    text-align: center;
}
.login-card h1 { font-size: 26px; margin-bottom: 24px; }
.login-card input[type=password] {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm);
    font-size: 18px;
    margin-bottom: 16px;
    background: var(--panel);
    color: var(--ink);
    font-family: var(--font-body);
}
.login-card button {
    width: 100%;
    padding: 8px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 18px;
    cursor: pointer;
    font-weight: 700;
    font-family: var(--font-body);
    transition: background 0.13s;
}
.login-card button:hover { background: var(--accent-h); }
.error-msg { color: var(--danger); font-size: 17px; margin-bottom: 12px; }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-weight: 700;
}
.badge-in     { background: var(--ok-s); color: var(--ok); }
.badge-out    { background: rgba(163, 48, 48, 0.10); color: var(--danger); }
.badge-adjust { background: var(--warn-s); color: var(--warn); }

/* ── Purchase order status badges ── */
.badge-status-draft              { background: rgba(107, 117, 112, 0.10); color: var(--muted); }
.badge-status-issued             { background: rgba(13, 107, 93, 0.10); color: var(--accent); }
.badge-status-partially_received { background: var(--warn-s); color: var(--warn); }
.badge-status-received           { background: var(--ok-s); color: var(--ok); }
.badge-status-cancelled          { background: rgba(163, 48, 48, 0.10); color: var(--danger); }

/* ── Num ── */
.num {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
}
.num.ok    { color: var(--ok); }
.num.warn  { color: var(--warn); }
.num.muted { color: var(--muted); opacity: 0.55; }

/* ── Misc utilities ── */
.text-muted { color: var(--muted); font-size: 16px; }
.text-danger { color: var(--danger); }
.mt-8 { margin-top: 8px; }
.htmx-indicator { opacity: 0; transition: opacity 200ms; }
.htmx-request .htmx-indicator { opacity: 1; }
.htmx-request.htmx-indicator { opacity: 1; }

/* ── Alert boxes ── */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 17px;
}
.alert-error {
    background: rgba(163, 48, 48, 0.08);
    border: 1px solid rgba(163, 48, 48, 0.25);
    color: var(--danger);
}
.alert-warn {
    background: var(--warn-s);
    border: 1px solid rgba(184, 95, 46, 0.30);
    color: var(--warn);
}
.alert-success {
    background: var(--ok-s);
    border: 1px solid rgba(42, 122, 82, 0.25);
    color: var(--ok);
}

/* ── KPI strip (dashboard) ── */
.kpi-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.kpi-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.kpi-card .kpi-label {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.kpi-card .kpi-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    line-height: 1.1;
}
.kpi-card .kpi-value.hero {
    font-size: 36px;
}
.kpi-card .kpi-sub {
    font-size: 14px;
    color: var(--muted);
}
.kpi-card.kpi-ok   { border-left: 3px solid var(--ok); }
.kpi-card.kpi-warn { border-left: 3px solid var(--warn); }
.kpi-card.kpi-danger { border-left: 3px solid var(--danger); }
.kpi-card.kpi-hero {
    background: linear-gradient(135deg, rgba(13, 107, 93, 0.06) 0%, rgba(255, 255, 255, 0.90) 100%);
    border-left: 4px solid var(--accent);
}

/* Full-width hero banner: headline metric spans the whole row */
.kpi-card.kpi-banner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
}
.kpi-card.kpi-banner .kpi-banner-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.kpi-card.kpi-banner .kpi-banner-note {
    max-width: 460px;
    text-align: right;
}
@media (max-width: 640px) {
    .kpi-card.kpi-banner .kpi-banner-note { text-align: left; }
}

.stale-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.stale-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stale-card .kpi-label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stale-card .kpi-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stale-card .kpi-sub   { font-size: 14px; color: var(--muted); }
.stale-30  { border-left: 3px solid var(--warn); }
.stale-90  { border-left: 3px solid rgba(184, 95, 46, 0.75); }
.stale-180 { border-left: 3px solid rgba(163, 48, 48, 0.70); }
.stale-365 { border-left: 3px solid var(--danger); }
.stale-30  .kpi-value { color: var(--warn); }
.stale-90  .kpi-value { color: rgba(184, 95, 46, 0.90); }
.stale-180 .kpi-value { color: rgba(163, 48, 48, 0.80); }
.stale-365 .kpi-value { color: var(--danger); }

/* ── Bulk-stock modal ── */
.bulk-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(26, 41, 38, 0.45);
    z-index: 400;
    align-items: center;
    justify-content: center;
}
.bulk-modal-overlay.is-open {
    display: flex;
}
.bulk-modal-panel {
    background: var(--panel);
    border: 1px solid var(--line-2);
    border-radius: var(--radius);
    box-shadow: 0 8px 40px rgba(20, 30, 26, 0.18);
    width: min(680px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.bulk-modal-panel > form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: inherit;
}
.bulk-modal-header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.bulk-modal-header h2 {
    font-size: 19px;
    margin: 0;
}
.bulk-modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
}
.bulk-modal-close:hover { background: var(--soft); color: var(--ink); }
.bulk-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 20px;
}
.bulk-modal-table { width: 100%; border-collapse: collapse; font-size: 16px; }
.bulk-modal-table th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 2px solid var(--line);
    font-weight: 600;
    color: var(--muted);
    font-size: 14px;
}
.bulk-modal-table td { padding: 8px 8px; border-bottom: 1px solid var(--line); }
.bulk-modal-table td:last-child { width: 100px; }
.bulk-modal-table input[type="number"] {
    width: 90px;
    padding: 4px 8px;
    border: 1px solid var(--line-2);
    border-radius: 6px;
    font-size: 16px;
    text-align: right;
}
.bulk-modal-memo {
    margin-top: 14px;
}
.bulk-modal-memo label { font-size: 15px; color: var(--muted); display: block; margin-bottom: 4px; }
.bulk-modal-memo input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--line-2);
    border-radius: 6px;
    font-size: 16px;
}
.bulk-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: var(--panel);
}

.audit-detail-list {
    display: grid;
    grid-template-columns: max-content minmax(180px, 1fr);
    gap: 4px 10px;
    margin: 6px 0 0;
    font-size: var(--fs-sm);
    line-height: var(--lh-snug);
}
.audit-detail-list dt {
    color: var(--muted);
    font-weight: 700;
}
.audit-detail-list dd {
    margin: 0;
    word-break: break-all;
}

/* ── Inventory table: fixed layout + column resize ── */
.inventory-list-panel .table-wrap {
    width: 100%;
    max-width: 100%;
}
table.inv-table {
    table-layout: fixed;
    width: 100%;
    min-width: 1320px;
}
table.inv-table thead th.inv-th {
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    user-select: none;
}
table.inv-table tbody td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
table.inv-table .inv-check-cell {
    text-align: center;
    overflow: visible;
    text-overflow: clip;
    padding-left: 0;
    padding-right: 0;
}
table.inv-table tbody td.inv-row-actions {
    overflow: visible;
    text-overflow: clip;
}
table.inv-table.boss-inventory-table tbody td.boss-image-cell {
    overflow: visible;
    text-overflow: clip;
    padding-left: 8px;
    padding-right: 8px;
}
table.inv-table.boss-inventory-table tbody td.boss-image-cell img {
    display: block;
    margin: 0 auto;
}
table.inv-table.boss-inventory-table tbody td.boss-code-cell {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
table.inv-table.boss-inventory-table {
    min-width: 1426px;
}
table.inv-table tbody td.cell-clip,
table.inv-table.boss-inventory-table tbody td.boss-code-cell.cell-clip {
    position: relative;
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
}
table.inv-table tbody td.cell-clip:hover,
table.inv-table tbody td.cell-clip:focus-within,
table.inv-table.boss-inventory-table tbody td.boss-code-cell.cell-clip:hover,
table.inv-table.boss-inventory-table tbody td.boss-code-cell.cell-clip:focus-within {
    overflow: visible;
    z-index: 40;
}
table.inv-table .inv-check-cell .col-resize-handle {
    display: none;
}
table.inv-table .inv-check-cell input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0;
    accent-color: var(--accent);
    vertical-align: middle;
}
.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    background: transparent;
    z-index: 1;
}
.col-resize-handle:hover,
.col-resize-handle:active {
    background: rgba(13, 107, 93, 0.30);
}
