/*
 * Theme layer on top of Bootstrap 5.3. Bootstrap's distributed CSS is
 * precompiled from Sass, so hover/focus/active shades are baked in as fixed
 * colors — overriding the global --bs-primary variable alone would leave
 * hover states showing default Bootstrap blue. Bootstrap 5.3 exposes
 * per-component custom properties (e.g. --bs-btn-hover-bg) specifically so
 * themes can override them without a Sass rebuild — that's what this file
 * relies on, plus a handful of plain property overrides where that's not
 * available (pagination, links).
 */

:root {
    /* ---------- Brand palette ----------
       Taken from the Skinnique logo (public/images/logo.png): plum is the logo's main colour, rose gold
       its petal gradient. Plum carries every primary action; rose gold is only an accent (thin lines,
       the active-menu marker) — as text it's too light, so --brand-accent-text is a darker shade of it. */
    --brand-primary: #531D4E;        /* logo plum */
    --brand-primary-dark: #3E1239;   /* hover / pressed */
    --brand-primary-light: #F3ECF3;  /* tints: selected rows, soft badges, today in the calendar */
    --brand-primary-rgb: 83, 29, 78;
    --brand-accent: #C28F8B;         /* logo rose gold (mid petal) */
    --brand-accent-text: #8E5A55;    /* rose gold dark enough for small text (5.6:1 on white) */
    --brand-accent-light: #F6ECEA;
    --text-color: #2B1A29;           /* warm near-black instead of slate */
    --text-muted: #6B5A69;
    --sidebar-bg: #2B1029;           /* deep plum */
    --sidebar-bg-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(194, 143, 139, 0.18);
    --body-bg: #F7F5F7;              /* the logo's own off-white, with a hint of plum */
    --border-color: #ECE6EB;

    /* Bootstrap's own variables, so utilities (text-primary, bg-primary, links, focus rings, subtle
       backgrounds) follow the brand too. */
    --bs-primary: var(--brand-primary);
    --bs-primary-rgb: var(--brand-primary-rgb);
    --bs-primary-text-emphasis: var(--brand-primary-dark);
    --bs-primary-bg-subtle: var(--brand-primary-light);
    --bs-primary-border-subtle: #DCC8DA;
    --bs-link-color: var(--brand-primary);
    --bs-link-color-rgb: var(--brand-primary-rgb);
    --bs-link-hover-color: var(--brand-primary-dark);
    --bs-link-hover-color-rgb: 62, 18, 57;
    --bs-focus-ring-color: rgba(var(--brand-primary-rgb), 0.25);
    --bs-body-color: var(--text-color);
    --bs-secondary-color: rgba(43, 26, 41, 0.7);   /* .text-muted etc.: warm plum-grey, not slate */

    /* ---------- Functional icon palette ----------
       One fixed colour per action/metric so an icon reads before its label or
       tooltip does. Used by .btn-icon-* (table action buttons), .icon-wrap-*
       (dashboard tiles) and .nav-icon-* (sidebar) below. */
    --icon-view: #2563eb;
    --icon-view-bg: #eff6ff;
    --icon-edit: #d97706;
    --icon-edit-bg: #fffbeb;
    --icon-delete: #dc2626;
    --icon-delete-bg: #fef2f2;
    --icon-download: #7c3aed;
    --icon-download-bg: #f5f3ff;
    --icon-key: #4f46e5;
    --icon-key-bg: #eef2ff;
    --icon-activate: #16a34a;
    --icon-activate-bg: #f0fdf4;
    --icon-deactivate: #64748b;
    --icon-deactivate-bg: #f8fafc;
    /* INV-03: nearing-expiry warning tier (the already-expired tier reuses --icon-delete). */
    --icon-warning: #d97706;
}

body {
    font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--body-bg);
    color: var(--text-color);
}

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

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

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

/* ---------- Bootstrap component re-theming ---------- */

.btn-primary {
    --bs-btn-bg: var(--brand-primary);
    --bs-btn-border-color: var(--brand-primary);
    --bs-btn-hover-bg: var(--brand-primary-dark);
    --bs-btn-hover-border-color: var(--brand-primary-dark);
    --bs-btn-active-bg: var(--brand-primary-dark);
    --bs-btn-active-border-color: var(--brand-primary-dark);
    --bs-btn-focus-shadow-rgb: var(--brand-primary-rgb);
    --bs-btn-disabled-bg: var(--brand-primary);
    --bs-btn-disabled-border-color: var(--brand-primary);
}

.btn-outline-primary {
    --bs-btn-color: var(--brand-primary);
    --bs-btn-border-color: var(--brand-primary);
    --bs-btn-hover-bg: var(--brand-primary);
    --bs-btn-hover-border-color: var(--brand-primary);
    --bs-btn-active-bg: var(--brand-primary);
    --bs-btn-active-border-color: var(--brand-primary);
    --bs-btn-focus-shadow-rgb: var(--brand-primary-rgb);
    --bs-btn-disabled-color: var(--brand-primary);
    --bs-btn-disabled-border-color: var(--brand-primary);
}

.btn-link {
    --bs-btn-color: var(--brand-primary);
    --bs-btn-hover-color: var(--brand-primary-dark);
    --bs-btn-active-color: var(--brand-primary-dark);
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--brand-primary-rgb), 0.15);
}

.form-check-input:checked {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
}

/* The switch knob turns Bootstrap-blue while focused; make it a light plum instead. */
.form-switch .form-check-input:focus:not(:checked) {
    --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23B98FB4'/%3e%3c/svg%3e");
}

.dropdown-menu {
    --bs-dropdown-link-active-bg: var(--brand-primary);
}

.page-link {
    color: var(--brand-primary);
}

.page-link:hover {
    color: var(--brand-primary-dark);
}

.page-item.active .page-link {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
}

.nav-tabs .nav-link.active {
    border-bottom: 2px solid var(--brand-primary);
}

/* ---------- Auth pages (login, forced password change) ---------- */

/* Deep plum through the logo plum to rose gold, the same journey as the logo's lotus petals. */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--sidebar-bg) 0%, var(--brand-primary) 55%, var(--brand-accent-text) 100%);
    padding: 16px;
}

.auth-card {
    max-width: 400px;
    width: 100%;
    border-radius: 0.75rem;
    border-top: 4px solid var(--brand-accent) !important;
}

.auth-logo {
    display: block;
    width: 180px;
    max-width: 70%;
    height: auto;
    margin: 0 auto 12px;
}

.auth-card .brand-mark {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--brand-primary-light);
    color: var(--brand-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin: 0 auto 16px;
}

/* Show/hide password button. Edge ships its own reveal eye; hide it so a field never has two. */
.password-group input::-ms-reveal,
.password-group input::-ms-clear {
    display: none;
}

.password-toggle {
    min-width: 2.75rem; /* 44px touch target */
    border-color: var(--bs-border-color);
    color: var(--bs-secondary-color);
}

.password-toggle:hover {
    color: var(--bs-body-color);
    background: var(--bs-tertiary-bg);
    border-color: var(--bs-border-color);
}

.password-toggle[aria-pressed="true"] {
    color: var(--brand-primary);
}

.password-toggle:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
    z-index: 5; /* keep the ring above the input's border */
}

/* ---------- App shell ---------- */

.app-topbar {
    height: 60px;
    border-bottom-color: var(--border-color) !important;
    box-shadow: inset 0 -2px 0 var(--brand-accent-light);
}

.app-brand-logo {
    height: 40px;
    width: auto;
    display: block;
}

/* "Clinic Management System" next to the logo, separated by a thin rose-gold rule. */
.app-brand-name {
    border-left: 1px solid var(--brand-accent);
    padding-left: 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1.2;
}

.app-layout {
    padding-top: 60px;
}

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    position: fixed;
    top: 60px;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    z-index: 15;
}

.sidebar .nav-link,
.offcanvas .nav-link {
    color: rgba(255, 255, 255, 0.65);
    border-radius: 0;
    border-left: 3px solid transparent;
    padding: 0.7rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.92rem;
    transition: background 150ms ease, color 150ms ease;
}

.sidebar .nav-link i,
.offcanvas .nav-link i {
    width: 18px;
    text-align: center;
}

/* Each nav item keeps its own colour at rest, so the menu reads as a set of
   distinct destinations rather than one uniform grey list; it brightens
   slightly on hover/active to match the link's own state change. */
.sidebar .nav-link .nav-icon,
.offcanvas .nav-link .nav-icon {
    opacity: 0.85;
    transition: opacity 150ms ease;
}

.sidebar .nav-link:hover .nav-icon,
.sidebar .nav-link.active .nav-icon,
.offcanvas .nav-link:hover .nav-icon,
.offcanvas .nav-link.active .nav-icon {
    opacity: 1;
}

/* Still one distinct colour per menu, but soft tones that sit on the plum sidebar instead of neon. */
.nav-icon-dashboard { color: #9CC9E8; }
.nav-icon-users { color: #D7B8E6; }
.nav-icon-patients { color: #9FD8C4; }
.nav-icon-appointments { color: #E8C77A; }
.nav-icon-consultations { color: #F4A6BD; }
.nav-icon-billing { color: #E2B3AC; }
.nav-icon-inventory { color: #F2B48C; }
.nav-icon-expenses { color: #C5D99A; }
.nav-icon-masters { color: #B8C4E8; }
.nav-icon-settings { color: #BFB3BD; }

/* ---------- Menu Role Management (User Management > Roles & Permissions) ---------- */

.role-card {
    border: 1px solid var(--bs-border-color);
    transition: border-color .15s, box-shadow .15s;
}

.role-card:hover {
    border-color: var(--brand-primary);
}

.role-card-active {
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 2px var(--brand-primary-light);
}

.role-card-icon {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-primary-light);
    color: var(--brand-primary);
    font-size: 1.1rem;
}

.perm-table .perm-col {
    width: 88px;
}

.perm-table .perm-page-icon {
    width: 16px;
}

.perm-table .form-switch .form-check-input {
    width: 2.4em;
    height: 1.3em;
    cursor: pointer;
    float: none;
}

.perm-table .form-check-input:disabled {
    cursor: not-allowed;
}

.perm-lock {
    position: absolute;
    right: -14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: .7rem;
    color: var(--bs-secondary-color);
}

/* A cell changed since the last save. */
.perm-cell.perm-unsaved {
    background: #fff8e1;
    box-shadow: inset 0 -2px 0 #f59e0b;
}

.perm-savebar {
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
    padding: .6rem .9rem;
    box-shadow: 0 -4px 12px rgba(43, 16, 41, .06);
    margin-bottom: 1rem;
}

.perm-savebar-dirty {
    border-color: #f59e0b;
}

/* Extra Access page: a permission the user already gets from their role. */
.access-from-role {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    background: #e7f7ee;
    color: #16a34a;
    font-size: .75rem;
}

.access-legend-role {
    display: inline-block;
    width: .8rem;
    height: .8rem;
    border-radius: 50%;
    background: #e7f7ee;
    border: 1px solid #16a34a;
    vertical-align: -1px;
}

@media (min-width: 1200px) {
    .perm-side {
        position: sticky;
        top: 80px;
    }
}

/* Company logos: a small fixed rectangle each, side by side, image kept to its own shape.
   Used on the invoice screen and as the preview on Settings > Company Profile. */
.company-logos {
    display: flex;
    align-items: center;
    gap: 8px;
}

.company-logo {
    width: 120px;
    height: 48px;
    object-fit: contain;
    object-position: left center;
}

/* Invoice header: Logo 1 hugs the left edge, Logo 2 the right. */
.invoice-logos {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.company-logo-end {
    object-position: right center;
}

/* Invoice screen: Logo 1 is the clinic's main logo, so it gets a larger box than Logo 2. */
.invoice-doc .company-logo-main {
    width: 240px;
    height: 104px;
}

/* Invoice screen / print view: a smaller type scale so a bill fits on one printed page. Bootstrap's
   .small / badges are relative (em), so they shrink along with it. */
.invoice-doc {
    font-size: 0.8125rem;
}

.invoice-doc .h4 {
    font-size: 1.2rem;
}

.invoice-doc .fs-4 {
    font-size: 1.1rem !important;
}

.invoice-doc .fs-5 {
    font-size: 0.95rem !important;
}

.invoice-doc .table,
.invoice-doc .list-group {
    font-size: inherit;
}

.invoice-doc .list-group-item {
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
}

.invoice-terms {
    border-top: 1px solid var(--border-color);
}

.logo-slot {
    width: 160px;
    height: 64px;
    border: 1px dashed var(--bs-border-color);
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bs-tertiary-bg);
    overflow: hidden;
}

.logo-slot img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

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

/* Rose-gold marker on the active menu: plum on the plum sidebar wouldn't show. */
.sidebar .nav-link.active,
.offcanvas .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
    border-left-color: var(--brand-accent);
}

/* Mobile menu: same plum as the desktop sidebar, with the logo on a light strip at the top. */
.app-offcanvas {
    background: var(--sidebar-bg);
    color: #fff;
}

.app-offcanvas .offcanvas-header {
    background: #fff;
    border-bottom: 2px solid var(--brand-accent-light);
}

.content {
    margin-left: 240px;
    padding: 1.75rem;
}

@media (max-width: 991.98px) {
    .content {
        margin-left: 0;
    }
}

/* ---------- Cards & stat tiles ---------- */

.card {
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(43, 16, 41, 0.05);
}

.stat-card .icon-wrap {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--brand-primary-light);
    color: var(--brand-primary);
    font-size: 1.15rem;
    flex-shrink: 0;
}

/* Thematic tints for stat tiles and other icon-wrap badges outside the
   sidebar, so each metric/card is recognisable by colour, not just label. */
.icon-wrap-blue { background: #eff6ff; color: #2563eb; }
.icon-wrap-amber { background: #fffbeb; color: #d97706; }
.icon-wrap-violet { background: #f5f3ff; color: #7c3aed; }
.icon-wrap-green { background: #f0fdf4; color: #16a34a; }
.icon-wrap-red { background: #fef2f2; color: #dc2626; }
.icon-wrap-cyan { background: #ecfeff; color: #0891b2; }

/* INV-03: near-expiry / expired flag on the Inventory Items table. */
.text-icon-warning { color: var(--icon-warning); }
.text-icon-critical { color: var(--icon-delete); }

/* Two tiles per row on a phone leaves ~150px each: smaller icon and padding so labels like "Appointments" fit. */
@media (max-width: 575.98px) {
    .stat-card .card-body {
        padding: 0.75rem;
        gap: 0.6rem !important;
    }

    .stat-card .icon-wrap {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }
}

/* Every modal here wraps modal-header/-body/-footer in a single <form> (one
   submit target, no split-state between "form" and "modal"). Bootstrap's
   .modal-content is a flex column that expects those three to be its direct
   children — with .modal-dialog-scrollable, only .modal-body scrolls and the
   header/footer stay pinned. A <form> in between becomes the flex child
   instead, so that sizing never applies and long forms (Patients) push the
   footer/submit button off-screen with no way to reach it. display:contents
   removes the <form> from layout while keeping it functional, so its children
   act as .modal-content's direct flex items again. */
.modal-content > form {
    display: contents;
}

.table-wrap {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
}

table.dataTable {
    width: 100% !important;
}

/* ---------- Data table typography ----------
   A dedicated, compact type scale for tabular data: a smaller size and a
   tighter line-height keep dense grids scannable on one screen, headers get
   a light uppercase treatment to separate them from rows, and numeric
   columns get tabular figures so amounts line up down the column. */
.table-wrap table {
    font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 0.8125rem;
    line-height: 1.35;
}

.table-wrap table thead th {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
    border-bottom-width: 1px;
}

.table-wrap table tbody td,
.table-wrap table tbody th {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.table-wrap table td.text-end,
.table-wrap table th.text-end {
    font-variant-numeric: tabular-nums;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_paginate {
    font-size: 0.8125rem;
}

/* ---------- Data-table action icon buttons ----------
   Flat, colour-coded icon buttons replace the old uniform grey outline
   buttons so the action itself (view/edit/delete/download/...) is
   recognisable at a glance, before the tooltip is even read. Colours come
   from the palette defined on :root. */
.btn-icon {
    --icon-color: var(--brand-primary);
    --icon-color-bg: var(--brand-primary-light);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--icon-color);
    font-size: 0.85rem;
    line-height: 1;
    transition: background-color 120ms ease, color 120ms ease;
}

.btn-icon:hover,
.btn-icon:focus {
    color: var(--icon-color);
    background: var(--icon-color-bg);
}

.btn-icon:disabled,
.btn-icon.disabled {
    opacity: 0.4;
}

.btn-icon + .btn-icon {
    margin-left: 2px;
}

.btn-icon-view { --icon-color: var(--icon-view); --icon-color-bg: var(--icon-view-bg); }
.btn-icon-edit { --icon-color: var(--icon-edit); --icon-color-bg: var(--icon-edit-bg); }
.btn-icon-delete { --icon-color: var(--icon-delete); --icon-color-bg: var(--icon-delete-bg); }
.btn-icon-download { --icon-color: var(--icon-download); --icon-color-bg: var(--icon-download-bg); }
.btn-icon-key { --icon-color: var(--icon-key); --icon-color-bg: var(--icon-key-bg); }
.btn-icon-activate { --icon-color: var(--icon-activate); --icon-color-bg: var(--icon-activate-bg); }
.btn-icon-deactivate { --icon-color: var(--icon-deactivate); --icon-color-bg: var(--icon-deactivate-bg); }

/* ---------- Soft badges ----------
   Bootstrap's default badges are solid-fill; a soft/tinted badge reads more
   like a status chip in a professional admin panel, so we add a few. */

.badge-soft-primary { background: var(--brand-primary-light); color: var(--brand-primary); }
.badge-soft-success { background: #e7f7ee; color: #16a34a; }
.badge-soft-secondary { background: #f1f3f5; color: #6b7280; }
.badge-soft-purple { background: #f1eefc; color: #6d28d9; }
.badge-soft-warning { background: #fef6e7; color: #b45309; }
.badge-soft-danger { background: #fdecec; color: #dc2626; }

/* ---------- Calendar (Appointments module) ---------- */

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
}

/* FullCalendar's default toolbar buttons are plain Bootstrap-esque but unthemed;
   these overrides just bring them in line with the app's primary color. */
/* FullCalendar's own theme variables (disabled "today" button, today highlight, borders). */
.fc {
    --fc-button-bg-color: var(--brand-primary);
    --fc-button-border-color: var(--brand-primary);
    --fc-button-hover-bg-color: var(--brand-primary-dark);
    --fc-button-hover-border-color: var(--brand-primary-dark);
    --fc-button-active-bg-color: var(--brand-primary-dark);
    --fc-button-active-border-color: var(--brand-primary-dark);
    --fc-today-bg-color: var(--brand-primary-light);
    --fc-border-color: var(--border-color);
}

/* Day numbers and weekday headers are links (they open that day), but shouldn't look like body links. */
.fc .fc-daygrid-day-number,
.fc .fc-col-header-cell-cushion {
    color: var(--text-color);
    text-decoration: none;
}

.fc .fc-daygrid-day-number:hover,
.fc .fc-col-header-cell-cushion:hover {
    color: var(--brand-primary);
}

.fc .fc-button-primary {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
}

.fc .fc-button-primary:hover {
    background-color: var(--brand-primary-dark);
    border-color: var(--brand-primary-dark);
}

.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
    background-color: var(--brand-primary-dark);
    border-color: var(--brand-primary-dark);
}

.fc .fc-daygrid-day.fc-day-today,
.fc .fc-timegrid-col.fc-day-today {
    background-color: var(--brand-primary-light);
}

.fc-event {
    cursor: pointer;
    border: none;
}

/* ---------- Printing an invoice (BILL-07) ----------
   Only the invoice card should reach the paper: no top bar, sidebar or action buttons. */

@media print {
    .app-topbar,
    .sidebar,
    .offcanvas,
    .toast-container,
    .no-print {
        display: none !important;
    }

    .app-layout {
        padding-top: 0;
    }

    .content {
        margin-left: 0;
        padding: 0;
    }

    body {
        background: #fff;
    }

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

    /* The patient name links to their profile on screen; on paper it's just text. */
    .invoice-doc a {
        color: inherit;
        text-decoration: none;
    }
}

/* ---------- Consultation queue (CLN-02 "now serving" indicator) ---------- */

.now-serving-pulse {
    animation: now-serving-pulse 1.6s ease-in-out infinite;
}

@keyframes now-serving-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}
