/* =====================================================================
   Digital Pharmacy - Theme Stylesheet
   Light green theme built on top of Bootstrap 5.
   Created by: Pankaj
   All page styling must come from this file - no inline "style"
   attributes anywhere in the markup.
   ===================================================================== */

:root {
    --color-primary: #3EA65C;
    --color-primary-dark: #2E7D45;
    --color-primary-light: #E8F6EC;
    --color-accent: #1FA79E;
    --color-bg: #F5FAF6;
    --color-surface: #FFFFFF;
    --color-text: #1F2D24;
    --color-text-muted: #6B7C70;
    --color-border: #DCEEDF;
    --color-danger: #E5484D;
    --color-warning: #F5A524;
    --color-info: #2F86D6;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 3px rgba(31, 45, 36, 0.08);
    --shadow-md: 0 6px 18px rgba(31, 45, 36, 0.10);
    --sidebar-width: 250px;
}

* {
    box-sizing: border-box;
}

body {
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px;
}

a {
    color: var(--color-primary-dark);
    text-decoration: none;
}

a:hover {
    color: var(--color-primary);
}

/* ---------------------------------------------------------------------
   Auth pages (login / register) - centered card layout
   --------------------------------------------------------------------- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, var(--color-primary-light) 0%, var(--color-bg) 60%);
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 36px 32px;
}

.auth-card.wide {
    max-width: 640px;
}

.auth-card .brand-logo {
    display: block;
    max-width: 170px;
    margin: 0 auto 20px;
}

.auth-card h1 {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
}

.auth-card p.subtitle {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 13px;
    margin-bottom: 24px;
}

/* ---------------------------------------------------------------------
   Store select screen - each branch is one big tappable card. The
   native radio input stays in the DOM (for the form submit + required
   validation) but is visually hidden; the whole label acts as the
   clickable/tappable target and gets a highlighted border+background
   once its radio is checked.
   --------------------------------------------------------------------- */
.store-select-card {
    display: block;
    position: relative;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md, 10px);
    padding: 14px 16px;
    margin-bottom: 12px;
    cursor: pointer;
    background: var(--color-surface);
    transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.store-select-card:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.store-select-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.store-select-card:has(input:checked) {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
    box-shadow: 0 0 0 2px var(--color-primary) inset;
}

.store-select-card:has(input:focus-visible) {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------------
   Application shell - sidebar + top bar + main content
   --------------------------------------------------------------------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--sidebar-width);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 20px 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    transition: margin-left 0.2s ease;
}

.app-sidebar .brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 20px 18px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 6px;
}

.app-sidebar .brand img {
    height: 42px;
    max-width: 190px;
    object-fit: contain;
}

.app-sidebar .nav-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    padding: 16px 20px 8px;
    margin-top: 6px;
    border-top: 1px solid var(--color-border);
}

.app-sidebar .nav-section-label:first-of-type {
    border-top: none;
    margin-top: 0;
}

.app-sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: var(--color-text);
    border-left: 3px solid transparent;
    font-size: 14px;
}

.app-sidebar .nav-link i {
    width: 18px;
    flex-shrink: 0;
    text-align: center;
    font-size: 16px;
    color: var(--color-text-muted);
}

.app-sidebar .nav-link:hover {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
}

.app-sidebar .nav-link:hover i {
    color: var(--color-primary-dark);
}

.app-sidebar .nav-link.active {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    border-left-color: var(--color-primary);
    font-weight: 600;
}

.app-sidebar .nav-link.active i {
    color: var(--color-primary-dark);
}

.app-main {
    flex: 1;
    min-width: 0;
}

.app-topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-topbar .page-title {
    font-size: 17px;
    font-weight: 700;
}

.app-topbar .store-badge {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    border-radius: var(--radius-sm);
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 600;
}

.app-content {
    padding: 24px;
}

.sidebar-toggle {
    display: none;
}

/* ---------------------------------------------------------------------
   Cards, stat tiles, tables
   --------------------------------------------------------------------- */
.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 20px;
}

.panel-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 16px;
}

.logo-preview {
    height: 60px;
    max-width: 220px;
    object-fit: contain;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 8px;
    background: var(--color-bg);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 16px 18px;
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 6px;
}

.stat-card .stat-value {
    font-size: 22px;
    font-weight: 700;
}

.stat-card.warning {
    border-left-color: var(--color-warning);
}

.stat-card.danger {
    border-left-color: var(--color-danger);
}

.table-wrapper {
    overflow-x: auto;
}

table.app-table {
    width: 100%;
    border-collapse: collapse;
}

table.app-table thead th {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 10px 12px;
    text-align: left;
    white-space: nowrap;
}

table.app-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    font-size: 14px;
}

table.app-table tbody tr:hover {
    background: var(--color-primary-light);
}

.badge-status-active {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
}

.badge-status-inactive {
    background: #F3F4F1;
    color: var(--color-text-muted);
}

.badge-status-paid {
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
}

.badge-status-unpaid {
    background: #FBE7E7;
    color: #B3261E;
}

.badge-status-partial {
    background: #FDEEDC;
    color: #A15C00;
}

.badge-expiry-soon {
    background: #FDEEDC;
    color: #A15C00;
}

/* ---------------------------------------------------------------------
   Smart Table - search/sort/pagination/export toolbar injected by
   assets/js/smart-table.js around every <table data-smart-table>.
   --------------------------------------------------------------------- */
.smart-table-wrapper {
    margin-top: 8px;
}

.smart-table-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.smart-table-search input {
    min-width: 220px;
}

.smart-table-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

table.app-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 22px;
}

table.app-table thead th.sortable::after {
    content: '\2195';
    position: absolute;
    right: 8px;
    opacity: 0.35;
    font-size: 11px;
}

table.app-table thead th.sort-asc::after {
    content: '\2191';
    opacity: 1;
}

table.app-table thead th.sort-desc::after {
    content: '\2193';
    opacity: 1;
}

.smart-table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.smart-table-info {
    font-size: 12px;
    color: var(--color-text-muted);
}

.smart-table-pages {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

/* ---------------------------------------------------------------------
   Searchable Select - type-to-filter combobox built by
   assets/js/searchable-select.js around every <select data-searchable>.
   --------------------------------------------------------------------- */
.searchable-select {
    position: relative;
}

.searchable-select-native {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
}

.searchable-select-input {
    position: relative;
    z-index: 1;
    background: var(--color-surface);
}

.searchable-select-list {
    display: none;
    position: absolute;
    z-index: 20;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 220px;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-top: 4px;
}

.searchable-select-list.open {
    display: block;
}

.searchable-select-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
}

.searchable-select-item:hover,
.searchable-select-item.active {
    background: var(--color-primary-light);
}

.searchable-select-empty {
    padding: 8px 12px;
    color: var(--color-text-muted);
    font-size: 13px;
}

/* ---------------------------------------------------------------------
   Billing (POS) step flow - single top-to-bottom column so the cart,
   the fields it needs and the save button always sit together instead
   of being split across left/right cards.
   --------------------------------------------------------------------- */
.billing-flow {
    max-width: 900px;
}

.billing-step {
    position: relative;
    border-left: 3px solid var(--color-primary);
}

.billing-step-label {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #fff;
    background: var(--color-primary);
    padding: 2px 10px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.billing-subsection-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin: 18px 0 10px;
    padding-top: 12px;
    border-top: 1px dashed var(--color-border);
}

.billing-subsection-title:first-of-type {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

/* ---------------------------------------------------------------------
   Printable invoice
   --------------------------------------------------------------------- */
.invoice-sheet {
    max-width: 800px;
    margin: 0 auto;
}

.invoice-header {
    display: flex;
    align-items: center;
    gap: 16px;
}

.invoice-logo {
    height: 56px;
    width: auto;
}

.invoice-store-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-primary-dark, var(--color-primary));
}

.invoice-meta {
    margin: 16px 0;
    font-size: 14px;
}

.invoice-prescription {
    background: var(--color-primary-light);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

.invoice-items-table th,
.invoice-items-table td {
    font-size: 13px;
}

.invoice-totals {
    max-width: 320px;
    margin-left: auto;
    margin-top: 12px;
    font-size: 14px;
}

.invoice-net {
    font-weight: 700;
    font-size: 17px;
    border-top: 1px solid var(--color-border);
    margin-top: 6px;
    padding-top: 6px;
    color: var(--color-primary);
}

.invoice-payments {
    margin-top: 16px;
    font-size: 14px;
}

@media print {
    .no-print,
    .app-sidebar,
    .mobile-more-sheet,
    .sidebar-toggle {
        display: none !important;
    }

    .app-main {
        margin: 0 !important;
        width: 100% !important;
    }

    .invoice-sheet {
        border: none !important;
        box-shadow: none !important;
    }
}

/* ---------------------------------------------------------------------
   Buttons and forms - overriding Bootstrap defaults to the theme color
   --------------------------------------------------------------------- */
.btn-primary {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

.btn-outline-primary {
    color: var(--color-primary-dark);
    border-color: var(--color-primary);
}

.btn-outline-primary:hover {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 0.2rem rgba(62, 166, 92, 0.18);
}

/* ---------------------------------------------------------------------
   Custom toast + confirm modal (replaces browser alert()/confirm())
   --------------------------------------------------------------------- */
.app-toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.app-toast {
    min-width: 260px;
    max-width: 340px;
    background: var(--color-surface);
    border-left: 4px solid var(--color-primary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: 12px 16px;
    font-size: 14px;
    animation: app-toast-in 0.2s ease;
}

.app-toast.success {
    border-left-color: var(--color-primary);
}

.app-toast.error {
    border-left-color: var(--color-danger);
}

.app-toast.warning {
    border-left-color: var(--color-warning);
}

@keyframes app-toast-in {
    from {
        transform: translateX(20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ---------------------------------------------------------------------
   Mobile bottom tab bar + "More" bottom sheet (app-style navigation,
   replaces the desktop sidebar on small screens - see the media query
   below). Markup lives at the end of sidebar-owner.php / sidebar-store.php.
   --------------------------------------------------------------------- */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -2px 10px rgba(31, 45, 36, 0.10);
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-bottom-nav .nav-row {
    display: flex;
    align-items: stretch;
}

.mobile-bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 8px 2px 6px;
    color: var(--color-text-muted);
    font-size: 11px;
    border: none;
    background: none;
}

.mobile-bottom-nav .nav-item i {
    font-size: 19px;
    line-height: 1;
}

.mobile-bottom-nav .nav-item.active {
    color: var(--color-primary-dark);
}

.mobile-more-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 25, 18, 0.45);
    z-index: 55;
}

.mobile-more-sheet {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-surface);
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-md);
    z-index: 60;
    max-height: 70vh;
    overflow-y: auto;
    padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}

.mobile-more-sheet .sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--color-border);
    border-radius: 4px;
    margin: 6px auto 10px;
}

.mobile-more-sheet .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
}

.mobile-more-sheet .nav-section-label {
    padding: 10px 20px 4px;
}

body.more-sheet-open .mobile-more-backdrop,
body.more-sheet-open .mobile-more-sheet {
    display: block;
}

/* ---------------------------------------------------------------------
   Responsive - below 768px the left sidebar and its topbar hamburger
   are replaced entirely by the fixed bottom tab bar above.
   --------------------------------------------------------------------- */
@media (max-width: 768px) {
    .app-sidebar {
        display: none;
    }

    .sidebar-toggle {
        display: none;
    }

    .mobile-bottom-nav {
        display: block;
    }

    .app-content {
        padding: 16px 16px calc(16px + 64px + env(safe-area-inset-bottom));
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: 26px 20px;
    }
}
