/* Afya Soft — professional pharmacy UI */
:root {
  --bg: #f0f4f8;
  --bg-card: #ffffff;
  --sidebar: #1a365d;
  --sidebar-hover: #2c5282;
  --sidebar-active: #2b6cb0;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #64748b;
  --accent: #2b6cb0;
  --accent-hover: #2c5282;
  --success: #276749;
  --success-bg: #c6f6d5;
  --warning: #b7791f;
  --warning-bg: #feebc8;
  --danger: #c53030;
  --danger-bg: #fed7d7;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(26, 54, 93, 0.08), 0 4px 12px rgba(26, 54, 93, 0.06);
  --shadow-sm: 0 1px 2px rgba(26, 54, 93, 0.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --topbar-h: 56px;
  --sidebar-w: 248px;
  --table-head-bg: #f8fafc;
  --menu-bg: #ffffff;
  --menu-hover: #f8fafc;
  --badge-inverse-bg: #1a202c;
  --badge-inverse-text: #ffffff;
  --surface-soft: #fafbfc;
  --surface-hover: #ffffff;
  --surface-info: #ebf8ff;
  --surface-ok: #e6fffa;
  --login-gradient: linear-gradient(160deg, #ebf4ff 0%, #f0f4f8 45%, #e6f0f9 100%);
  --info-text: #2c5282;
  --ok-text: #234e52;
}

:root[data-theme="dark"],
html.theme-dark {
  --bg: #0b1220;
  --bg-card: #111827;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #334155;
  --border: #1f2937;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --success: #4ade80;
  --success-bg: rgba(34, 197, 94, 0.15);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.2);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.2);
  --shadow: 0 1px 3px rgba(2, 6, 23, 0.6), 0 8px 20px rgba(2, 6, 23, 0.55);
  --shadow-sm: 0 1px 2px rgba(2, 6, 23, 0.55);
  --table-head-bg: #0f172a;
  --menu-bg: #0f172a;
  --menu-hover: #1f2937;
  --badge-inverse-bg: #e5e7eb;
  --badge-inverse-text: #111827;
  --surface-soft: #0f172a;
  --surface-hover: #1f2937;
  --surface-info: rgba(96, 165, 250, 0.14);
  --surface-ok: rgba(45, 212, 191, 0.16);
  --login-gradient: linear-gradient(160deg, #0b1220 0%, #0f172a 45%, #111827 100%);
  --info-text: #93c5fd;
  --ok-text: #99f6e4;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  transition: background 0.2s ease, color 0.2s ease;
}

html.theme-dark body {
  background: var(--bg);
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

.app-shell {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.sidebar-brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 8px;
}

.sidebar-brand-title {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: #fff;
  margin: 0;
}

.sidebar-brand-sub {
  font-size: 0.75rem;
  color: #94a3b8;
  margin: 0.2rem 0 0;
  font-weight: 500;
}

.sidebar-nav {
  padding: 0.75rem 0.5rem;
  flex: 1;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  color: #cbd5e1;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
  margin-bottom: 2px;
}

.nav-link svg {
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-link:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
}

.nav-link.active svg {
  opacity: 1;
}

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

.topbar {
  min-height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.topbar-page {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem 0.75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4299e1, #2b6cb0);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
}

.btn-logout {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-logout:hover {
  background: var(--bg);
  color: var(--text);
  border-color: #cbd5e1;
}

.content {
  padding: 1.5rem;
  flex: 1;
}

/* Cards & layout */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.grid-cards-split {
  grid-template-columns: 1fr 1fr;
  align-items: start;
}

@media (max-width: 768px) {
  .grid-cards-split {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 0.35rem;
}

.card-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin: 0;
}

.card-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin: 0.35rem 0 0;
}

.card-metric {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.card-metric-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-info);
  color: var(--accent);
}

.card-metric-icon.warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.card-metric-icon.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Chart */
.chart-card {
  margin-bottom: 1.5rem;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chart-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  height: 140px;
  padding-top: 0.5rem;
  min-width: min(100%, 520px);
}

.chart-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 140px;
  gap: 0.35rem;
  min-width: 0;
}

.chart-bar {
  width: 100%;
  max-width: 48px;
  background: linear-gradient(180deg, #63b3ed 0%, #2b6cb0 100%);
  border-radius: 6px 6px 4px 4px;
  min-height: 4px;
  transition: opacity 0.2s ease;
}

.chart-bar-wrap:hover .chart-bar {
  opacity: 0.88;
}

.chart-bar-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--table-head-bg);
}

.data-table tbody tr {
  transition: background 0.12s ease;
}

.data-table tbody tr:hover {
  background: var(--surface-soft);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.row-low {
  background: var(--warning-bg) !important;
}

.row-expired {
  background: var(--danger-bg) !important;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-low {
  background: var(--warning-bg);
  color: #9c4221;
}

.badge-ok {
  background: var(--surface-ok);
  color: var(--ok-text);
}

.badge-expiry-critical {
  background: var(--danger-bg);
  color: #9b2c2c;
}

.badge-expiry-warning {
  background: var(--warning-bg);
  color: #9c4221;
}

.badge-expiry-notice {
  background: var(--surface-info);
  color: var(--info-text);
}

.badge-expiry-expired {
  background: var(--badge-inverse-bg);
  color: var(--badge-inverse-text);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn-danger {
  background: #c53030;
  color: #fff;
}

.btn-danger:hover {
  background: #9b2c2c;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  padding: 0.35rem 0.65rem;
}

.btn-ghost:hover {
  background: #ebf8ff;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8125rem;
}

.date-cell {
  white-space: nowrap;
  line-height: 1.35;
}

.action-menu {
  position: relative;
  display: inline-block;
  text-align: left;
}

.action-menu-toggle {
  list-style: none;
  border: 1px solid var(--border);
  background: var(--menu-bg);
  color: var(--text);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.action-menu-toggle::-webkit-details-marker {
  display: none;
}

.action-menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 140px;
  z-index: 30;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--menu-bg);
  box-shadow: var(--shadow);
  padding: 0.3rem;
}

.action-menu-item {
  display: flex;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  font-size: 0.84rem;
  cursor: pointer;
}

.action-menu-item:hover {
  background: var(--menu-hover);
}

.action-menu-item-danger {
  color: var(--danger);
}

.action-popup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.action-popup-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
  cursor: pointer;
  padding: 0.45rem 0.65rem;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.action-popup-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.action-popup-btn-danger {
  color: #9b2c2c;
  border-color: #feb2b2;
  background: #fff5f5;
}

.action-popup-btn-danger:hover {
  background: #fed7d7;
}

#actions-dialog .modal-dialog-inner {
  min-width: min(92vw, 420px);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

/* Forms */
.input {
  width: 100%;
  max-width: 320px;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.15);
}

.input.select {
  max-width: 100%;
  cursor: pointer;
}

.form-row {
  margin-bottom: 1rem;
}

.form-row label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.form-card {
  max-width: 520px;
  padding: 1.5rem;
}

.errorlist {
  list-style: none;
  padding: 0;
  margin: 0.25rem 0 0;
  font-size: 0.8125rem;
  color: var(--danger);
}

/* Messages */
.messages {
  margin-bottom: 1rem;
}

.message {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
}

.message-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #9ae6b4;
}

.message-error {
  background: var(--danger-bg);
  color: #9b2c2c;
  border: 1px solid #fc8181;
}

.message-info {
  background: var(--surface-info);
  color: var(--info-text);
  border: 1px solid #90cdf4;
}

/* POS layout */
.pos-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.25rem;
  align-items: start;
}

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

.pos-panel {
  padding: 1.25rem;
}

.pos-search {
  width: 100%;
  max-width: none;
  margin-bottom: 1rem;
}

.medicine-list {
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.medicine-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: 0.75rem;
  transition: background 0.12s ease;
}

.medicine-item:last-child {
  border-bottom: none;
}

.medicine-item:hover {
  background: var(--surface-hover);
}

.medicine-item-info strong {
  display: block;
  font-size: 0.9rem;
}

.medicine-item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.cart-panel {
  position: sticky;
  top: calc(var(--topbar-h) + 1rem);
}

.cart-lines {
  max-height: 280px;
  overflow-y: auto;
  margin: 1rem 0;
  font-size: 0.875rem;
}

.cart-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  gap: 0.5rem;
}

.cart-line:last-child {
  border-bottom: none;
}

.cart-total {
  font-size: 1.25rem;
  font-weight: 700;
  padding-top: 0.75rem;
  border-top: 2px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  line-height: 1;
  transition: background 0.12s ease;
}

.qty-btn:hover {
  background: var(--bg);
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--login-gradient);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 2rem;
}

.login-brand {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-brand-logo {
  width: 120px;
  height: auto;
  object-fit: contain;
  margin-bottom: 0.35rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--sidebar);
  letter-spacing: -0.03em;
}

.login-brand p {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.login-form .form-row .input {
  max-width: none;
}

/* Receipt */
.receipt {
  max-width: 400px;
  margin: 0 auto;
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.receipt-header {
  text-align: center;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

.receipt-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

@media print {
  .sidebar,
  .topbar,
  .receipt-actions,
  .messages {
    display: none !important;
  }

  .main-wrap {
    margin-left: 0;
  }

  .content {
    padding: 0;
  }

  .receipt {
    border: none;
    box-shadow: none;
  }
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.modal-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: 420px;
  background: var(--bg-card);
  box-shadow: var(--shadow);
}

.modal-dialog::backdrop {
  background: rgba(26, 54, 93, 0.35);
  backdrop-filter: blur(2px);
}

.modal-dialog-inner {
  padding: 1.5rem;
}

.modal-dialog-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

.link-muted {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.link-muted:hover {
  color: var(--accent);
}

/* —— Mobile: drawer sidebar, bottom nav, touch —— */
.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.sidebar-toggle:hover {
  background: var(--bg);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 54, 93, 0.4);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.sidebar-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.touch-target {
  min-height: 44px;
  min-width: 44px;
}

.btn.btn-sm.touch-target,
.btn-ghost.btn-sm.touch-target {
  min-height: 40px;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.btn-checkout {
  min-height: 48px;
  font-size: 1rem;
}

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 6px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  justify-content: space-around;
  align-items: stretch;
  gap: 2px;
  box-shadow: 0 -4px 20px rgba(26, 54, 93, 0.08);
}

.bottom-nav-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.bottom-nav-icon {
  opacity: 0.9;
  width: 1.3rem;
  height: 1.3rem;
  flex-shrink: 0;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.bottom-nav-link:hover,
.bottom-nav-link.active {
  color: var(--accent);
  background: #ebf8ff;
}

.bottom-nav-link:hover .bottom-nav-icon,
.bottom-nav-link.active .bottom-nav-icon {
  opacity: 1;
  transform: translateY(-1px);
}

.offline-banner {
  margin: 0 1rem;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  background: #fffbeb;
  border: 1px solid #fbd38d;
  color: #9c4221;
}

.offline-banner.is-hidden {
  display: none;
}

.offline-banner.is-offline {
  display: block;
}

.offline-banner.is-queued {
  background: #ebf8ff;
  border-color: #90cdf4;
  color: #2c5282;
}

.sync-toast {
  margin: 0.5rem 1rem 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  background: var(--danger-bg);
  color: #9b2c2c;
  border-radius: 8px;
}

.pending-sync-badge {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
}

.pending-sync-badge.is-visible {
  display: inline-flex;
}

.role-pill {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: #ebf8ff;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  display: none;
}

.whatsapp-contact-fab {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #25d366;
  color: #ffffff;
  border-radius: 999px;
  padding: 0.6rem 0.85rem;
  font-size: 0.8125rem;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(18, 140, 78, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.whatsapp-contact-fab:hover {
  color: #ffffff;
  background: #1ebe5d;
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(18, 140, 78, 0.34);
}

.offline-receipt-card {
  margin-top: 1.25rem;
  padding: 1.25rem;
}

body.drawer-open {
  overflow: hidden;
}

@media (max-width: 899px) {
  /* Sidebar is off-canvas; main area must use full viewport width */
  .main-wrap {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
  }

  .app-shell {
    overflow-x: hidden;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .sidebar-backdrop {
    display: block;
  }

  .role-pill {
    display: inline-block;
  }

  .whatsapp-contact-fab {
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
    padding: 0.55rem 0.75rem;
    font-size: 0.75rem;
  }

  .user-name-text {
    display: none;
  }

  .topbar-user {
    gap: 0.35rem 0.5rem;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.12);
    width: min(var(--sidebar-w), 88vw);
    max-width: 300px;
  }

  .sidebar.sidebar--open {
    transform: translateX(0);
  }

  .bottom-nav {
    display: flex;
  }

  .content {
    padding: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    max-width: 100%;
    box-sizing: border-box;
  }

  .topbar {
    padding: 0.5rem max(0.5rem, env(safe-area-inset-left)) 0.5rem
      max(0.5rem, env(safe-area-inset-right));
  }

  .topbar-page {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
  }

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

  .input {
    max-width: none;
  }

  .form-card {
    max-width: none;
  }

  .medicine-list {
    max-height: min(50vh, 360px);
  }

  .cart-panel {
    position: relative;
    top: auto;
  }

  .data-table {
    font-size: 0.8125rem;
  }

  .data-table th,
  .data-table td {
    padding: 0.6rem 0.65rem;
  }

  .table-wrap {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .offline-banner {
    margin-left: max(0.75rem, env(safe-area-inset-left));
    margin-right: max(0.75rem, env(safe-area-inset-right));
  }

  .receipt {
    max-width: 100%;
    margin: 0;
  }
}

@media (max-width: 599px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .btn {
    margin-left: 0 !important;
    width: 100%;
    justify-content: center;
  }

  .toolbar form {
    width: 100%;
  }

  .toolbar .input {
    max-width: none;
    width: 100%;
  }

  .medicine-item {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .medicine-item .btn {
    width: 100%;
    justify-content: center;
  }

  .cart-line {
    flex-direction: column;
    align-items: flex-start;
  }

  .qty-control {
    align-self: flex-end;
  }

  .date-cell {
    white-space: normal;
  }

  .btn-logout {
    padding: 0.35rem 0.55rem;
    font-size: 0.75rem;
  }

  .action-popup-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 900px) {
  .bottom-nav {
    display: none !important;
  }
}

@media print {
  .bottom-nav,
  .sidebar-toggle,
  .sidebar-backdrop,
  .offline-banner,
  .pending-sync-badge,
  .role-pill {
    display: none !important;
  }
}
