/* ============================================================
   CRM SKIN  —  Ninatrans design-system token source
   ------------------------------------------------------------
   Ports the ninatrans-crm design language onto FMS components.
   Component rules are activated by the `crm-skin` class, which
   now lives on <body> so modals, dropdowns and toasts inherit it.

   TOKEN CONVENTION (§2 of documentation/NINATRANS_UI_RULES.md):
   colours are stored as BARE HSL COMPONENTS and must always be
   wrapped: `hsl(var(--primary))`, `hsl(var(--primary) / 0.08)`.
   `ninatrans-theme.css` re-tunes the same tokens and loads last.

   The few tokens below the "resolved colour aliases" heading are
   the exception: they are consumed as finished colours from
   outside this file (templates, base.html) and stay wrappable-free.
   ============================================================ */

:root {
    /* ---- Brand ------------------------------------------------ */
    --primary: 343 94% 34%;              /* #AB0534 */
    --primary-dark: 342 94% 27%;         /* #85042A */
    --primary-light: 343 90% 88%;
    --primary-foreground: 0 0% 100%;
    --ring: 343 94% 34%;

    /* ---- Surfaces & text -------------------------------------- */
    --background: 0 0% 100%;
    --card: 0 0% 100%;
    --foreground: 240 6% 10%;            /* #18181B */
    --card-border: 240 6% 90%;           /* #E4E4E7 */
    --border: 240 6% 90%;
    --secondary: 240 5% 96%;             /* #F4F4F5 */
    --muted: 240 5% 96%;
    --muted-foreground: 240 4% 46%;      /* #71717A */

    /* ---- Status ----------------------------------------------- */
    --success: 142 71% 45%;
    --success-light: 142 76% 90%;
    --warning: 45 93% 47%;
    --warning-light: 45 93% 90%;
    --danger: 0 84% 60%;
    --danger-light: 0 84% 95%;
    --info: 217 91% 60%;
    --info-light: 217 91% 90%;

    /* ---- Shape & elevation ------------------------------------ */
    --radius: 0.5rem;
    --shadow-card: 0 1px 3px hsl(240 5% 0% / 0.06);
    /* Overlays (dropdowns, search results) reuse the card shadow — §7 forbids
       introducing new shadow values; the 1px hairline carries the separation. */
    --shadow-elevated: var(--shadow-card);
    --shadow-primary: 0 4px 12px hsl(343 94% 34% / 0.18);
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --wms-header-height: 64px;
    --wms-sidebar-width: 256px;

    /* ---- Resolved colour aliases ------------------------------
       Read as finished colours by base.html and by template-level
       <style> blocks, so they must NOT be bare HSL components. */
    --surface: hsl(var(--background));
    --accent-red: hsl(var(--primary));
    --gradient-primary: hsl(var(--primary));  /* §7 bans gradients */
    --gradient-subtle: hsl(var(--background));
}

.crm-skin {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
        'Helvetica Neue', Arial, sans-serif;
    color: hsl(var(--foreground));
}

/* ---- Page header ------------------------------------------------ */
.crm-skin .admin-header {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--card-border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    margin-bottom: 1.5rem;
}

.crm-skin .admin-title {
    color: hsl(var(--foreground));
    letter-spacing: -0.02em;
}

.crm-skin .admin-subtitle {
    color: hsl(var(--muted-foreground));
}

/* ---- Cards ------------------------------------------------------ */
.crm-skin .modern-card {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--card-border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    transition: var(--transition-smooth);
}

.crm-skin .modern-card:hover {
    transform: none;
    box-shadow: var(--shadow-card);
}

.crm-skin .card-header-modern {
    border-bottom: 1px solid hsl(var(--card-border));
}

.crm-skin .card-title-modern {
    color: hsl(var(--foreground));
}

.crm-skin .card-subtitle-modern {
    color: hsl(var(--muted-foreground));
}

/* Stat cards: drop the coloured top accent line, keep elevation flat.
   `!important` is required to override the inline `border-top` set per card. */
.crm-skin .dashboard-stat-card {
    border-top: 0 !important;
}

.crm-skin .dashboard-stat-card:hover {
    transform: none;
    box-shadow: var(--shadow-card) !important;
}

/* ---- Tables ----------------------------------------------------- */
.crm-skin .modern-table-container {
    border: 1px solid hsl(var(--card-border));
    border-radius: var(--radius);
}

.crm-skin .modern-table thead {
    background: hsl(var(--muted));
}

.crm-skin .modern-table th {
    color: hsl(var(--muted-foreground));
    border-bottom: 1px solid hsl(var(--card-border));
    font-size: 0.75rem;
}

.crm-skin .modern-table td {
    border-bottom: 1px solid hsl(var(--card-border));
    color: hsl(var(--foreground));
}

.crm-skin .modern-table tbody tr:hover {
    background: hsl(var(--muted));
}

.crm-skin .expiry-scroll thead th {
    background: hsl(var(--muted));
}

/* ---- Toolbar stat badges --------------------------------------- */
.crm-skin .stat-badge {
    background: hsl(var(--muted));
    color: hsl(var(--muted-foreground));
    border: 1px solid hsl(var(--card-border));
    border-radius: var(--radius);
}

/* ---- Buttons ---------------------------------------------------- */
/* Normalise size so primary & secondary action buttons always match,
   regardless of the extra Bootstrap `.btn` class on some primaries.
   Colour is enforced centrally in ninatrans-buttons.css (§5.1). */
.crm-skin .btn-primary-modern,
.crm-skin .btn-secondary-modern {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
}

.crm-skin .btn-primary-modern,
.crm-skin .btn.btn-primary {
    background: hsl(var(--primary));
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-primary);
    color: hsl(var(--primary-foreground));
}

.crm-skin .btn-primary-modern:hover,
.crm-skin .btn.btn-primary:hover {
    background: hsl(var(--primary-dark));
    box-shadow: var(--shadow-primary);
    color: hsl(var(--primary-foreground));
}

.crm-skin .btn-secondary-modern {
    border-radius: var(--radius);
    border-color: hsl(var(--card-border));
    color: hsl(var(--muted-foreground));
}

.crm-skin .btn-secondary-modern:hover {
    background: hsl(var(--muted));
    border-color: hsl(var(--card-border));
}

/* ---- Nav tabs --------------------------------------------------- */
.crm-skin .modern-tabs-container {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--card-border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}

.crm-skin .modern-tabs {
    background: hsl(var(--muted));
}

.crm-skin .modern-tab {
    color: hsl(var(--muted-foreground));
    border-radius: calc(var(--radius) - 2px);
}

.crm-skin .modern-tab:hover {
    background: hsl(var(--primary) / 0.08);
    color: hsl(var(--primary));
}

.crm-skin .modern-tab.active {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    box-shadow: var(--shadow-primary);
}

.crm-skin .action-btn {
    border-radius: calc(var(--radius) - 2px);
    border-color: hsl(var(--card-border));
    color: hsl(var(--muted-foreground));
}

/* ---- Form controls --------------------------------------------- */
.crm-skin .form-control,
.crm-skin .form-select {
    border-radius: var(--radius);
    border-color: hsl(var(--card-border));
}

.crm-skin .form-control:focus,
.crm-skin .form-select:focus {
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.12);
}

.crm-skin .input-group-text {
    border-color: hsl(var(--card-border));
    background: hsl(var(--card));
}

/* ---- Badges (map Bootstrap states to the CRM status palette) ---- */
.crm-skin .badge {
    border-radius: 9999px;
    font-weight: 600;
}

.crm-skin .badge.bg-success {
    background: hsl(var(--success)) !important;
}

.crm-skin .badge.bg-danger {
    background: hsl(var(--danger)) !important;
}

.crm-skin .badge.bg-warning {
    background: hsl(var(--warning)) !important;
    color: hsl(var(--foreground)) !important;
}

.crm-skin .badge.bg-info {
    background: hsl(var(--info)) !important;
}

/* ============================================================
   Sidebar navigation
   `.crm-skin .sidebar` keeps specificity above base.html's inline
   `.sidebar .nav-link` rules so these reliably win.
   Sizing mirrors the CRM sidebar (px-3 py-2.5, 20px icons, 0.5rem radius).
   ============================================================ */
.crm-skin .sidebar {
    background: hsl(var(--card));
    border-right: 1px solid hsl(var(--card-border));
}

.crm-skin .sidebar .navbar-brand {
    border-bottom: 1px solid hsl(var(--card-border));
}

.crm-skin .sidebar .navbar-brand span {
    color: hsl(var(--foreground));
}

/* Default nav items */
.crm-skin .sidebar .nav-link,
.crm-skin .sidebar .nav-category .nav-link {
    color: hsl(var(--muted-foreground)) !important;
    padding: 0.625rem 0.75rem;
    gap: 0.75rem;
    font-size: 0.875rem;
    border-radius: var(--radius);
}

.crm-skin .sidebar .nav-link i,
.crm-skin .sidebar .nav-category .nav-link i {
    color: hsl(var(--muted-foreground));
    width: 20px;
    font-size: 1.05rem;
}

/* Hover (non-active) */
.crm-skin .sidebar .nav-link:hover:not(.active),
.crm-skin .sidebar .nav-category .nav-link:hover:not(.active) {
    background: hsl(var(--muted)) !important;
    color: hsl(var(--primary)) !important;
    border-left-color: transparent;
}

.crm-skin .sidebar .nav-link:hover:not(.active) i,
.crm-skin .sidebar .nav-category .nav-link:hover:not(.active) i {
    color: hsl(var(--primary)) !important;
}

/* Active item */
.crm-skin .sidebar .nav-link.active,
.crm-skin .sidebar .nav-category .nav-link.active {
    background: hsl(var(--primary) / 0.10) !important;
    color: hsl(var(--primary)) !important;
    border-left-color: transparent !important;
    font-weight: 600;
}

.crm-skin .sidebar .nav-link.active i,
.crm-skin .sidebar .nav-category .nav-link.active i {
    color: hsl(var(--primary)) !important;
}

/* Category headers */
.crm-skin .sidebar .nav-category-header:hover {
    background: hsl(var(--primary) / 0.07);
}

/* Collapse toggle: top-right of the sidebar (CRM placement) */
.crm-skin .sidebar .sidebar-toggle {
    position: sticky;
    top: 0;
    z-index: 2;
    align-self: flex-end;
    width: 2rem;
    height: 2rem;
    margin: 0.5rem 0.5rem 0 0;
    padding: 0;
    border: 1px solid hsl(var(--card-border));
    border-radius: calc(var(--radius) - 2px);
    color: hsl(var(--muted-foreground));
    background: hsl(var(--card));
}

.crm-skin .sidebar .sidebar-toggle:hover {
    color: hsl(var(--primary));
    background: hsl(var(--primary) / 0.06);
}

/* ============================================================
   Top navigation bar (CRM-style) — search + user profile
   Layout mirrors the CRM header: items right-aligned, 4rem tall.
   Full-bleed sticky bar inside .main-content (cancels its padding).
   ============================================================ */
.crm-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1035;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: var(--wms-header-height);
    padding: 0 1.5rem;
    background: hsl(var(--card));
    border-bottom: 1px solid hsl(var(--card-border));
    box-shadow: var(--shadow-card);
}

.crm-topbar-brand {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
}

.crm-topbar-logo {
    height: 2rem;
    width: auto;
    object-fit: contain;
}

.crm-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Search footprint — expanded for vertical nav; compact in horizontal (see ninatrans-components) */
.crm-topbar-search {
    position: relative;
}

.crm-topbar-search-icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: hsl(var(--muted-foreground));
    font-size: 0.85rem;
    pointer-events: none;
}

.crm-topbar-input {
    width: 100%;
    height: 2.5rem;
    padding: 0 0.85rem 0 2.25rem;
    border: 1px solid hsl(var(--card-border));
    border-radius: var(--radius);
    background: hsl(var(--muted));
    font-size: 0.875rem;
    color: hsl(var(--foreground));
    outline: none;
    transition: all 0.15s ease;
}

.crm-topbar-input:focus {
    background: hsl(var(--card));
    border-color: hsl(var(--primary));
    box-shadow: 0 0 0 3px hsl(var(--primary) / 0.12);
}

.crm-topbar-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    display: none;
    max-height: 360px;
    overflow-y: auto;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--card-border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-elevated);
    z-index: 1050;
}

.crm-search-group {
    padding: 0.4rem 0.85rem 0.2rem;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: hsl(var(--muted-foreground));
    background: hsl(var(--muted));
    border-bottom: 1px solid hsl(var(--card-border));
}

.crm-search-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.85rem;
    text-decoration: none;
    color: hsl(var(--foreground));
    border-bottom: 1px solid hsl(var(--card-border));
}

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

.crm-search-item:hover,
.crm-search-item.is-active {
    background: hsl(var(--muted));
}

.crm-search-item .title {
    font-weight: 600;
    font-size: 0.85rem;
}

.crm-search-item .subtitle {
    font-size: 0.74rem;
    color: hsl(var(--muted-foreground));
}

.crm-search-empty {
    padding: 0.85rem;
    text-align: center;
    color: hsl(var(--muted-foreground));
    font-size: 0.8rem;
}

/* User profile menu (CRM avatar: h-8 w-8 = 32px, bg-primary/10 text-primary) */
.crm-usermenu {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s ease;
    user-select: none;
}

.crm-usermenu:hover {
    background: hsl(var(--muted));
}

.crm-user-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: hsl(var(--primary) / 0.1);
    color: hsl(var(--primary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.crm-user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.crm-user-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: hsl(var(--foreground));
}

.crm-user-role {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

.crm-user-chevron {
    font-size: 0.65rem;
    color: hsl(var(--muted-foreground));
    transition: transform 0.2s ease;
}

.crm-usermenu.open .crm-user-chevron {
    transform: rotate(180deg);
}

.crm-usermenu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 14rem;
    display: none;
    padding: 0.35rem;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--card-border));
    border-radius: var(--radius);
    box-shadow: var(--shadow-elevated);
    z-index: 1050;
}

.crm-usermenu.open .crm-usermenu-dropdown {
    display: block;
}

.crm-usermenu-label {
    padding: 0.4rem 0.6rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: hsl(var(--muted-foreground));
    font-weight: 700;
}

.crm-usermenu-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: none;
    border-radius: calc(var(--radius) - 2px);
    background: transparent;
    font-size: 0.82rem;
    color: hsl(var(--foreground));
    text-decoration: none;
    cursor: pointer;
    text-align: left;
}

.crm-usermenu-item:hover {
    background: hsl(var(--muted));
    color: hsl(var(--foreground));
}

.crm-usermenu-item.danger {
    color: hsl(var(--danger));
}

.crm-usermenu-item.danger:hover {
    background: hsl(var(--danger) / 0.08);
}

.crm-usermenu-sep {
    height: 1px;
    background: hsl(var(--card-border));
    margin: 0.3rem 0;
}

/* Responsive */
@media (max-width: 991.98px) {
    .crm-topbar {
        padding-left: 4rem; /* clear the fixed mobile menu button */
    }
    .crm-user-info {
        display: none;
    }
}

@media (max-width: 576px) {
    .crm-topbar-search {
        flex: 1 1 auto;
        width: auto;
        max-width: none;
        min-width: 0;
    }
    .crm-topbar-logo {
        height: 1.6rem;
    }
}

/* ---- Notification bell (ITSM-style) ------------------------------------ */
.notif-bell {
    position: relative;
    flex-shrink: 0;
}

.notif-bell-btn {
    position: relative;
    width: 2.25rem;
    height: 2.25rem;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}

.notif-bell-btn:hover,
.notif-bell.open .notif-bell-btn {
    background: hsl(var(--muted));
    color: hsl(var(--primary));
}

.notif-badge {
    position: absolute;
    top: -0.15rem;
    right: -0.15rem;
    min-width: 1.1rem;
    height: 1.1rem;
    padding: 0 0.25rem;
    border-radius: 999px;
    background: hsl(var(--primary));
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1.1rem;
    text-align: center;
}

.notif-panel {
    display: none;
    position: absolute;
    top: calc(100% + 0.45rem);
    right: 0;
    width: 22rem;
    max-width: min(22rem, calc(100vw - 1.5rem));
    background: #fff;
    border: 1px solid hsl(var(--card-border));
    border-radius: 0.75rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
    z-index: 1100;
    overflow: hidden;
}

.notif-bell.open .notif-panel {
    display: block;
}

.notif-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid hsl(var(--card-border));
    background: hsl(var(--muted) / 0.45);
}

.notif-panel-header h3 {
    margin: 0;
    font-size: 0.92rem;
    font-weight: 700;
}

.notif-mark-all {
    border: none;
    background: transparent;
    color: hsl(var(--muted-foreground));
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.2rem 0.35rem;
    border-radius: 0.35rem;
}

.notif-mark-all:hover {
    color: hsl(var(--primary));
    background: rgba(171, 5, 52, 0.06);
}

.notif-list {
    max-height: 400px;
    overflow-y: auto;
}

.notif-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 2rem 1rem;
    color: hsl(var(--muted-foreground));
}

.notif-empty i {
    font-size: 1.5rem;
    opacity: 0.45;
}

.notif-empty p {
    margin: 0;
    font-size: 0.85rem;
}

.notif-item {
    display: flex;
    gap: 0.7rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid hsl(var(--card-border));
    cursor: pointer;
    transition: background 0.12s ease;
}

.notif-item:hover {
    background: hsl(var(--muted) / 0.55);
}

.notif-item.is-unread {
    background: rgba(171, 5, 52, 0.04);
}

.notif-item-icon {
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1.4;
}

.notif-item-body {
    flex: 1;
    min-width: 0;
}

.notif-item-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.notif-item-title {
    font-size: 0.84rem;
    font-weight: 600;
    color: hsl(var(--foreground));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notif-item.is-unread .notif-item-title {
    color: hsl(var(--foreground));
}

.notif-item:not(.is-unread) .notif-item-title {
    color: hsl(var(--muted-foreground));
}

.notif-item-message {
    margin-top: 0.15rem;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notif-item-time {
    margin-top: 0.25rem;
    font-size: 0.7rem;
    color: hsl(var(--muted-foreground) / 0.85);
}

.notif-item-delete {
    opacity: 0;
    border: none;
    background: transparent;
    color: hsl(var(--muted-foreground));
    cursor: pointer;
    padding: 0.1rem 0.25rem;
    border-radius: 0.3rem;
    line-height: 1;
}

.notif-item:hover .notif-item-delete {
    opacity: 1;
}

.notif-item-delete:hover {
    color: hsl(0 70% 38%);
    background: rgba(220, 38, 38, 0.08);
}

.notif-item-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: hsl(var(--primary));
    flex-shrink: 0;
    margin-top: 0.35rem;
}
