/* ============================================================
   Medical POS System v2.0 - Professional Pharmacy Stylesheet
   ============================================================ */

/* --- CSS Variables --- */
:root {
    --primary: #0d6efd;
    --primary-light: #3d8bfd;
    --primary-dark: #0a58ca;
    --primary-bg: #e7f1ff;
    --success: #198754;
    --success-light: #20c997;
    --success-bg: #d1e7dd;
    --warning: #ffc107;
    --warning-bg: #fff3cd;
    --danger: #dc3545;
    --danger-bg: #f8d7da;
    --info: #0dcaf0;
    --info-bg: #cff4fc;
    --secondary: #6c757d;
    --secondary-bg: #e9ecef;
    --light: #f8f9fa;
    --dark: #212529;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #212529;
    --text-muted: #6c757d;
    --border: #dee2e6;
    --sidebar-width: 250px;
    --topbar-height: 56px;
    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --transition: all 0.2s ease;
}

/* --- Reset --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; }
h1,h2,h3,h4,h5,h6 { font-weight: 600; line-height: 1.3; }

/* --- App Layout --- */
.app-wrapper { display: flex; min-height: 100vh; }

/* =================== SIDEBAR =================== */
.sidebar {
    width: var(--sidebar-width); background: linear-gradient(180deg, #0b1a3e 0%, #102a5a 60%, #0d6efd 100%);
    color: #fff; position: fixed; top: 0; left: 0; bottom: 0; z-index: 1000;
    overflow-y: auto; overflow-x: hidden; transition: transform 0.3s ease;
    scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px; }

.sidebar-header {
    padding: 18px 20px 14px; border-bottom: 1px solid rgba(255,255,255,0.08);
    background: rgba(0,0,0,0.15);
}
.sidebar-header .logo { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; letter-spacing: 0.3px; }
.sidebar-header .logo i { font-size: 22px; color: #20c997; }
.sidebar-header .logo span { white-space: nowrap; }
.sidebar-version { font-size: 10px; color: rgba(255,255,255,0.35); margin-top: 4px; letter-spacing: 0.5px; }

.sidebar-nav ul { list-style: none; padding: 8px 0 20px; }
.sidebar-nav li a {
    display: flex; align-items: center; gap: 11px; padding: 10px 20px;
    color: rgba(255,255,255,0.7); transition: var(--transition); font-size: 13px;
    border-left: 3px solid transparent; position: relative;
}
.sidebar-nav li a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav li.active a {
    background: rgba(255,255,255,0.12); color: #fff;
    border-left-color: #20c997; font-weight: 600;
}
.sidebar-nav li a i { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; opacity: 0.85; }
.sidebar-nav li.active a i { opacity: 1; }
.sidebar-nav li a span { flex: 1; white-space: nowrap; }

/* Nav section headers */
.sidebar-nav .nav-section { padding: 18px 20px 6px; }
.sidebar-nav .nav-section span {
    display: block; font-size: 10px; text-transform: uppercase;
    letter-spacing: 1.2px; color: rgba(255,255,255,0.3); font-weight: 700;
}
.sidebar-nav .nav-section-sub { padding: 12px 20px 4px; }
.sidebar-nav .nav-section-sub span {
    display: block; font-size: 9px; text-transform: uppercase;
    letter-spacing: 1px; color: rgba(255,255,255,0.22); font-weight: 600;
}

/* Nav badges */
.nav-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    font-size: 10px; font-weight: 700; line-height: 1;
}
.nav-badge-danger { background: var(--danger); color: #fff; }
.nav-badge-warning { background: var(--warning); color: #333; }

/* =================== MAIN CONTENT =================== */
/* min-width:0 is critical: without it a wide data table's min-content size
   inflates this flex item past the viewport and, with html/body overflow-x
   clipped, every page element gets cut off with no way to scroll. */
.main-content { flex: 1; min-width: 0; margin-left: var(--sidebar-width); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left 0.3s ease; }

/* Desktop collapsed sidebar state */
.sidebar.collapsed { transform: translateX(-100%); box-shadow: none; }
.main-content.sidebar-collapsed { margin-left: 0; }

/* =================== TOP BAR =================== */
.top-bar {
    height: var(--topbar-height); background: var(--card-bg); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 20px; position: sticky; top: 0; z-index: 500;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04); gap: 15px;
}
.sidebar-toggle { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text); padding: 6px 8px; border-radius: var(--radius-sm); }
.sidebar-toggle:hover { background: var(--light); }

.top-bar-center { flex: 1; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.top-alert {
    display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px;
    border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.top-alert-danger { background: var(--danger-bg); color: var(--danger); }
.top-alert-warning { background: var(--warning-bg); color: #856404; }
.top-alert i { font-size: 11px; }

.top-bar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.user-info { display: flex; align-items: center; gap: 8px; }
.user-role-badge {
    background: var(--primary); color: #fff; padding: 2px 10px;
    border-radius: 20px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
}
.user-name { font-weight: 500; font-size: 13px; color: var(--text); white-space: nowrap; }
.user-name i { color: var(--text-muted); margin-right: 2px; }
.btn-logout {
    color: var(--danger); font-size: 16px; padding: 5px 8px; border-radius: var(--radius-sm);
    transition: var(--transition);
}
.btn-logout:hover { background: var(--danger-bg); color: var(--danger); }

/* =================== PAGE CONTENT =================== */
.page-content { flex: 1; padding: 20px; }
.page-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}
.page-header h1 { font-size: 22px; color: var(--dark); display: flex; align-items: center; gap: 10px; font-weight: 700; }
.page-header h1 i { color: var(--primary); font-size: 20px; }

/* =================== CARDS =================== */
.card {
    background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
    margin-bottom: 20px; overflow: hidden; border: 1px solid rgba(0,0,0,0.04);
}
.card-header {
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--light);
}
.card-header h3 { font-size: 14px; color: var(--dark); display: flex; align-items: center; gap: 8px; font-weight: 600; }
.card-header h3 i { color: var(--primary); }
.card-body { padding: 20px; }
.card-danger .card-header { background: #fef2f2; border-bottom-color: #fecaca; }

/* =================== BUTTONS =================== */
.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
    border: none; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
    cursor: pointer; transition: var(--transition); text-decoration: none;
    line-height: 1.4; white-space: nowrap;
}
.btn:hover { opacity: 0.92; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #157347; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #bb2d3b; color: #fff; }
.btn-warning { background: var(--warning); color: #333; }
.btn-info { background: var(--info); color: #333; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--light); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { display: flex; width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none !important; }

/* Date-range preset chips */
.range-presets { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.range-presets-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; margin-right: 2px; }
.range-chip {
    display: inline-block; padding: 4px 12px; border: 1px solid var(--border); border-radius: 20px;
    background: var(--card-bg); color: var(--text); font-size: 12px; font-weight: 500; line-height: 1.5;
    text-decoration: none; white-space: nowrap; transition: var(--transition);
}
.range-chip:hover { background: var(--light); border-color: var(--primary); color: var(--primary); }
.range-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Dashboard period toolbar */
.period-bar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: linear-gradient(135deg, rgba(13,110,253,0.06), rgba(13,110,253,0.02));
    border: 1px solid rgba(13,110,253,0.15); border-radius: var(--radius-lg); padding: 12px 16px;
}
.period-bar .range-presets-label { display: inline-flex; align-items: center; gap: 6px; }
.period-bar .range-presets-label i { color: var(--primary); }
.period-current {
    display: inline-flex; align-items: center; gap: 6px; margin-left: 4px; padding: 4px 12px;
    background: rgba(13,110,253,0.10); border-radius: 20px; font-size: 12px; font-weight: 600; color: var(--primary);
}
.period-custom { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-left: auto; padding-left: 12px; border-left: 1px dashed var(--border); }
.period-custom-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); }
.period-date {
    padding: 5px 10px; font-size: 12px; color: var(--text); background: var(--card-bg);
    border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none; transition: var(--transition);
}
.period-date:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,110,253,0.12); }
.period-apply {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border: none; border-radius: var(--radius-sm);
    background: var(--primary); color: #fff; font-size: 12px; font-weight: 600; cursor: pointer;
    transition: var(--transition); white-space: nowrap;
}
.period-apply:hover { filter: brightness(1.1); }
@media (max-width: 900px) {
    .period-custom { margin-left: 0; padding-left: 0; border-left: none; width: 100%; padding-top: 10px; border-top: 1px dashed var(--border); }
}

/* =================== FORMS =================== */
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; font-size: 13px; color: var(--text); }
.form-control {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 13px; transition: var(--transition); background: #fff; color: var(--text);
    font-family: var(--font);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,110,253,0.12); }
.form-control::placeholder { color: #adb5bd; }
.form-control-sm { padding: 6px 10px; font-size: 12px; }
.form-control-xs { padding: 4px 8px; font-size: 11px; min-height: 26px; }
.form-control-lg { padding: 12px 16px; font-size: 16px; }
.form-row { display: flex; gap: 15px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 150px; }
.form-row .col-md-3 { flex: 0 0 25%; min-width: 140px; }
.form-row .col-md-4 { flex: 0 0 33.33%; min-width: 150px; }
.form-row .col-md-6 { flex: 0 0 50%; min-width: 200px; }
.form-row .col-md-8 { flex: 0 0 66.66%; min-width: 200px; }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 60px; }
.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

/* Filter Form */
.filter-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.filter-form .form-group { margin-bottom: 0; flex: 1; min-width: 120px; }

/* =================== TABLES =================== */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.page-content { max-width: 100%; }
.card, .card-body { max-width: 100%; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    background: var(--primary); color: #fff; padding: 10px 12px;
    font-size: 11px; font-weight: 600; text-align: left;
    text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.table tbody tr:hover { background: #f8f9fa; }
.table tbody tr:last-child td { border-bottom: none; }
.table-sm th, .table-sm td { padding: 7px 10px; font-size: 12px; }
.table .text-right { text-align: right; }
.row-cancelled { opacity: 0.5; text-decoration: line-through; }
.actions-cell { white-space: nowrap; display: flex; gap: 4px; }

/* =================== BADGES =================== */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-success { background: var(--success-bg); color: #0f5132; }
.badge-danger { background: var(--danger-bg); color: #842029; }
.badge-warning { background: var(--warning-bg); color: #664d03; }
.badge-info { background: var(--info-bg); color: #055160; }
.badge-primary { background: var(--primary-bg); color: #084298; }
.badge-secondary { background: var(--secondary-bg); color: #41464b; }

/* =================== STATS GRID =================== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 15px; margin-bottom: 20px; }
.stat-card {
    background: var(--card-bg); border-radius: var(--radius); padding: 18px 20px;
    box-shadow: var(--shadow); display: flex; align-items: center; gap: 15px;
    position: relative; overflow: hidden; border: 1px solid rgba(0,0,0,0.04);
}
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; border-radius: 0 4px 4px 0; }
.stat-card.stat-primary::before { background: var(--primary); }
.stat-card.stat-success::before { background: var(--success); }
.stat-card.stat-warning::before { background: var(--warning); }
.stat-card.stat-danger::before { background: var(--danger); }
.stat-card.stat-info::before { background: var(--info); }
.stat-card.stat-secondary::before { background: var(--secondary); }
.stat-icon {
    width: 48px; height: 48px; border-radius: var(--radius-lg); display: flex;
    align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0;
}
.stat-primary .stat-icon { background: var(--primary-bg); color: var(--primary); }
.stat-success .stat-icon { background: var(--success-bg); color: var(--success); }
.stat-warning .stat-icon { background: var(--warning-bg); color: #997404; }
.stat-danger .stat-icon { background: var(--danger-bg); color: var(--danger); }
.stat-info .stat-icon { background: var(--info-bg); color: #087990; }
.stat-secondary .stat-icon { background: var(--secondary-bg); color: var(--secondary); }
.stat-info h3, .stat-card h3 { font-size: 20px; font-weight: 700; color: var(--text); margin: 0; }
.stat-info p { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }
.stat-footer { position: absolute; bottom: 8px; right: 15px; font-size: 10px; color: var(--text-muted); }

/* Quick Actions */
.quick-actions { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.quick-action-btn {
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    padding: 16px 28px; background: var(--card-bg); border-radius: var(--radius);
    box-shadow: var(--shadow); transition: var(--transition); color: var(--text);
    font-size: 12px; font-weight: 500; border: 1px solid rgba(0,0,0,0.04);
}
.quick-action-btn:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); color: var(--primary); }
.quick-action-btn i { font-size: 22px; color: var(--primary); }

/* Dashboard Grid */
.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.dashboard-right { display: flex; flex-direction: column; gap: 20px; }

/* =================== FLASH MESSAGES =================== */
.flash-message {
    padding: 12px 20px; margin: 0 0 15px; border-radius: var(--radius-sm);
    display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 500;
}
.flash-success { background: var(--success-bg); color: #0f5132; border: 1px solid #badbcc; }
.flash-error { background: var(--danger-bg); color: #842029; border: 1px solid #f5c2c7; }
.flash-info { background: var(--info-bg); color: #055160; border: 1px solid #b6effb; }
.flash-close { background: none; border: none; font-size: 20px; cursor: pointer; margin-left: auto; color: inherit; opacity: 0.6; line-height: 1; }
.flash-close:hover { opacity: 1; }

/* =================== MODAL =================== */
.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 2000; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(2px); }
.modal-content {
    position: relative; background: var(--card-bg); border-radius: var(--radius-lg);
    width: 90%; max-width: 550px; max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg); animation: modalSlide 0.25s ease;
}
.modal-content.modal-lg { max-width: 800px; }
.modal-header {
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); padding: 0 4px; }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 20px; }
.modal-footer { padding: 15px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
@keyframes modalSlide { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* =================== PAGINATION =================== */
.pagination { margin-top: 15px; }
.pagination ul { display: flex; list-style: none; gap: 5px; justify-content: center; flex-wrap: wrap; }
.pagination li a { padding: 6px 12px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; color: var(--text); }
.pagination li.active a { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination li a:hover { background: var(--light); }

/* =================== LOGIN PAGE =================== */
.login-body { background: linear-gradient(135deg, #0b1a3e 0%, #102a5a 50%, #0d6efd 100%); display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-container { text-align: center; }
.login-card { background: var(--card-bg); border-radius: 16px; padding: 40px; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); }
.login-header { margin-bottom: 30px; }
.login-logo { width: 70px; height: 70px; background: var(--primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 15px; }
.login-logo i { font-size: 30px; color: #fff; }
.login-header h1 { font-size: 22px; color: var(--dark); }
.login-header p { color: var(--text-muted); font-size: 13px; }
.login-form .form-group { margin-bottom: 20px; text-align: left; }
.login-form .form-control { padding: 12px 15px; font-size: 14px; }
.login-footer { margin-top: 20px; color: rgba(255,255,255,0.7); font-size: 12px; }

/* Install Page */
.install-body { background: linear-gradient(135deg, #0b1a3e, #0d6efd); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.install-container { width: 100%; max-width: 500px; }
.install-card { background: var(--card-bg); border-radius: 16px; padding: 40px; box-shadow: var(--shadow-lg); }
.install-header { text-align: center; margin-bottom: 30px; }
.install-header i { font-size: 50px; color: var(--primary); }
.install-header h1 { font-size: 22px; color: var(--dark); }
.install-form h3 { margin: 20px 0 10px; color: var(--primary); font-size: 14px; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.install-success { text-align: center; padding: 20px; }

/* =================== POS SCREEN =================== */
.pos-container {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 440px); gap: 16px;
    height: calc(100vh - var(--topbar-height) - 42px);
}
.pos-products { display: flex; flex-direction: column; overflow: hidden; position: relative; }
.pos-cart {
    background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
    display: flex; flex-direction: column; overflow: hidden; border: 1px solid rgba(0,0,0,0.04);
    flex: 1; min-height: 0;
}
/* Right column: summary + payment */
.pos-side {
    background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow);
    border: 1px solid rgba(0,0,0,0.04);
    display: flex; flex-direction: column; overflow-y: auto;
}
.pos-side .cart-summary { border-top: none; }
.pos-side .cart-actions { margin-top: auto; }

/* POS Search Bar */
.pos-search-bar { display: flex; gap: 10px; margin-bottom: 12px; position: relative; }
.search-input-wrapper {
    flex: 1; position: relative; display: flex; align-items: center;
}
.search-input-wrapper i.fa-search {
    position: absolute; left: 14px; color: var(--text-muted); font-size: 14px; z-index: 2; pointer-events: none;
}
.pos-search-input {
    width: 100%; padding: 12px 44px 12px 40px; border: 2px solid var(--border);
    border-radius: var(--radius); font-size: 14px; transition: var(--transition);
    background: #fff; font-family: var(--font);
}
.pos-search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13,110,253,0.1); }
.pos-search-input::placeholder { color: #adb5bd; }
.search-input-wrapper .barcode-scan-btn {
    position: absolute; right: 6px; z-index: 2; padding: 6px 10px;
    border-radius: var(--radius-sm); background: var(--light); border: 1px solid var(--border);
}

/* Search Results Dropdown */
.search-results-wrapper { position: relative; z-index: 100; }
.search-results {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); max-height: 340px; overflow-y: auto;
    position: absolute; z-index: 100; width: 100%; top: 0;
    margin-top: 2px;
}
.search-result-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 14px; cursor: pointer; border-bottom: 1px solid #f0f0f0;
    transition: background 0.12s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f0f7ff; }
.search-result-item.sr-expired { opacity: 0.5; background: #fef2f2; }
.search-result-item.sr-low { background: #fffbeb; }
.search-result-item .sr-info { flex: 1; min-width: 0; }
.search-result-item .sr-info strong { display: block; font-size: 13px; font-weight: 600; color: var(--dark); }
.search-result-item .sr-info small { color: var(--text-muted); font-size: 11px; display: block; margin-top: 1px; }
.search-result-item .sr-price-box { text-align: right; flex-shrink: 0; margin-left: 12px; }
.search-result-item .sr-price { font-weight: 700; color: var(--success); font-size: 14px; }
.search-result-item .sr-price small { font-weight: 400; color: var(--text-muted); font-size: 10px; }
.search-result-item .sr-alt-price { display: block; font-size: 10px; color: var(--text-muted); }
.search-result-item .sr-mrp { font-size: 10px; color: var(--text-muted); text-decoration: line-through; }
.search-no-result { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.search-no-result i { margin-right: 6px; }

/* POS Placeholder */
.pos-placeholder {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; color: var(--text-muted); gap: 10px; padding: 40px;
}
.pos-placeholder i { font-size: 40px; color: var(--border); }
.pos-placeholder p { font-size: 14px; margin: 0; }

/* POS Product Grid */
.pos-product-grid { flex: 1; overflow-y: auto; padding: 4px; }

/* =================== CART =================== */
.cart-header {
    padding: 14px 16px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--light);
}
.cart-header h3 { font-size: 14px; display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 0; }
.cart-header h3 i { color: var(--primary); }
.cart-header-actions { display: flex; align-items: center; gap: 8px; }
.cart-item-count { font-size: 11px; color: var(--text-muted); font-weight: 500; background: var(--secondary-bg); padding: 2px 8px; border-radius: 10px; }

/* Cart Customer */
.cart-customer { padding: 10px 16px; border-bottom: 1px solid var(--border); }

/* Cart Items */
.cart-items { flex: 1; overflow-y: auto; padding: 8px; }
.cart-empty { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.cart-empty i { margin-bottom: 10px; color: var(--border); font-size: 32px; }
.cart-empty p { font-size: 13px; }

/* Cart Item Card */
.cart-item {
    padding: 10px 12px; margin-bottom: 6px; background: #f8f9fa;
    border-radius: var(--radius-sm); border: 1px solid #eee;
}
.cart-item-top {
    display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 6px;
}
.cart-item-name strong { font-size: 13px; font-weight: 600; display: block; line-height: 1.3; }
.cart-item-rack { font-size: 10px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 3px; margin-top: 1px; }
.cart-item-rack i { font-size: 9px; }
.cart-item-bottom {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.cart-item-rate { font-size: 12px; color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.cart-item-total { font-weight: 700; color: var(--success); font-size: 13px; margin-left: 8px; white-space: nowrap; }
.cart-unit-select { width: 92px; height: 34px; padding: 4px 6px; font-size: 12px; }
.cart-item-equiv { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* Cart expand: centered full-screen view of the same cart panel */
.cart-expand-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(2px); z-index: 2050;
}
body.cart-expanded .pos-container {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: min(1100px, 96vw); height: min(88vh, 860px);
    z-index: 2100; border-radius: var(--radius-lg);
    background: transparent;
}
body.cart-expanded .pos-cart,
body.cart-expanded .pos-side {
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
}
body.cart-expanded .cart-header { padding: 14px 18px; }
body.cart-expanded .cart-header h3 { font-size: 16px; }
body.cart-expanded .cart-items { padding: 14px; }
body.cart-expanded .cart-item { padding: 12px 16px; margin-bottom: 8px; }
body.cart-expanded .cart-item-name strong { font-size: 15px; }
body.cart-expanded .cart-item-rate { font-size: 13px; }
body.cart-expanded .cart-item-total { font-size: 15px; }
body.cart-expanded .cart-item-equiv { font-size: 12px; }

/* Qty Controls */
.qty-controls { display: flex; align-items: center; gap: 0; }
.qty-controls button {
    width: 34px; height: 34px; border: 1px solid var(--border); background: #fff;
    cursor: pointer; font-size: 16px; font-weight: 700; color: var(--text);
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition); user-select: none;
}
.qty-controls button:first-child { border-radius: 4px 0 0 4px; }
.qty-controls button:last-child { border-radius: 0 4px 4px 0; }
.qty-controls button:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.qty-controls button:active { transform: scale(0.95); }
.qty-controls input {
    width: 48px; text-align: center; border: 1px solid var(--border); border-left: none; border-right: none;
    padding: 6px 2px; font-size: 14px; font-weight: 600; height: 34px; font-family: var(--font);
}
.qty-controls input:focus { outline: none; }
.btn-remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; padding: 2px 4px; opacity: 0.7; }
.btn-remove:hover { opacity: 1; }

/* =================== CART SUMMARY =================== */
.cart-summary { padding: 12px 16px; border-top: 2px solid var(--border); background: #fafbfc; }
.summary-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; font-size: 13px; }
.discount-row { padding: 6px 0; }
.discount-inputs { display: flex; align-items: center; gap: 5px; font-size: 13px; }
.discount-inputs span { white-space: nowrap; }
.total-row {
    font-size: 18px; font-weight: 700; color: var(--dark);
    padding: 10px 0 4px; border-top: 2px solid var(--border); margin-top: 6px;
}
.cart-total-amount { color: var(--success); }

/* =================== CART PAYMENT =================== */
.cart-payment { padding: 12px 16px; border-top: 1px solid var(--border); }
.payment-method label { font-size: 12px; font-weight: 600; margin-bottom: 6px; display: block; color: var(--text); }
.payment-buttons { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.payment-btn {
    padding: 7px 12px; border: 1px solid var(--border); background: #fff;
    border-radius: var(--radius-sm); cursor: pointer; font-size: 11px; font-weight: 500;
    display: flex; align-items: center; gap: 5px; transition: var(--transition);
    font-family: var(--font);
}
.payment-btn:hover { border-color: var(--primary); color: var(--primary); }
.payment-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.payment-row { display: flex; gap: 12px; align-items: flex-end; }
.payment-amount { flex: 1; }
.payment-amount label { font-size: 12px; font-weight: 600; margin-bottom: 4px; display: block; }
.payment-change { flex: 1; }
.payment-change label { font-size: 12px; font-weight: 600; margin-bottom: 4px; display: block; }
.change-amount {
    font-size: 18px; font-weight: 700; color: var(--success);
    padding: 8px 12px; background: var(--success-bg); border-radius: var(--radius-sm);
    text-align: center;
}
.payment-due {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; background: var(--danger-bg); border-radius: var(--radius-sm); margin-top: 8px;
}
.payment-due span:first-child { font-size: 12px; font-weight: 600; color: var(--danger); }

/* Cart Actions */
.cart-actions { padding: 12px 16px; }
.cart-actions .btn-lg { font-size: 15px; font-weight: 700; padding: 14px 24px; }

/* =================== INVOICE =================== */
.invoice-container { max-width: 800px; margin: 0 auto; }
.invoice-card { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px; }
.invoice-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 25px; padding-bottom: 20px; border-bottom: 3px solid var(--primary); }
.invoice-logo h1 { font-size: 24px; color: var(--dark); }
.invoice-logo p { color: var(--text-muted); font-size: 13px; margin: 2px 0; }
.invoice-meta h2 { font-size: 28px; color: var(--primary); font-weight: 800; text-align: right; }
.invoice-meta-table { font-size: 13px; }
.invoice-meta-table td { padding: 2px 8px; }
.invoice-table { width: 100%; border-collapse: collapse; margin: 20px 0; }
.invoice-table th { background: var(--primary); color: #fff; padding: 10px 12px; font-size: 12px; }
.invoice-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.invoice-total-row td { font-size: 16px; border-top: 2px solid var(--primary); }
.invoice-footer-info { padding: 15px 0; border-top: 1px solid var(--border); font-size: 13px; }
.invoice-footer { text-align: center; padding-top: 20px; color: var(--text-muted); font-size: 13px; }

/* =================== UTILITY CLASSES =================== */
.fw-bold { font-weight: 700 !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-primary { color: var(--primary) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.mb-3 { margin-bottom: 15px; }
.mt-3 { margin-top: 15px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.d-flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* =================== CUSTOMER CREDIT INFO (POS) =================== */
.customer-credit-info { background: var(--light); border-radius: var(--radius-sm); padding: 8px 12px; margin-top: 6px; font-size: 12px; }
.credit-info-row { display: flex; justify-content: space-between; align-items: center; padding: 2px 0; }
.credit-info-row span { color: var(--text-muted); }
.credit-info-row strong { font-size: 13px; }
.credit-warning { background: rgba(255,193,7,0.15); border: 1px solid rgba(255,193,7,0.4); border-radius: 4px; padding: 4px 8px; margin-top: 4px; display: flex; align-items: center; gap: 6px; color: #856404; font-weight: 600; }
.credit-warning i { color: #ffc107; }

/* =================== RESPONSIVE =================== */
@media (max-width: 1200px) {
    .pos-container { grid-template-columns: minmax(0, 1fr) minmax(320px, 380px); }
}

@media (max-width: 1024px) {
    .pos-container { grid-template-columns: 1fr; height: auto; }
    .pos-products { min-height: 400px; }
    .pos-cart { max-height: 600px; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

/* Short laptop screens (e.g. 1366x768): tighten the POS chrome so the
   full-height grid still fits without double scrollbars. */
@media (max-height: 820px) and (min-width: 1025px) {
    .page-content { padding: 14px 20px; }
    .pos-container { height: calc(100vh - var(--topbar-height) - 30px); }
    .cart-actions .btn-lg { padding: 10px 20px; }
}

@media (max-width: 768px) {
    :root { --sidebar-width: 260px; }
    .sidebar { transform: translateX(-100%); box-shadow: none; max-width: 80vw; }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.3); }
    .main-content { margin-left: 0; }
    .page-content { padding: 15px; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header h1 { font-size: 18px; }
    .form-row { flex-direction: column; gap: 0; }
    .form-row .form-group, .form-row .col-md-3, .form-row .col-md-4, .form-row .col-md-6, .form-row .col-md-8 {
        flex: 1 1 100%; min-width: auto;
    }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .invoice-header { flex-direction: column; gap: 15px; }
    .invoice-meta h2 { text-align: left; }
    .modal-content { width: 95%; max-width: none; border-radius: var(--radius); }
    .filter-form { flex-direction: column; align-items: stretch; }
    .filter-form .form-group { width: 100%; }
    .top-bar { padding: 0 12px; }
    .top-bar-center { display: none; }
    .pos-search-bar { flex-direction: column; }
    .pos-search-bar select { max-width: 100% !important; }
}

@media (max-width: 480px) {
    .page-content { padding: 10px; }
    .stats-grid { grid-template-columns: 1fr; }
    .quick-actions { flex-direction: column; }
    .quick-action-btn { flex-direction: row; padding: 12px 15px; justify-content: flex-start; }
    .card-body { padding: 14px; }
    .payment-buttons { gap: 4px; }
    .payment-btn { padding: 6px 8px; font-size: 10px; }
    .login-card { padding: 20px; }
    .modal-content { padding: 0; }
    .modal-body { padding: 15px; }
    /* Top bar: keep sync pill + logout reachable; hide the user name text */
    .top-bar { gap: 8px; padding: 0 10px; }
    .user-name { display: none; }
    .user-role-badge { font-size: 9px; padding: 2px 8px; }
    .top-bar-right { gap: 6px; }
}

/* =================== PRINT STYLES =================== */
@media print {
    .sidebar, .top-bar, .page-header, .app-footer, .btn, .filter-form, .pagination,
    .actions-cell, .flash-message, .pos-search-bar, .search-results-wrapper,
    .cart-payment, .cart-actions { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd; }
    .invoice-card { box-shadow: none !important; padding: 0; }
    body { background: #fff; font-size: 12px; }
    .table th { background: #333 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .pos-container { display: block; height: auto; }
}

/* =================== PERMISSION MATRIX =================== */
.perm-section-title {
    display: flex; align-items: center; gap: 8px;
    font-size: 14px; font-weight: 600; margin: 18px 0 10px;
    padding-top: 14px; border-top: 1px dashed var(--border);
}
.perm-toolbar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 10px 12px; margin-bottom: 12px;
    background: linear-gradient(135deg, rgba(13,110,253,0.06), rgba(13,110,253,0.02));
    border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.perm-matrix {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 10px; max-height: 420px; overflow-y: auto; padding: 2px;
}
.perm-module {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--card-bg); overflow: hidden;
    transition: box-shadow var(--transition), border-color var(--transition);
}
.perm-module:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(13,110,253,0.12); }
.perm-module-head {
    padding: 8px 10px; background: var(--light, #f8f9fa);
    border-bottom: 1px solid var(--border);
}
.perm-module-toggle {
    display: flex; align-items: center; gap: 7px; cursor: pointer;
    font-size: 13px; margin: 0; flex-wrap: wrap;
}
.perm-module-toggle input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }
.perm-module-toggle i { color: var(--primary); width: 16px; text-align: center; }
.perm-actions {
    display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px;
}
.perm-action {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px; padding: 4px 8px; margin: 0;
    border: 1px solid var(--border); border-radius: 20px;
    cursor: pointer; user-select: none; background: var(--card-bg);
    transition: all var(--transition);
}
.perm-action:hover { border-color: var(--primary); }
.perm-action input { width: 13px; height: 13px; accent-color: var(--primary); cursor: pointer; margin: 0; }
.perm-action:has(input:checked) {
    background: rgba(25,135,84,0.1); border-color: var(--success); color: var(--success); font-weight: 600;
}
.perm-manage { color: var(--warning); font-weight: 700; }
.perm-action:has(input:checked) .perm-manage { color: var(--warning); }

/* Permission summary (user profile modal) */
.perm-summary { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.perm-summary li {
    padding: 7px 12px; font-size: 13px;
    background: rgba(13,110,253,0.06); border-left: 3px solid var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.profile-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; margin-bottom: 6px;
}
.profile-grid > div { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }

/* =================== ROLE TILES =================== */
.role-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px;
}
.role-tile {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 14px; background: var(--card-bg);
    display: flex; flex-direction: column; gap: 8px;
    transition: box-shadow var(--transition), border-color var(--transition);
}
.role-tile:hover { border-color: var(--primary); box-shadow: 0 3px 10px rgba(13,110,253,0.12); }
.role-tile-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.role-tile-desc { font-size: 12px; color: var(--text-muted); margin: 0; flex: 1; line-height: 1.45; }

/* ============================================================
   P&L / Business Report Styles
   ============================================================ */
.section-title {
    font-size: 18px; font-weight: 700; color: var(--dark);
    border-bottom: 2px solid var(--primary); padding-bottom: 8px; margin-bottom: 16px;
    display: flex; align-items: center; gap: 8px;
}
.section-title i { color: var(--primary); }
.kpi-mini {
    background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 10px 14px; display: flex; flex-direction: column; gap: 2px;
}
.kpi-mini .kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-mini strong { font-size: 15px; }
.pnl-table .pnl-section td { background: #f0f4f8; font-weight: 600; padding-top: 10px; border-top: 2px solid var(--border); }
.pnl-table .pnl-subtotal td { background: #f8f9fa; font-weight: 700; border-top: 1px solid #dee2e6; }
.pnl-table .pnl-total td { background: #e8f4fd; font-weight: 700; border-top: 2px solid var(--primary); }
.pnl-table .pnl-grand td { border-top: 3px double #333; padding: 10px 8px; }

@media print {
    .section-title { page-break-before: auto; }
    .stats-grid, .dashboard-grid { page-break-inside: avoid; }
    .card { page-break-inside: avoid; margin-bottom: 10px; }
    canvas { display: none; }
    body { font-size: 11px; }
}

@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }
    .kpi-mini { padding: 8px 10px; }
    .kpi-mini strong { font-size: 13px; }
    .section-title { font-size: 16px; }
    .pnl-table td { padding: 6px 4px; font-size: 12px; }
}

/* ============================================================
   Receipt Template Designer
   ============================================================ */
.rds-grid {
    display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
    gap: 16px; align-items: start;
}
.rds-controls .card-header h3 { font-size: 14px; }
.rds-chk-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 10px;
}
.check-inline {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 400; margin: 0 12px 4px 0; cursor: pointer;
}
.check-inline input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }
.form-range {
    width: 100%; height: 6px; accent-color: var(--primary); cursor: pointer;
}
.rds-list {
    list-style: none; margin: 0; padding: 0;
    display: flex; flex-direction: column; gap: 5px;
}
.rds-list li {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 6px 10px; background: var(--card-bg);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.rds-list li .check-inline { margin: 0; }
.rds-arrows { display: inline-flex; gap: 3px; }
.mv {
    border: 1px solid var(--border); background: var(--card-bg); color: var(--text-muted);
    border-radius: 4px; width: 24px; height: 24px; font-size: 11px;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.mv:hover { border-color: var(--primary); color: var(--primary); }
.ft-add { padding: 4px 10px !important; font-size: 12px !important; }
.rds-preview-body {
    background: #e9ecef; border-radius: var(--radius-sm);
    display: flex; justify-content: center; padding: 12px;
    max-height: 75vh; overflow: auto;
}
.rds-preview-body iframe {
    width: 100%; max-width: 420px; min-height: 560px; height: 68vh;
    border: 1px solid var(--border); border-radius: 4px; background: #fff;
}

@media (max-width: 1100px) {
    /* Tablet / narrow screens: controls full width, preview below */
    .rds-grid { grid-template-columns: 1fr; }
    .rds-preview .card { position: static !important; }
    .rds-preview-body iframe { height: 480px; }
}

/* ─────────── POS keyboard workflow ─────────── */
/* Highlighted search result (Arrow Up/Down navigation) */
.search-result-item.active {
    background: #e8f4fd;
    outline: 2px solid var(--primary, #2f80ed);
    outline-offset: -2px;
}
/* Selected cart row */
.cart-item:focus {
    outline: 2px solid var(--primary, #2f80ed);
    outline-offset: -2px;
    background: #f5f9ff;
}
.cart-item { transition: background .15s ease; }
.cart-item-flash { animation: cartFlash 1.2s ease; }
@keyframes cartFlash {
    0% { background: #d3ecd9; }
    100% { background: transparent; }
}
/* Editable rate + line discount */
.cart-item-rate.editable { cursor: pointer; text-decoration: underline dotted; }
.cart-item-rate.editable:hover { color: var(--primary, #2f80ed); }
.cart-item-disc { font-size: 11px; color: #c0392b; white-space: nowrap; }
.cart-item-disc-muted { color: #adb5bd; font-size: 10px; cursor: pointer; }
.cart-item-disc a { color: inherit; }
.inline-edit-input {
    display: inline-block; width: 80px !important; padding: 2px 6px !important;
    font-size: 12px !important; height: auto !important;
}
/* Shortcut hint badges */
kbd, .kb-hint {
    display: inline-block; padding: 2px 7px; font-size: 11px;
    font-family: Consolas, "Courier New", monospace;
    background: #f1f3f5; color: #333; border: 1px solid #ced4da;
    border-bottom-width: 2px; border-radius: 4px; line-height: 1.3;
}
.btn-success .kb-hint { background: rgba(255,255,255,.25); color: #fff; border-color: rgba(255,255,255,.5); margin-left: 6px; }
/* Sale-completed banner (keyboard workflow) */
.pos-success-banner {
    display: flex; align-items: center; gap: 10px;
    margin: 10px 16px 0; padding: 10px 14px;
    background: #d4edda; color: #155724; border: 1px solid #c3e6cb;
    border-radius: var(--radius-sm, 6px); font-weight: 600;
}
.pos-success-banner i { color: #28a745; }
.pos-success-banner a { color: #0b5ed7; margin-left: auto; font-weight: 600; }
.pos-success-banner button {
    background: none; border: none; font-size: 18px; line-height: 1;
    color: #155724; cursor: pointer; padding: 0 4px;
}
/* Shortcuts help modal */
.kb-help-table td { vertical-align: middle; padding: 6px 8px; }
.kb-help-table td:first-child { width: 130px; white-space: nowrap; }
@media (max-width: 576px) {
    .pos-success-banner { flex-wrap: wrap; }
    .kb-help-table td:first-child { width: 96px; }
}

/* ─────────── AI Invoice Scanner ─────────── */
.scanner-page-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.scanner-page-header h1 { margin: 0; }

/* Notices */
.scanner-notice {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px; border-radius: var(--radius-sm, 6px);
    margin-bottom: 16px; font-size: 14px; line-height: 1.45;
}
.scanner-notice > i { margin-top: 2px; }
.scanner-notice-info    { background: #e7f1ff; color: #1a4f8b; border: 1px solid #bcd7f7; }
.scanner-notice-warn    { background: #fff6e0; color: #7a5b00; border: 1px solid #f0ddab; }
.scanner-notice-error   { background: #fdecea; color: #a02418; border: 1px solid #f5c2bc; }
.scanner-notice-success { background: #e2f5e7; color: #1c6b34; border: 1px solid #bfe4c9; }

/* Layout grid */
.scanner-grid { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 16px; }
.scanner-review-grid { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 16px; align-items: start; }

/* Dropzone */
.scanner-dropzone {
    border: 2px dashed #b9c6d8; border-radius: var(--radius, 8px);
    background: #f8fafc; text-align: center; padding: 34px 16px;
    cursor: pointer; transition: border-color .15s, background .15s;
}
.scanner-dropzone:hover, .scanner-dropzone.drag-over { border-color: var(--primary, #2f80ed); background: #eef5ff; }
.scanner-dropzone i { color: #8aa4c4; margin-bottom: 10px; }
.scanner-dropzone p { margin: 0 0 6px; }
.scanner-upload-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* Upload progress */
.scanner-progress { margin-top: 16px; }
.scanner-progress-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.progress-track { background: #e4e9f0; border-radius: 99px; height: 10px; overflow: hidden; }
.progress-fill { background: var(--primary, #2f80ed); height: 100%; border-radius: 99px; transition: width .2s ease; }

/* Preview panels */
.scanner-preview-body { padding: 0 !important; min-height: 220px; display: flex; align-items: stretch; justify-content: center; background: #eef1f5; }
.scanner-preview-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 40px 20px; color: #90a0b4; text-align: center; }
.scanner-preview-img { max-width: 100%; max-height: 70vh; object-fit: contain; }
.scanner-preview-frame { width: 100%; height: 70vh; min-height: 420px; border: 0; background: #fff; }
.scanner-review-preview .card-body { max-height: 80vh; }

/* Scan status badges */
.scan-status { font-size: 11px; padding: 3px 9px; border-radius: 99px; font-weight: 600; white-space: nowrap; }
.scan-status-uploaded        { background: #e3ecf7; color: #2b5e96; }
.scan-status-processing      { background: #fff3d6; color: #8a6100; }
.scan-status-review_required { background: #ffe8d6; color: #a24f00; }
.scan-status-confirmed       { background: #d7f0dd; color: #1c6b34; }
.scan-status-cancelled       { background: #eceff2; color: #5c6773; }
.scan-status-failed          { background: #fbdcdc; color: #a02418; }

/* Match-status legend + row badges */
.scanner-items-title { display: flex; align-items: center; gap: 10px; margin: 18px 0 8px; }
.scanner-items-legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.scanner-items-legend .badge { font-size: 10px; padding: 2px 8px; }
.badge.match-detected     { background: #e3ecf7; color: #2b5e96; }
.badge.match-matched      { background: #d7f0dd; color: #1c6b34; }
.badge.match-new_product  { background: #e2dcf7; color: #4c36a3; }
.badge.match-new_batch    { background: #d6eef2; color: #12647a; }
.badge.match-missing      { background: #fbdcdc; color: #a02418; }
.badge.match-needs_review { background: #fff3d6; color: #8a6100; }

/* Review items table */
.scanner-items-wrap { max-height: 52vh; overflow: auto; border: 1px solid var(--border, #dee2e6); border-radius: var(--radius-sm, 6px); }
.scanner-items-table { margin-bottom: 0; }
.scanner-items-table th { position: sticky; top: 0; background: #f4f6f9; color: var(--text, #334155); z-index: 2; font-size: 11px; text-transform: uppercase; letter-spacing: .3px; }
.scanner-items-table td { padding: 4px 5px; vertical-align: middle; }
.scanner-items-table .form-control-xs { padding: 3px 6px; font-size: 12px; height: auto; min-width: 60px; }
.scanner-items-table select.form-control-xs { min-width: 96px; }
.match-row-needs_review { background: #fffbe8; }
.match-row-missing      { background: #fdeeee; }
.match-row-matched      { background: #f3fbf5; }
.match-row-new_product  { background: #f6f3ff; }
.match-row-new_batch    { background: #eff9fb; }

/* Review form + actions */
.scanner-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.scanner-review-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.scan-actions-cell { white-space: nowrap; }
.scan-actions-cell .btn { padding: 3px 8px; }

/* Responsive: tablet + mobile */
@media (max-width: 1100px) {
    .scanner-grid, .scanner-review-grid { grid-template-columns: 1fr; }
    .scanner-review-preview { order: -1; }
}
@media (max-width: 576px) {
    .scanner-form-grid { grid-template-columns: 1fr; }
    .scanner-dropzone { padding: 24px 12px; }
    .scanner-upload-actions .btn { flex: 1; }
    .scanner-preview-frame { height: 50vh; min-height: 320px; }
    .scanner-review-actions .btn { flex: 1 1 100%; }
}

/* Per-field extraction status markers (Phase 3) */
.fs-extracted { background: #e6f6ec; color: #1d7a3d; }
.fs-uncertain { background: #fff6e0; color: #9a6b00; }
.fs-missing { background: #fdeaea; color: #b02a2a; }
.fs-needs_review { background: #eef9ff; color: #0b6bcb; }
.scanner-fs-badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.scanner-fs-badges .badge { font-size: 10px; padding: 2px 6px; }
.scanner-raw-text summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.scanner-raw-text pre {
    max-height: 280px; overflow: auto; background: #f6f8fa; border: 1px solid var(--border, #e3e8ef);
    padding: 10px; border-radius: 6px; font-size: 12px; white-space: pre-wrap; margin-top: 8px;
}

/* ============================================================
   Phase 12 — Sync indicator + Sync Dashboard
   ============================================================ */
.sync-indicator {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
    text-decoration: none; margin-right: 12px; border: 1px solid transparent;
    transition: background .2s, color .2s; white-space: nowrap;
}
.sync-ind-init    { background: #eef1f5; color: #64748b; }
.sync-ind-online  { background: #e6f7ee; color: #14804a; border-color: #b7e6cd; }
.sync-ind-local   { background: #eef3fb; color: #3867b0; border-color: #c7d8f2; }
.sync-ind-offline { background: #fdf3e3; color: #b26205; border-color: #f2ddb4; }
.sync-ind-pending { background: #e9f2ff; color: #2563b8; border-color: #c4dbf9; }
.sync-ind-syncing { background: #e9f2ff; color: #2563b8; border-color: #c4dbf9; }
.sync-ind-error   { background: #fdeaea; color: #b02a2a; border-color: #f3c1c1; }
.sync-indicator:hover { filter: brightness(.97); }

.sync-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.sync-card {
    background: var(--card-bg, #fff); border: 1px solid var(--border, #e3e8ef); border-radius: 10px;
    padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
}
.sync-card .sync-card-label { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: #7c8ba1; font-weight: 600; }
.sync-card .sync-card-value { font-size: 20px; font-weight: 700; color: var(--text, #334155); }
.sync-card .sync-card-sub { font-size: 12px; color: #7c8ba1; }
.sync-state-ok   { color: #14804a !important; }
.sync-state-warn { color: #b26205 !important; }
.sync-state-bad  { color: #b02a2a !important; }
.sync-state-info { color: #2563b8 !important; }

.sync-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 18px; }
.sync-section-title { font-size: 15px; font-weight: 700; margin: 22px 0 10px; color: var(--text, #334155); display: flex; align-items: center; gap: 8px; }
.sync-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sync-table th, .sync-table td { padding: 8px 10px; border-bottom: 1px solid var(--border, #e3e8ef); text-align: left; vertical-align: top; }
.sync-table th { background: #f4f7fb; color: #51607a; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.sync-pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.sync-pill-pending  { background: #e9f2ff; color: #2563b8; }
.sync-pill-syncing  { background: #e9f2ff; color: #2563b8; }
.sync-pill-synced   { background: #e6f7ee; color: #14804a; }
.sync-pill-failed   { background: #fdeaea; color: #b02a2a; }
.sync-pill-conflict { background: #fdf3e3; color: #b26205; }
.sync-pill-open     { background: #fdf3e3; color: #b26205; }
.sync-pill-resolved { background: #e6f7ee; color: #14804a; }
.sync-pill-ignored  { background: #eef1f5; color: #64748b; }
.sync-pill-success  { background: #e6f7ee; color: #14804a; }
.sync-pill-partial  { background: #fdf3e3; color: #b26205; }
.sync-pill-error    { background: #fdeaea; color: #b02a2a; }
.sync-muted { color: #8494ab; font-size: 12px; }
.sync-note {
    background: #eef3fb; border: 1px solid #c7d8f2; color: #3867b0; border-radius: 8px;
    padding: 10px 14px; font-size: 13px; margin-bottom: 16px;
}
@media (max-width: 700px) {
    .sync-indicator span { display: none; }
    .sync-indicator { padding: 6px 8px; }
}

/* ============================================================
   PHASE 15 — Responsive & PWA layer
   (mobile-first touch enhancements; desktop look untouched)
   ============================================================ */

/* Prevent accidental horizontal page overflow on every screen */
html, body { overflow-x: clip; }

/* iOS/Android focus-zoom prevention: inputs >= 16px on touch devices */
@media (max-width: 768px) {
    input, select, textarea { font-size: 16px; }

    /* Accessible touch targets (>= 44px) */
    .btn { min-height: 44px; padding: 10px 16px; }
    .btn-sm { min-height: 38px; }
    .sidebar-menu a { padding: 13px 20px; min-height: 46px; display: flex; align-items: center; gap: 12px; }
    .qty-controls button { width: 44px; height: 44px; font-size: 18px; }
    .qty-controls input { min-height: 44px; }
    .search-bar input, .search-bar select { min-height: 46px; }
    .table td, .table th { white-space: nowrap; }
    .modal-content { border-radius: 14px 14px 0 0; max-height: 92vh; overflow-y: auto; }
    .modal { padding: 0; align-items: flex-end; }
    .form-row, .form-grid { grid-template-columns: 1fr !important; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
    .page-header { flex-wrap: wrap; gap: 10px; }
    .page-header h1 { font-size: 20px; }
    .app-header { flex-wrap: wrap; }
    .app-footer { font-size: 12px; padding: 12px; }
    /* keep action rows usable on phones */
    .filters-row, .toolbar-row { flex-wrap: wrap; }
}

/* Sidebar backdrop (off-canvas menu at <= 768px) */
.sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(11, 26, 62, 0.55);
    z-index: 998; opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.sidebar-backdrop.active { opacity: 1; pointer-events: auto; }

/* Safe-area insets for notched Android devices */
@supports (padding: env(safe-area-inset-bottom)) {
    .app-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    .pwa-banner { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

/* ---------------- PWA banners (install / update) ---------------- */
.pwa-banner {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1500;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    flex-wrap: wrap; padding: 12px 16px;
    background: #0b1a3e; color: #fff; font-size: 14px;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.25);
}
.pwa-update-banner { background: #123a6d; }
.pwa-banner-text { display: flex; align-items: center; gap: 10px; }
.pwa-banner-text i { color: #20c997; }
.pwa-banner-actions { display: flex; gap: 8px; }
.pwa-btn {
    border: 1px solid rgba(255, 255, 255, 0.35); background: transparent; color: #fff;
    border-radius: 8px; padding: 8px 14px; font-size: 13px; font-weight: 600;
    cursor: pointer; min-height: 40px;
}
.pwa-btn-primary { background: #0d6efd; border-color: #0d6efd; }
.pwa-btn:disabled { opacity: .6; cursor: default; }

/* ---------------- Camera / barcode scanning modal ---------------- */
.camera-modal {
    position: fixed; inset: 0; z-index: 1600; background: rgba(4, 10, 26, 0.92);
    display: none; flex-direction: column; align-items: center; justify-content: center; padding: 16px;
}
.camera-modal.active { display: flex; }
.camera-modal video {
    width: 100%; max-width: 560px; max-height: 62vh; border-radius: 12px; background: #000;
}
.camera-modal .camera-frame {
    position: relative; width: 100%; max-width: 560px;
}
.camera-modal .camera-frame::after {
    content: ''; position: absolute; inset: 18% 12%;
    border: 2px solid rgba(32, 201, 151, 0.85); border-radius: 12px; pointer-events: none;
}
.camera-modal .camera-status {
    color: #cbd5e1; font-size: 13px; margin: 12px 0; text-align: center; min-height: 18px;
}
.camera-modal .camera-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.camera-modal .camera-close {
    position: absolute; top: 10px; right: 10px; z-index: 2;
    width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
    background: rgba(255, 255, 255, 0.15); color: #fff; font-size: 18px;
}

/* ---------------- POS mobile cart FAB ---------------- */
.cart-fab {
    display: none; position: fixed; right: 16px; bottom: 18px; z-index: 1200;
    min-width: 58px; height: 58px; border-radius: 999px; border: none; cursor: pointer;
    background: #0d6efd; color: #fff; font-size: 22px;
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.45);
    align-items: center; justify-content: center; gap: 8px; padding: 0 18px;
}
.cart-fab .cart-fab-count {
    background: #20c997; color: #06283d; border-radius: 999px; font-size: 13px; font-weight: 700;
    padding: 2px 8px; min-width: 24px; text-align: center;
}
@media (max-width: 1024px) {
    .cart-fab { display: inline-flex; }
    body.cart-expanded .cart-fab { display: none; }
}

/* POS touch polish for phones/tablets */
@media (max-width: 1024px) {
    .medicine-search input { min-height: 50px; font-size: 16px; }
    .cart-items { -webkit-overflow-scrolling: touch; }
    .payment-methods button, .payment-methods .btn { min-height: 52px; font-size: 15px; }
    .checkout-btn, .btn-sale, .btn-primary.btn-lg { min-height: 54px; font-size: 16px; }
    .product-card, .medicine-card { padding: 12px; }
    .unit-selector button, .unit-selector .unit-btn { min-height: 44px; padding: 8px 14px; }
}

/* Table wrap helper (pwa.js wraps bare tables) */
.pwa-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }

/* Reports filters stack on phones */
@media (max-width: 768px) {
    .report-filters, .filters-bar { flex-direction: column; align-items: stretch; }
    .report-filters .btn, .filters-bar .btn { width: 100%; justify-content: center; }
    .summary-cards, .report-summary { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .summary-cards, .report-summary { grid-template-columns: 1fr; }
}

/* License screens: keep key material readable-but-not-exposed on phones */
@media (max-width: 768px) {
    .license-key-display { word-break: break-all; font-size: 12px; }
    .license-grid, .license-cards { grid-template-columns: 1fr; }
}

/* ================================================================
   Phase 16 - Backup, Recovery & Data Migration layer
   ================================================================ */
.p16-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.p16-grid .card { margin-bottom: 0; }

/* Wizard stepper */
.p16-steps { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; }
.p16-steps li {
    display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px;
    background: var(--light); border: 1px solid var(--border); border-radius: 20px;
    font-size: 12px; font-weight: 600; color: var(--muted);
}
.p16-steps li.active { background: var(--primary-bg); border-color: var(--primary); color: #084298; }
.p16-steps li.done { background: var(--success-bg); border-color: #198754; color: #0f5132; }
.p16-steps li .step-num {
    width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,.08);
    display: inline-flex; align-items: center; justify-content: center; font-size: 10px;
}

/* Mapping + preview tables */
.p16-map-table td, .p16-map-table th { vertical-align: middle; padding: 6px 8px; }
.p16-map-table select { min-width: 180px; }
.p16-row-errors { color: #842029; font-size: 12px; }
.p16-row-warnings { color: #664d03; font-size: 12px; }
.p16-summary-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.p16-tile { background: var(--light); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; text-align: center; }
.p16-tile .num { font-size: 20px; font-weight: 700; color: var(--dark); display: block; }
.p16-tile .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.p16-note { background: var(--info-bg); border: 1px solid #b6e3f0; color: #055160; border-radius: 8px; padding: 10px 14px; font-size: 13px; margin: 10px 0; }

@media (max-width: 900px) {
    .p16-grid { grid-template-columns: 1fr; }
    .p16-map-table { font-size: 12px; }
    .p16-map-table select { min-width: 130px; }
}


