/* ==========================================================================
   Components
   ========================================================================== */

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.page-head .subtitle { margin-top: 4px; color: var(--text-muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumb { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 8px; color: var(--text-muted); font-size: 13px; }
.crumb:hover { color: var(--accent); }
.crumb .icon { width: 14px; height: 14px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 38px;
    padding: 0 15px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font-weight: 500;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: var(--surface-3); border-color: #4a5264; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .icon-btn:focus-visible, .qty-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }
.btn .icon { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.btn-danger { background: var(--danger-soft); border-color: rgba(248, 113, 113, 0.35); color: var(--danger); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.22); border-color: var(--danger); }
.btn-success { background: var(--success-soft); border-color: rgba(52, 211, 153, 0.35); color: var(--success); }
.btn-success:hover { background: rgba(52, 211, 153, 0.22); border-color: var(--success); }
.btn-sm { height: 32px; padding: 0 11px; font-size: 13px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; gap: 5px; }
.btn-xs .icon { width: 13px; height: 13px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-block { width: 100%; }
.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn .icon { width: 17px; height: 17px; }
.link { color: var(--accent); }
.link:hover { color: var(--accent-hover); text-decoration: underline; }
.inline-form { display: inline; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card-head h2 .icon, .card-head h3 .icon { color: var(--text-muted); width: 17px; height: 17px; }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }
.card-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 1100px) { .grid-sidebar { grid-template-columns: 1fr; } }
@media (max-width: 800px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 20px; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat {
    position: relative;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color .15s, transform .15s;
}
a.stat:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.stat-label { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 13px; font-weight: 500; }
.stat-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.stat-icon .icon { width: 16px; height: 16px; }
.stat-value { margin-top: 12px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-sub { margin-top: 2px; color: var(--text-faint); font-size: 12.5px; }
.stat.warning .stat-icon { background: var(--warning-soft); color: var(--warning); }
.stat.danger .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat.success .stat-icon { background: var(--success-soft); color: var(--success); }
.stat.info .stat-icon { background: var(--info-soft); color: var(--info); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 800px) {
    .form-grid, .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: auto; }
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 500; color: var(--text-muted); }
.field .req { color: var(--accent); }
.form-section { margin: 26px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); font-size: 12px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-faint); }
.form-section:first-child { margin-top: 0; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=search],
input[type=date], input[type=url], input[type=tel], select, textarea {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
select {
    appearance: none;
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239aa3b2' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input[type=date]::-webkit-calendar-picker-indicator { filter: invert(0.75); cursor: pointer; }
input.num, .num input { text-align: right; font-variant-numeric: tabular-nums; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12.5px; }
.hint { color: var(--text-faint); font-size: 12.5px; }
.input-group { display: flex; }
.input-group > .addon {
    display: grid;
    place-items: center;
    padding: 0 11px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 13px;
}
.input-group > .addon:first-child { border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group > .addon:last-child { border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-group > input:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-group > input:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

.check { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.check input { appearance: none; width: 18px; height: 18px; margin: 0; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--bg); display: grid; place-items: center; cursor: pointer; }
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { content: ''; width: 5px; height: 9px; border: solid var(--on-accent); border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.check input:focus-visible { box-shadow: 0 0 0 3px var(--accent-ring); }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; flex-wrap: wrap; }
.errors-summary { margin-bottom: 18px; }

/* ---------- Filter bar ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.filters .search-input { position: relative; flex: 1 1 260px; min-width: 200px; }
.filters .search-input .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-faint); }
.filters .search-input input { padding-left: 36px; }
.filters select { width: auto; min-width: 130px; flex: 0 1 170px; }
.filters .filter-meta { margin-left: auto; color: var(--text-muted); font-size: 13px; white-space: nowrap; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    transition: all .15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: rgba(34, 211, 238, 0.4); color: var(--accent); }
.chip .count { color: var(--text-faint); font-size: 12px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; font-size: 13.5px; }
.table th {
    position: sticky;
    top: 0;
    padding: 11px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: var(--text-faint);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}
.table th a { display: inline-flex; align-items: center; gap: 4px; }
.table th a:hover, .table th a.sorted { color: var(--text); }
.table th .icon { width: 13px; height: 13px; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.022); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .center { text-align: center; }
.table .actions-col { width: 1%; white-space: nowrap; text-align: right; }
.table tr.inactive td { opacity: .55; }
.table tfoot td { border-top: 1px solid var(--border-strong); border-bottom: 0; font-weight: 600; }
.cell-title { font-weight: 600; color: var(--text); }
a.cell-title:hover { color: var(--accent); }
.cell-sub { color: var(--text-faint); font-size: 12.5px; margin-top: 1px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.sku { font-family: var(--mono); font-size: 12.5px; color: var(--accent); }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

.thumb {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    object-fit: cover;
    display: grid;
    place-items: center;
    color: var(--text-faint);
    overflow: hidden;
}
.thumb .icon { width: 18px; height: 18px; }
.item-cell { display: flex; align-items: center; gap: 12px; min-width: 220px; }
img.thumb.zoomable { cursor: zoom-in; transition: transform .15s, border-color .15s; }
img.thumb.zoomable:hover { transform: scale(1.06); border-color: var(--accent); }
.loc-cell { font-size: 13px; min-width: 130px; }
.loc-line { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.loc-line + .loc-line { margin-top: 6px; }
.loc-name { min-width: 0; white-space: nowrap; }
.loc-bin { white-space: normal; }
.loc-bin { display: block; margin-top: 1px; font-size: 11.5px; line-height: 1.3; color: var(--text-faint); }
.loc-qty { font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Lower-priority columns give way on mid-size screens so the +/- column stays visible. */
@media (min-width: 761px) and (max-width: 1520px) { .table .opt { display: none; } }
@media (min-width: 761px) and (max-width: 1120px) { .table .opt2 { display: none; } }

/* Items list → stacked cards on phones, with big +/- buttons for the stockroom. */
@media (max-width: 760px) {
    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-cards tr { position: relative; padding: 14px 16px; border-bottom: 1px solid var(--border); }
    .table-cards td { padding: 3px 0; border: 0; text-align: left !important; }
    .table-cards td[data-label]::before { content: attr(data-label); display: inline-block; min-width: 96px; color: var(--text-faint); font-size: 12px; }
    .table-cards td.hide-card { display: none; }
    .table-cards td.qty-cell { margin-top: 8px; }
    .table-cards .qty-stepper { width: 100%; justify-content: space-between; }
    .table-cards .qty-btn { width: 52px; height: 44px; }
    .table-cards .item-cell { min-width: 0; }
    .table-cards td.loc-cell { display: grid; grid-template-columns: 96px 1fr; align-items: start; }
    .table-cards td.loc-cell::before { grid-row: 1 / span 20; }
    .table-cards .loc-line { grid-column: 2; justify-content: space-between; gap: 12px; }
    .table-cards .loc-name { white-space: normal; overflow-wrap: anywhere; }
    .table-cards img.thumb.zoomable { width: 56px; height: 56px; }
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 22px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-muted { background: var(--surface-3); color: var(--text-muted); }
.badge.plain::before { display: none; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 5px; background: var(--surface-3); color: var(--text-muted); font-size: 12px; }

/* ---------- Qty stepper (the +/- buttons) ---------- */
.qty-stepper { display: inline-flex; align-items: center; gap: 4px; padding: 3px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg); }
.qty-btn {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--text-muted);
    transition: background .12s, color .12s, transform .06s;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}
.qty-btn .icon { width: 15px; height: 15px; }
.qty-btn.minus:hover { background: var(--danger-soft); color: var(--danger); }
.qty-btn.plus:hover { background: var(--success-soft); color: var(--success); }
.qty-btn:active { transform: scale(0.92); }
.qty-value {
    min-width: 54px;
    padding: 0 6px;
    text-align: center;
    font-weight: 700;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    transition: color .3s;
}
.qty-stepper .qty-value { cursor: text; border-radius: 5px; }
.qty-stepper .qty-value:hover { background: var(--surface-2); box-shadow: inset 0 -1px 0 var(--accent); }
.qty-input {
    display: block;
    width: 68px;
    height: 30px;
    margin: 0 auto;
    padding: 0 6px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-weight: 700;
    font-size: 15px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 0 0 3px var(--accent-ring);
    outline: none;
}
.qty-edit-loc { display: block; max-width: 110px; margin: 2px auto 0; font-size: 11px; color: var(--accent); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qty-value.flash-up { color: var(--success); }
.qty-value.flash-down { color: var(--danger); }
.qty-value.busy { opacity: .6; }
.qty-static { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.qty-uom { display: block; font-size: 11px; color: var(--text-faint); font-weight: 500; text-align: center; }

/* Location picker popover */
.popover {
    position: absolute;
    z-index: 80;
    min-width: 240px;
    max-width: 320px;
    padding: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    animation: pop .12s ease-out;
}
.popover-title { padding: 6px 10px 8px; color: var(--text-faint); font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.popover button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--text);
    text-align: left;
}
.popover button:hover, .popover button:focus-visible { background: var(--surface-3); outline: none; }
.popover button .q { color: var(--text-muted); font-variant-numeric: tabular-nums; font-weight: 600; }
.popover .popover-foot { margin-top: 4px; padding: 6px 10px 4px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-faint); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 14px;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .icon { width: 16px; height: 16px; }
.tab .count { padding: 0 7px; border-radius: 999px; background: var(--surface-3); color: var(--text-muted); font-size: 11.5px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 13px; flex-wrap: wrap; }
.pagination .pages { display: flex; gap: 4px; }
.pagination a, .pagination span.current {
    display: grid;
    place-items: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border-radius: 7px;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.pagination a:hover { border-color: var(--border-strong); color: var(--text); }
.pagination span.current { background: var(--accent-soft); border-color: rgba(34, 211, 238, 0.4); color: var(--accent); font-weight: 600; }
.pagination .gap { padding: 0 4px; align-self: center; }

/* ---------- Flash + toasts ---------- */
.flash {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid;
    border-radius: var(--radius);
    font-weight: 500;
}
.flash .icon { width: 18px; height: 18px; }
.flash span { flex: 1; }
.flash-success { background: var(--success-soft); border-color: rgba(52, 211, 153, 0.3); color: #a7f3d0; }
.flash-success .icon { color: var(--success); }
.flash-error { background: var(--danger-soft); border-color: rgba(248, 113, 113, 0.3); color: #fecaca; }
.flash-error .icon { color: var(--danger); }
.flash-info, .flash-warning { background: var(--warning-soft); border-color: rgba(251, 191, 36, 0.3); color: #fde68a; }
.flash-info .icon, .flash-warning .icon { color: var(--warning); }
.flash-close { border: 0; background: none; color: inherit; opacity: .6; padding: 2px; }
.flash-close:hover { opacity: 1; }
.flash-close .icon { width: 16px; height: 16px; }
.flash ul { margin: 4px 0 0 18px; }

.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 240px;
    max-width: 380px;
    padding: 11px 14px;
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-weight: 500;
    pointer-events: auto;
    animation: toast-in .2s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast .icon { width: 17px; height: 17px; }
.toast.error .icon { color: var(--danger); }
.toast.success .icon { color: var(--success); }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: all .2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) { .toast-stack { left: 16px; right: 16px; } .toast { max-width: none; } }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: none; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; background: rgba(5, 7, 10, 0.7); backdrop-filter: blur(3px); overflow-y: auto; }
.modal.open { display: flex; }
.modal-box { width: 100%; max-width: 480px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: pop .15s ease-out; }
.modal-box.wide { max-width: 680px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-body .field + .field { margin-top: 14px; }
.modal-body .form-grid .field + .field { margin-top: 0; }
.modal-body .form-section:first-child { margin-top: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---------- Empty state ---------- */
.empty-state { padding: 48px 24px; text-align: center; color: var(--text-muted); }
.empty-state.big { padding: 90px 24px; }
.empty-icon { display: inline-grid; place-items: center; width: 54px; height: 54px; margin-bottom: 14px; border-radius: 14px; background: var(--surface-2); color: var(--text-faint); }
.empty-icon .icon { width: 24px; height: 24px; }
.empty-state h2, .empty-state h3 { color: var(--text); font-size: 17px; margin-bottom: 6px; }
.empty-state p { max-width: 420px; margin: 0 auto 18px; }

/* ---------- Detail lists ---------- */
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 10px 16px; }
.dl dt { color: var(--text-faint); font-size: 13px; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 560px) { .dl { grid-template-columns: 1fr; gap: 2px; } .dl dd { margin-bottom: 10px; } }
.kv-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.kv-row:last-child { border-bottom: 0; }
.kv-row .k { color: var(--text-muted); }
.kv-row .v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- Item hero ---------- */
.item-hero { display: flex; gap: 20px; align-items: flex-start; }
.hero-image { width: 120px; height: 120px; border-radius: var(--radius); object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; color: var(--text-faint); flex-shrink: 0; cursor: zoom-in; }
.hero-image .icon { width: 34px; height: 34px; }
.hero-qty { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; margin-left: auto; }
.hero-qty .big { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
@media (max-width: 640px) { .item-hero { flex-wrap: wrap; } .hero-qty { margin-left: 0; align-items: flex-start; } .hero-image { width: 84px; height: 84px; } }

.barcode-box { display: inline-block; padding: 10px 12px 4px; background: #fff; border-radius: 8px; }
.barcode-box svg { display: block; height: 70px; width: auto; }

/* ---------- Gallery ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.gallery-item { position: relative; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface-2); }
.gallery-item img { width: 100%; aspect-ratio: 1; object-fit: cover; cursor: zoom-in; }
.gallery-item.primary { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.gallery-actions { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 6px 6px 6px 10px; font-size: 12px; color: var(--text-muted); }
.gallery-flag { position: absolute; top: 8px; left: 8px; }
.dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 26px;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    color: var(--text-muted);
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone .icon { width: 26px; height: 26px; color: var(--accent); }
.dropzone input { display: none; }

/* Photo capture */
.upload-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.upload-actions .btn { cursor: pointer; }
.upload-actions .dz-label:empty { display: none; }
.hero-add { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 6px; cursor: pointer; border-style: dashed; color: var(--accent); transition: border-color .15s, background .15s; }
.hero-add:hover { border-color: var(--accent); background: var(--accent-soft); }
.hero-add .icon { width: 28px; height: 28px; }
.hero-add .dz-label { font-size: 12px; font-weight: 600; }
.busy { opacity: .6; pointer-events: none; }
/* Camera button only where there's a camera (touch devices); drop zone only where you can drag. */
@media (hover: hover) and (pointer: fine) { .camera-only { display: none !important; } }
@media (hover: none), (pointer: coarse) { .desktop-only { display: none !important; } }

.lightbox { position: fixed; inset: 0; z-index: 150; display: none; place-items: center; padding: 30px; background: rgba(0, 0, 0, 0.88); cursor: zoom-out; }
.lightbox.open { display: grid; }
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: 8px; box-shadow: var(--shadow-lg); }

/* ---------- Settings lists ---------- */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--topbar-h) + 20px); }
.settings-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 500; }
.settings-nav a:hover { background: var(--surface-2); color: var(--text); }
.settings-nav a.active { background: var(--accent-soft); color: var(--accent); }
.settings-nav .icon { width: 16px; height: 16px; }
.settings-nav .count { margin-left: auto; font-size: 12px; color: var(--text-faint); }
@media (max-width: 860px) {
    .settings-layout { grid-template-columns: 1fr; }
    .settings-nav { position: static; flex-direction: row; overflow-x: auto; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
    .settings-nav a { white-space: nowrap; }
}
.tree-row { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border); min-height: 52px; }
.tree-row:last-child { border-bottom: 0; }
.tree-row:hover { background: rgba(255, 255, 255, 0.02); }
.tree-row .name { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.tree-row .indent { display: inline-block; width: 18px; flex-shrink: 0; border-left: 1px solid var(--border-strong); height: 20px; margin-left: 6px; }
.tree-row.inactive .name { opacity: .5; text-decoration: line-through; }
.tree-row .row-actions { display: flex; gap: 2px; opacity: .6; transition: opacity .15s; }
.tree-row:hover .row-actions, .tree-row:focus-within .row-actions { opacity: 1; }
.tree-row form.rename { display: none; flex: 1; gap: 8px; }
.tree-row.editing form.rename { display: flex; }
.tree-row.editing .name, .tree-row.editing .row-actions { display: none; }
.tree-row form.rename input, .tree-row form.rename select { height: 34px; }
.add-row { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); flex-wrap: wrap; }
.add-row input { flex: 1 1 200px; }
.add-row select { flex: 0 1 220px; }

/* ---------- PO ---------- */
.po-lines td { vertical-align: top; }
.po-lines td:first-child { min-width: 280px; }
.po-lines input, .po-lines textarea { height: 36px; }
.po-lines .col-qty { width: 110px; }
.po-lines .col-cost { width: 130px; }
.po-lines .col-total { width: 120px; }
.po-lines .col-x { width: 44px; }
.po-lines .line-total { padding-top: 9px; display: block; font-weight: 600; }
.po-lines .picked { margin-top: 4px; font-size: 12px; color: var(--text-faint); }
.item-picker { position: relative; }
.item-picker .results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 60;
    max-height: 320px;
    overflow-y: auto;
    padding: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.item-picker .results button { display: flex; justify-content: space-between; gap: 12px; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: none; color: var(--text); text-align: left; }
.item-picker .results button:hover, .item-picker .results button.active { background: var(--surface-3); }
.item-picker .results .meta { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.totals { margin-left: auto; width: 100%; max-width: 340px; }
.totals .kv-row .v input { width: 110px; height: 32px; text-align: right; }
.totals .grand { font-size: 17px; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; min-width: 60px; }
.progress > span { display: block; height: 100%; background: var(--success); border-radius: 99px; }
.supplier-group + .supplier-group { margin-top: 20px; }

/* ---------- Loans ---------- */
.loan-entry { display: flex; gap: 20px; justify-content: space-between; align-items: flex-start; padding: 16px 20px; border-bottom: 1px solid var(--border); border-left: 3px solid var(--info); }
.loan-entry:last-child { border-bottom: 0; }
.loan-entry.overdue { border-left-color: var(--danger); background: linear-gradient(90deg, rgba(248, 113, 113, 0.06), transparent 40%); }
.loan-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.loan-main > .cell-title { font-size: 15px; }
.loan-borrower { display: flex; gap: 12px; align-items: flex-start; }
.loan-borrower strong { font-size: 15px; }
.avatar.sm { width: 34px; height: 34px; flex-shrink: 0; background: linear-gradient(135deg, #155e75, #1e3a5f); border-color: #1f4f66; color: var(--accent); }
.loan-contact { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 3px; font-size: 13px; }
.loan-contact a { display: inline-flex; align-items: center; gap: 5px; }
.loan-contact .icon { width: 14px; height: 14px; }
.loan-facts { display: flex; flex-wrap: wrap; gap: 8px 26px; }
.loan-facts > div { display: flex; flex-direction: column; }
.loan-facts .k { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.loan-facts .v { font-weight: 600; }
.loan-facts .v small { display: block; font-size: 12px; font-weight: 500; }
.loan-notes { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.loan-notes > div:first-child { display: flex; align-items: center; gap: 6px; }
.loan-notes .icon { width: 14px; height: 14px; color: var(--text-faint); }
.loan-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; flex-shrink: 0; }
@media (max-width: 640px) {
    .loan-entry { flex-direction: column; padding: 14px 16px; }
    .loan-actions { flex-direction: row; flex-wrap: wrap; width: 100%; }
    .loan-actions .btn { flex: 1; }
}
.loan-signed { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; font-weight: 500; }
.loan-signed span { display: inline-flex; align-items: center; gap: 5px; }
.loan-signed .icon { width: 14px; height: 14px; }

/* Sign-out screen (hand the phone to the borrower) */
.sign-sheet { max-width: 760px; margin: 0 auto; }
.sign-sheet > * + * { margin-top: 16px; }
.sign-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 4px 0 2px; }
.sign-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px 20px; margin-top: 18px; }
.sign-facts > div { display: flex; flex-direction: column; }
.sign-facts .k { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.sign-facts .v { font-weight: 600; font-size: 15px; }
.sign-facts .s { font-size: 12.5px; color: var(--text-muted); }
.sign-notes { margin-top: 14px; color: var(--text-muted); }
.sign-terms { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-muted); font-size: 13px; }
.sig-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 2px dashed var(--border-strong); background: #fff; }
#sig-pad { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.sig-line { position: absolute; left: 20px; right: 20px; bottom: 44px; border-bottom: 1.5px solid #cbd5e1; pointer-events: none; }
.sig-line span { position: absolute; left: 0; bottom: 2px; color: #94a3b8; font-size: 16px; }
.sig-hint { position: absolute; inset: 0; display: grid; place-items: center; color: #94a3b8; font-size: 15px; pointer-events: none; }
@media (max-width: 640px) { #sig-pad { height: 240px; } .sign-title { font-size: 19px; } }
.check input[type=radio] { border-radius: 50%; }
.check input[type=radio]:checked::after { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--on-accent); transform: none; }
.check span strong { color: var(--text); }
.check { align-items: flex-start; }
.check input { margin-top: 2px; flex-shrink: 0; }

.tag .tag-icon, .tag .icon { width: 12px; height: 12px; display: inline-block; vertical-align: -1px; margin-right: 4px; }
.chip-sep { width: 1px; height: 22px; background: var(--border-strong); margin: 0 4px; align-self: center; }
.chip .icon { width: 14px; height: 14px; }
.chip.chip-danger:not(.active):hover { color: var(--danger); border-color: rgba(248, 113, 113, 0.4); }
.nav-badge.danger { background: var(--danger-soft); color: var(--danger); }
.nav-badge.info { background: var(--info-soft); color: var(--info); }
.check .icon { width: 16px; height: 16px; color: var(--accent); }

/* ---------- Timeline (movement history) ---------- */
.delta { font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--success); }
.delta.down { color: var(--danger); }

/* ---------- Auth pages ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
    radial-gradient(1200px 600px at 10% -10%, rgba(34, 211, 238, 0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(129, 140, 248, 0.10), transparent 60%), var(--bg); }
.auth-body .content { padding: 0; }
.auth-card { width: 100%; max-width: 400px; padding: 32px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); }
.auth-card.wide { max-width: 640px; }
.auth-card .brand { height: auto; padding: 0 0 22px; border: 0; }
.auth-card h1 { font-size: 21px; font-weight: 700; margin-bottom: 4px; letter-spacing: -0.01em; }
.auth-card .lead { color: var(--text-muted); margin-bottom: 22px; }
.auth-card .field + .field { margin-top: 14px; }

.password-field { position: relative; }
.password-field input { padding-right: 42px; }
.password-field button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: grid; place-items: center; width: 32px; height: 32px; border: 0; background: none; color: var(--text-faint); border-radius: 6px; }
.password-field button:hover { color: var(--text); }
.password-field button .icon { width: 17px; height: 17px; }

/* ---------- Utilities ---------- */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.w-auto { width: auto !important; }
.hidden { display: none !important; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
