/**
 * BakeryERP Pro reusable component styles (cards, forms, buttons, tables,
 * badges, alerts, pagination, skeleton/overlay loading, notif dropdown) —
 * ported from medikcare's app.css component section.
 */

/* ── Toastr (CDN default is a fixed 300px box anchored 12px from the right,
   which overflows a narrow phone viewport once its close button's own
   overflow is accounted for) ──────────────────────────────────────────── */
@media (max-width: 420px) {
  #toast-container { width: calc(100vw - 24px); right: 12px !important; left: 12px !important; }
  #toast-container > div { width: 100% !important; box-sizing: border-box; }
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 1px 6px rgba(0,0,0,.06); border: 1px solid #e2e8f0; }
.stat-card { background: #fff; border-radius: 12px; padding: 16px; box-shadow: 0 1px 6px rgba(0,0,0,.05); border: 1px solid #e2e8f0; }
a.card:hover, .card-link:hover { box-shadow: 0 6px 24px rgba(0,0,0,.09); transform: translateY(-2px); }
a.card, .card-link { transition: box-shadow .15s, transform .15s; text-decoration: none; }
html.dark .card, html.dark .stat-card { background: #1e293b; border-color: #334155; color: #cbd5e1; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-label { display: block; font-size: .8125rem; font-weight: 600; color: #374151; margin-bottom: 5px; }
.form-control { display: block; width: 100%; border: 1.5px solid #e2e8f0; border-radius: 8px; padding: 9px 12px; font-size: .875rem; font-family: inherit; color: #1e293b; background: #fff; transition: border-color .12s; }
.form-control:focus { outline: none; border-color: var(--pr); }
select.form-control { appearance: auto; }
.form-hint { font-size: .75rem; color: #94a3b8; margin-top: 4px; }
.form-error { font-size: .75rem; color: #dc2626; margin-top: 4px; }
.form-control.is-invalid { border-color: #dc2626; }
textarea.form-control { resize: vertical; min-height: 90px; }
html.dark .form-control { background: #0f172a; border-color: #475569; color: #e2e8f0; }
html.dark .form-control:focus { border-color: #3b82f6; }
html.dark .form-label { color: #94a3b8; }

.password-field { position: relative; }
.password-field .form-control { padding-right: 40px; }
.password-toggle-btn { position: absolute; top: 0; right: 0; height: 100%; width: 40px; display: flex; align-items: center; justify-content: center; background: none; border: none; color: #94a3b8; cursor: pointer; padding: 0; }
.password-toggle-btn:hover { color: var(--pr); }
html.dark .password-toggle-btn:hover { color: #93c5fd; }

.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; inset: 0; cursor: pointer; background: #cbd5e1; transition: background .18s; border-radius: 999px; }
.switch-slider::before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; bottom: 3px; background: #fff; transition: transform .18s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .switch-slider { background: #059669; }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }
.switch input:focus-visible + .switch-slider { outline: 2px solid var(--or); outline-offset: 2px; }
.switch input:disabled + .switch-slider { opacity: .5; cursor: not-allowed; }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 18px; border-radius: 8px; font-size: .8125rem; font-weight: 600; cursor: pointer; border: none; transition: all .12s; text-decoration: none; white-space: nowrap; flex-shrink: 0; }
.btn-sm { padding: 6px 12px; font-size: .75rem; border-radius: 6px; }
.btn-xs { padding: 4px 10px; font-size: .7rem; border-radius: 6px; gap: 4px; }
.btn-primary { background: var(--pr); color: #fff; }
.btn-primary:hover { filter: brightness(.9); color: #fff; }
.btn-outline { background: #fff; color: #374151; border: 1.5px solid #e2e8f0; }
.btn-outline:hover { border-color: var(--pr); color: var(--pr); background: #f0f7ff; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-success { background: #059669; color: #fff; }
.btn-success:hover { background: #047857; color: #fff; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-warning:hover { background: #d97706; color: #fff; }
html.dark .btn-outline { background: #1e293b; color: #94a3b8; border-color: #475569; }
html.dark .btn-outline:hover { background: #334155; color: #93c5fd; border-color: #3b82f6; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.dtable { width: 100%; border-collapse: collapse; font-size: .8125rem; }
.dtable th { padding: 10px 12px; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #64748b; border-bottom: 2px solid #e2e8f0; white-space: nowrap; background: #f8fafc; }
.dtable td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; color: #374151; }
.dtable tr:hover td { background: #fafbff; }
.dtable tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.dtable th:last-child, .dtable td:last-child { padding-right: 16px; }
html.dark .dtable th { background: #253347; color: #94a3b8; border-color: #334155; }
html.dark .dtable td { border-color: #334155; color: #cbd5e1; }
html.dark .dtable tr:hover td { background: #253347; }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: .7rem; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #64748b; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-navy { background: #e0e7ff; color: #1e3a8a; }
html.dark .badge-gray { background: #334155; color: #94a3b8; }
html.dark .badge-info { background: #1e3a5f; color: #93c5fd; }
html.dark .badge-success { background: #14532d; color: #86efac; }
html.dark .badge-danger { background: #450a0a; color: #fca5a5; }
html.dark .badge-warning { background: #422006; color: #fde68a; }
html.dark .badge-orange { background: #431407; color: #fdba74; }
html.dark .badge-navy { background: #1e3a5f; color: #93c5fd; }

/* ── Balance/status row (POS payment balance, Journal Entry debit=credit check) ── */
.payment-balance-row { font-size: .9rem; font-weight: 700; padding: 4px 8px; border-radius: 6px; margin-top: 4px; }
.payment-balance-row.due { background: #fee2e2; color: #991b1b; }
.payment-balance-row.change { background: #dcfce7; color: #166534; }
.payment-balance-row.exact { background: #f1f5f9; color: #475569; }
html.dark .payment-balance-row.exact { background: #334155; color: #cbd5e1; }

/* ── Financial statements (Income Statement, Balance Sheet, Trial Balance, Cash Flow,
   Budget vs Actual) — styled to read like an exported accounting-software report:
   a formal letterhead-style header, tabular figures, and a proper subtotal/grand-total
   hierarchy instead of a generic app table. See views/accounting/income-statement.php
   for the canonical structure. */
.fin-card { padding: 36px 44px; }
.fin-statement { max-width: 880px; margin: 0 auto; }
.fin-header { text-align: center; margin-bottom: 28px; padding-bottom: 20px; border-bottom: 3px solid #1e293b; }
.fin-header .fin-company { font-size: 1.625rem; font-weight: 800; letter-spacing: .01em; }
.fin-header .fin-report-title { font-size: 1.0625rem; font-weight: 700; color: #475569; margin-top: 5px; text-transform: uppercase; letter-spacing: .06em; }
.fin-header .fin-period { font-size: .875rem; color: #94a3b8; margin-top: 4px; }
html.dark .fin-header { border-color: #cbd5e1; }
html.dark .fin-header .fin-report-title { color: #94a3b8; }

.fin-table { width: 100%; font-size: .9375rem; border-collapse: collapse; }
.fin-table td, .fin-table th { padding: 9px 6px; font-variant-numeric: tabular-nums; }
.fin-table td:last-child, .fin-table th:last-child { text-align: right; white-space: nowrap; }
.fin-section-label td { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #64748b; padding-top: 22px; }
html.dark .fin-section-label td { color: #94a3b8; }
.fin-line td:first-child { padding-left: 24px; color: #475569; }
html.dark .fin-line td:first-child { color: #cbd5e1; }
.fin-subtotal td { border-top: 1px solid #e2e8f0; font-weight: 700; padding-top: 11px; }
html.dark .fin-subtotal td { border-color: #334155; }
.fin-grandtotal td { border-top: 3px solid #1e293b; font-weight: 800; font-size: 1.125rem; padding-top: 14px; }
html.dark .fin-grandtotal td { border-color: #cbd5e1; }
.fin-code { font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; font-size: .875rem; color: #64748b; }
html.dark .fin-code { color: #94a3b8; }

@media (max-width: 640px) {
  .fin-card { padding: 20px; }
  .fin-header .fin-company { font-size: 1.25rem; }
}

@media print {
  .sidebar, .topbar, .filter-bar, .no-print, .sidebar-overlay { display: none !important; }
  .main-wrap { margin-left: 0 !important; }
  body { background: #fff !important; }
  .card { box-shadow: none !important; border: none !important; padding: 0 !important; }
  .fin-statement { max-width: none; }
}

/* ── Alerts / flash messages ───────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 8px; font-size: .875rem; font-weight: 500; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; border-left: 4px solid transparent; position: relative; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; border-left-color: #059669; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; border-left-color: #dc2626; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; border-left-color: #f59e0b; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; border-left-color: #3b82f6; }

/* ── Pagination ─────────────────────────────────────────────────────────── */
.pagi { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.pagi a { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px; padding: 0 10px; border-radius: 6px; font-size: .8125rem; font-weight: 500; color: #64748b; border: 1.5px solid #e2e8f0; text-decoration: none; transition: all .12s; }
.pagi a:hover { border-color: var(--pr); color: var(--pr); background: #eff6ff; }
.pagi a.current { background: var(--pr); color: #fff; border-color: var(--pr); font-weight: 700; pointer-events: none; }

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-state .icon { font-size: 2.5rem; color: #e2e8f0; display: block; margin-bottom: .75rem; }
.empty-state .title { font-weight: 700; color: #cbd5e1; font-size: 1rem; margin-bottom: .3rem; }
.empty-state p { color: #94a3b8; font-size: .875rem; margin: 0; }

/* ── Section header ─────────────────────────────────────────────────────── */
.section-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.25rem; gap: 12px; }
.section-header h2 { font-size: 1rem; font-weight: 700; color: #1e293b; }
.section-header p { font-size: .8125rem; color: #94a3b8; margin-top: 2px; }
html.dark .section-header h2, html.dark .section-header h3 { color: #e2e8f0; }
@media (max-width: 640px) {
  /* Below this width the title block and the action-button block (whatever the
     header's last child is — one button, several, or a small form) no longer fit
     side by side without squeezing the title into a narrow wrapped column — stack
     them instead, and let a multi-button action block wrap onto its own rows. */
  .section-header { flex-direction: column; align-items: stretch; }
  .section-header > *:last-child:not(:first-child) { display: flex; flex-wrap: wrap; gap: 8px; }
}

/* ── Notification dropdown ─────────────────────────────────────────────── */
.notif-dropdown { position: absolute; right: 0; top: 48px; width: 340px; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.12); z-index: 100; display: none; }
.notif-dropdown.show { display: block; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid #f1f5f9; cursor: pointer; transition: background .1s; }
.notif-item:hover { background: #f8fafc; }
.notif-item.unread { background: #eff6ff; }
.notif-item:last-child { border-bottom: 0; }
html.dark .notif-dropdown { background: #1e293b; border-color: #334155; }

/* ── Skeleton shimmer ───────────────────────────────────────────────────── */
.skeleton { background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%); background-size: 200% 100%; animation: berp-shimmer 1.4s infinite; border-radius: 6px; display: block; }
html.dark .skeleton { background: linear-gradient(90deg, #334155 25%, #475569 50%, #334155 75%); background-size: 200% 100%; }
@keyframes berp-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Full-page overlay loader ───────────────────────────────────────────── */
#page-overlay { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; background: rgba(15,23,42,.35); opacity: 0; visibility: hidden; transition: opacity .15s ease; }
#page-overlay.active { opacity: 1; visibility: visible; }
#page-overlay .spinner-ring { width: 52px; height: 52px; border: 4px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: berp-spin .7s linear infinite; }
@keyframes berp-spin { to { transform: rotate(360deg); } }

/* ── Search box ─────────────────────────────────────────────────────────── */
.search-box { background: #f8fafc; border: 1.5px solid #e2e8f0; border-radius: 8px; padding: 7px 12px; display: flex; align-items: center; gap: 8px; transition: border-color .12s, box-shadow .12s; }
.search-box:focus-within { border-color: var(--pr); background: #fff; box-shadow: 0 0 0 3px rgba(24,14,111,.07); }
.search-box input { background: transparent; border: none; outline: none; font-size: .8125rem; color: #374151; width: 148px; font-family: inherit; }
html.dark .search-box { background: #0f172a; border-color: #475569; }
html.dark .search-box input { background: transparent; color: #e2e8f0; }

/* ── Topbar branch badge — keeps the user posted which branch they're logged into ── */
.topbar-branch-badge { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 20px; padding: 5px 12px; }
.topbar-branch-badge i { font-size: .7rem; color: var(--pr); }
.topbar-branch-badge span { font-size: .75rem; font-weight: 700; color: var(--pr); white-space: nowrap; }
html.dark .topbar-branch-badge { background: #1e3a5f; border-color: #2c5282; }
html.dark .topbar-branch-badge i { color: #93c5fd; }
html.dark .topbar-branch-badge span { color: #93c5fd; }

/* ── Sub-nav (settings) ────────────────────────────────────────────────── */
.subnav { display: flex; flex-direction: column; gap: 2px; }
.subnav a { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: 8px; font-size: .8125rem; font-weight: 600; color: #475569; text-decoration: none; transition: all .12s; }
.subnav a:hover { background: #f1f5f9; color: var(--pr); }
.subnav a.active { background: #eff6ff; color: var(--pr); }
.subnav a i { width: 16px; text-align: center; font-size: .8rem; color: #94a3b8; }
.subnav a:hover i, .subnav a.active i { color: var(--pr); }
html.dark .subnav a { color: #94a3b8; }
html.dark .subnav a:hover { background: #334155; color: #93c5fd; }
html.dark .subnav a.active { background: #1e3a5f; color: #93c5fd; }

.subnav-toggle { display: none; width: 100%; align-items: center; justify-content: space-between; background: none; border: none; padding: 8px 10px; font-size: .875rem; font-weight: 700; color: #1e293b; cursor: pointer; }
.subnav-toggle-chevron { font-size: .7rem; color: #94a3b8; transition: transform .15s; }
html.dark .subnav-toggle { color: #e2e8f0; }
/* Below this width the settings sub-nav (14 items on desktop, a persistent left rail) would
   otherwise force every settings page to scroll past the whole menu before reaching the actual
   form — collapsed by default here, tap the toggle to expand. */
@media (max-width: 991px) {
  .subnav-toggle { display: flex; }
  .subnav { max-height: 0; overflow: hidden; }
  .card.subnav-open .subnav { max-height: 600px; overflow-y: auto; margin-top: 8px; }
  .card.subnav-open .subnav-toggle-chevron { transform: rotate(180deg); }
}

/* ── Filter bar (list-page search + dropdown filters) ─────────────────────
   Markup: <div class="filter-bar"><form method="get" class="filter-bar-row">
   ...fields..., a trailing <button class="btn btn-primary btn-sm"><i class="fa-solid
   fa-filter"></i> Filter</button>, and when any filter is active a
   <a class="filter-clear">Clear <n> filter(s)</a>. See views/branches/index.php
   for the canonical example. */
.filter-bar { background: #fff; border-radius: 12px; padding: 14px 16px; box-shadow: 0 1px 6px rgba(0,0,0,.06); border: 1px solid #e2e8f0; margin-bottom: 16px; }
html.dark .filter-bar { background: #1e293b; border-color: #334155; }
.filter-bar-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.filter-field { flex: 1 1 160px; min-width: 140px; }
.filter-field.filter-field-search { flex: 2 1 220px; }
.filter-field label { display: block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #94a3b8; margin-bottom: 4px; }
.filter-bar .search-box { width: 100%; }
.filter-bar .search-box input { width: 100%; }
.filter-clear { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 600; color: #94a3b8; text-decoration: none; padding: 8px 4px; white-space: nowrap; transition: color .12s; }
.filter-clear:hover { color: #dc2626; }
.filter-clear i { font-size: .7rem; }
.filter-count { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 20px; font-size: .7rem; font-weight: 700; background: var(--pr); color: #fff; margin-left: 6px; }
.results-meta { font-size: .8125rem; color: #94a3b8; margin: 0 0 10px 2px; }
@media (max-width: 640px) {
  .filter-field { flex: 1 1 100%; }
}
