/* public/css/app.css
   Design system SIM Apotek — dipakai di semua halaman lewat layouts/app.blade.php.
   Cukup restyle komponen Bootstrap yang sudah ada (card, btn, table, dst),
   jadi semua halaman otomatis ikut fresh tanpa perlu diedit satu-satu. */

:root {
    --sidebar-width: 264px;
    --topbar-height: 64px;

    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --accent: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --bg-body: #f4f6fb;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;

    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border-color: #e7eaf3;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, .08);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }

body {
    background: var(--bg-body);
    color: var(--text-main);
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14.5px;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -0.01em; }

a { text-decoration: none; }

/* ===== Layout Shell ===== */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 1030;
    transition: transform .25s ease;
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
}

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-sidebar.show { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .app-main { margin-left: 0; }
    .sidebar-backdrop.show {
        position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 1025;
    }
}

.sidebar-brand {
    padding: 20px 22px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-brand .emoji { font-size: 26px; }
.sidebar-brand .logo-img { height: 40px; width: auto; flex-shrink: 0; object-fit: contain; }
.sidebar-brand .brand-text { font-weight: 800; font-size: 17px; color: var(--text-main); line-height: 1.1; }
.sidebar-brand .brand-sub { font-size: 11px; color: var(--text-light); font-weight: 500; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.sidebar-section-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-light);
    padding: 14px 12px 6px;
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13.8px;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
}
.sidebar-link i { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-link:hover { background: var(--primary-light); color: var(--primary); }
.sidebar-link.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border-color); }

/* ===== Topbar ===== */
.app-topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    position: sticky;
    top: 0;
    z-index: 1020;
}
.topbar-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 18px;
}
.topbar-btn:hover { background: var(--bg-body); color: var(--text-main); }

.notif-badge {
    position: absolute;
    top: 4px; right: 4px;
    width: 8px; height: 8px;
    background: var(--danger);
    border-radius: 50%;
    border: 2px solid #fff;
}

.user-chip {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px 6px 6px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
}
.user-avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
    flex-shrink: 0;
}

.page-body { padding: 24px; flex: 1; }

/* ===== Cards ===== */
.card {
    border: 1px solid var(--border-color) !important;
    box-shadow: var(--shadow-sm) !important;
    border-radius: var(--radius-lg) !important;
}

/* Stat card dashboard */
.stat-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
}
.stat-icon {
    width: 46px; height: 46px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.stat-icon.blue { background: #eef2ff; color: var(--primary); }
.stat-icon.green { background: #ecfdf5; color: var(--success); }
.stat-icon.orange { background: #fffbeb; color: var(--warning); }
.stat-icon.red { background: #fef2f2; color: var(--danger); }
.stat-icon.cyan { background: #ecfeff; color: var(--accent); }

/* ===== Buttons ===== */
.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: 13.6px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }
.btn-success { background: var(--success); border-color: var(--success); }
.btn-outline-success { color: var(--success); border-color: var(--success); }
.btn-outline-success:hover { background: var(--success); border-color: var(--success); }

/* ===== Tables ===== */
.table { font-size: 13.8px; }
.table thead th {
    background: #f8f9fc;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--border-color);
    padding: 11px 14px;
}
.table tbody td { padding: 11px 14px; vertical-align: middle; border-bottom: 1px solid var(--border-color); }
.table tbody tr:last-child td { border-bottom: none; }
.table-hover tbody tr:hover { background: #fafbff; }

/* ===== Forms ===== */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border-color);
    font-size: 13.8px;
    padding: 9px 12px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-label { font-weight: 600; font-size: 13px; color: var(--text-main); margin-bottom: 5px; }

/* ===== Badges ===== */
.badge { font-weight: 600; font-size: 11px; padding: 5px 9px; border-radius: 6px; }

/* ===== Alerts ===== */
.alert { border-radius: var(--radius-md); border: 1px solid transparent; }

/* ===== Modal ===== */
.modal-content { border-radius: var(--radius-lg); border: none; box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--border-color); }
.modal-footer { border-top: 1px solid var(--border-color); }

/* Page header helper (opsional dipakai di view: <div class="page-header">) */
.page-header { margin-bottom: 20px; }
.page-header h3 { margin: 0; font-size: 21px; }
.page-header p { color: var(--text-muted); margin: 2px 0 0; font-size: 13.5px; }
.page-body > .container.py-4 { padding-top: 0 !important; padding-bottom: 0 !important; }
.content-container { max-width: 1440px; }
.page-header-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-kicker { margin-bottom: 5px; color: var(--primary); font-size: 10.5px; font-weight: 800; letter-spacing: .08em; }
.page-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.page-actions .btn { display: inline-flex; align-items: center; gap: 6px; }
.app-filter-bar { margin-right: 0; margin-left: 0; padding: 12px; border: 1px solid var(--border-color); border-radius: var(--radius-md); background: var(--bg-card); box-shadow: var(--shadow-sm); }
.app-filter-bar > [class*="col-"] { min-width: 0; }
.table-card { overflow: hidden; }
.sales-summary-card { display: flex; align-items: center; gap: 12px; }
.sales-summary-icon { display: flex; width: 42px; height: 42px; align-items: center; justify-content: center; border-radius: 12px; background: #ecfdf5; color: var(--success); font-size: 19px; }
.sales-summary-label { margin-bottom: 2px; color: var(--text-muted); font-size: 12px; font-weight: 700; }
.sales-summary-card strong { font-size: 19px; }

/* ===== Dashboard ===== */
.dashboard-page { max-width: 1440px; margin: 0 auto; }
.dashboard-hero {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}
.dashboard-eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 10.5px;
    font-weight: 800;
    letter-spacing: .09em;
}
.dashboard-hero h3 { margin: 0; font-size: 25px; }
.dashboard-hero > div > p:last-child { margin: 5px 0 0; color: var(--text-muted); }
.dashboard-quick-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dashboard-quick-actions .btn { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.dashboard-alert { box-shadow: var(--shadow-sm); }
.dashboard-stats { margin-bottom: 12px; }
.dashboard-stat-card {
    display: flex;
    align-items: flex-start;
    gap: 13px;
    min-height: 128px;
    padding: 18px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-main);
    box-shadow: var(--shadow-sm);
}
.dashboard-stat-link { transition: transform .15s ease, box-shadow .15s ease; }
.dashboard-stat-link:hover { color: var(--text-main); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.dashboard-stat-icon {
    display: flex;
    width: 43px;
    height: 43px;
    flex: 0 0 43px;
    align-items: center;
    justify-content: center;
    border-radius: 13px;
    font-size: 19px;
}
.dashboard-stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.dashboard-stat-icon.success { background: #ecfdf5; color: var(--success); }
.dashboard-stat-icon.warning { background: #fffbeb; color: var(--warning); }
.dashboard-stat-icon.danger { background: #fef2f2; color: var(--danger); }
.dashboard-stat-label { color: var(--text-muted); font-size: 11.5px; font-weight: 700; }
.dashboard-stat-value { margin: 4px 0; color: var(--text-main); font-size: 20px; font-weight: 800; letter-spacing: -.03em; line-height: 1.2; }
.dashboard-stat-meta { color: var(--text-light); font-size: 10.5px; font-weight: 600; }
.dashboard-secondary-metrics { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 18px; }
.dashboard-mini-metric {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 12px;
    box-shadow: var(--shadow-sm);
}
.dashboard-mini-metric strong { color: var(--text-main); }
.dashboard-mini-metric > .bi { color: var(--primary); font-size: 17px; line-height: 1; }
.dashboard-mini-icon { color: var(--primary); }
a.dashboard-mini-metric:hover { color: var(--primary); background: var(--primary-light); }
.dashboard-main-grid { margin-bottom: 18px; }
.dashboard-panel { padding: 18px; }
.dashboard-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.dashboard-panel-header h5 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 15px; }
.dashboard-panel-header p { margin: 4px 0 0; color: var(--text-light); font-size: 11.5px; }
.dashboard-panel-header .form-select { min-width: 96px; }
.dashboard-link { color: var(--primary); font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.dashboard-chart-wrap { position: relative; min-height: 255px; }
.dashboard-empty-state {
    display: flex;
    min-height: 255px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    text-align: center;
}
.dashboard-empty-state i { font-size: 34px; }
.dashboard-empty-state p { margin: 10px 0 0; font-size: 12px; }
.dashboard-empty-state.compact { min-height: 180px; }
.dashboard-stock-list { display: flex; flex-direction: column; }
.dashboard-stock-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
}
.dashboard-stock-item:last-child { border-bottom: 0; }
.dashboard-stock-item:hover { color: var(--primary); }
.dashboard-stock-icon {
    display: flex;
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: #f8fafc;
    color: var(--primary);
}
.dashboard-stock-name { min-width: 0; flex: 1; }
.dashboard-stock-name strong,
.dashboard-stock-name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-stock-name strong { font-size: 12.5px; }
.dashboard-stock-name small { margin-top: 2px; color: var(--text-light); font-size: 10.5px; }
.dashboard-stock-qty { min-width: 28px; padding: 3px 6px; border-radius: 6px; background: #fef2f2; color: var(--danger); font-size: 11px; font-weight: 800; text-align: center; }
.dashboard-recent-panel { margin-bottom: 6px; }
.dashboard-transaction-row {
    display: grid;
    grid-template-columns: minmax(170px, 1.25fr) minmax(120px, .8fr) minmax(120px, .75fr);
    gap: 14px;
    align-items: center;
    padding: 11px 0;
    border-bottom: 1px solid var(--border-color);
}
.dashboard-transaction-row:last-child { border-bottom: 0; }
.dashboard-transaction-main strong,
.dashboard-transaction-main span,
.dashboard-transaction-total strong,
.dashboard-transaction-total span { display: block; }
.dashboard-transaction-main strong { font-size: 12.5px; }
.dashboard-transaction-main span,
.dashboard-transaction-items { margin-top: 3px; color: var(--text-light); font-size: 10.5px; }
.dashboard-transaction-total { text-align: right; }
.dashboard-transaction-total strong { color: var(--success); font-size: 12.5px; }
.dashboard-transaction-total span { margin-top: 3px; color: var(--text-light); font-size: 10px; font-weight: 700; }

/* ===== Form Operasional Pembelian ===== */
.operation-branch-note {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin: -6px 0 16px;
    padding: 8px 11px;
    border: 1px solid #dbeafe;
    border-radius: var(--radius-sm);
    background: #eff6ff;
    color: #35517a;
    font-size: 12px;
}
.operation-card-title { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
.operation-card-title h5 { margin: 0; font-size: 15px; }
.operation-card-title p { margin: 3px 0 0; color: var(--text-light); font-size: 11.5px; }
.operation-card-icon {
    display: flex;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: #f0fdf4;
    color: var(--success);
    font-size: 16px;
}
.operation-card-icon.primary { background: var(--primary-light); color: var(--primary); }
.operation-info-card,
.operation-item-card,
.operation-transaction-card { padding: 18px !important; }
.operation-list-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}
.operation-list-header h5 { margin: 0; font-size: 16px; }
.operation-list-header p { margin: 4px 0 0; color: var(--text-light); font-size: 11.5px; }
.operation-grand-total { display: flex; flex-direction: column; align-items: flex-end; color: var(--text-muted); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.operation-grand-total strong { margin-top: 2px; color: var(--text-main); font-size: 18px; text-transform: none; }
.purchase-order-total h5 { margin: 0; font-size: 17px; }
.purchase-save-button { display: inline-flex; align-items: center; gap: 7px; }

/* ===== Stok & Harga Obat ===== */
.stock-card { overflow: hidden; }
.stock-table-wrap { max-width: 100%; }
.stock-table { width: 100%; table-layout: auto; }
.stock-table .stock-drug-col { width: 38%; }
.stock-drug-cell { overflow-wrap: anywhere; }
.stock-drug-name { font-weight: 700; color: var(--text-main); margin-bottom: 4px; }
.stock-drug-meta { display: flex; flex-wrap: wrap; gap: 5px 9px; color: var(--text-light); font-size: 11.5px; }
.stock-drug-meta code { color: var(--primary); background: var(--primary-light); border-radius: 4px; padding: 1px 5px; }
.stock-drug-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.stock-price { width: 15%; white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 12.5px; }
.stock-price-label { color: var(--text-light); display: inline-block; width: 29px; font-size: 11px; }
.stock-price-sell { color: var(--success); font-weight: 700; }
.stock-quantity { width: 15%; font-weight: 700; }
.stock-expiry { color: var(--text-light); font-size: 11px; font-weight: 500; margin-top: 4px; white-space: nowrap; }
.stock-actions-cell { width: 132px; }
.stock-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.stock-actions .btn { margin: 0 !important; }
.stock-pagination { padding: 16px 18px 4px; }

/* ===== Pembelian ===== */
.purchase-card { overflow: hidden; }
.purchase-table { width: 100%; table-layout: fixed; }
.purchase-table th:first-child, .purchase-po { width: 22%; }
.purchase-table th:nth-child(2), .purchase-details { width: 46%; }
.purchase-total { width: 17%; color: var(--success); font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.purchase-actions { width: 15%; white-space: nowrap; }
.purchase-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.purchase-pagination { padding: 16px 18px 4px; }

/* Riwayat faktur: kolom diprioritaskan untuk pelacakan dokumen tanpa membuat
   nama obat, nomor faktur, dan nilai pembelian saling berhimpitan. */
.invoice-history-table { width: 100%; min-width: 940px; table-layout: fixed; font-size: 13px; }
.invoice-history-table th { white-space: normal; }
.invoice-history-table .history-drug-col { width: 22%; }
.invoice-history-table .history-document-col { width: 19%; }
.invoice-history-table .history-supplier-col { width: 17%; }
.invoice-history-table .history-batch-col { width: 13%; }
.invoice-history-table .history-quantity-col { width: 8%; }
.invoice-history-table .history-price-col { width: 12%; }
.invoice-history-table .history-action-col { width: 9%; }
.history-drug-name { color: var(--text-main); line-height: 1.35; overflow-wrap: anywhere; }
.history-meta { color: var(--text-light); font-size: 11.5px; line-height: 1.45; overflow-wrap: anywhere; }
.history-drug-cell, .history-document-cell, .history-supplier-cell, .history-batch-cell { vertical-align: top; }
.history-document-cell .history-label { color: var(--text-light); font-size: 10px; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; margin-bottom: 2px; }
.history-quantity-cell, .history-price-cell { white-space: nowrap; font-variant-numeric: tabular-nums; }
.history-price-cell { color: var(--success); font-weight: 700; }
.history-action-cell { white-space: nowrap; }

/* Form item Pembelian: gabungkan rincian harga tanpa membuat kolom sempit. */
.purchase-item-table { width: 100%; table-layout: fixed; }
.purchase-item-table th:first-child { width: 23%; }
.purchase-item-table th:nth-child(2) { width: 18%; }
.purchase-item-table th:nth-child(3) { width: 31%; }
.purchase-item-table th:nth-child(4) { width: 12%; }
.purchase-item-table th:nth-child(5) { width: 12%; }
.purchase-item-table th:last-child { width: 48px; }
.item-field-label { display: block; margin: 0 0 4px; color: var(--text-light); font-size: 10.5px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; }
.purchase-order-fields { display: grid; grid-template-columns: minmax(0, 1fr) 64px; gap: 8px; }
.purchase-price-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) 76px minmax(78px, .95fr); gap: 8px; align-items: end; }
.purchase-final-price { padding: 9px 10px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); background: #f8fafc; min-height: 55px; }
.purchase-final-price .item-field-label { margin-bottom: 2px; }
.purchase-item-table .form-control, .purchase-item-table .form-select { min-width: 0; }
.purchase-item-table .subtotal-cell, .purchase-item-table .harga-jual-cell { padding-top: 9px; white-space: nowrap; }

/* ===== POS / Penjualan =====
   Hasil pencarian Tom Select dipasang ke <body> (lihat sales/create) agar
   tidak dipotong oleh area formulir. */
.sales-item-table-wrap { width: 100%; overflow: visible; }
.purchase-item-table-wrap { width: 100%; overflow: visible; }
.sales-items-heading { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; font-size: 16px; }
.sales-items-heading i { color: var(--primary); }
.sales-add-item-area { display: flex; align-items: center; gap: 10px; }
.sales-add-help { display: inline-block; }
.sales-mobile-checkout { display: none; }
body > .ts-dropdown { z-index: 1080 !important; }

/* Form faktur langsung: item diisi satu per satu lalu dimasukkan ke daftar,
   sehingga tetap mudah dipakai tanpa tabel lebar di layar ponsel. */
.direct-invoice-item-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
}
.direct-field-drug { grid-column: span 2; }
.direct-invoice-item-grid .ts-wrapper { width: 100%; }

/* Daftar item faktur langsung memiliki tujuh kolom. Aturan tabel pembelian
   biasa hanya menyediakan lima kolom, sehingga subtotal sebelumnya terjepit
   menjadi tulisan vertikal. */
.direct-invoice-table-wrap { width: 100%; overflow-x: auto; overflow-y: hidden; }
.direct-invoice-table { min-width: 900px; table-layout: fixed; }
.direct-invoice-table th { white-space: nowrap; }
.direct-invoice-table th:nth-child(1) { width: 23%; }
.direct-invoice-table th:nth-child(2) { width: 11%; }
.direct-invoice-table th:nth-child(3) { width: 12%; }
.direct-invoice-table th:nth-child(4) { width: 18%; }
.direct-invoice-table th:nth-child(5) { width: 12%; }
.direct-invoice-table th:nth-child(6) { width: 15%; }
.direct-invoice-table th:nth-child(7) { width: 70px; }
.direct-invoice-table td:nth-child(3),
.direct-invoice-table td:nth-child(4),
.direct-invoice-table td:nth-child(6),
.direct-invoice-table td:nth-child(7) { white-space: nowrap; }

@media (max-width: 1100px) {
    .purchase-item-table { font-size: 12px; }
    .purchase-item-table th:first-child { width: 21%; }
    .purchase-item-table th:nth-child(2) { width: 17%; }
    .purchase-item-table th:nth-child(3) { width: 34%; }
    .purchase-price-grid { grid-template-columns: minmax(0, 1.15fr) 66px minmax(70px, .9fr); gap: 5px; }
    .purchase-order-fields { grid-template-columns: minmax(0, 1fr) 54px; gap: 5px; }
    .direct-invoice-item-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 767.98px) {
    .page-body { padding: 16px; }
    .dashboard-hero { align-items: flex-start; }
    .dashboard-hero h3 { font-size: 22px; }
    .dashboard-stat-card { min-height: 118px; padding: 15px; }
    .dashboard-stat-value { font-size: 17px; }
    .dashboard-panel { padding: 16px; }
    .stock-table { min-width: 0; font-size: 12px; }
    .stock-table .stock-drug-col { width: 40%; }
    .stock-table .stock-drug-meta { font-size: 10.5px; }
    .stock-actions-cell { width: 108px; }
    .purchase-table { font-size: 12px; }
    .purchase-table th:first-child, .purchase-po { width: 25%; }
    .purchase-table th:nth-child(2), .purchase-details { width: 42%; }
    .purchase-total { width: 19%; }
    .purchase-actions { width: 14%; }
    .purchase-actions .btn { padding: 4px 6px; font-size: 11px; }
}

/* Tabel pada ponsel portrait: jaga ukuran teks tetap nyaman dibaca dan
   gulirkan hanya area tabel, bukan seluruh halaman. */
@media (max-width: 575.98px) {
    .page-body { padding: 12px; }
    .app-topbar { height: 58px; padding: 0 12px; }
    .app-topbar .fw-bold { font-size: 13px !important; }
    .app-topbar .btn-outline-primary { max-width: 145px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar-btn { width: 34px; height: 34px; }
    .user-chip { gap: 4px; padding: 3px; border-color: transparent; }
    .user-chip .bi-chevron-down { display: none; }

    .dashboard-hero { display: block; margin-bottom: 18px; }
    .dashboard-hero h3 { font-size: 21px; }
    .dashboard-hero > div > p:last-child { font-size: 12px; line-height: 1.45; }
    .dashboard-quick-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 14px; }
    .dashboard-quick-actions .btn { justify-content: center; padding: 9px 7px; font-size: 11.5px; }
    .dashboard-alert { font-size: 12px; line-height: 1.45; }
    .dashboard-alert .fs-4 { font-size: 18px !important; }
    .dashboard-stat-card { min-height: 112px; gap: 10px; padding: 13px; }
    .dashboard-stat-icon { width: 36px; height: 36px; flex-basis: 36px; border-radius: 10px; font-size: 16px; }
    .dashboard-stat-label { font-size: 10px; }
    .dashboard-stat-value { margin: 3px 0; font-size: 15px; overflow-wrap: anywhere; }
    .dashboard-stat-meta { font-size: 9.5px; }
    .dashboard-secondary-metrics { display: grid; grid-template-columns: 1fr; gap: 7px; margin-bottom: 14px; }
    .dashboard-mini-metric { justify-content: flex-start; border-radius: var(--radius-sm); font-size: 11.5px; }
    .dashboard-mini-metric > .bi { margin-left: auto; }
    .dashboard-panel { padding: 14px; }
    .dashboard-panel-header { margin-bottom: 12px; }
    .dashboard-panel-header h5 { font-size: 14px; }
    .dashboard-panel-header p { font-size: 10.5px; }
    .dashboard-panel-header .form-select { min-width: 82px; padding: 6px 8px; font-size: 11px; }
    .dashboard-chart-wrap,
    .dashboard-empty-state { min-height: 215px; }
    .dashboard-empty-state.compact { min-height: 130px; }
    .dashboard-transaction-row { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 10px 0; }
    .dashboard-transaction-items { grid-column: 1 / -1; margin: 0; }
    .dashboard-transaction-main strong { font-size: 11.5px; }
    .dashboard-transaction-main span,
    .dashboard-transaction-items { font-size: 9.5px; }
    .dashboard-transaction-total strong { font-size: 11.5px; }
    .operation-branch-note { display: flex; margin: -2px 0 14px; font-size: 11px; line-height: 1.4; }
    .operation-info-card,
    .operation-item-card,
    .operation-transaction-card { padding: 14px !important; }
    .operation-card-title { margin-bottom: 13px; }
    .operation-card-icon { width: 32px; height: 32px; flex-basis: 32px; font-size: 14px; }
    .operation-card-title h5 { font-size: 14px; }
    .operation-card-title p { font-size: 10.5px; line-height: 1.4; }
    .operation-list-header { margin-bottom: 12px; }
    .operation-list-header h5 { font-size: 14px; }
    .operation-list-header p { font-size: 10px; }
    .operation-grand-total { font-size: 9.5px; }
    .operation-grand-total strong { font-size: 15px; }
    .page-header > div.page-actions.purchase-type-switcher { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
    .purchase-type-switcher .btn { width: 100%; padding: 7px 4px !important; font-size: 10px !important; }
    .purchase-order-total h5 { font-size: 16px; }

    .page-header { align-items: flex-start !important; margin-bottom: 14px; }
    .page-header h3 { font-size: 19px; }
    .page-header p { font-size: 12px; line-height: 1.45; }
    .page-header > div:last-child { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; width: 100%; }
    .page-header > div:last-child .btn { width: 100%; margin: 0 !important; padding: 7px 8px; font-size: 11.5px; }
    .content-container.py-4 { padding-top: 4px !important; padding-bottom: 4px !important; }
    .page-kicker { font-size: 9.5px; }
    .app-filter-bar { padding: 10px; }
    .app-filter-bar > [class*="col-"] { width: 100%; }
    .sales-summary-card { padding: 13px !important; }
    .sales-summary-card strong { font-size: 17px; }

    .table-responsive,
    .mobile-table-scroll {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        border-radius: var(--radius-sm);
    }

    .mobile-table-scroll { margin-bottom: 8px; }
    .table-responsive > .table,
    .mobile-table-scroll > .table {
        min-width: 620px;
        margin-bottom: 0;
        font-size: 12px;
    }

    .table thead th {
        padding: 9px 10px;
        font-size: 10px;
        white-space: nowrap;
    }
    .table tbody td { padding: 9px 10px; }
    .table .btn-sm { padding: 4px 7px; font-size: 11px; }
    .table .badge { font-size: 10px; padding: 4px 6px; }

    /* Tabel yang memuat kolom formulir/aksi butuh ruang sedikit lebih lebar. */
    .stock-table-wrap .stock-table { min-width: 700px; }
    .purchase-table { min-width: 660px !important; }
    .invoice-history-table { min-width: 900px !important; font-size: 12px; }
    .invoice-history-table .history-drug-col { width: 24%; }
    .invoice-history-table .history-document-col { width: 20%; }
    .invoice-history-table .history-supplier-col { width: 17%; }
    .invoice-history-table .history-batch-col { width: 13%; }
    .invoice-history-table .history-quantity-col { width: 8%; }
    .invoice-history-table .history-price-col { width: 11%; }
    .invoice-history-table .history-action-col { width: 7%; }
    .invoice-history-table .history-meta { font-size: 10.5px; }
    .invoice-history-table .history-action-cell .btn { padding: 4px 6px; font-size: 10.5px; }
    .purchase-item-table,
    #item-table { min-width: 740px !important; }
    .sales-item-table-wrap {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        margin-bottom: 8px;
    }
    .purchase-item-table-wrap {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        margin-bottom: 8px;
    }
    .direct-invoice-table { min-width: 900px !important; }
    .direct-invoice-item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .direct-field-drug, .direct-add-action { grid-column: span 2; }

    /* Form operasi (penjualan, PO, penerimaan, faktur langsung): setiap
       item menjadi kartu vertikal di ponsel. Desktop tetap memakai tabel. */
    #item-table.mobile-operation-table,
    #direct-invoice-table.mobile-operation-table {
        min-width: 0 !important;
        table-layout: auto !important;
    }
    .sales-item-table-wrap,
    .purchase-item-table-wrap,
    .direct-invoice-table-wrap {
        overflow: visible;
    }
    .mobile-operation-table,
    .mobile-operation-table tbody,
    .mobile-operation-table tr,
    .mobile-operation-table td {
        display: block;
        width: 100%;
    }
    .mobile-operation-table thead { display: none; }
    .mobile-operation-table tbody { padding: 0; }
    .mobile-operation-table tbody tr {
        margin: 0 0 12px;
        padding: 12px;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-sm);
        background: #fff;
        box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
    }
    .mobile-operation-table tbody td {
        display: grid;
        grid-template-columns: minmax(98px, 36%) minmax(0, 1fr);
        gap: 10px;
        align-items: start;
        padding: 8px 0;
        border: 0;
        white-space: normal;
    }
    .mobile-operation-table tbody td::before {
        content: attr(data-label);
        color: var(--text-light);
        font-size: 11px;
        font-weight: 800;
        letter-spacing: .025em;
        text-transform: uppercase;
        padding-top: 8px;
    }
    .mobile-operation-table tbody td > .form-control,
    .mobile-operation-table tbody td > .form-select,
    .mobile-operation-table tbody td > .input-group,
    .mobile-operation-table tbody td > .ts-wrapper { min-width: 0; width: 100%; }
    .mobile-operation-table .purchase-price-grid { grid-template-columns: minmax(0, 1fr) 82px; }
    .mobile-operation-table .purchase-final-price { grid-column: span 2; }
    .mobile-operation-table .item-field-label { display: none; }
    .mobile-operation-table tbody td[data-label="Aksi"] {
        display: flex;
        justify-content: flex-end;
        padding-top: 10px;
    }
    .mobile-operation-table tbody td[data-label="Aksi"]::before,
    .mobile-operation-table tbody td[colspan]::before { display: none; }
    .mobile-operation-table tbody td[data-label="Aksi"] .btn::after { content: ' Hapus'; }
    .mobile-operation-table tbody td[colspan] {
        display: block;
        text-align: center;
    }

    .sales-barcode-card { padding: 16px !important; }
    .sales-barcode-input {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
        max-width: none !important;
    }
    .sales-barcode-input > .form-control,
    .sales-barcode-input > .btn {
        width: 100% !important;
        border-radius: var(--radius-sm) !important;
    }
    .sales-barcode-input > .btn { min-height: 43px; }

    .sales-items-card { padding: 16px !important; }
    .sales-items-heading { margin-bottom: 12px; }
    .sales-add-item-area { display: block; }
    .sales-add-item-btn { width: 100%; min-height: 44px; font-size: 14px; }
    .sales-add-help { margin: 9px 2px 0; line-height: 1.45; }

    /* Susunan khusus POS di ponsel: obat penuh, satuan + qty berdampingan,
       lalu harga/stok dan subtotal sebagai ringkasan kasir. */
    .sales-item-table.mobile-operation-table tbody tr {
        position: relative;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 12px;
        padding: 14px;
    }
    .sales-item-table.mobile-operation-table tbody td {
        display: block;
        min-width: 0;
        padding: 9px 0;
    }
    .sales-item-table.mobile-operation-table tbody td::before {
        display: block;
        padding-top: 0;
        margin-bottom: 6px;
    }
    .sales-item-table.mobile-operation-table tbody td:nth-child(1),
    .sales-item-table.mobile-operation-table tbody td:nth-child(6) {
        grid-column: 1 / -1;
    }
    .sales-item-table.mobile-operation-table tbody td:nth-child(1) { padding-right: 48px; }
    .sales-item-table.mobile-operation-table tbody td:nth-child(2) { grid-column: 1; }
    .sales-item-table.mobile-operation-table tbody td:nth-child(5) { grid-column: 2; grid-row: 2; }
    .sales-item-table.mobile-operation-table tbody td:nth-child(3),
    .sales-item-table.mobile-operation-table tbody td:nth-child(4) {
        margin-top: 4px;
        padding: 10px;
        border-radius: var(--radius-sm);
        background: #f8fafc;
    }
    .sales-item-table.mobile-operation-table tbody td:nth-child(6) {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-top: 4px;
        padding: 12px;
        border-radius: var(--radius-sm);
        background: var(--primary-light);
        color: var(--primary);
        font-weight: 800;
    }
    .sales-item-table.mobile-operation-table tbody td:nth-child(6)::before {
        margin: 0;
        color: var(--primary);
    }
    .sales-item-table.mobile-operation-table tbody td[data-label="Aksi"] {
        position: absolute;
        top: 14px;
        right: 14px;
        display: block;
        width: auto;
        margin: 0;
        padding: 0;
    }
    .sales-item-table.mobile-operation-table tbody td[data-label="Aksi"] .btn {
        width: 34px;
        height: 34px;
        padding: 0;
    }
    .sales-item-table.mobile-operation-table tbody td[data-label="Aksi"] .btn::after { content: ''; }

    #form-sale { padding-bottom: 92px; }
    .sales-total-summary,
    .sales-save-button { display: none; }
    .sales-payment-field { max-width: none !important; }
    .sales-mobile-checkout {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1030;
        display: grid;
        grid-template-columns: minmax(96px, .7fr) minmax(0, 1.3fr);
        gap: 12px;
        align-items: center;
        padding: 11px 14px calc(11px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border-color);
        background: rgba(255, 255, 255, .98);
        box-shadow: 0 -4px 16px rgba(15, 23, 42, .12);
    }
    .sales-mobile-total { display: flex; flex-direction: column; line-height: 1.2; }
    .sales-mobile-total span { color: var(--text-muted); font-size: 12px; font-weight: 700; }
    .sales-mobile-total strong { color: var(--text-main); font-size: 18px; }
    .sales-mobile-save { min-height: 46px; font-size: 13px; font-weight: 700; }

    .stock-pagination,
    .purchase-pagination { padding: 12px 12px 4px; }
    .pagination { flex-wrap: wrap; gap: 2px; }
    .page-link { padding: 5px 8px; font-size: 12px; }
}
