:root {
    --bg: #f4f7fb;
    --card: rgba(255,255,255,.9);
    --border: #e6ebf2;
    --text: #132238;
    --muted: #68778f;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --hero1: #0f766e;
    --hero2: #0f172a;
}

body { color: var(--text); background: var(--bg); }
.auth-shell {
    background: radial-gradient(circle at top left, #dff5f2 0, #eff4ff 40%, #f7fafc 100%);
}
.app-shell { background: linear-gradient(180deg, #f7fafc 0%, #eef4fb 100%); }
.navbar { backdrop-filter: blur(12px); }
.navbar .nav-link { font-weight: 600; color: #395067; }
.navbar .nav-link:hover, .navbar .nav-link.active { color: var(--primary-dark); }
.brand-mark {
    width: 2rem; height: 2rem; display: inline-flex; align-items: center; justify-content: center;
    border-radius: .9rem; background: linear-gradient(135deg, var(--primary), #38bdf8); color: #fff;
}

.app-navbar-brand {
    min-width: 0;
    max-width: 220px;
    flex: 0 1 220px;
}
.app-navbar-clinic-name {
    display: block;
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.1;
    font-size: clamp(.60rem, .40rem + .30vw, 1rem);
}
@media (max-width: 1399.98px) {
    .app-navbar-brand {
        max-width: 220px;
        flex-basis: 220px;
    }
}
@media (max-width: 1199.98px) {
    .app-navbar-brand {
        max-width: none;
        flex: 1 1 auto;
    }
    .app-navbar-clinic-name {
        font-size: .95rem;
    }
}
.shadow-sm-sm { box-shadow: 0 10px 30px rgba(15, 23, 42, .05); }
.auth-card, .app-card, .metric-card, .detail-card { border-radius: 1.6rem; }
.auth-card { border: 1px solid rgba(255,255,255,.5); }
.auth-side { background: linear-gradient(135deg, var(--hero1), var(--hero2)); }
.hero-panel {
    background: linear-gradient(135deg, rgba(15,118,110,.98), rgba(15,23,42,.98));
    color: white;
    box-shadow: 0 25px 80px rgba(15, 23, 42, .16);
}
.metric-card, .app-card, .detail-card {
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .05);
}
.metric-card { padding: 1.25rem 1.3rem; display: flex; flex-direction: column; gap: .35rem; min-height: 120px; }
.metric-card span { color: var(--muted); font-weight: 600; }
.metric-card strong { font-size: 2rem; line-height: 1; }
.metric-card.success strong { color: #15803d; }
.metric-card.danger strong { color: #b91c1c; }
.metric-card.warning strong { color: #b45309; }
.app-card { padding: 1.5rem; }
.table th { font-size: .86rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom-color: var(--border); }
.product-table td, .product-table th { padding: 1rem .8rem; vertical-align: middle; }
.table-danger-soft { background: rgba(254, 226, 226, .55); }
.group-accordion .accordion-button { border-radius: 0 !important; box-shadow: none; font-size: 1.05rem; }
.group-accordion .accordion-button:not(.collapsed) { background: rgba(15,118,110,.08); color: var(--primary-dark); }
.group-accordion .accordion-item { background: rgba(255,255,255,.92); }
.stock-input { min-width: 90px; max-width: 110px; }
.top-offset { top: 90px; }
.request-card { background: #fff; }
.role-select { min-width: 150px; }
.detail-grid .detail-card { padding: 1rem 1.1rem; height: 100%; }
.detail-card span { display: block; color: var(--muted); margin-bottom: .35rem; font-size: .9rem; }
.detail-card strong { font-size: 1.1rem; }
.detail-thumb { width: 100%; max-height: 220px; object-fit: cover; }
.product-image-large { width: 100%; max-height: 420px; object-fit: cover; }
.image-placeholder { min-height: 300px; background: rgba(148, 163, 184, .08); }
.form-control, .form-select {
    border-radius: 1rem; border-color: #d9e2ec; min-height: 48px;
    box-shadow: none !important;
}
.form-control:focus, .form-select:focus { border-color: #7dd3c8; }
.btn { border-radius: 999px; font-weight: 600; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.alert { border-radius: 1.2rem; }
.text-secondary { color: var(--muted) !important; }
@media (max-width: 991.98px) {
    .top-offset { top: 0; }
    .app-card { padding: 1.2rem; }
    .metric-card strong { font-size: 1.7rem; }
}

.low-stock-badge {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

.expired-badge {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
}
.table-danger-soft {
    background:
        linear-gradient(90deg, rgba(239, 68, 68, .14) 0 6px, rgba(254, 226, 226, .58) 6px 100%);
}

.action-inline-wrap .btn { white-space: nowrap; }
.action-inline-wrap form { margin: 0; }

.action-inline-wrap { display: inline-flex !important; flex-wrap: nowrap !important; gap: .5rem; align-items: center; }
.action-inline-wrap form { display: inline-flex !important; }
.action-col { min-width: 250px; width: 250px; }
@media (max-width: 991.98px) { .action-col { min-width: 220px; width: 220px; } }

.inventory-toolbar .btn.active-sort {
    background: rgba(15,118,110,.08);
    border-color: rgba(15,118,110,.35);
    color: var(--primary-dark);
}
.group-card {
    background: rgba(255,255,255,.92);
    border-color: var(--border) !important;
}
.group-card-header {
    background: rgba(248,250,252,.9);
    border-bottom: 1px solid var(--border);
}
.group-toggle-btn {
    color: var(--text);
    font-size: 1.05rem;
}
.group-toggle-btn:hover { color: var(--primary-dark); }
.group-toggle-btn[aria-expanded="true"] i { transform: rotate(0deg); }
.group-toggle-btn[aria-expanded="false"] i { transform: rotate(-90deg); }
.group-toggle-btn i { transition: transform .2s ease; display: inline-block; }
.products-responsive { overflow-x: auto; }
.products-table-wide { width: 100%; min-width: 1240px; }
.products-table-wide td, .products-table-wide th { white-space: nowrap; }
.stock-col { min-width: 420px; width: 420px; }
.stock-inline-form { display: inline-flex; flex-wrap: nowrap !important; width: 100%; }
.stock-inline-form .stock-input { min-width: 82px; width: 82px; max-width: 82px; }
.stock-unit-label { min-width: 34px; text-align: left; }
.action-col { min-width: 280px; width: 280px; }
.action-inline-wrap { display: inline-flex !important; flex-wrap: nowrap !important; gap: .5rem; align-items: center; }
.action-inline-wrap .btn, .action-inline-wrap form { flex-shrink: 0; }
@media (max-width: 1399.98px) {
    .products-table-wide { min-width: 1040px; }
}
@media (max-width: 1199.98px) {
    .products-table-wide { min-width: 980px; }
    .action-col { min-width: 250px; width: 250px; }
}


.actions-cell, .action-col { min-width: 220px; white-space: nowrap; }
.stock-cell { min-width: 170px; }
.stock-form { display:flex; gap:.4rem; align-items:center; flex-wrap:nowrap; }
.stock-input { width:80px; }
.products-table td, .products-table th, .product-table td, .product-table th { white-space: nowrap; }
.request-card { font-size: .95rem; }
@media (min-width: 1200px) {
  .dashboard-main-col { width: 87%; }
  .dashboard-side-col { width: 13%; }
}
.table-sort-link { color: inherit; text-decoration: none; }
.table-sort-link:hover { text-decoration: underline; }


@media (min-width: 1200px) {
  .dashboard-main-col { flex: 0 0 auto; width: 87%; }
  .dashboard-side-col { flex: 0 0 auto; width: 13%; }
}
.wholesaler-list .form-control { min-height: 40px; }
.wholesaler-inline-form .btn { white-space: nowrap; }
.request-card .btn { white-space: nowrap; }

.compact-input { min-height: 42px; }
.compact-number { max-width: 100%; }
@media (min-width: 992px) {
  .product-form-actions { margin-top: .25rem !important; }
}


.compact-multiselect {
    min-height: 132px;
    font-size: .95rem;
}
.compact-multiselect option {
    padding: .2rem .45rem;
}


.status-picker { position: relative; }
.status-trigger { display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; }
.status-trigger::after { content: ""; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid #64748b; margin-left: .75rem; flex-shrink: 0; }
.status-picker.open .status-trigger::after { transform: rotate(180deg); }
.status-summary { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: .5rem; }
.status-panel { position: absolute; top: calc(100% + .4rem); left: 0; width: 100%; z-index: 30; background: #fff; border: 1px solid #d9e2ec; border-radius: 1rem; padding: .65rem .75rem; max-height: 240px; overflow-y: auto; }
.status-option { display: flex; align-items: center; gap: .55rem; padding: .35rem 0; cursor: pointer; }
.status-option input { margin: 0; }
.status-option span { line-height: 1.25; }


.product-meta-row td { border-top: 0 !important; padding-top: 0; }
.product-meta-cell { white-space: normal !important; line-height: 1.35; padding-top: 0 !important; padding-bottom: .9rem !important; color: #64748b; }
.product-name-cell { min-width: 220px; }
.products-table-wide td, .products-table-wide th { white-space: nowrap; }
.product-table td.product-meta-cell, .product-table th.product-meta-cell, .product-table .product-meta-cell { white-space: normal !important; }
.compact-notes { max-width: 100%; }
@media (min-width: 992px) {
  .compact-number { max-width: 120px; }
  .compact-notes { max-width: 280px; }
}


.stock-change-input { min-width: 78px; width: 78px; max-width: 78px; }
.stock-reason-select { min-width: 112px; max-width: 112px; min-height: 34px; padding-top: .2rem; padding-bottom: .2rem; font-size: .78rem; }
@media (max-width: 1399.98px) {
  .stock-col { min-width: 420px; width: 420px; }
}
.reason-filter-chip { display:inline-flex; align-items:center; gap:.45rem; padding:.55rem .9rem; border:1px solid var(--border); border-radius:999px; background:#fff; cursor:pointer; font-weight:600; }
.reason-filter-chip input { margin:0; }
.stats-progress { height: 14px; border-radius: 999px; background: rgba(15,118,110,.10); }
.stats-progress .progress-bar { background: linear-gradient(90deg, var(--primary), #38bdf8); border-radius: 999px; }
.reason-summary-box { padding: .9rem 1rem; border: 1px solid var(--border); border-radius: 1rem; background: rgba(248,250,252,.7); }

.inventory-search-wrap { min-width: 220px; }
.inventory-search-wrap .form-control { min-height: 38px; }

.trial-banner { background: #fff7ed; color: #7c2d12; border-left: 6px solid #f59e0b; }


.product-form-card-scroll {
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.product-form-card-scroll::-webkit-scrollbar { width: 10px; }
.product-form-card-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 999px; }
.product-form-actions-sticky {
  position: sticky;
  bottom: -1px;
  padding-top: 1rem;
  padding-bottom: .25rem;
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,.96) 24%, rgba(255,255,255,.98) 100%);
}
@media (max-width: 991.98px) {
  .product-form-card-scroll {
    max-height: none;
    overflow: visible;
  }
  .product-form-actions-sticky {
    position: static;
    background: transparent;
    padding-top: 0;
  }
}


/* products.php layout fixes */
.products-page { align-items: flex-start; }
.product-form-column { align-self: flex-start; }
.product-form-column .app-card {
  position: sticky;
  top: 96px;
  max-height: calc(100vh - 118px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  display: flex;
  flex-direction: column;
}
.product-form-column .app-card form { display: flex; flex-wrap: wrap; align-content: flex-start; }
.product-form-column .product-form-actions-sticky {
  position: sticky;
  bottom: 0;
  z-index: 4;
}
.product-list-column .app-card { overflow: hidden; }
.product-table-wrap { overflow-x: visible !important; }
.products-toolbar .compact-filter-select {
  min-height: 38px;
  padding-top: .35rem;
  padding-bottom: .35rem;
  min-width: 145px;
}
.product-table { width: 100%; table-layout: fixed; }
.product-table td, .product-table th {
  white-space: normal !important;
  word-break: break-word;
  padding: .65rem .5rem;
  font-size: .93rem;
}
.product-table th:nth-child(1), .product-table td:nth-child(1) { width: 15%; }
.product-table th:nth-child(2), .product-table td:nth-child(2) { width: 18%; }
.product-table th:nth-child(3), .product-table td:nth-child(3) { width: 12%; white-space: nowrap !important; }
.product-table th:nth-child(4), .product-table td:nth-child(4),
.product-table th:nth-child(5), .product-table td:nth-child(5),
.product-table th:nth-child(6), .product-table td:nth-child(6) { width: 9%; white-space: nowrap !important; }
.product-table .action-col { width: 28%; min-width: 230px; white-space: nowrap !important; }
.product-table .action-inline-wrap { gap: .35rem; }
.product-table .btn { padding-left: .7rem; padding-right: .7rem; }

.product-list-column .product-table thead th {
  white-space: nowrap !important;
  word-break: normal !important;
  letter-spacing: -.01em;
}
.product-list-column .product-table th:nth-child(3),
.product-list-column .product-table td:nth-child(3) {
  text-align: left;
}
.product-meta-cell { white-space: normal !important; font-size: .86rem; line-height: 1.25; }
@media (max-width: 1199.98px) {
  .product-form-column .app-card {
    position: static;
    max-height: none;
    overflow: visible;
  }
  .product-form-column .product-form-actions-sticky { position: static; }
  .product-table-wrap { overflow-x: auto !important; }
  .product-table { min-width: 980px; }
}


.products-toolbar .products-filter-form {
  row-gap: .35rem !important;
  column-gap: .6rem !important;
}
.products-toolbar .filter-inline-block {
  white-space: nowrap;
}
.products-toolbar .compact-filter-select {
  min-width: 120px;
}


/* Dashboard groups/products header fix */
.products-responsive .product-table.products-table-wide {
  table-layout: auto !important;
  min-width: 1180px;
}
.products-responsive .product-table.products-table-wide th,
.products-responsive .product-table.products-table-wide td {
  white-space: nowrap !important;
  word-break: normal !important;
}
.products-responsive .product-table.products-table-wide th:nth-child(7),
.products-responsive .product-table.products-table-wide td:nth-child(7) {
  min-width: 120px;
}
.products-responsive .product-table.products-table-wide th:nth-child(8),
.products-responsive .product-table.products-table-wide td:nth-child(8) {
  min-width: 170px;
}
.products-responsive .product-table.products-table-wide .product-name-cell,
.products-responsive .product-table.products-table-wide .product-meta-cell {
  white-space: normal !important;
}


/* Statistics v2 */
.stats-tab-pills .btn { min-width: 92px; }
.stats-card-grid-six .app-card { min-height: 108px; }
@media (max-width: 991.98px) { .stats-card-grid-six .h4 { font-size: 1.3rem; } }


/* users page readability */
.users-table { table-layout: auto; }
.users-table th, .users-table td { white-space: nowrap; }
.users-table th:nth-child(1), .users-table td:nth-child(1) { min-width: 180px; }
.users-table th:nth-child(2), .users-table td:nth-child(2) { min-width: 110px; }
.users-table .user-email-cell { min-width: 250px; max-width: 360px; }
.users-table .user-email-text { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.users-table .badge { padding: .45rem .65rem !important; }
.users-table .role-select { min-width: 145px; }
.users-action-cell { min-width: 210px; }
.users-action-wrap { flex-wrap: nowrap !important; white-space: nowrap; }
.users-table th:nth-child(<?= 0 ?>) {}


/* products.php sticky form must stay below the top menu */
.navbar.sticky-top { z-index: 2000; }
.products-page { position: relative; z-index: 0; }
.product-form-column { position: relative; z-index: 1; }
.product-form-column .app-card {
  position: sticky;
  top: 118px !important;
  z-index: 1 !important;
  max-height: calc(100vh - 140px) !important;
}
.product-form-column .product-form-actions-sticky {
  z-index: 2;
}
@media (max-width: 991.98px) {
  .product-form-column .app-card {
    position: static !important;
    top: auto !important;
    max-height: none !important;
  }
}


/* ==== FIX: historia zmian - grupa bliżej produktu ==== */
body.page-history .product-table { table-layout: fixed; }
body.page-history .product-table th:nth-child(2),
body.page-history .product-table td:nth-child(2) { width: 15%; }
body.page-history .product-table th:nth-child(3),
body.page-history .product-table td:nth-child(3) { width: 19%; }
body.page-history .product-table th:nth-child(4),
body.page-history .product-table td:nth-child(4) { width: 14%; }

/* ==== FIX: statystyki - zbiorcza lista ruchów, grupa bliżej produktu ==== */
body.page-statistics .product-table { table-layout: fixed; }
body.page-statistics .product-table th:nth-child(2),
body.page-statistics .product-table td:nth-child(2) { width: 15%; }
body.page-statistics .product-table th:nth-child(3),
body.page-statistics .product-table td:nth-child(3) { width: 20%; }

.dashboard-side-col .app-card { padding: 1.1rem; }
.dashboard-side-col .request-card { padding: .8rem !important; }
.dashboard-side-col .h5 { font-size: 1rem; }
.inventory-toolbar .btn.btn-sm.rounded-pill,
.group-card .btn.btn-sm.rounded-pill { font-size: .8rem; padding: .38rem .72rem; }
.expired-badge, .low-stock-badge { font-size: .74rem; padding: .38rem .62rem !important; white-space: nowrap; }
.products-table-wide { min-width: 1110px; }
.products-responsive .product-table.products-table-wide th:nth-child(7),
.products-responsive .product-table.products-table-wide td:nth-child(7) { min-width: 98px; }
.products-responsive .product-table.products-table-wide th:nth-child(8),
.products-responsive .product-table.products-table-wide td:nth-child(8) { min-width: 120px; }


.restock-status-badge {
    background: #ffedd5;
    color: #c2410c;
    border: 1px solid #fdba74;
}

.expired-status-badge {
    background: #e0f2fe;
    color: #b91c1c;
    border: 1px solid #93c5fd;
}

.orders-table-wide { min-width: 0; width: 100%; }

.pagination .page-link {
    border: 1px solid var(--border);
    color: var(--text);
}

.pagination .page-item.active .page-link {
    background: linear-gradient(135deg, var(--primary), #38bdf8);
    border-color: transparent;
}


/* Login/footer positioning fix: keeps footer at bottom on tall screens. */
html { min-height: 100%; }
body { min-height: 100vh; display: flex; flex-direction: column; }
body > .container-fluid { flex: 1 0 auto; }
footer { flex-shrink: 0; }
