/* MedGrid — uses Frappe Espresso base-theme variables
   Structural only: logo injection, sidebar header, logout button,
   help-hiding, admin guards. All colors come from Frappe's own CSS
   variables so the default Frappe look is preserved automatically.
*/

/* ── Hide Help / Support / Theme / Frappe branding ─────────── */
.dropdown-help  { display: none !important; }
.dropdown-theme { display: none !important; }

use[href="#icon-circle-question-mark"],
use[href="#icon-info"],
use[href="#icon-moon"],
use[href="#icon-support"] { display: none !important; }

a:has(use[href="#icon-info"]),
a:has(use[href="#icon-support"]),
a:has(use[href="#icon-moon"]),
li:has(use[href="#icon-info"]),
li:has(use[href="#icon-moon"]),
li:has(use[href="#icon-support"]) { display: none !important; }

.sidebar-header-menu .dropdown-item[data-name="help"],
.sidebar-header-menu li[data-name="help"] { display: none !important; }

/* Hide original Frappe sidebar header (replaced by custom MedGrid header) */
.sidebar-header { display: none !important; }

/* ── Custom MedGrid sidebar header (logo area) ──────────────── */
.custom-sidebar-header {
    background-color: var(--fg-color, #ffffff);
    border-bottom: 1px solid var(--border-color, #ededed);
    flex-shrink: 0;
    user-select: none;
    overflow: hidden;
}

.custom-sidebar-header .mg-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
}

.custom-sidebar-header .mg-sidebar-logo {
    height: 28px;
    width: auto;
    max-width: 130px;
    border-radius: 4px;
    object-fit: contain;
    flex-shrink: 0;
    display: block;
}

/* ── Collapsed sidebar: logo only, centered ──────────────────── */
.body-sidebar-container.closed .custom-sidebar-header .mg-sidebar-brand,
.body-sidebar-container:not(.expanded) .custom-sidebar-header .mg-sidebar-brand {
    justify-content: center;
    padding: 10px 8px;
    gap: 0;
}

.body-sidebar-container.closed .custom-sidebar-header .mg-sidebar-logo,
.body-sidebar-container:not(.expanded) .custom-sidebar-header .mg-sidebar-logo {
    max-width: 28px;
    margin: 0 auto;
}

/* ── Navbar: swap Frappe logo for MedGrid logo ──────────────── */
[data-medgrid=active] #brand-logo { display: none !important; }

[data-medgrid=active] .navbar-home {
    display: flex !important;
    align-items: center !important;
    padding: 0 !important;
}

[data-medgrid=active] .mg-navbar-brand-logo {
    height: 36px !important;
    width: auto !important;
    object-fit: contain !important;
    display: block !important;
    flex-shrink: 0 !important;
}

/* ── Custom user icon ───────────────────────────────────────── */
[data-medgrid=active] .navbar .mg-user-icon {
    width: 26px;
    height: 26px;
    object-fit: contain;
    vertical-align: middle;
    display: inline-block;
    border-radius: 50%;
}

[data-medgrid] .desktop-avatar {
    background-color: transparent !important;
    color: inherit !important;
}

/* ── Sidebar bottom: collapse link + user info ─────────────── */
/* Ensure the Frappe "Collapse" toggle is always rendered correctly */
.body-sidebar .body-sidebar-bottom {
    display: block !important;
    visibility: visible !important;
}

.body-sidebar .collapse-sidebar-link {
    display: flex !important;
    visibility: visible !important;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: var(--border-radius, 6px);
    color: var(--text-muted, var(--ink-gray-5, #6c757d));
    font-size: var(--text-sm, 13px);
    cursor: pointer;
    text-decoration: none !important;
    transition: background-color 0.2s;
}

.body-sidebar .collapse-sidebar-link:hover {
    background-color: var(--sidebar-hover-color, #f3f3f3);
    color: var(--text-color, var(--ink-gray-8, #1f272e));
}

.body-sidebar .collapse-sidebar-link span {
    display: inline !important;
    color: inherit;
}

/* Hide Frappe "Getting Started" onboarding — not used in MedGrid */
.body-sidebar .onboarding-sidebar { display: none !important; }

/* Ensure user info section renders correctly in expanded sidebar */
.body-sidebar-container.expanded .dropdown-navbar-user,
.body-sidebar .dropdown-navbar-user {
    display: block !important;
}

.body-sidebar .sidebar-user-button {
    display: flex !important;
    align-items: center;
    padding: var(--padding-sm, 8px);
    border-radius: var(--border-radius-sm, 4px);
    text-decoration: none !important;
    min-height: 40px;
}

.body-sidebar .sidebar-user-button:hover {
    background-color: var(--sidebar-hover-color, #f3f3f3);
}

.body-sidebar .avatar-name-email {
    margin-left: 8px;
    overflow: hidden;
    flex: 1;
}

.body-sidebar .avatar-name-email span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--text-sm, 13px);
}

/* Collapsed sidebar: hide text labels in bottom section */
.body-sidebar-container:not(.expanded) .collapse-sidebar-link span {
    display: none !important;
}

.body-sidebar-container:not(.expanded) .collapse-sidebar-link {
    justify-content: center;
    padding: 6px;
}

.body-sidebar-container:not(.expanded) .avatar-name-email {
    display: none !important;
}

.body-sidebar-container:not(.expanded) .sidebar-user-button {
    justify-content: center;
    padding: 8px;
}

/* ── Logout button ──────────────────────────────────────────── */
.mg-logout-container {
    margin-top: auto;
    border-top: 1px solid var(--border-color, #ededed);
    padding-top: 4px;
}

.mg-logout-item {
    border-radius: var(--border-radius, 6px);
    margin: 4px 8px;
    transition: background-color 0.2s;
}

.mg-logout-anchor {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    text-decoration: none !important;
    cursor: pointer;
    border-radius: var(--border-radius, 6px);
    width: 100%;
}

.mg-logout-icon {
    stroke: var(--red-600, #cc2929);
    fill: none;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.mg-logout-label {
    color: var(--red-600, #cc2929) !important;
    font-weight: 500;
    font-size: 13px;
}

.mg-logout-item:hover { background-color: var(--red-100, #fff0f0) !important; }
.mg-logout-item:hover .mg-logout-label { color: var(--red-700, #b52a2a) !important; }
.mg-logout-item:hover .mg-logout-icon  { stroke: var(--red-700, #b52a2a); }

/* Collapsed state: icon only */
.body-sidebar-container:not(.expanded) .mg-logout-label {
    display: none !important;
}
.body-sidebar-container:not(.expanded) .mg-logout-anchor {
    justify-content: center;
    padding: 8px;
}

/* ── Login page ─────────────────────────────────────────────── */
.page-card-head img { max-height: 115px !important; }

body[data-path="login"] nav.navbar  { display: none !important; }
body[data-path="login"] .page-card { margin-top: 120px !important; }

/* ── Website pages: keep navbar readable ────────────────────── */
body:not([data-spy]) .navbar:not(.navbar-expand),
.website-top-bar {
    background-color: #ffffff !important;
    border-bottom: 1px solid #e8eaf0 !important;
}

body:not([data-spy]) .navbar:not(.navbar-expand) .nav-link,
body:not([data-spy]) .navbar:not(.navbar-expand) .navbar-brand,
.website-top-bar .nav-link,
.website-top-bar .navbar-brand { color: #001540 !important; }

body:not([data-spy]) .navbar:not(.navbar-expand) .nav-link:hover,
.website-top-bar .nav-link:hover { color: #1A3A8F !important; }

/* ── Sidebar section-break labels: black text ─────────────── */
.section-item .section-break .sidebar-item-label {
    color: var(--text-color, #1f272e) !important;
    font-weight: 600;
}

/* ── Vendor: hide Assigned To & Share sections in right sidebar ── */
[data-medgrid-vendor=active] .form-sidebar .form-assignments,
[data-medgrid-vendor=active] .form-sidebar .form-shared { display: none !important; }

/* ── Vendor: hide ALL search (navbar + sidebar) ────────────── */
[data-medgrid-vendor=active] .search-bar,
[data-medgrid-vendor=active] .navbar-search-bar,
[data-medgrid-vendor=active] #navbar-modal-search,
[data-medgrid-vendor=active] .body-sidebar .sidebar-search,
[data-medgrid-vendor=active] .body-sidebar .sidebar-search-container,
[data-medgrid-vendor=active] .body-sidebar input[type="search"],
[data-medgrid-vendor=active] .body-sidebar .search-sidebar { display: none !important; }

/* ── Sales User: hide ALL search (navbar + sidebar + awesomebar) ── */
[data-medgrid-salesuser=active] .search-bar,
[data-medgrid-salesuser=active] .navbar-search-bar,
[data-medgrid-salesuser=active] #navbar-search,
[data-medgrid-salesuser=active] #navbar-modal-search,
[data-medgrid-salesuser=active] .navbar .search-bar,
[data-medgrid-salesuser=active] .navbar input[type="search"],
[data-medgrid-salesuser=active] .body-sidebar .sidebar-search,
[data-medgrid-salesuser=active] .body-sidebar .sidebar-search-container,
[data-medgrid-salesuser=active] .body-sidebar input[type="search"],
[data-medgrid-salesuser=active] .body-sidebar .search-sidebar { display: none !important; }

/* ── Medgrid Admin: hide system / developer UI ──────────────── */
[data-medgrid-admin=active] .dev-mode,
[data-medgrid-admin=active] #dev-mode-indicator,
[data-medgrid-admin=active] .dev-mode-indicator { display: none !important; }

[data-medgrid-admin=active] .custom-actions .btn-customize,
[data-medgrid-admin=active] [data-label="Customize"] { display: none !important; }

[data-medgrid-admin=active] .modules-section,
[data-medgrid-admin=active] .all-modules { display: none !important; }
