/* ============================================================
   PharmaCare – Main Stylesheet  (mobile-first)
   ============================================================ */

:root {
    --primary:        #5B4DE8;
    --primary-dark:   #4a3cc7;
    --primary-light:  #ede9fd;
    --orange:         #F59E0B;
    --orange-light:   #FEF3C7;
    --green:          #10B981;
    --green-light:    #D1FAE5;
    --red:            #EF4444;
    --red-light:      #FEE2E2;
    --blue:           #3B82F6;
    --blue-light:     #DBEAFE;
    --gray:           #6B7280;
    --gray-light:     #F3F4F6;
    --bg:             #F1F2F7;
    --surface:        #FFFFFF;
    --border:         #E5E7EB;
    --text:           #111827;
    --text-muted:     #6B7280;
    --text-light:     #9CA3AF;
    --sidebar-w:      260px;
    --topbar-h:       56px;
    --radius:         12px;
    --radius-sm:      8px;
    --shadow:         0 1px 4px rgba(0,0,0,.08);
    --shadow-md:      0 4px 16px rgba(0,0,0,.10);
    --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-w); height: 100vh;
    background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 200; transition: transform .25s ease;
    transform: translateX(-100%);
}
.sidebar.open { transform: translateX(0); box-shadow: var(--shadow-md); }
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.4); z-index: 199;
}
.sidebar-overlay.open { display: block; }
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 16px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; }
.brand-icon {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-icon svg { width: 18px; height: 18px; }
.brand-name { display: block; font-weight: 700; font-size: 15px; }
.brand-sub  { display: block; font-size: 10px; color: var(--text-muted); letter-spacing: .08em; }
.sidebar-close {
    width: 32px; height: 32px; background: var(--gray-light); border: none;
    border-radius: 8px; display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
}
.sidebar-close svg { width: 16px; height: 16px; }
.sidebar-nav { flex: 1; padding: 10px 8px; overflow-y: auto; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 12px; border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: 14px; font-weight: 500;
    transition: background .15s, color .15s; margin-bottom: 2px;
}
.nav-item:hover  { background: var(--gray-light); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-icon svg { width: 18px; height: 18px; }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--border); flex-shrink: 0; }
.user-info { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; }
.user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary-light); color: var(--primary);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-avatar svg { width: 16px; height: 16px; }
.user-name  { font-size: 13px; font-weight: 600; }
.user-email { font-size: 11px; color: var(--text-muted); word-break: break-all; }
.role-badge {
    display: inline-block; font-size: 10px; font-weight: 700;
    padding: 1px 7px; border-radius: 20px;
    background: var(--primary-light); color: var(--primary);
    letter-spacing: .06em; margin-top: 3px;
}
.role-badge-doctor  { background: var(--primary-light); color: var(--primary); }
.role-badge-cashier { background: var(--green-light);   color: var(--green); }
.logout-btn {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--text-muted); padding: 8px 4px;
    background: none; border: none; width: 100%; transition: color .15s;
}
.logout-btn:hover { color: var(--red); }
.logout-btn svg { width: 16px; height: 16px; }

/* Desktop: sidebar always visible */
@media (min-width: 769px) {
    .sidebar { transform: translateX(0); }
    .sidebar-close { display: none; }
    .sidebar-overlay { display: none !important; }
}

/* ============================================================
   MAIN LAYOUT / TOPBAR
   ============================================================ */
.main-wrapper { margin-left: 0; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    height: var(--topbar-h); background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
    padding: 0 16px; position: sticky; top: 0; z-index: 150;
}
.menu-btn {
    width: 36px; height: 36px; background: var(--gray-light);
    border: none; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); flex-shrink: 0;
}
.menu-btn svg { width: 20px; height: 20px; }
.topbar-title { font-size: 15px; font-weight: 600; flex: 1; }
.topbar-brand {
    display: flex; align-items: center; gap: 8px;
    font-size: 15px; font-weight: 700; color: var(--primary);
}
.topbar-brand .brand-icon { width: 30px; height: 30px; border-radius: 8px; }
.topbar-brand .brand-icon svg { width: 14px; height: 14px; }
.page-content { padding: 14px 14px 24px; flex: 1; }

@media (min-width: 769px) {
    .main-wrapper { margin-left: var(--sidebar-w); }
    .menu-btn { display: none; }
    .topbar-title { display: none; }
    .topbar-brand { display: none; }
    .page-content { padding: 24px 28px; max-width: 1200px; }
}
/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    margin-bottom: 18px; gap: 10px; flex-wrap: wrap;
}
.page-title    { font-size: 20px; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
@media (min-width: 769px) {
    .page-title { font-size: 26px; }
    .page-header { margin-bottom: 24px; }
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px; margin-bottom: 18px;
}
.stats-grid-2 { grid-template-columns: repeat(2, 1fr); }
.stat-card {
    background: var(--surface); border-radius: var(--radius);
    padding: 14px 12px; box-shadow: var(--shadow);
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.stat-body { flex: 1; min-width: 0; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.stat-value { font-size: 20px; font-weight: 700; line-height: 1.1; }
.stat-note  { font-size: 11px; color: var(--text-light); margin-top: 3px; }
.stat-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-purple { background: var(--primary); color: #fff; }
.stat-orange { background: var(--orange);  color: #fff; }
.stat-green  { background: var(--green);   color: #fff; }
.stat-blue   { background: var(--blue);    color: #fff; }
.stat-red    { background: var(--red);     color: #fff; }
.stat-gray   { background: var(--gray);    color: #fff; }
@media (min-width: 769px) {
    .stats-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
    .stat-card { padding: 20px; }
    .stat-icon { width: 52px; height: 52px; }
    .stat-icon svg { width: 24px; height: 24px; }
    .stat-value { font-size: 28px; }
}

/* ============================================================
   PANELS
   ============================================================ */
.panel {
    background: var(--surface); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px; gap: 8px;
}
.panel-title { font-size: 15px; font-weight: 600; }
.panel-link  { font-size: 13px; color: var(--primary); font-weight: 500; white-space: nowrap; }
.panel-link:hover { text-decoration: underline; }
.panel-section-title {
    font-size: 11px; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .07em;
    margin-bottom: 12px; display: flex; align-items: center; gap: 6px;
}
.dash-panels { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) {
    .panel { padding: 20px; margin-bottom: 20px; }
    .panel-title { font-size: 16px; }
    .dash-panels { grid-template-columns: 1fr 1fr; gap: 20px; }
}

/* ============================================================
   TABLES
   ============================================================ */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
.table-scroll::-webkit-scrollbar { height: 4px; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.data-table { width: 100%; font-size: 13px; min-width: 480px; }
.data-table th {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .07em; color: var(--text-muted);
    padding: 8px 10px; border-bottom: 1px solid var(--border);
    text-align: left; white-space: nowrap;
}
.data-table td {
    padding: 10px 10px; border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--gray-light); }
@media (min-width: 769px) {
    .data-table { font-size: 14px; }
    .data-table th { padding: 8px 12px; font-size: 11px; }
    .data-table td { padding: 12px 12px; }
}
.monthly-sheet tfoot td {
    padding: 10px 12px; background: var(--gray-light);
    font-size: 13px; border-top: 2px solid var(--border);
}
.tfoot-totals td { font-weight: 700; }
.row-today    { background: #fffbe6 !important; }
.row-selected { background: var(--primary-light) !important; }
.date-link { color: var(--primary); font-weight: 500; }
.date-link:hover { text-decoration: underline; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 20px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-purple { background: var(--primary-light); color: var(--primary); }
.badge-green  { background: var(--green-light);   color: var(--green); }
.badge-orange { background: var(--orange-light);  color: #92400e; }
.badge-red    { background: var(--red-light);     color: var(--red); }
.badge-blue   { background: var(--blue-light);    color: var(--blue); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px 16px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 600; border: none;
    transition: background .15s, opacity .15s; white-space: nowrap;
    touch-action: manipulation;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-light); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost  { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--gray-light); }
.btn-full   { width: 100%; }
.btn-sm     { padding: 7px 12px; font-size: 12px; }
.btn-icon {
    width: 34px; height: 34px; border-radius: 8px;
    display: inline-flex; align-items: center; justify-content: center;
    border: none; background: var(--gray-light); color: var(--text-muted);
    transition: background .15s, color .15s; flex-shrink: 0;
}
.btn-icon svg { width: 14px; height: 14px; }
.btn-edit:hover   { background: var(--primary-light); color: var(--primary); }
.btn-delete:hover { background: var(--red-light);     color: var(--red); }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 600;
    margin-bottom: 5px; color: var(--text);
}
input[type="text"], input[type="number"], input[type="email"],
input[type="password"], input[type="date"], input[type="month"],
select, textarea, .form-input {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 15px; background: var(--surface); color: var(--text);
    transition: border-color .15s; -webkit-appearance: none; appearance: none;
}
input:focus, select:focus, textarea:focus, .form-input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(91,77,232,.12);
}
textarea { resize: vertical; }
.form-textarea { width: 100%; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: block; }
.form-row  { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; gap: 0; } }

/* ============================================================
   SEARCH / FILTER BAR
   ============================================================ */
.filter-bar {
    display: flex; align-items: flex-end; gap: 8px;
    flex-wrap: wrap; margin-bottom: 14px;
}
.filter-select {
    padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 14px;
    background: var(--surface); min-width: 130px;
    -webkit-appearance: none; appearance: none;
}
/* ── Shared search bar ── */
.search-wrap { position: relative; flex: 1; min-width: 160px; }
.search-icon {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    width: 16px; height: 16px; color: var(--text-muted); pointer-events: none;
    display: block; line-height: 0;
}
.search-icon svg { display: block; width: 16px; height: 16px; }
.search-input {
    width: 100%; padding: 10px 12px 10px 34px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 15px; background: var(--surface); color: var(--text);
    -webkit-appearance: none; appearance: none;
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91,77,232,.12); }

/* ── Billing drug search wrapper (keeps dropdown below input) ── */
.drug-search-wrap {
    position: relative;
    display: block;
}
.drug-search-input {
    width: 100%; padding: 11px 38px 11px 14px;
    border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    font-size: 15px; background: var(--surface); color: var(--text);
    -webkit-appearance: none; appearance: none; transition: border-color .15s;
    display: block; position: relative; z-index: 1;
}
.drug-search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91,77,232,.12); }
.drug-search-clear {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--gray-light); border: none; color: var(--text-muted);
    display: none; align-items: center; justify-content: center;
    font-size: 12px; line-height: 1; cursor: pointer;
}
.drug-search-clear.visible { display: flex; }
.drug-search-clear svg { width: 11px; height: 11px; }

/* Dropdown */
.search-dropdown {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
    z-index: 60; max-height: 260px; overflow-y: auto; display: none;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 300;
    align-items: flex-end; justify-content: center;
    padding: 0;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%; max-width: 100%;
    max-height: 92vh; overflow-y: auto;
    box-shadow: var(--shadow-md);
    animation: slideUp .22s ease;
}
@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}
.modal-lg { max-width: 100%; }
@media (min-width: 600px) {
    .modal-overlay { align-items: center; padding: 16px; }
    .modal { border-radius: var(--radius); max-width: 500px; animation: none; }
    .modal-lg { max-width: 660px; }
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 18px 0;
}
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close {
    width: 30px; height: 30px; border: none; background: var(--gray-light);
    border-radius: 6px; display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
}
.modal-close svg { width: 14px; height: 14px; }
.modal-form  { padding: 14px 18px; }
.modal-footer {
    padding: 0 18px 18px;
    display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
}

/* ============================================================
   TABS
   ============================================================ */
.tab-bar {
    display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
}
.tab-btn {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 8px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text-muted); transition: all .15s; white-space: nowrap;
    touch-action: manipulation;
}
.tab-btn:hover  { border-color: var(--primary); color: var(--primary); }
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-count { font-size: 11px; background: rgba(0,0,0,.1); border-radius: 10px; padding: 1px 5px; }
.tab-btn.active .tab-count { background: rgba(255,255,255,.25); }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
    padding: 12px 14px; border-radius: var(--radius-sm);
    font-size: 14px; margin-bottom: 14px; font-weight: 500;
}
.alert-success { background: var(--green-light);  color: #065f46; }
.alert-error   { background: var(--red-light);    color: #991b1b; }
.alert-warning { background: var(--orange-light); color: #92400e; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    text-align: center; padding: 36px 20px; color: var(--text-muted);
}
.empty-state svg { width: 44px; height: 44px; margin: 0 auto 10px; display: block; opacity: .35; }
.empty-state p   { font-size: 14px; }

/* ============================================================
   UTILITY
   ============================================================ */
.text-muted  { color: var(--text-muted); }
.text-red    { color: var(--red); }
.text-orange { color: var(--orange); }
.text-green  { color: var(--green); }
.actions-cell { white-space: nowrap; }
.link-primary { color: var(--primary); font-weight: 600; }
.link-primary:hover { text-decoration: underline; }
.ml-auto  { margin-left: auto; }
.text-right { text-align: right; }
.nowrap   { white-space: nowrap; }
.report-controls { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.report-controls label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 4px; }
.report-summary { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.user-avatar-sm {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--primary-light); color: var(--primary);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-avatar-sm svg { width: 14px; height: 14px; }
.input-eye-wrap { position: relative; }
.input-eye-wrap input { padding-right: 42px; }
.eye-btn {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted); padding: 4px;
}
.eye-icon { width: 16px; height: 16px; }
.inline-form { display: flex; align-items: center; gap: 6px; }
.qty-input { width: 60px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

/* ============================================================
   BILLING PAGE
   ============================================================ */
.bill-wrap { display: flex; flex-direction: column; gap: 0; }
.bill-left, .bill-right { width: 100%; }
@media (min-width: 900px) {
    .bill-wrap { flex-direction: row; align-items: flex-start; gap: 20px; }
    .bill-left  { flex: 1 1 0; min-width: 0; }
    .bill-right { flex: 0 0 340px; width: 340px; }
}

/* Dropdown items */
.dd-item {
    padding: 12px 14px; cursor: pointer;
    border-bottom: 1px solid var(--border); transition: background .1s; outline: none;
}
.dd-item:last-child { border-bottom: none; }
.dd-item:hover, .dd-item:focus { background: var(--primary-light); }
.dd-brand   { font-size: 14px; font-weight: 700; display: block; }
.dd-generic { font-size: 11px; color: var(--text-muted); display: block; margin-top: 1px; }
.dd-meta    { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.dd-price   { margin-left: auto; font-weight: 700; color: var(--primary); font-size: 13px; }
.dd-empty   { padding: 16px; text-align: center; font-size: 13px; color: var(--text-muted); }

/* Qty Picker */
.qty-picker {
    margin-top: 12px; padding: 14px;
    background: var(--primary-light); border: 1px solid #c4b5fd;
    border-radius: var(--radius-sm); animation: slideDown .15s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.qty-picker-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 8px; margin-bottom: 12px;
}
.qp-name  { font-size: 14px; font-weight: 700; color: var(--primary); }
.qp-stock { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.preset-row   { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.preset-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; white-space: nowrap; }
.preset-btns  { display: flex; flex-wrap: wrap; gap: 6px; }
.preset-btn {
    padding: 6px 14px; border: 1.5px solid var(--primary); border-radius: 20px;
    background: #fff; color: var(--primary); font-size: 13px; font-weight: 700;
    cursor: pointer; transition: all .1s; min-width: 42px; touch-action: manipulation;
}
.preset-btn:hover, .preset-btn:active { background: var(--primary); color: #fff; }
.qp-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.qty-ctrl {
    display: inline-flex; align-items: center;
    border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff;
}
.qty-ctrl button {
    width: 36px; height: 38px; background: var(--gray-light); border: none;
    font-size: 18px; cursor: pointer; flex-shrink: 0; touch-action: manipulation;
    transition: background .1s;
}
.qty-ctrl button:hover { background: var(--primary-light); }
.qty-ctrl span, .qty-ctrl input {
    width: 50px; height: 38px; text-align: center; border: none; outline: none;
    font-size: 15px; font-weight: 700; padding: 0; background: #fff;
    -moz-appearance: textfield;
}
.qty-ctrl input::-webkit-outer-spin-button,
.qty-ctrl input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-ctrl-lg { /* alias */ }
.env-check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; font-weight: 600; }
.env-check input { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.check-price { color: var(--primary); }

/* Cart */
.cart-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 5px;
    background: var(--primary); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700;
}
.cart-tbl  { font-size: 12px; }
.c-name    { font-weight: 600; font-size: 13px; }
.c-gen     { font-size: 11px; color: var(--text-muted); }
.c-retail  { color: var(--primary); font-weight: 600; }
.c-actual  { color: var(--orange); font-weight: 600; }
.cart-foot td { background: var(--gray-light); padding: 8px 10px; font-size: 12px; }
.mini-check { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; cursor: pointer; }
.mini-check input { accent-color: var(--primary); cursor: pointer; }

/* Extra charges */
.xcharge-row {
    display: flex; align-items: center; gap: 10px; padding: 12px 0;
    border-bottom: 1px solid var(--border); cursor: pointer;
}
.xcharge-row:last-child { border-bottom: none; }
.xcheck { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.xcharge-name  { flex: 1; font-size: 14px; font-weight: 600; }
.xcharge-price { font-size: 13px; font-weight: 700; color: var(--primary); white-space: nowrap; }

/* Bill summary */
.sum-group-label {
    font-size: 10px; font-weight: 800; text-transform: uppercase;
    letter-spacing: .08em; color: var(--text-muted); margin: 8px 0 4px;
}
.sum-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.sum-row:last-of-type { border-bottom: none; }
.sum-divider { height: 1px; background: var(--border); margin: 8px 0; }
.sum-retail  { color: var(--primary); font-weight: 700; }
.sum-actual  { color: var(--orange);  font-weight: 700; }
.sum-grand   { font-size: 17px; font-weight: 800; border: none; padding-top: 10px; }
.sum-profit  { font-size: 12px; color: var(--green); font-weight: 700; border: none; }
.doc-manual  { background: var(--gray-light); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 4px; }
.form-label-sm { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; display: block; }
.prefix-input {
    display: flex; align-items: center; border: 1px solid var(--border);
    border-radius: 8px; overflow: hidden; background: #fff;
}
.prefix-input span { padding: 9px 10px; background: var(--gray-light); font-size: 12px; font-weight: 700; color: var(--text-muted); border-right: 1px solid var(--border); }
.prefix-input input { border: none; outline: none; padding: 9px 10px; font-size: 14px; width: 100%; background: transparent; -moz-appearance: textfield; }
.prefix-input input::-webkit-outer-spin-button,
.prefix-input input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* Invoice */
.inv-wrap { padding: 4px 0 8px; }
.inv-clinic { text-align: center; margin-bottom: 12px; }
.inv-clinic h2 { font-size: 16px; color: var(--primary); }
.inv-clinic p  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.inv-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; background: var(--gray-light); padding: 10px; border-radius: var(--radius-sm); margin: 10px 0; }
.inv-meta div { display: flex; flex-direction: column; font-size: 12px; }
.inv-lbl  { color: var(--text-muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.inv-totals { margin-top: 10px; }

/* Daily record layout */
.daily-layout { display: flex; flex-direction: column; gap: 16px; }
.sheet-meta { display: flex; gap: 16px; font-size: 13px; margin-bottom: 10px; color: var(--text-muted); flex-wrap: wrap; }
@media (min-width: 900px) {
    .daily-layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
    .sheet-meta { gap: 24px; }
}

/* Stock inline form */
.barcode-bar { display: flex; gap: 8px; }
.barcode-bar input { flex: 1; }

/* Summary rows on sales detail */
.summary-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.summary-total { font-size: 16px; font-weight: 700; border-bottom: none; padding-top: 10px; }
.invoice-meta p { font-size: 13px; margin-bottom: 4px; }
.invoice-totals { margin-top: 16px; max-width: 300px; margin-left: auto; }

/* ============================================================
   PRINT
   ============================================================ */
@media print {
    .sidebar, .topbar, .filter-bar, .btn, .alert, .sidebar-overlay { display: none !important; }
    .main-wrapper { margin-left: 0; }
    .page-content { padding: 0; }
    .panel { box-shadow: none; border: 1px solid #ddd; }
    body { background: #fff; }
}

/* ============================================================
   PURCHASE ORDER PAGE
   ============================================================ */

/* Page layout: sidebar + main */
.po-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.po-sidebar { width: 100%; }
.po-main    { width: 100%; }

@media (min-width: 860px) {
    .po-layout  { flex-direction: row; align-items: flex-start; gap: 20px; }
    .po-sidebar { flex: 0 0 260px; width: 260px; position: sticky; top: calc(var(--topbar-h) + 12px); }
    .po-main    { flex: 1 1 0; min-width: 0; }
}

/* Saved orders list */
.po-order-list { display: flex; flex-direction: column; gap: 2px; }
.po-order-item {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    transition: background .12s; cursor: pointer;
    border: 1px solid transparent;
}
.po-order-item:hover  { background: var(--gray-light); }
.po-order-item.active { background: var(--primary-light); border-color: #c4b5fd; }
.po-order-main  { flex: 1; min-width: 0; }
.po-order-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.po-order-meta  { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Alert summary cards on default view */
.po-alert-grid {
    display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px;
}
.po-alert-card {
    flex: 1; min-width: 90px;
    border-radius: var(--radius-sm); padding: 14px 12px; text-align: center;
    border: 1px solid var(--border);
}
.po-alert-red    { background: var(--red-light);    border-color: #fca5a5; }
.po-alert-orange { background: var(--orange-light); border-color: #fcd34d; }
.po-alert-num    { font-size: 28px; font-weight: 800; line-height: 1; }
.po-alert-red    .po-alert-num { color: var(--red); }
.po-alert-orange .po-alert-num { color: #92400e; }
.po-alert-label  { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .05em; }

/* ── Modal XL size ── */
.modal-xl {
    max-width: 100%;
}
@media (min-width: 600px) {
    .modal-xl { max-width: 880px; }
}

/* ── Builder two-column layout inside modal ── */
.po-builder {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 4px;
}
.po-picker,
.po-order-builder {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    background: var(--gray-light);
}
@media (min-width: 680px) {
    .po-builder         { flex-direction: row; gap: 14px; }
    .po-picker          { flex: 1 1 0; min-width: 0; }
    .po-order-builder   { flex: 0 0 320px; width: 320px; }
}

.po-section-label {
    font-size: 11px; font-weight: 800; text-transform: uppercase;
    letter-spacing: .07em; color: var(--text-muted);
    margin-bottom: 10px; display: flex; align-items: center;
}

/* Auto-generate strip */
.po-autogen {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--primary-light); border: 1px solid #c4b5fd;
    border-radius: var(--radius-sm); padding: 8px 12px;
    margin-bottom: 10px; gap: 8px; flex-wrap: wrap;
}
.po-autogen-text { font-size: 13px; font-weight: 600; color: var(--primary); }

/* Medicine list (left panel) */
.po-med-list-wrap {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); overflow: hidden;
}
.po-med-list-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; border-bottom: 1px solid var(--border);
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .06em; color: var(--text-muted);
    background: var(--gray-light);
}
.po-med-list {
    max-height: 320px; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.po-med-row {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-bottom: 1px solid var(--border);
    transition: background .1s;
}
.po-med-row:last-child  { border-bottom: none; }
.po-med-row:hover       { background: var(--primary-light); }
.po-med-row.in-order    { opacity: .55; }
.po-med-info    { flex: 1; min-width: 0; }
.po-med-name    { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.po-med-generic { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-left: 5px; }
.po-med-badges  { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }

/* Order items list (right panel) */
.po-items-list {
    max-height: 340px; overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex; flex-direction: column; gap: 6px;
}
.po-item-row {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 12px;
    display: flex; flex-direction: column; gap: 8px;
}
.po-item-info   { }
.po-item-name   { font-size: 13px; font-weight: 700; }
.po-item-meta   { display: flex; gap: 6px; align-items: center; margin-top: 3px; flex-wrap: wrap; }
.po-item-controls {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.po-item-reason { flex: 1; min-width: 100px; }
.po-reason-input {
    width: 100%; padding: 5px 8px; font-size: 12px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--surface); color: var(--text);
}
.po-reason-input:focus { outline: none; border-color: var(--primary); }
.po-item-qty {
    display: flex; flex-direction: column; align-items: center; gap: 2px; flex-shrink: 0;
}

/* ============================================================
   MEDICINE BATCH SECTION (in Add modal)
   ============================================================ */
.batch-section {
    background: var(--gray-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-top: 8px;
}
.batch-section-title {
    font-size: 12px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .07em; color: var(--text-muted);
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 10px;
}
.batch-toggle-label {
    display: inline-flex; align-items: center; gap: 8px;
    font-size: 14px; font-weight: 600; cursor: pointer;
}

/* ── Bottle counter in billing ── */
.bottle-ctrl {
    display: inline-flex; align-items: center;
    border: 1px solid var(--border); border-radius: 8px;
    overflow: hidden; background: #fff; margin: 0 6px;
}
.bottle-btn {
    width: 30px; height: 30px; border: none; background: var(--gray-light);
    font-size: 16px; font-weight: 700; cursor: pointer; color: var(--text);
    transition: background .1s; flex-shrink: 0; touch-action: manipulation;
}
.bottle-btn:hover { background: var(--primary-light); color: var(--primary); }
.bottle-ctrl span {
    min-width: 28px; text-align: center; font-size: 14px; font-weight: 700;
    padding: 0 4px;
}

/* ── Bill summary total cost row ── */
.sum-total-cost {
    font-size: 13px; font-weight: 700;
    color: var(--orange); border-bottom: 1px solid var(--border);
    padding: 8px 0;
}
