/* ========================================
   CyberCash Top Navigation
   Color theme is controlled by CSS variables below.
   Change --topnav-primary to retheme the entire nav.
   ======================================== */

:root {
    --topnav-primary: #2d5016;
    --topnav-primary-dark: #1e3a0e;
    --topnav-primary-light: #3a6b1c;
    --topnav-menubar-bg: #3c3c3c;
    --topnav-menubar-hover: #555;
    --topnav-text: #fff;
    --topnav-text-muted: rgba(255,255,255,0.7);
    --topnav-dropdown-bg: #fff;
    --topnav-dropdown-text: #323130;
    --topnav-dropdown-hover: #f3f2f1;
    --topnav-avatar-admin-border: #ffc107;
    --topnav-avatar-branch-admin-border: #17a2b8;
    --topnav-font: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

/* Reset */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: var(--topnav-font);
    line-height: 1.6;
    color: #323130;
    background-color: #f3f2f1;
}

/* Keep the bar's anchors un-underlined. Some pages (the Global Settings manager, which pulls in
   partials/header.ejs) also load signup_login_form.css, and that sheet carries a global
   `a:hover { text-decoration: underline }`. Element + pseudo-class outranks our
   `.topnav-menu-link` class rule, so on those pages every menu item underlined on hover while
   the Accounting pages — which never load that sheet — stayed clean. This scoped rule wins on
   specificity without touching the sheet itself, so links in page content keep their hover
   underline where a page styles one. */
.topnav a:hover,
.topnav a:focus {
    text-decoration: none;
}

/* ---- TOP BAR (row 1) ---- */
.topnav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--topnav-primary);
    padding: 0 1rem;
    height: 40px;
    font-size: 13px;
}

.topnav-bar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topnav-logo {
    color: var(--topnav-text);
    font-weight: 700;
    font-size: 16px;
    text-decoration: none;
    letter-spacing: 0.5px;
}

.topnav-divider {
    width: 1px;
    height: 20px;
    background: rgba(255,255,255,0.35);
}

.topnav-service-label {
    color: var(--topnav-text);
    font-weight: 500;
    font-size: 13px;
}

.topnav-bar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Branch selector */
.topnav-branch-wrapper { position: relative; }

.topnav-branch {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    color: var(--topnav-text);
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s;
    font-size: 13px;
    background: none;
    border: none;
    font-family: var(--topnav-font);
}
.topnav-branch:hover { background: rgba(255,255,255,0.12); }
.topnav-branch-arrow { font-size: 10px; }

.topnav-branch-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 180px;
    background: var(--topnav-dropdown-bg);
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    border: 1px solid #e1e1e1;
    padding: 4px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: all 0.18s ease;
    z-index: 3000;
}
.topnav-branch-wrapper.open .topnav-branch-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.topnav-branch-dropdown-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    color: var(--topnav-dropdown-text);
    text-decoration: none;
    font-size: 13px;
    border-radius: 4px;
    transition: background 0.12s;
}
.topnav-branch-dropdown-link:hover {
    background: var(--topnav-dropdown-hover);
}

/* Icon buttons (gear, support, help)
   These are a mix of <a> (Support, Help) and <button> (Settings, which opens a dropdown).
   The button element brings its own user-agent background, border and inset shadow, which made
   the gear look raised with a pale highlight until hover; the reset below makes it sit flat in
   the bar exactly like the two anchors. */
.topnav-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    font: inherit;
    color: var(--topnav-text-muted);
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
}
.topnav-icon-btn:hover {
    background: rgba(255,255,255,0.12);
    color: var(--topnav-text);
}

/* ---- USER AVATAR ---- */
.topnav-user { position: relative; }

.topnav-avatar-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    transition: background 0.15s;
}
.topnav-avatar-btn:hover { background: rgba(255,255,255,0.12); }

.topnav-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #667eea;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
    border: 2px solid transparent;
}

/* Admin indicator: colored border on avatar */
.topnav-avatar.is-admin {
    border-color: var(--topnav-avatar-admin-border);
    box-shadow: 0 0 0 1px var(--topnav-avatar-admin-border);
}
.topnav-avatar.is-branch-admin {
    border-color: var(--topnav-avatar-branch-admin-border);
    box-shadow: 0 0 0 1px var(--topnav-avatar-branch-admin-border);
}

.topnav-user-arrow {
    color: var(--topnav-text-muted);
    font-size: 10px;
}

/* User dropdown card */
.topnav-user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    width: 280px;
    background: var(--topnav-dropdown-bg);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    border: 1px solid #e1e1e1;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: all 0.2s ease;
    z-index: 3000;
}
.topnav-user.open .topnav-user-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.topnav-user-card-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid #eee;
}

.topnav-user-card-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #667eea;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
    flex-shrink: 0;
    border: 2px solid transparent;
}
.topnav-user-card-avatar.is-admin {
    border-color: var(--topnav-avatar-admin-border);
}
.topnav-user-card-avatar.is-branch-admin {
    border-color: var(--topnav-avatar-branch-admin-border);
}

.topnav-user-card-info { flex: 1; min-width: 0; }

.topnav-user-card-name {
    font-weight: 600;
    font-size: 14px;
    color: #323130;
    margin: 0 0 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topnav-user-card-email {
    font-size: 12px;
    color: #666;
    margin: 0 0 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topnav-user-card-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: #6c757d;
}
.topnav-user-card-badge.enterprise-admin { background: #28a745; }
.topnav-user-card-badge.branch-admin { background: #17a2b8; }

.topnav-user-card-actions {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.topnav-user-card-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: none;
    background: none;
    color: var(--topnav-dropdown-text);
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
    text-decoration: none;
    width: 100%;
    font-family: var(--topnav-font);
}
.topnav-user-card-btn:hover { background: var(--topnav-dropdown-hover); }
.topnav-logout-btn:hover { color: #d32f2f; }


/* ---- MENU BAR (row 2) ---- */
.topnav-menubar {
    display: flex;
    align-items: center;
    background: var(--topnav-menubar-bg);
    padding: 0 1rem;
    height: 34px;
    font-size: 13px;
    position: relative;
}

.topnav-menu {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    align-items: center;
    height: 100%;
}

.topnav-menu-item {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
}

.topnav-menu-link {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 12px;
    height: 100%;
    color: var(--topnav-text);
    text-decoration: none;
    font-weight: 400;
    white-space: nowrap;
    transition: background 0.15s;
    font-size: 13px;
}
.topnav-menu-link:hover { background: var(--topnav-menubar-hover); }
.topnav-menu-link.active { background: var(--topnav-menubar-hover); font-weight: 500; }

.topnav-arrow { font-size: 9px; margin-left: 2px; }

/* Dropdown menus */
.topnav-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: var(--topnav-dropdown-bg);
    border-radius: 0 0 6px 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    border: 1px solid #e1e1e1;
    border-top: none;
    list-style: none;
    padding: 4px 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: all 0.18s ease;
    z-index: 2000;
}

.topnav-has-dropdown:hover > .topnav-dropdown,
.topnav-has-dropdown.open > .topnav-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.topnav-dropdown li a {
    display: block;
    padding: 7px 14px;
    color: var(--topnav-dropdown-text);
    text-decoration: none;
    font-size: 13px;
    transition: background 0.12s, padding-left 0.12s;
    border-radius: 4px;
    margin: 1px 4px;
}
.topnav-dropdown li a:hover {
    background: var(--topnav-dropdown-hover);
    padding-left: 18px;
}

.topnav-sep {
    height: 1px;
    background: #e8e8e8;
    margin: 4px 10px;
}

/* Dropdown group headers (non-clickable category labels) */
.topnav-group-header {
    padding: 6px 14px 3px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #8a8886;
    cursor: default;
    user-select: none;
    margin-top: 2px;
}

/* Dropdown group children (indented under a header) */
.topnav-group-child a {
    padding-left: 26px !important;
    font-size: 12.5px;
}

/* Hamburger (mobile) */
.topnav-hamburger-btn {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
}
.topnav-hamburger-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--topnav-text);
    border-radius: 1px;
    transition: all 0.2s;
}

/* ---- RESPONSIVE ---- */
@media (max-width: 900px) {
    .topnav-hamburger-btn { display: flex; }

    .topnav-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--topnav-menubar-bg);
        flex-direction: column;
        padding: 8px 0;
        box-shadow: 0 6px 20px rgba(0,0,0,0.2);
        z-index: 1999;
    }
    .topnav-menu.open { display: flex; }

    .topnav-menu-item { height: auto; width: 100%; }
    .topnav-menu-link { padding: 10px 16px; width: 100%; }

    .topnav-dropdown {
        position: static;
        box-shadow: none;
        border: none;
        border-radius: 0;
        background: rgba(255,255,255,0.05);
        opacity: 1;
        visibility: visible;
        transform: none;
        display: none;
    }
    .topnav-has-dropdown.open > .topnav-dropdown { display: block; }

    .topnav-dropdown li a {
        color: var(--topnav-text);
        padding-left: 28px;
    }
    .topnav-dropdown li a:hover {
        background: rgba(255,255,255,0.1);
    }
}

@media (max-width: 600px) {
    .topnav-branch-name { max-width: 100px; overflow: hidden; text-overflow: ellipsis; }
    .topnav-service-label { display: none; }
}

/* Print */
@media print {
    .topnav { display: none; }
}

/* High contrast */
@media (prefers-contrast: high) {
    .topnav-bar { background: #000; border-bottom: 2px solid #fff; }
    .topnav-menubar { background: #222; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .topnav-dropdown, .topnav-user-dropdown, .topnav-menu-link { transition: none; }
}
