/* Medicine stock admin page (inventory.html). Mobile first; wider layouts from 760px. */
:root { --ink: #1f2937; --mut: #6b7280; --line: #e5e7eb; --pri: #4f46e5; --pri-bg: #eef2ff; --red: #b91c1c; --red-bg: #fee2e2;
        --grn: #047857; --grn-bg: #d1fae5; --amb: #92400e; --amb-bg: #fef3c7; --yel-bg: #fef9c3; --blue: #1e40af; --blue-bg: #dbeafe; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Devanagari', sans-serif; background: #f3f4f6; color: var(--ink); padding-bottom: 48px; line-height: 1.45; }
body.auth-pending { visibility: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
.inv-header { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #fff; border-bottom: 1px solid #dbe4e7; }
.inv-header h1 { flex: 1; min-width: 0; font-size: 1rem; overflow-wrap: anywhere; }
.inv-header h1 small { display: block; font-size: 0.75rem; color: var(--mut); font-weight: 400; }
.inv-back { display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px; border: 1px solid #d1d5db; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.85rem; white-space: nowrap; }
.inv-wrap { max-width: 1100px; margin: 0 auto; padding: 12px; }
#inv-status { min-height: 20px; font-size: 0.82rem; color: var(--mut); margin-bottom: 6px; }
.inv-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 7px 13px; border: 1px solid transparent; border-radius: 8px; font-weight: 600; font-size: 0.85rem; cursor: pointer; background: #fff; text-decoration: none; }
.inv-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.inv-btn-pri { background: var(--pri); color: #fff; }
.inv-btn-grn { background: var(--grn); color: #fff; }
.inv-btn-red { background: var(--red-bg); color: var(--red); border-color: #fecaca; }
.inv-btn-out { border-color: #d1d5db; color: var(--ink); }
.inv-btn-sm { min-height: 34px; padding: 4px 10px; font-size: 0.78rem; }
.inv-btn:focus-visible, .inv-chipbtn:focus-visible, .inv-tabs button:focus-visible { outline: 2px solid #087f8c; outline-offset: 2px; }

.inv-kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.inv-kpi { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.inv-kpi b { display: block; font-size: 1.35rem; line-height: 1.2; }
.inv-kpi span { font-size: 0.78rem; color: var(--mut); }
.inv-kpi-red b { color: var(--red); } .inv-kpi-amber b { color: var(--amb); } .inv-kpi-green b { color: var(--grn); }

.inv-alert { border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; font-size: 0.88rem; border: 1px solid; }
.inv-alert-red { background: var(--red-bg); border-color: #fecaca; color: #7f1d1d; }
.inv-alert-amber { background: var(--amb-bg); border-color: #fde68a; color: #78350f; }
.inv-alert-blue { background: var(--blue-bg); border-color: #bfdbfe; color: #1e3a8a; }
.inv-alert ol, .inv-alert ul { margin: 4px 0 0 18px; }

.inv-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: thin; }
.inv-tabs button { flex: none; min-height: 42px; padding: 6px 14px; border: 1px solid #d1d5db; border-radius: 999px; background: #fff; font-weight: 600; font-size: 0.86rem; cursor: pointer; white-space: nowrap; }
.inv-tabs button[aria-selected="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.inv-tabs .inv-count { margin-left: 4px; font-size: 0.72rem; background: var(--red); color: #fff; border-radius: 999px; padding: 0 6px; }

.inv-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.inv-card h2 { font-size: 0.98rem; margin-bottom: 6px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.inv-help { font-size: 0.82rem; color: var(--mut); margin: 2px 0 8px; }
.inv-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.inv-toolbar input[type="search"] { flex: 1 1 220px; min-width: 0; min-height: 42px; padding: 8px 12px; border: 1px solid #d1d5db; border-radius: 10px; }
.inv-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.inv-chipbtn { min-height: 36px; padding: 4px 12px; border: 1px solid #d1d5db; border-radius: 999px; background: #fff; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.inv-chipbtn[aria-pressed="true"] { background: var(--pri-bg); border-color: var(--pri); color: #3730a3; }

.inv-pill { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.inv-pill-green { background: var(--grn-bg); color: var(--grn); } .inv-pill-amber { background: var(--amb-bg); color: var(--amb); }
.inv-pill-red { background: var(--red-bg); color: var(--red); } .inv-pill-gray { background: #f3f4f6; color: #4b5563; }
.inv-pill-blue { background: var(--blue-bg); color: var(--blue); } .inv-pill-yellow { background: var(--yel-bg); color: #854d0e; }

.inv-items { display: grid; gap: 8px; }
.inv-item { background: #fff; border: 1px solid var(--line); border-left: 4px solid #9ca3af; border-radius: 10px; padding: 10px 12px; }
.inv-item-ok { border-left-color: #16a34a; } .inv-item-low { border-left-color: #d97706; } .inv-item-out { border-left-color: #dc2626; } .inv-item-retired { opacity: 0.7; }
.inv-item-head { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.inv-item-head b { font-size: 0.96rem; overflow-wrap: anywhere; }
.inv-item-head small { color: var(--mut); }
.inv-qty { margin-left: auto; text-align: right; font-size: 0.85rem; white-space: nowrap; }
.inv-qty b { font-size: 1.15rem; }
.inv-meta { font-size: 0.78rem; color: var(--mut); margin: 2px 0 6px; overflow-wrap: anywhere; }
.inv-uses { font-size: 0.76rem; color: var(--grn); font-weight: 600; margin: 4px 0 0; }
.inv-uses span { display: inline-block; background: var(--grn-bg); border-radius: 999px; padding: 1px 8px; margin: 2px 4px 0 0; }
.inv-batches { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin: 4px 0 6px; }
.inv-batches th { text-align: left; color: var(--mut); font-weight: 600; font-size: 0.72rem; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.inv-batches td { padding: 5px 6px; border-bottom: 1px solid #f3f4f6; vertical-align: middle; }
.inv-batch-actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.inv-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.inv-empty { text-align: center; color: var(--mut); padding: 18px 8px; font-size: 0.88rem; }

.inv-table-wrap { overflow-x: auto; }
.inv-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.inv-table th { text-align: left; padding: 6px 8px; color: var(--mut); font-size: 0.72rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
.inv-table td { padding: 7px 8px; border-bottom: 1px solid #f3f4f6; vertical-align: top; }
.inv-plus { color: var(--grn); font-weight: 700; } .inv-minus { color: var(--red); font-weight: 700; }

.inv-rule { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: #fff; }
.inv-rule header { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-bottom: 4px; }
.inv-rule header b { font-size: 0.95rem; overflow-wrap: anywhere; }
.inv-rule ul { margin: 2px 0 6px 18px; font-size: 0.84rem; }
.inv-rule p { font-size: 0.84rem; margin: 3px 0; }
.inv-rule-approved { border-left: 4px solid #16a34a; } .inv-rule-draft { border-left: 4px solid #d97706; } .inv-rule-retired { border-left: 4px solid #9ca3af; opacity: 0.8; }

.inv-modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; background: rgba(15, 23, 42, 0.55); padding: 0; }
.inv-modal[hidden] { display: none; }
.inv-dialog { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 16px; }
.inv-dialog h2 { font-size: 1.05rem; margin-bottom: 4px; padding-right: 40px; }
.inv-close { position: sticky; top: 0; float: right; width: 40px; height: 40px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; cursor: pointer; font-size: 1.1rem; }
.inv-form { display: grid; gap: 10px; margin-top: 10px; }
.inv-form label { display: grid; gap: 3px; font-size: 0.8rem; color: #374151; font-weight: 600; }
.inv-form input, .inv-form select, .inv-form textarea { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.95rem; font-weight: 400; background: #fff; }
.inv-form .inv-check { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; }
.inv-form .inv-check input { width: 22px; min-height: 22px; height: 22px; flex: none; margin-top: 1px; }
.inv-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inv-row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 6px; align-items: end; }
.inv-or { font-size: 0.78rem; color: var(--mut); text-align: center; }
.inv-error { color: var(--red); font-weight: 600; font-size: 0.86rem; min-height: 1.2em; }
.inv-form-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.inv-results { display: grid; gap: 6px; margin-top: 8px; }
.inv-result { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.inv-result div { flex: 1 1 200px; min-width: 0; }
.inv-result small { display: block; color: var(--mut); overflow-wrap: anywhere; }
.inv-problems { background: var(--amb-bg); border: 1px solid #fde68a; color: #78350f; border-radius: 8px; padding: 8px 10px; font-size: 0.84rem; }
.inv-problems ul { margin-left: 18px; }

#inv-toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 90; max-width: 92vw; padding: 10px 16px; border-radius: 10px; background: #111827; color: #fff; font-size: 0.88rem; display: none; }
#inv-toast.inv-show { display: block; }
#inv-toast.inv-toast-error { background: #7f1d1d; }

@media (min-width: 760px) {
    .inv-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .inv-modal { align-items: center; padding: 14px; }
    .inv-dialog { border-radius: 16px; }
}
@media (max-width: 480px) {
    .inv-row3 { grid-template-columns: 1fr 1fr; }
    .inv-row3 > :first-child { grid-column: 1 / -1; }
    .inv-batches thead { display: none; }
    .inv-batches tr { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid #f3f4f6; }
    .inv-batches td { padding: 0; border: 0; }
    .inv-batches td:nth-child(4) { display: none; }
    .inv-batches td:last-child { grid-column: 1 / -1; }
    .inv-batches td[data-label]::before { content: attr(data-label) " "; color: var(--mut); font-size: 0.72rem; }
    .inv-batch-actions { justify-content: flex-start; }
}
@media print {
    .inv-header, .inv-tabs, .inv-toolbar, .inv-chips, .inv-actions, .inv-batch-actions, .inv-kpis, #inv-alerts { display: none !important; }
    body { background: #fff; }
}
