{{define "sidebar_email.html"}}
<nav class="sidebar bg-dark border-end border-secondary position-fixed h-100" style="width: var(--sidebar-width); z-index: 1000;">
    <div class="d-flex flex-column h-100">
        <div class="p-3 border-bottom border-secondary d-flex align-items-start justify-content-between">
            <div>
                <h5 class="text-white mb-0">
                    <i class="bi bi-server me-2"></i>
                    SMTP Server
                </h5>
                <small class="text-muted">Management Console</small>
            </div>
            <button id="sidebarPinBtn" class="btn btn-sm btn-outline-secondary" title="Unpin sidebar (auto-hide)" onclick="toggleSidebarPin()">
                <i class="bi bi-pin-angle-fill" id="sidebarPinIcon"></i>
            </button>
        </div>

        <div class="flex-grow-1 overflow-auto">
            <ul class="nav nav-pills flex-column p-3">
                <li class="nav-item mb-2">
                    <a href="/pymta-manager/" class="nav-link text-white {{if eq (dget . "active") "dashboard"}}active{{end}}">
                        <i class="bi bi-speedometer2 me-2"></i>
                        Dashboard
                    </a>
                </li>

                <li class="nav-item mb-2">
                    <h6 class="text-muted text-uppercase small mb-2 mt-3">
                        <i class="bi bi-globe me-1"></i>
                        Email Server Management
                    </h6>
                </li>

                <li class="nav-item mb-1">
                    <a href="/pymta-manager/domains" class="nav-link text-white {{if eq (dget . "active") "domains"}}active{{end}}">
                        <i class="bi bi-list-ul me-2"></i>
                        Domains
                        <span class="badge bg-secondary ms-auto">{{dget . "domain_count"}}</span>
                    </a>
                </li>

                <li class="nav-item mb-1">
                    <a href="/pymta-manager/senders" class="nav-link text-white {{if eq (dget . "active") "senders"}}active{{end}}">
                        <i class="bi bi-people me-2"></i>
                        Allowed Senders
                        <span class="badge bg-secondary ms-auto">{{dget . "sender_count"}}</span>
                    </a>
                </li>

                <li class="nav-item mb-1">
                    <a href="/pymta-manager/mailboxes" class="nav-link text-white {{if eq (dget . "active") "mailboxes"}}active{{end}}">
                        <i class="bi bi-inbox me-2"></i>
                        Mailboxes
                        <span class="badge bg-secondary ms-auto">{{dget . "mailbox_count"}}</span>
                    </a>
                </li>

                <li class="nav-item mb-1">
                    <a href="/pymta-manager/ips" class="nav-link text-white {{if eq (dget . "active") "ips"}}active{{end}}">
                        <i class="bi bi-router me-2"></i>
                        Whitelisted IPs
                        <span class="badge bg-secondary ms-auto">{{dget . "ip_count"}}</span>
                    </a>
                </li>

                <li class="nav-item mb-1">
                    <a href="/pymta-manager/dkim" class="nav-link text-white {{if eq (dget . "active") "dkim"}}active{{end}}">
                        <i class="bi bi-shield-check me-2"></i>
                        DKIM Keys
                        <span class="badge bg-secondary ms-auto">{{dget . "dkim_count"}}</span>
                    </a>
                </li>

                {{if dget . "is_global_admin"}}
                <li class="nav-item mb-1">
                    <a href="/pymta-manager/letsencrypt" class="nav-link text-white {{if eq (dget . "active") "letsencrypt"}}active{{end}}">
                        <i class="bi bi-patch-check me-2"></i>
                        Let's Encrypt
                    </a>
                </li>
                {{end}}

                <li class="nav-item mb-1">
                    <a href="/pymta-manager/logs" class="nav-link text-white {{if eq (dget . "active") "logs"}}active{{end}}">
                        <i class="bi bi-journal-text me-2"></i>
                        Emails Log
                    </a>
                </li>

                {{if dget . "is_global_admin"}}
                <li class="nav-item mb-2">
                    <h6 class="text-muted text-uppercase small mb-2 mt-3">
                        <i class="bi bi-shield-lock me-1"></i>
                        Security
                    </h6>
                </li>
                <li class="nav-item mb-1">
                    <a href="/pymta-manager/blacklist" class="nav-link text-white {{if eq (dget . "active") "blacklist"}}active{{end}}">
                        <i class="bi bi-shield-x me-2"></i>
                        Blacklist
                        <span class="badge bg-secondary ms-auto">{{dget . "blacklist_count"}}</span>
                    </a>
                </li>
                {{end}}

                <li class="nav-item mb-2">
                    <h6 class="text-muted text-uppercase small mb-2 mt-3">
                        <i class="bi bi-gear me-1"></i>
                        Configuration
                    </h6>
                </li>

                {{if dget . "is_global_admin"}}
                <li class="nav-item mb-1">
                    <a href="/pymta-manager/settings" class="nav-link text-white {{if eq (dget . "active") "settings"}}active{{end}}">
                        <i class="bi bi-sliders me-2"></i>
                        Server Settings
                    </a>
                </li>
                {{end}}

                <li class="nav-item mb-1">
                    <a href="/pymta-manager/admins" class="nav-link text-white {{if eq (dget . "active") "admins"}}active{{end}}">
                        <i class="bi bi-people-fill me-2"></i>
                        Admins
                    </a>
                </li>

                <li class="nav-item mb-1">
                    <a href="/pymta-manager/account" class="nav-link text-white {{if eq (dget . "active") "account"}}active{{end}}">
                        <i class="bi bi-person-circle me-2"></i>
                        Account
                    </a>
                </li>

                <li class="nav-item mb-1">
                    <a href="/webmail/login" target="_blank" class="nav-link text-white" title="Give this link to mailbox owners for self-service password/MFA/app-password management">
                        <i class="bi bi-mailbox2-flag me-2"></i>
                        Webmail Portal
                        <i class="bi bi-box-arrow-up-right ms-1 small"></i>
                    </a>
                </li>

                <li class="nav-item mb-1">
                    <form method="post" action="/pymta-manager/logout">
                        <button type="submit" class="nav-link text-white w-100 text-start border-0 bg-transparent">
                            <i class="bi bi-box-arrow-right me-2"></i>
                            Sign out
                        </button>
                    </form>
                </li>
            </ul>
        </div>

        <div class="p-3 border-top border-secondary">
            <div class="d-flex align-items-center">
                <div class="flex-grow-1">
                    <small class="text-muted d-block">Server Status</small>
                    <small class="{{if eq .health.Status "healthy"}}text-success{{else}}text-warning{{end}} status-indicator"
                           data-bs-toggle="tooltip"
                           data-bs-html="true"
                           data-bs-placement="top"
                           title="{{safe (printf "<div class='text-start'><strong>Service Status:</strong><br>SMTP Server: %s<br>Web Frontend: %s<br>Database: %s</div>" (title .health.Services.smtp_server) (title .health.Services.web_frontend) (title .health.Services.database))}}">
                        <i class="bi bi-circle-fill me-1" style="font-size: 0.5rem;"></i>
                        {{title .health.Status}}
                    </small>
                </div>
                <button class="btn btn-outline-secondary btn-sm" title="Refresh Status" onclick="location.reload()">
                    <i class="bi bi-arrow-clockwise"></i>
                </button>
            </div>
        </div>
    </div>
</nav>

<style>
.sidebar .nav-link { border-radius: 0.375rem; padding: 0.75rem 1rem; margin-bottom: 0.25rem; transition: all 0.2s ease; }
.sidebar .nav-link:hover { background-color: rgba(255, 255, 255, 0.1); transform: translateX(4px); }
.sidebar .nav-link.active { background-color: #0d6efd; color: white !important; }
.sidebar .nav-link.active:hover { background-color: #0b5ed7; }
.sidebar h6 { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.05em; border-bottom: 1px solid rgba(255, 255, 255, 0.1); padding-bottom: 0.5rem; margin-bottom: 1rem !important; }
.sidebar .badge { font-size: 0.7rem; }
.status-indicator { cursor: pointer; }
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.3s ease; }
    .sidebar.show { transform: translateX(0); }
    .content-area { margin-left: 0 !important; }
}
</style>

<script>
document.addEventListener('DOMContentLoaded', function() {
    const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
    tooltipTriggerList.forEach(function(tooltipTriggerEl) {
        new bootstrap.Tooltip(tooltipTriggerEl, { html: true, placement: 'top', trigger: 'hover' });
    });
});
</script>
{{end}}
