/**
 * Ifakara Health Institute (IHI) Theme
 * DigSign - Digital Signature System
 * 
 * IHI Brand Colors (Updated Green Theme):
 * Primary Green: #43A047
 * Secondary Green: #2F4A30
 * Accent Green: #66BB6A
 * Success Green: #28A745 (Health Green)
 * Light Green: #EDF7ED (Light Background)
 * Dark Green: #243726
 */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800&display=swap');

:root {
    /* IHI Primary Colors - Green Theme */
    --ihi-primary: #43A047;
    --ihi-primary-dark: #2F4A30;
    --ihi-primary-light: #66BB6A;
    
    /* IHI Secondary Colors */
    --ihi-teal: #2F4A30;
    --ihi-teal-light: #43A047;
    --ihi-teal-dark: #243726;
    
    /* Status Colors */
    --ihi-success: #28A745;
    --ihi-warning: #FFC107;
    --ihi-danger: #DC3545;
    --ihi-info: #17A2B8;
    
    /* Background Colors */
    --ihi-bg-light: #EDF7ED;
    --ihi-bg-lighter: #FFFFFF;
    --ihi-bg-white: #FFFFFF;
    
    /* Text Colors */
    --ihi-text-primary: #2F4A30;
    --ihi-text-secondary: #555555;
    --ihi-text-light: #777777;
    --ihi-text-white: #FFFFFF;
    
    /* Border Colors */
    --ihi-border: #DEE2E6;
    --ihi-border-light: #EDF7ED;
    
    /* Bootstrap override */
    --bs-primary: #43A047;
    --bs-primary-rgb: 67, 160, 71;
}

/* Body and General Styles */
body {
    font-family: 'Montserrat', 'Helvetica Neue', Arial, sans-serif;
    background-color: #ffffff;
    color: var(--ihi-text-primary);
}

/* App Shell */
.app-top-strip {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 36px;
    background: var(--ihi-primary-dark);
    color: var(--ihi-text-white);
    z-index: 1050;
}

.app-navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 66px;
    background: #ffffff !important;
    border-bottom: 1px solid var(--ihi-border-light);
    box-shadow: 0 8px 24px rgba(47, 74, 48, 0.08);
    z-index: 1045;
}

.app-authenticated .app-navbar {
    top: 36px;
}

.app-brand {
    color: var(--ihi-primary-dark) !important;
    font-weight: 700;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
}

.app-brand-logo {
    height: 40px;
    width: auto;
    max-width: 170px;
    object-fit: contain;
    background: #ffffff;
    border-radius: 8px;
    padding: 4px 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.app-navbar .navbar-toggler {
    border: 1px solid var(--ihi-border);
}

.app-navbar .navbar-toggler-icon {
    filter: invert(0.35);
}

.app-navbar .nav-link {
    color: var(--ihi-primary-dark) !important;
    font-weight: 500;
    transition: all 0.3s ease;
    padding: 0.45rem 0.8rem;
}

.app-navbar .nav-link:hover {
    color: var(--ihi-primary) !important;
}

.app-authenticated .app-main {
    margin-top: 102px;
    margin-left: 280px;
    min-height: calc(100vh - 102px);
    padding: 1.5rem 1.5rem 2.25rem;
}

.app-main {
    margin-top: 66px;
    min-height: calc(100vh - 66px);
}

.app-sidebar {
    position: fixed;
    top: 102px;
    left: 0;
    width: 280px;
    height: calc(100vh - 102px);
    overflow-y: auto;
    background: linear-gradient(180deg, var(--ihi-primary-dark) 0%, #203423 100%);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 2px 0 14px rgba(19, 33, 20, 0.18);
    z-index: 1030;
}

.app-sidebar-inner {
    padding: 1rem 0.65rem 1.5rem;
}

.app-sidebar-menu .nav-link {
    color: rgba(255, 255, 255, 0.86);
    padding: 0.75rem 0.85rem;
    margin: 0.16rem 0.35rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    border-left: 3px solid transparent;
}

.app-sidebar-menu .nav-link i {
    width: 20px;
    text-align: center;
}

.app-sidebar-menu .nav-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.11);
    border-left-color: var(--ihi-primary-light);
}

.app-sidebar-menu .nav-link.active {
    color: #ffffff;
    font-weight: 600;
    background: linear-gradient(90deg, rgba(67, 160, 71, 0.55) 0%, rgba(67, 160, 71, 0.2) 100%);
    border-left-color: #ffffff;
}

.app-menu-section {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    margin: 0.9rem 0.7rem 0.4rem;
}

/* ── Collapsible treeview section toggles ───────────────────────── */
.app-menu-section-toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: rgba(255, 255, 255, 0.94);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 700;
    margin: 0.85rem 0.35rem 0.15rem;
    padding: 0.46rem 0.62rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    cursor: pointer;
    user-select: none;
    list-style: none;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.app-menu-section-toggle:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.26);
}

.app-menu-section-toggle > i:not(.chevron) {
    color: rgba(255, 255, 255, 0.92);
}

/* Chevron points down when section is open (default) */
.app-menu-section-toggle .chevron {
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.92);
    transition: transform 0.22s ease;
    transform: rotate(0deg);
}

/* Chevron points right when section is collapsed */
.app-menu-section-toggle.collapsed .chevron {
    transform: rotate(-90deg);
}

/* Indent child items under each collapsible group */
.app-sidebar-subtree {
    position: relative;
    padding-left: 1.25rem;
    margin: 0.22rem 0.2rem 0.5rem;
}

/* Vertical dotted tree connector */
.app-sidebar-subtree::before {
    content: "";
    position: absolute;
    left: 0.62rem;
    top: 0.1rem;
    bottom: 0.1rem;
    border-left: 1px dotted rgba(255, 255, 255, 0.36);
}

.app-sidebar-subtree .nav-item {
    position: relative;
}

/* Horizontal branch connector into each child node */
.app-sidebar-subtree .nav-item::before {
    content: "";
    position: absolute;
    left: -0.63rem;
    top: 1.2rem;
    width: 0.58rem;
    border-top: 1px dotted rgba(255, 255, 255, 0.36);
}

/* Stop the vertical connector at the last child for cleaner tree ending */
.app-sidebar-subtree .nav-item:last-child::after {
    content: "";
    position: absolute;
    left: -0.63rem;
    top: 1.2rem;
    bottom: -0.35rem;
    width: 2px;
    background: #203423;
}

.app-sidebar-subtree .nav-link {
    margin-left: 0.1rem;
    background: rgba(255, 255, 255, 0.02);
}

.app-sidebar-subtree .nav-link:hover {
    background: rgba(255, 255, 255, 0.13);
}

.app-sidebar-offcanvas {
    background: linear-gradient(180deg, var(--ihi-primary-dark) 0%, #203423 100%);
    color: #fff;
}

.app-sidebar-offcanvas .offcanvas-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.app-sidebar-offcanvas .btn-close {
    filter: invert(1);
}

.app-sidebar-offcanvas .app-sidebar-menu .nav-link {
    color: rgba(255, 255, 255, 0.9);
}

.app-sidebar-offcanvas .app-menu-section {
    color: rgba(255, 255, 255, 0.66);
}

.main-content {
    padding: 1.5rem;
}

.app-authenticated .main-content {
    max-width: calc(100vw - 280px);
}

.app-meta-footer {
    margin-left: 280px;
    border-top: 1px solid var(--ihi-border-light);
    background: #ffffff;
    padding: 0.55rem 0;
}

.app-meta-footer-inner {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.app-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--ihi-text-light);
    background: #f8fbf8;
    border: 1px solid var(--ihi-border-light);
    border-radius: 999px;
    padding: 0.2rem 0.6rem;
}

.app-meta-item i {
    color: var(--ihi-primary);
}

@media (max-width: 991.98px) {
    .app-top-strip {
        height: 34px;
    }

    .app-authenticated .app-navbar {
        top: 34px;
        height: 62px;
    }

    .app-navbar {
        height: 62px;
    }

    .app-authenticated .app-main {
        margin-top: 96px;
        margin-left: 0;
        max-width: 100vw;
        padding: 1.1rem 0.9rem 1.5rem;
    }

    .main-content {
        padding: 1.1rem 0.9rem;
    }

    .app-meta-footer {
        margin-left: 0;
        padding: 0.5rem 0;
    }

    .app-meta-footer-inner {
        justify-content: center;
    }

    .app-main {
        margin-top: 62px;
    }
}

@media (max-width: 575.98px) {
    .app-top-strip {
        font-size: 0.75rem;
    }

    .app-brand {
        font-size: 1.05rem;
    }

    .app-authenticated .app-main {
        padding: 0.9rem 0.65rem 1.4rem;
    }
}

/* Card Styles */
.card {
    border: none;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 75, 135, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 75, 135, 0.12);
}

.card-header {
    background: linear-gradient(135deg, var(--ihi-primary) 0%, var(--ihi-primary-light) 100%);
    color: var(--ihi-text-white);
    font-weight: 600;
    border: none;
    border-radius: 8px 8px 0 0 !important;
    padding: 1rem 1.25rem;
}

/* Button Styles */
.btn-primary {
    background: linear-gradient(135deg, var(--ihi-primary) 0%, var(--ihi-primary-light) 100%);
    border: none;
    color: var(--ihi-text-white);
    font-weight: 500;
    padding: 0.5rem 1.5rem;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--ihi-primary-dark) 0%, var(--ihi-primary) 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 75, 135, 0.3);
}

.btn-secondary {
    background-color: var(--ihi-teal);
    border: none;
    color: var(--ihi-text-white);
    font-weight: 500;
    padding: 0.5rem 1.5rem;
    border-radius: 6px;
}

.btn-secondary:hover {
    background-color: var(--ihi-teal-dark);
}

.btn-success {
    background-color: var(--ihi-success);
    border: none;
}

.btn-outline-primary {
    border-color: var(--ihi-primary);
    color: var(--ihi-primary);
}

.btn-outline-primary:hover {
    background-color: var(--ihi-primary);
    color: var(--ihi-text-white);
}

/* Badge Styles */
.badge {
    font-weight: 500;
    padding: 0.4em 0.8em;
    border-radius: 4px;
}

.badge-primary {
    background-color: var(--ihi-primary-light);
}

.badge-secondary {
    background-color: var(--ihi-teal);
}

/* Alert Styles */
.alert {
    border: none;
    border-left: 4px solid;
    border-radius: 6px;
}

.alert-info {
    background-color: #E8F4F8;
    border-left-color: var(--ihi-primary-light);
    color: var(--ihi-primary);
}

.alert-success {
    border-left-color: var(--ihi-success);
}

.alert-warning {
    border-left-color: var(--ihi-warning);
}

.alert-danger {
    border-left-color: var(--ihi-danger);
}

/* Table Styles */
.table {
    background-color: var(--ihi-bg-white);
}

.table thead th {
    background-color: var(--ihi-primary);
    color: var(--ihi-text-white);
    border: none;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.875rem;
    padding: 1rem;
}

.table-striped tbody tr:nth-of-type(odd) {
    background-color: var(--ihi-bg-light);
}

.table-hover tbody tr:hover {
    background-color: rgba(0, 163, 163, 0.1);
}

/* Form Styles */
.form-control:focus,
.form-select:focus {
    border-color: var(--ihi-teal);
    box-shadow: 0 0 0 0.2rem rgba(0, 163, 163, 0.25);
}

.form-label {
    color: var(--ihi-text-primary);
    font-weight: 500;
    margin-bottom: 0.5rem;
}

/* Pagination */
.pagination .page-link {
    color: var(--ihi-primary);
    border-color: var(--ihi-border);
}

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

.pagination .page-link:hover {
    background-color: var(--ihi-bg-light);
    color: var(--ihi-primary-dark);
}

/* Progress Bar */
.progress-bar {
    background: linear-gradient(90deg, var(--ihi-primary) 0%, var(--ihi-teal) 100%);
}

/* Status Indicators */
.status-pending {
    color: var(--ihi-warning);
}

.status-approved {
    color: var(--ihi-success);
}

.status-rejected {
    color: var(--ihi-danger);
}

.status-completed {
    color: var(--ihi-teal);
}

.status-in-progress {
    color: var(--ihi-primary-light);
}

/* Dashboard Cards */
.dashboard-card {
    background: linear-gradient(135deg, rgba(0, 75, 135, 0.05) 0%, rgba(0, 163, 163, 0.05) 100%);
    border-left: 4px solid var(--ihi-primary);
    padding: 1.5rem;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.dashboard-card:hover {
    border-left-color: var(--ihi-teal);
    box-shadow: 0 4px 12px rgba(0, 75, 135, 0.15);
}

.dashboard-card h3 {
    color: var(--ihi-primary);
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.dashboard-card p {
    color: var(--ihi-text-secondary);
    margin: 0;
}

/* Document Status Colors */
.doc-status-draft {
    background-color: #6c757d;
    color: white;
}

.doc-status-pending {
    background-color: var(--ihi-warning);
    color: var(--ihi-text-primary);
}

.doc-status-in-progress {
    background-color: var(--ihi-primary-light);
    color: white;
}

.doc-status-approved {
    background-color: var(--ihi-success);
    color: white;
}

.doc-status-rejected {
    background-color: var(--ihi-danger);
    color: white;
}

.doc-status-completed {
    background-color: var(--ihi-teal);
    color: white;
}

/* Footer */
.footer {
    background-color: var(--ihi-primary-dark);
    color: var(--ihi-text-white);
    padding: 2rem 0;
    margin-top: 3rem;
}

.footer a {
    color: var(--ihi-teal-light);
    text-decoration: none;
}

.footer a:hover {
    color: var(--ihi-text-white);
}

/* Breadcrumb */
.breadcrumb {
    background-color: transparent;
}

.breadcrumb-item.active {
    color: var(--ihi-primary);
}

.breadcrumb-item a {
    color: var(--ihi-teal);
    text-decoration: none;
}

.breadcrumb-item a:hover {
    color: var(--ihi-primary);
}

/* Loading Spinner */
.spinner-border-primary {
    color: var(--ihi-primary) !important;
}

/* Tooltip */
.tooltip-inner {
    background-color: var(--ihi-primary);
}

.tooltip.bs-tooltip-top .tooltip-arrow::before {
    border-top-color: var(--ihi-primary);
}

/* Signature Field Styles */
.signature-field {
    border: 2px dashed var(--ihi-teal) !important;
    background-color: rgba(0, 163, 163, 0.05) !important;
}

.signature-field:hover {
    border-color: var(--ihi-primary) !important;
    background-color: rgba(0, 75, 135, 0.05) !important;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--ihi-bg-light);
}

::-webkit-scrollbar-thumb {
    background: var(--ihi-teal);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--ihi-teal-dark);
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .sidebar {
        min-height: auto;
    }
    
    .navbar-brand {
        font-size: 1.2rem;
    }
}

/* Animation Classes */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

/* IHI Logo Placeholder */
.ihi-logo-text {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--ihi-primary-dark);
}

@media (max-width: 576px) {
    .app-brand-logo {
        height: 34px;
        max-width: 140px;
        padding: 3px 6px;
    }

    .ihi-logo-text {
        font-size: 1.05rem;
    }
}
