:root {
    --sidebar-w: 230px;
    --topbar-h: 60px;
    --border: #e3e7ed;
    --bg: #f4f6f9;
    --text: #2b2f38;
    --text-muted: #7c8494;
    --brand: #2f6fed;
    --brand-dark: #1e4fc4;
    --green: #21a366;
    --red: #e5484d;
    --purple: #7c4dff;
    --sidebar-bg: #ffffff;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Shell layout ---------- */
.shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
}

.sidebar {
    grid-area: sidebar;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}
/* Nav items scroll independently of the profile chip below, which stays pinned to the
   sidebar's bottom edge regardless of how many menu items there are. */
.sidebar-scroll { flex: 1 1 auto; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }

.sidebar-brand {
    min-height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.brand-logo-box {
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--bg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    color: var(--brand);
}
.brand-titles { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.brand-title { font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; }
.brand-title .mark { color: var(--brand); }
.sidebar-brand .sub {
    font-weight: 600; color: var(--text-muted); font-size: 10px;
    letter-spacing: .06em; text-transform: uppercase;
}

.nav-section-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    color: var(--text-muted);
    padding: 18px 20px 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 2px 10px;
    padding: 9px 12px;
    border-radius: 9px;
    color: var(--text);
    font-size: 13.5px;
    font-weight: 500;
}
.nav-link:hover { background: #f0f4ff; text-decoration: none; }
.nav-link:hover .icon { color: var(--brand); }
.nav-link.active { background: #e8f0ff; color: var(--brand); font-weight: 600; }
.nav-link .icon {
    width: 19px;
    height: 19px;
    flex: 0 0 19px;
    color: var(--text-muted);
}
.nav-link.active .icon { color: var(--brand); }

.topbar {
    grid-area: topbar;
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }

/* ---------- Sidebar profile chip + popover menu ---------- */
.sidebar-profile { flex: 0 0 auto; position: relative; border-top: 1px solid var(--border); padding: 10px; }
.sidebar-profile-trigger {
    width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 8px;
    border-radius: 9px; background: transparent; border: none; cursor: pointer; text-align: left;
    font-family: inherit; color: var(--text);
}
.sidebar-profile-trigger:hover { background: var(--bg); }
.sidebar-profile-trigger .avatar {
    flex: 0 0 32px; width: 32px; height: 32px; border-radius: 50%;
    background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
}
.sidebar-profile-info { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; gap: 1px; }
.sidebar-profile-name {
    font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.sidebar-profile-org { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }
.sidebar-profile-caret { width: 15px; height: 15px; flex: 0 0 15px; color: var(--text-muted); transition: transform .15s; }
.sidebar-profile.open .sidebar-profile-caret { transform: rotate(180deg); }

.profile-menu {
    display: none;
    position: absolute; left: 10px; right: 10px; bottom: calc(100% + 6px);
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 12px 28px rgba(20, 24, 33, .16); padding: 6px; z-index: 200;
}
.sidebar-profile.open .profile-menu { display: block; }
.profile-menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px;
    border-radius: 7px; border: none; background: transparent; color: var(--text);
    font-size: 13px; font-weight: 500; font-family: inherit; cursor: pointer; text-align: left;
}
.profile-menu-item:hover { background: var(--bg); text-decoration: none; }
.profile-menu-item svg { width: 16px; height: 16px; flex: 0 0 16px; color: var(--text-muted); }
.profile-menu-item-danger { color: var(--red); }
.profile-menu-item-danger svg { color: var(--red); }
.profile-menu-divider { height: 1px; background: var(--border); margin: 4px 6px; }

.main {
    grid-area: main;
    padding: 22px;
    overflow-x: hidden;
}

/* ---------- Cards / overview ---------- */
.card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 18px;
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    background: #fff;
    border: 1px solid var(--border);
    border-top: 3px solid var(--brand);
    border-radius: 8px;
    padding: 14px 16px;
}
.stat-card.c-blue { border-top-color: var(--brand); }
.stat-card.c-green { border-top-color: var(--green); }
.stat-card.c-red { border-top-color: var(--red); }
.stat-card.c-purple { border-top-color: var(--purple); }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--text); }
.stat-card.c-blue .value { color: var(--brand); }
.stat-card.c-green .value { color: var(--green); }
.stat-card.c-red .value { color: var(--red); }
.stat-card.c-purple .value { color: var(--purple); }
.stat-card .label { font-size: 11px; font-weight: 700; letter-spacing: .03em; color: var(--text-muted); margin-top: 2px; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.panel-row {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 16px;
    align-items: start;
}
@media (max-width: 1000px) {
    .panel-row { grid-template-columns: 1fr; }
}

.panel-title {
    font-size: 14px;
    font-weight: 700;
    margin: 0 0 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
}
.page-header h2 { margin: 0; font-size: 20px; }

/* Groups the static template buttons and the JS-rendered ones (Hold/Close/Send for Sign-off/
   etc., injected into #project-actions) into ONE continuous flex-wrap row instead of two
   independently-wrapping boxes — the ragged "some buttons wrap, some don't" layout otherwise
   happens because #project-actions is a block-level flex item whose own button children only
   follow normal inline text flow, wrapping at a different width than the outer row. */
.project-action-bar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
.project-actions-slot { display: contents; }

.btn, .btn-outline {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .01em;
    cursor: pointer;
    line-height: 1.2;
    white-space: nowrap;
    transition: background .15s, box-shadow .15s, border-color .15s, transform .05s;
}
.btn svg, .btn-outline svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn {
    background: var(--brand);
    color: #fff;
    border: none;
    box-shadow: 0 1px 2px rgba(47, 111, 237, .3), 0 1px 3px rgba(20, 24, 33, .08);
}
.btn:hover { background: var(--brand-dark); box-shadow: 0 2px 6px rgba(47, 111, 237, .4), 0 1px 3px rgba(20, 24, 33, .1); }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn-outline:disabled { opacity: .65; cursor: default; transform: none; box-shadow: none; }
.btn-spinner {
    display: inline-block; width: 12px; height: 12px; margin-right: 6px;
    border: 2px solid rgba(255, 255, 255, .5); border-top-color: #fff; border-radius: 50%;
    vertical-align: -1px; animation: mat-spin .7s linear infinite;
}
.btn-outline .btn-spinner { border-color: rgba(43, 47, 56, .25); border-top-color: var(--text); }

/* ---------- Auth page ---------- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #eef2fb, #f8fafc);
}
.auth-card {
    width: 360px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 32px 30px;
    box-shadow: 0 10px 30px rgba(30, 40, 80, .08);
}
.auth-brand { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.auth-brand-mark { color: var(--brand); }
.auth-brand-sub { color: var(--text); margin-left: 4px; }
.auth-tagline { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }
.auth-error {
    background: #fdeceb; color: var(--red); border: 1px solid #f6c8c6;
    padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 14px;
}
.auth-success {
    background: #e9f9f1; color: var(--green); border: 1px solid #bfe9d3;
    padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 14px;
}
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.auth-form input {
    border: 1px solid var(--border); border-radius: 6px; padding: 9px 10px; font-size: 14px; font-family: inherit;
}

.password-wrap { position: relative; display: flex; }
.password-wrap input { flex: 1; padding-right: 38px !important; }
.auth-form .password-toggle-btn {
    position: absolute; right: 0; top: 0; bottom: 0; width: 36px; height: auto;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; padding: 0; margin: 0; cursor: pointer; color: var(--text-muted);
}
.auth-form .password-toggle-btn:hover { background: transparent; color: var(--brand); }
.password-toggle-btn svg { width: 18px; height: 18px; }
.auth-form button {
    margin-top: 6px; background: var(--brand); color: #fff; border: none; border-radius: 6px;
    padding: 10px; font-size: 14px; font-weight: 700; cursor: pointer;
}
.auth-form button:hover { background: var(--brand-dark); }

.auth-row {
    display: flex; align-items: center; justify-content: space-between; font-size: 13px; margin-top: -4px;
}
.auth-checkbox {
    display: flex !important; flex-direction: row !important; align-items: center; gap: 6px;
    font-weight: 400 !important; color: var(--text) !important; cursor: pointer;
}
.auth-checkbox input { width: auto; }
.auth-link { color: var(--brand); font-size: 13px; }
.auth-hint { color: var(--text-muted); font-size: 12.5px; }
.auth-reset-link { font-size: 12.5px; word-break: break-all; margin: 0 0 10px; }

.master-detail-heading { font-weight: 700; font-size: 13px; margin-bottom: 8px; }

/* ---------- Material-style modal (Customers/Partners add-edit) ---------- */
.mat-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .5);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.mat-modal-card {
    background: #fff;
    border-radius: 16px;
    width: 480px;
    max-width: 100%;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 24px 48px -12px rgba(15, 23, 42, .35), 0 0 0 1px rgba(15, 23, 42, .04);
    animation: mat-pop .16s ease-out;
}
.mat-modal-card-wide { width: 640px; }
.mat-field-error {
    display: none;
    color: var(--red, #e5484d);
    font-size: 12px;
    margin-top: 4px;
}
.mat-field-error.show { display: block; }
.mat-input.mat-input-invalid { border-color: var(--red, #e5484d); }
@keyframes mat-pop {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.mat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
}
.mat-modal-header h3 { margin: 0; font-size: 19px; font-weight: 700; }
.mat-modal-close {
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
}
.mat-modal-close:hover { background: var(--bg); color: var(--text); }
.mat-modal-body { padding: 20px 24px 4px; display: flex; flex-direction: column; gap: 18px; }
.mat-field { display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 0; }
.mat-field-row { display: flex; gap: 14px; }
.mat-field-checkbox { justify-content: flex-end; }
.mat-field label { font-size: 13.5px; font-weight: 700; color: var(--text); }
.mat-field label .mat-required { color: var(--red); font-weight: 700; margin-left: 2px; }
.mat-field label .mat-optional { color: var(--text-muted); font-weight: 400; margin-left: 2px; }
.mat-input::placeholder, .mat-textarea::placeholder { color: #9aa3b2; }
.mat-textarea { resize: vertical; min-height: 78px; line-height: 1.5; }
.mat-checkbox-label { display: flex !important; flex-direction: row !important; align-items: center; gap: 6px; font-size: 14px !important; font-weight: 400 !important; color: var(--text) !important; height: 42px; cursor: pointer; }
.mat-checkbox-label input { width: auto; }
.mat-input {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 14px;
    font-size: 14px;
    font-family: inherit;
    background: #fbfbfd;
    transition: border-color .15s, box-shadow .15s, background .15s;
    width: 100%;
}
.mat-input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(47, 111, 237, .15);
    background: #fff;
}
.mat-modal-footer {
    display: flex; justify-content: flex-end; gap: 10px; padding: 18px 24px 24px;
    border-top: 1px solid var(--border); margin-top: 4px;
}

.side-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .35);
    z-index: 1000;
    display: flex;
    justify-content: flex-end;
}
.side-drawer {
    background: #fff;
    width: 560px;
    max-width: 92vw;
    height: 100%;
    box-shadow: -24px 0 48px -12px rgba(15, 23, 42, .25), 0 0 0 1px rgba(15, 23, 42, .04);
    display: flex;
    flex-direction: column;
    animation: side-drawer-in .18s ease-out;
}
@keyframes side-drawer-in {
    from { transform: translateX(24px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
.side-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}
.side-drawer-header h3 { margin: 0; font-size: 19px; font-weight: 700; }
.side-drawer-body { padding: 20px 24px; overflow-y: auto; flex: 1 1 auto; }

/* In-app PDF viewer. Opened from the sign-off drawer, so it sits above that drawer's
   backdrop (both default to z-index 1000) rather than relying on DOM order alone. */
.mat-modal-backdrop.pdf-viewer-backdrop { z-index: 1100; }
.pdf-viewer-card {
    width: 1000px;
    max-width: 95vw;
    height: 92vh;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.pdf-viewer-card .mat-modal-header { flex: 0 0 auto; }
.pdf-viewer-actions { display: flex; align-items: center; gap: 10px; }
.pdf-viewer-actions .btn { text-decoration: none; }
.pdf-viewer-newtab { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.pdf-viewer-newtab:hover { color: var(--brand); }

.la-summary { display: flex; align-items: center; gap: 10px; margin: 0 0 0 4px; font-size: 12px; }
.la-summary-warn { color: var(--red); font-weight: 600; }
/* Seven columns don't fit a narrow viewport. Without a floor the browser keeps shrinking them
   until names and timestamps wrap one character per line; this makes the table scroll inside
   its .fg-table-wrap (which is already overflow-x:auto) instead of crushing. */
.la-table { min-width: 980px; }
.la-table .la-nowrap { white-space: nowrap; }
.la-table .fg-cell-name { min-width: 0; }
.la-table .fg-name-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.la-detail-cell { flex-direction: column; align-items: flex-start; gap: 2px; }
.la-detail-label { font-size: 13px; }
/* Clamped rather than truncated to one line: the useful part of an IdP error is often at the
   end of the string. Full text stays available via the title attribute. */
.la-detail-text {
    font-size: 11.5px; color: var(--text-muted); line-height: 1.35;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pdf-viewer-body { flex: 1 1 auto; min-height: 0; background: var(--bg); }
.pdf-viewer-frame { width: 100%; height: 100%; border: 0; display: block; }

.mat-logo-row {
    display: flex; align-items: center; gap: 12px; background: var(--bg);
    border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; flex-wrap: wrap;
}
.mat-logo-thumb {
    width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--border);
    background: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 9px; color: var(--text-muted); text-align: center; flex: 0 0 44px; overflow: hidden;
}
.mat-logo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.mat-logo-actions { display: flex; gap: 8px; }
.mat-logo-hint { flex-basis: 100%; font-size: 11.5px; color: var(--text-muted); }
.mat-btn {
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(47, 111, 237, .35);
    transition: background .15s, box-shadow .15s;
}
.mat-btn:hover { background: var(--brand-dark); box-shadow: 0 4px 14px rgba(47, 111, 237, .45); }
.mat-btn:disabled { opacity: .6; cursor: default; box-shadow: none; }
.mat-btn-outline:disabled { opacity: .6; cursor: default; }

.mat-btn-spinner {
    display: inline-block;
    width: 13px;
    height: 13px;
    margin-right: 6px;
    border: 2px solid rgba(255, 255, 255, .5);
    border-top-color: #fff;
    border-radius: 50%;
    vertical-align: -2px;
    animation: mat-spin .7s linear infinite;
}
.mat-btn-outline .mat-btn-spinner { border-color: rgba(43, 47, 56, .25); border-top-color: var(--text); }
@keyframes mat-spin {
    to { transform: rotate(360deg); }
}
.mat-btn-outline {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.mat-btn-outline:hover { background: var(--bg); }
.mat-btn-text {
    background: none;
    border: none;
    color: var(--brand);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.mat-btn-text:hover { background: rgba(47, 111, 237, .08); }
.mat-btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 8px; }
.mat-empty { color: var(--text-muted); text-align: center; padding: 20px 12px; font-size: 13px; }
.mat-icon-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; border-radius: 4px; width: 24px; height: 24px; flex: 0 0 24px; }
.mat-icon-btn:hover { background: #fdeceb; color: var(--red); }
.mat-static-value { font-size: 14px; color: var(--text); padding: 11px 0 0; }
.mat-static-value.mat-muted { color: var(--text-muted); font-size: 13px; }
.mat-hint { font-size: 11.5px; color: var(--text-muted); margin-top: -4px; }

.mat-users-toolbar { display: flex; align-items: center; justify-content: space-between; }
.mat-users-count { font-size: 13px; color: var(--text-muted); }
.mat-user-form-card {
    background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-top: 4px;
    display: flex; flex-direction: column; gap: 12px;
}
.mat-user-form-title { font-weight: 700; font-size: 13.5px; }
.mat-user-form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.mat-user-list { display: flex; flex-direction: column; gap: 8px; }
.mat-user-card {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 10px;
}
.mat-avatar {
    width: 36px; height: 36px; border-radius: 50%; flex: 0 0 36px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 13px; font-weight: 700;
}
.mat-avatar.mat-avatar-img { background: var(--bg); border: 1px solid var(--border); overflow: hidden; }
.mat-avatar.mat-avatar-img img { width: 100%; height: 100%; object-fit: cover; }
.mat-user-info { flex: 1; min-width: 0; }
.mat-user-name { font-weight: 600; font-size: 13.5px; }
.mat-user-email { font-size: 12.5px; color: var(--text-muted); }

.fg-filter-row td { padding: 6px 8px; background: #fafbfc; }
.fg-input-filter {
    width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
    font-size: 12.5px; font-family: inherit; background: #fff;
}
.mat-user-pills { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }

.fg-locked-banner {
    background: #fff8e6; color: #92650a; border: 1px solid #f2dca3;
    padding: 10px 14px; border-radius: 8px; font-size: 13px; margin: 0 20px 14px;
}

.auth-card-wide { width: 480px; }
.auth-card-xwide { width: 560px; }
.sign-summary {
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    padding: 12px 14px; margin-top: 4px;
}
.sign-summary-title { font-weight: 700; margin-bottom: 4px; }
.sign-summary-line { font-size: 12.5px; color: var(--text-muted); }

.sign-pad-label { font-size: 13px; color: var(--text-muted); font-weight: 600; margin-bottom: 6px; }
.sign-pad-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
/* Selectors below are deliberately `.sign-pad-tabs button` / `.sign-pad-actions button` (two
   classes' worth of specificity via the wrapper) rather than the bare `.sign-pad-tab-btn` class
   alone — `.auth-form button` elsewhere sets a blue filled background on every <button> inside
   the form, and a single-class selector loses to that compound one, silently falling back to
   the submit-button look for any tab that isn't `.active`. */
.sign-pad-tabs button.sign-pad-tab-btn {
    flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
    background: #fff; color: var(--text-muted); font-size: 12.5px; font-weight: 600; cursor: pointer;
    font-family: inherit; margin-top: 0;
}
.sign-pad-tabs button.sign-pad-tab-btn.active { border-color: var(--brand); color: var(--brand); background: #eef4ff; }
.sign-pad-canvas-wrap { position: relative; }
.sign-pad-canvas {
    width: 100%; height: 160px; border: 1px dashed var(--border); border-radius: 8px;
    background: #fff; cursor: crosshair; touch-action: none; display: block;
}
.sign-pad-placeholder {
    position: absolute; top: 50%; left: 0; right: 0; text-align: center; transform: translateY(-50%);
    color: #b7bfcc; font-size: 13px; pointer-events: none;
}
.sign-pad-actions { display: flex; justify-content: flex-end; margin-top: 6px; }
.sign-pad-actions button.sign-pad-clear-btn {
    background: transparent; border: none; color: var(--text-muted); font-size: 12px; cursor: pointer;
    padding: 2px 6px; font-family: inherit; margin-top: 0;
}
.sign-pad-actions button.sign-pad-clear-btn:hover { color: var(--brand); }
.sign-pad-upload-wrap {
    border: 1px dashed var(--border); border-radius: 8px; padding: 16px; text-align: center; background: #fbfbfd;
}
.sign-pad-upload-preview { max-height: 110px; max-width: 100%; margin: 0 auto 10px; display: block; }
.sign-pad-upload-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }

.sign-history { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 16px; }
.sign-history-title { font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.sign-history-row {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
    padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12.5px;
}
.sign-history-row:last-child { border-bottom: none; }
.sign-history-name { font-weight: 600; color: var(--text); }
.sign-history-email { color: var(--text-muted); font-size: 11.5px; }
.sign-history-when { color: var(--text-muted); font-size: 11px; white-space: nowrap; margin-top: 3px; }

.sso-btn {
    width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
    background: #fff; border: 1px solid var(--border); border-radius: 6px;
    padding: 10px; font-size: 14px; font-weight: 600; color: var(--text);
    cursor: pointer; margin-bottom: 16px; text-decoration: none;
    font-family: inherit; box-sizing: border-box;
}
.sso-btn:hover { background: var(--bg); border-color: #b9c2d1; text-decoration: none; }
/* Placeholder state, used while single sign-on isn't configured. */
.sso-btn:disabled { cursor: not-allowed; opacity: .7; background: #fff; border-color: var(--border); }
.sso-btn-mark {
    width: 20px; height: 20px; border-radius: 5px; background: var(--brand); color: #fff;
    display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800;
}
.auth-divider {
    display: flex; align-items: center; text-align: center; color: var(--text-muted);
    font-size: 12px; margin-bottom: 16px;
}
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; border-bottom: 1px solid var(--border); }
.auth-divider span { padding: 0 10px; }

.btn-outline {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(20, 24, 33, .04);
}
.btn-outline:hover { background: var(--bg); border-color: #b9c2d1; box-shadow: 0 1px 3px rgba(20, 24, 33, .1); }
.btn-outline:active { transform: scale(.97); }
.btn-outline svg { color: var(--text-muted); }
.btn-outline:hover svg { color: var(--brand); }
.btn-green { background: var(--green); }
.btn-green:hover { background: #1c8a56; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #c53438; }

/* ---------- Feature tree grid (plain HTML/JS) ---------- */
.fg-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}
.fg-tab-btn {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}
.fg-tab-btn:hover { color: var(--text); }
.fg-tab-btn.fg-tab-active { color: var(--brand); border-bottom-color: var(--brand); }
.fg-tab-count {
    background: var(--bg);
    color: var(--text-muted);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
}
.fg-tab-btn.fg-tab-active .fg-tab-count { background: var(--brand); color: #fff; }
.fg-tab-btn-mode { margin-left: 10px; padding-left: 14px; border-left: 1px solid var(--border); }

.fg-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.fg-toolbar-left { display: flex; align-items: center; gap: 8px; }
.fg-dirty-actions { display: none; align-items: center; gap: 8px; }
.fg-search-input {
    -webkit-appearance: none;
    appearance: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13px;
    width: 260px;
    font-family: inherit;
}

.fg-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.tree-grid-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tree-grid-table th {
    text-align: left;
    background: #f8f9fb;
    border-bottom: 1px solid var(--border);
    padding: 9px 10px;
    font-weight: 700;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.tree-grid-table td { border-bottom: 1px solid var(--border); padding: 0; vertical-align: middle; }
.tree-grid-table tr.fg-row:hover td { background: #f7f9fc; }
.tree-grid-table tr.fg-row-new td { background: #eef7ff; }
.tree-grid-table tr.fg-row-dirty td { background: #fffaeb; }
.tree-grid-table tr.fg-row-focused td { box-shadow: inset 0 0 0 1px var(--brand); }
.tree-grid-table tr.fg-row-selected td { background: #eaf2ff; }
.tree-grid-table .fg-empty-row td { padding: 18px 10px; color: var(--text-muted); text-align: center; }

.fg-select-cell { cursor: pointer; user-select: none; }
.fg-select-cell .fg-cell { justify-content: center; gap: 4px; }
.fg-row-selected .fg-select-cell .fg-cell { color: var(--brand); font-weight: 700; }
.fg-select-cell[draggable="true"] { cursor: grab; }
.fg-drag-handle { color: var(--border); font-size: 12px; line-height: 1; letter-spacing: -2px; }
.fg-select-cell:hover .fg-drag-handle { color: var(--text-muted); }

.tree-grid-table tr.fg-row-dragging { opacity: 0.4; }
.tree-grid-table tr.fg-drop-before td { box-shadow: inset 0 2px 0 0 var(--brand); }
.tree-grid-table tr.fg-drop-after td { box-shadow: inset 0 -2px 0 0 var(--brand); }

.fg-cell { padding: 8px 10px; min-height: 34px; display: flex; align-items: center; gap: 6px; cursor: text; }
.fg-cell-name { gap: 6px; }
.fg-toggle {
    width: 16px;
    flex: 0 0 16px;
    text-align: center;
    cursor: pointer;
    color: var(--text-muted);
    user-select: none;
    font-size: 11px;
}
.fg-toggle.fg-toggle-leaf { visibility: hidden; cursor: default; }
.fg-name-text { flex: 1; word-break: break-word; }
.fg-highlight { background: #fff3a0; border-radius: 2px; padding: 0 1px; }

.fg-cell-description { align-items: flex-start; }
.fg-description-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: pre-wrap;
    word-break: break-word;
}
.tree-grid-table.fg-autofit .fg-description-text {
    display: block;
    -webkit-line-clamp: unset;
    overflow: visible;
}
.fg-autofit-btn.fg-autofit-active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}
.fg-cell-description-edit { align-items: flex-start; }
.fg-cell textarea {
    border: 1px solid var(--brand);
    border-radius: 4px;
    padding: 5px 7px;
    font-size: 13px;
    width: 100%;
    font-family: inherit;
    resize: vertical;
    min-height: 44px;
}

.fg-rownum-cell .fg-cell { justify-content: center; color: var(--text-muted); font-size: 12px; }
.fg-actions-cell { padding: 0 6px; }
.fg-row-actions { display: flex; gap: 6px; opacity: 0; justify-content: flex-end; }
.tree-grid-table tr:hover .fg-row-actions { opacity: 1; }
.fg-icon-btn {
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex: 0 0 30px;
}
.fg-icon-btn svg { width: 16px; height: 16px; }
.fg-icon-btn:hover { background: #e8f0ff; color: var(--brand); border-color: #c7d7fb; }
.fg-icon-btn.fg-icon-delete:hover { background: #fdeceb; color: var(--red); border-color: #f6c8c6; }
.fg-icon-btn.fg-icon-users { background: #f1ecff; border-color: #ded0ff; color: var(--purple); }
.fg-icon-btn.fg-icon-users:hover { background: #e5d9ff; border-color: var(--purple); color: var(--purple); }
a.fg-icon-btn { text-decoration: none; }
.fg-cell-icon-link { justify-content: center; cursor: default; }

.fg-cell input[type="text"] {
    border: 1px solid var(--brand);
    border-radius: 4px;
    padding: 5px 7px;
    font-size: 13px;
    width: 100%;
    font-family: inherit;
}

.fg-cell-static { cursor: default; }
.fg-cell-static a { cursor: pointer; }
.fg-cell-checkbox { justify-content: center; cursor: default; }
.fg-cell-checkbox input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; margin: 0; }

.fg-audit { line-height: 1.35; }
.fg-audit-name { font-size: 12.5px; color: var(--text); }
.fg-audit-date { font-size: 11px; color: var(--text-muted); }
.fg-cell select {
    border: 1px solid var(--brand);
    border-radius: 4px;
    padding: 5px 7px;
    font-size: 13px;
    width: 100%;
    font-family: inherit;
    background: #fff;
}

.fg-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.fg-tag-chip-static {
    background: #eef2fb;
    color: var(--text);
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 12px;
}
.fg-tag-empty { color: var(--text-muted); font-size: 12px; }

.fg-tag-editor { position: relative; width: 100%; }
.fg-tag-editor-box {
    border: 1px solid var(--brand);
    border-radius: 4px;
    padding: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    background: #fff;
    min-height: 26px;
}
.fg-tag-editor-box input {
    border: none;
    outline: none;
    flex: 1;
    min-width: 60px;
    font-size: 13px;
    padding: 2px;
    font-family: inherit;
}
.fg-tag-chip {
    background: #e8f0ff;
    color: var(--brand-dark);
    border-radius: 10px;
    padding: 2px 6px 2px 8px;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.fg-tag-chip .x { cursor: pointer; font-weight: 700; color: var(--text-muted); }
.fg-tag-chip .x:hover { color: var(--red); }

.fg-tag-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 6px 16px rgba(20, 30, 60, .12);
    max-height: 180px;
    overflow-y: auto;
    z-index: 50;
    margin-top: 2px;
}
.fg-tag-option { padding: 6px 10px; font-size: 13px; cursor: pointer; }
.fg-tag-option:hover, .fg-tag-option.fg-active { background: #f0f4ff; }

/* Anchored via JS (getBoundingClientRect) instead of CSS containment, so a scrollable
   ancestor (e.g. .fg-table-wrap) can never clip it. */
.fg-tag-dropdown-portal {
    position: fixed;
    left: auto;
    right: auto;
    margin-top: 0;
    z-index: 3000;
}
.fg-tag-option-empty { padding: 6px 10px; font-size: 12px; color: var(--text-muted); }

/* Toast */
#toast {
    position: fixed; bottom: 20px; right: 20px; z-index: 3000;
    background: #2b2f38; color: #fff; padding: 10px 16px; border-radius: 6px;
    font-size: 13px; opacity: 0; transform: translateY(8px); transition: all .2s ease; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: var(--red); }
#toast.success { background: var(--green); }

/* Generic modal dialog */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(20, 24, 33, .45);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000; padding: 20px;
}
.modal-card {
    background: #fff; border-radius: 10px; width: 460px; max-width: 100%;
    max-height: 90vh; overflow-y: auto; padding: 22px 24px;
    box-shadow: 0 20px 50px rgba(20, 24, 33, .25);
}
.modal-title { font-size: 17px; font-weight: 700; margin: 0 0 16px; color: var(--text); }
.modal-form { display: flex; flex-direction: column; gap: 14px; }
.modal-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.modal-form input, .modal-form select {
    border: 1px solid var(--border); border-radius: 6px; padding: 9px 10px;
    font-size: 14px; font-family: inherit; color: var(--text);
}
.modal-form .fg-tag-editor-box { min-height: 38px; border: 1px solid var(--border); border-radius: 6px; }
.modal-form .fg-tag-editor { position: relative; }
.modal-hint { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.modal-note-label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.modal-textarea {
    width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
    font-size: 13px; font-family: inherit; color: var(--text); background: #fbfbfd;
    resize: vertical; min-height: 64px; line-height: 1.5;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.modal-textarea::placeholder { color: #9aa3b2; }
.modal-textarea:focus {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47, 111, 237, .15); background: #fff;
}

.mat-email-preview-frame {
    border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
    height: 420px; background: #fff;
}
.mat-email-preview-frame iframe { width: 100%; height: 100%; border: none; display: block; }

.modal-card-confirm { width: 420px; }
.modal-confirm-message { font-size: 14px; color: var(--text); line-height: 1.5; margin: 0; }

.modal-card-wide { width: 560px; }
.modal-card-xwide { width: 780px; }

.team-groups { display: flex; flex-direction: column; gap: 18px; max-height: 400px; overflow-y: auto; margin-top: 4px; }
.team-group-title {
    font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-muted); margin-bottom: 6px;
}
.team-group-empty { font-size: 12.5px; color: var(--text-muted); padding: 4px 2px; }
.team-user-row {
    display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 6px;
    cursor: pointer; font-size: 13px;
}
.team-user-row:hover { background: var(--bg); }
.team-user-row input { width: auto; margin: 0; }
.team-user-name { font-weight: 600; color: var(--text); }
.team-user-email { color: var(--text-muted); font-size: 12px; margin-left: auto; white-space: nowrap; }

.modal-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 16px;
}
.modal-form-grid .modal-field-full { grid-column: 1 / -1; }

.status-pill {
    display: inline-flex; align-items: center; padding: 5px 12px; border-radius: 999px;
    font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .02em;
    white-space: nowrap;
}
.status-pill-hold { background: #fff3cd; color: #92650a; }
.status-pill-sent { background: #e0ecff; color: var(--brand-dark); }
.status-pill-signed { background: #e0f7e9; color: #1c8a56; }
.status-pill-neutral { background: #eef1f6; color: var(--text-muted); }
.status-pill-inactive { background: #fdeceb; color: var(--red); }
.status-pill-review { background: #f3e8ff; color: #7c3aed; }

.mat-switch { position: relative; display: inline-block; width: 44px; height: 24px; cursor: pointer; flex: 0 0 44px; }
.mat-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.mat-switch-track { position: absolute; inset: 0; background: #cbd2e0; border-radius: 999px; transition: background .15s; }
.mat-switch-track::before {
    content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.mat-switch input:checked + .mat-switch-track { background: var(--brand); }
.mat-switch input:checked + .mat-switch-track::before { transform: translateX(20px); }

.mat-settings-row {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 14px 0; border-bottom: 1px solid var(--border);
}
.mat-settings-row:last-of-type { border-bottom: none; }
.mat-settings-row-title { font-weight: 700; font-size: 14px; }
.mat-settings-row-desc { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.mat-event-card { border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 14px; }
.mat-event-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.mat-event-card-title { font-weight: 700; font-size: 14px; }
.mat-event-card-desc { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }
.mat-event-card-placeholders { font-size: 11px; color: var(--text-muted); margin-top: 6px; font-family: monospace; }
.mat-event-card-bottom {
    display: flex; align-items: center; justify-content: space-between; margin-top: 14px;
    padding-top: 12px; border-top: 1px solid var(--border);
}
.mat-event-template-label { font-size: 12px; color: var(--text-muted); }

.wf-recipients-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.wf-recipient-row { display: grid; grid-template-columns: 1fr 1.4fr 28px; gap: 8px; align-items: center; }
.wf-recipient-row input {
    border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 13px; font-family: inherit;
}
