/* ============================================
   iMotion Sign Lite — Design System
   Brand: Navy #1B3A6B | Orange #E87722 | Cream #FDF5EE
   ============================================ */

:root {
    /* ── Brand colours ── */
    --primary: #1B3A6B;
    --primary-hover: #15305a;
    --primary-dark: #0f2040;
    --primary-light: #EEF3FB;
    --primary-muted: #5A7BA8;
    --accent: #E87722;
    --accent-hover: #cc6618;
    --accent-light: #FEF0E3;
    --on-primary: #FFFFFF;
    --link: #1B3A6B;
    /* ── Semantic ── */
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #1B3A6B;
    --info-light: #EEF3FB;
    /* ── Surface / text ── */
    --bg: #FDF5EE;
    --bg-alt: #F5EDE4;
    --card: #FFFFFF;
    --sidebar: #1B3A6B;
    --sidebar-text: #aebcce;
    --sidebar-active-bg: #ffffff22;
    --text: #1B2A3B;
    --muted: #6B7A8D;
    --border: #E5D9CC;
    --border-light: #F0E8DF;
    /* ── Shadows ── */
    --shadow-sm: 0 1px 2px rgba(27,58,107,0.06);
    --shadow: 0 2px 4px rgba(27,58,107,0.08);
    --shadow-md: 0 4px 12px rgba(27,58,107,0.10);
    --shadow-lg: 0 10px 24px rgba(27,58,107,0.12);
    /* ── Shape / spacing ── */
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 0.2s ease;
}

/* ── Reset ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

input, select, textarea {
    font-family: inherit;
}

img, svg {
    display: block;
    max-width: 100%;
}

/* ================================================
   LAYOUT
   ================================================ */
.app {
    display: flex;
    min-height: 100vh;
}

/* ── Overlay ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.55);
    z-index: 90;
    opacity: 0;
    transition: opacity var(--transition);
    backdrop-filter: blur(2px);
}

    .sidebar-overlay.active,
    .sidebar-overlay.open {
        display: block;
        opacity: 1;
    }

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition), width 0.25s ease;
    overflow: hidden;
}

    /* When collapsed, sidebar must allow tooltip overflow */
    .sidebar.collapsed {
        overflow: visible;
    }

.sidebar-header {
    padding: 18px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1 1 auto;
}

.logo-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, #1B3A6B 0%, #c45a10 100%);
    border: 1px solid rgba(255,255,255,.25);
    box-shadow: 0 1px 5px rgba(0,0,0,.25);
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex: 0 0 auto;
    display: none;
}

.sidebar.collapsed .logo-icon {
    display: flex;
}

    .logo-icon img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        padding: 4px;
        box-sizing: border-box;
    }

.logo-title-img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 60px;
    object-fit: contain;
    
}

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
    flex: 1 1 auto;
}

.logo-title {
    font-weight: 700;
    font-size: 14px;
    color: #fff;
}

.logo-sub {
    font-size: 11px;
    color: rgba(255,255,255,.55);
    margin-top: 4px;
}

.sidebar-close {
    display: none;
    padding: 6px;
    color: var(--sidebar-text);
    border-radius: 6px;
}

    .sidebar-close svg {
        width: 20px;
        height: 20px;
    }

    .sidebar-close:hover {
        background: rgba(255,255,255,.1);
        color: #fff;
    }

/* ── Sidebar nav ── */
.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
}

.nav-section {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255,255,255,.35);
    padding: 12px 12px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 9px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--sidebar-text);
    transition: all .15s;
    width: 100%;
    text-align: left;
}

    .nav-item svg {
        width: 18px;
        height: 18px;
        flex-shrink: 0;
    }

    .nav-item:hover {
        background: rgba(255,255,255,.08);
        color: #fff;
    }

    .nav-item.active {
        background: var(--sidebar-active-bg);
        color: #fff;
    }

        .nav-item.active svg {
            stroke: var(--accent);
        }

.nav-logout {
    color: var(--sidebar-text);
}

    .nav-logout:hover {
        background: rgba(220,38,38,.15);
        color: #fca5a5;
    }

/* ── Sidebar footer ── */
.sidebar-footer {
    padding: 12px 10px 16px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.portal-link {
    color: rgba(255,255,255,.4);
    font-size: 12px;
    padding: 4px 12px;
}

    .portal-link:hover {
        color: var(--accent);
    }

/* ── Sidebar collapsed (desktop) ── */
.sidebar.collapsed {
    width: 64px;
}

    .sidebar.collapsed .logo-text {
        display: none;
    }

    .sidebar.collapsed .nav-section {
        display: none;
    }

    .sidebar.collapsed .nav-item {
        justify-content: center;
        padding: 10px 0;
        gap: 0;
        width: 100%;
        position: relative;
    }

        .sidebar.collapsed .nav-item span {
            display: block;
            position: absolute;
            left: calc(100% + 12px);
            top: 50%;
            transform: translateY(-50%);
            background: #1e293b;
            color: #fff;
            font-size: 12px;
            font-weight: 500;
            white-space: nowrap;
            padding: 5px 10px;
            border-radius: 6px;
            pointer-events: none;
            opacity: 0;
            transition: opacity 0.15s;
            z-index: 9999;
            box-shadow: 0 4px 12px rgba(0,0,0,.2);
        }

            .sidebar.collapsed .nav-item span::before {
                content: '';
                position: absolute;
                right: 100%;
                top: 50%;
                transform: translateY(-50%);
                border: 5px solid transparent;
                border-right-color: #1e293b;
            }

        .sidebar.collapsed .nav-item:hover span {
            opacity: 1;
        }

    .sidebar.collapsed .sidebar-header {
        justify-content: center;
        padding: 20px 8px;
    }

    .sidebar.collapsed .sidebar-nav {
        padding: 12px 8px;
        align-items: center;
        overflow: visible;
    }

    .sidebar.collapsed .sidebar-footer {
        padding: 12px 8px 20px;
        align-items: center;
        overflow: visible;
    }

.main-wrapper.sidebar-collapsed {
    margin-left: 64px;
}

/* ── Main wrapper ── */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.25s ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ================================================
   TOPBAR
   ================================================ */
.topbar {
    height: var(--topbar-height);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    color: var(--text);
    transition: background var(--transition);
}

    .menu-toggle:hover {
        background: var(--primary-light);
        color: var(--primary);
    }

    .menu-toggle svg {
        width: 22px;
        height: 22px;
    }

.topbar-search {
    flex: 1;
    max-width: 480px;
    position: relative;
}

    .topbar-search svg {
        position: absolute;
        left: 12px;
        top: 50%;
        transform: translateY(-50%);
        width: 17px;
        height: 17px;
        color: var(--muted);
    }

    .topbar-search input {
        width: 100%;
        height: 40px;
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 0 14px 0 38px;
        background: var(--bg);
        font-size: 14px;
        color: var(--text);
        outline: none;
        transition: border-color var(--transition), box-shadow var(--transition);
    }

        .topbar-search input:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(27,58,107,.12);
        }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    transition: background var(--transition), color var(--transition);
}

    .icon-btn:hover {
        background: var(--primary-light);
        color: var(--primary);
    }

    .icon-btn svg {
        width: 20px;
        height: 20px;
    }

.btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

    .btn-icon:hover {
        background: var(--primary-light);
        color: var(--primary);
    }

    .btn-icon svg {
        width: 18px;
        height: 18px;
    }

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 4px 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--transition);
}

    .user-menu:hover {
        background: var(--primary-light);
    }

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
}

.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
}

.user-role {
    font-size: 11px;
    color: var(--muted);
}

/* ================================================
   BUTTONS
   ================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all .15s;
    white-space: nowrap;
}

    .btn svg {
        width: 16px;
        height: 16px;
    }

.btn-primary {
    background: var(--primary);
    color: #fff;
}

    .btn-primary:hover {
        background: var(--primary-hover);
        box-shadow: var(--shadow-md);
        color: #fff;
    }

    .btn-primary:disabled {
        opacity: .5;
        cursor: not-allowed;
    }

.btn-accent {
    background: var(--accent);
    color: #fff;
}

    .btn-accent:hover {
        background: var(--accent-hover);
        box-shadow: var(--shadow-md);
        color: #fff;
    }

.btn-secondary, .btn-light {
    background: var(--card);
    color: var(--text);
    border-color: var(--border);
}

    .btn-secondary:hover, .btn-light:hover {
        background: var(--bg);
        border-color: var(--primary);
        color: var(--primary);
    }

.btn-ghost {
    color: var(--muted);
    padding: 8px 12px;
}

    .btn-ghost:hover {
        background: var(--primary-light);
        color: var(--primary);
    }

.btn-danger {
    background: var(--danger);
    color: #fff;
}

    .btn-danger:hover {
        background: #b91c1c;
    }

.btn-sm {
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
}

.btn-lg {
    height: 46px;
    padding: 0 24px;
    font-size: 15px;
}

.btn-text {
    font-size: 13px;
    color: var(--primary);
    font-weight: 500;
    padding: 4px 8px;
}

    .btn-text:hover {
        text-decoration: underline;
    }

.btn-link-action {
    color: var(--primary);
    font-weight: 600;
    font-size: 13.5px;
    background: none;
    padding: 0 6px;
}

    .btn-link-action:hover {
        text-decoration: underline;
    }

.btn-link-muted {
    color: var(--muted);
    font-weight: 600;
    font-size: 13.5px;
    background: none;
    padding: 0 6px;
}

    .btn-link-muted:hover {
        color: var(--text);
    }

    .btn-link-muted:disabled {
        opacity: .4;
        cursor: not-allowed;
    }

.btn-link-danger {
    color: #dc2626;
    font-weight: 600;
    font-size: 13.5px;
    background: none;
    padding: 0 6px;
}

    .btn-link-danger:hover {
        text-decoration: underline;
    }

.btn-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    transition: all var(--transition);
}

    .btn-fab:hover {
        transform: scale(1.05);
        background: var(--primary-hover);
    }

    .btn-fab svg {
        width: 24px;
        height: 24px;
    }

/* Create / New buttons (used in views) */
.btn-create {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 0 20px;
    height: 40px;
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s;
}

    .btn-create:hover {
        background: var(--primary-hover);
        color: #fff;
    }

/* ================================================
   PAGE SCAFFOLDING
   ================================================ */
.main-content {
    flex: 1;
    padding: 0;
}

.page {
    padding: 28px 32px;
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 800;
    margin: 0;
    color: var(--text);
}

.page-sub {
    color: var(--muted);
    font-size: 14px;
    margin-top: 4px;
}

.page-header-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* view-specific head used in Template/Packet/etc */
.tm-wrap {
    padding: 28px 32px;
}

.tm-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.tm-head-left h1 {
    font-size: 1.6rem;
    font-weight: 800;
    margin: 0 0 4px;
    color: var(--text);
}

.tm-head-left p {
    font-size: .875rem;
    color: var(--muted);
    margin: 0;
}

/* ================================================
   CARDS
   ================================================ */
.card, .card2 {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

    .card-header h2, .card-header h3 {
        font-size: 15px;
        font-weight: 600;
    }

.card-body {
    padding: 22px;
}

/* ================================================
   STAT CARDS
   ================================================ */
.stats-grid, .stat-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 22px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
}

    .stat-card:hover {
        box-shadow: var(--shadow-md);
        transform: translateY(-1px);
    }

.stat-top, .stat-card-top {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.stat-ico, .stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

    .stat-ico svg, .stat-icon svg {
        width: 21px;
        height: 21px;
        color: var(--primary);
    }

    .stat-icon.blue {
        background: var(--primary-light);
        color: var(--primary);
    }

    .stat-icon.green {
        background: var(--success-light);
        color: var(--success);
    }

    .stat-icon.amber {
        background: var(--warning-light);
        color: var(--warning);
    }

    .stat-icon.red {
        background: var(--danger-light);
        color: var(--danger);
    }

.stat-value, .stat-num {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 4px;
    color: var(--text);
}

.stat-label, .stat-lbl {
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.stat-delta {
    font-size: 12.5px;
    color: var(--success);
    font-weight: 600;
    margin-top: 4px;
}

/* audit stat colours */
.stat-blue .stat-num {
    color: var(--primary);
}

.stat-indigo .stat-num {
    color: var(--primary-hover);
}

.stat-green .stat-num {
    color: var(--success);
}

.stat-amber .stat-num {
    color: var(--warning);
}

.stat-trend {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 6px;
}

    .stat-trend.up {
        background: var(--success-light);
        color: var(--success);
    }

    .stat-trend.down {
        background: var(--danger-light);
        color: var(--danger);
    }

/* ================================================
   DASHBOARD GRID / CHARTS
   ================================================ */
.dashboard-grid, .dash-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 18px;
    height: 220px;
    padding: 16px;
    background: var(--bg-alt);
    border-radius: 12px;
}

.bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    height: 100%;
    justify-content: flex-end;
}

.bar {
    width: 60%;
    max-width: 46px;
    background: var(--primary);
    border-radius: 8px 8px 0 0;
    transition: .4s;
}

    .bar.last {
        background: var(--primary-muted);
    }

.bar-x {
    font-size: 12px;
    color: var(--muted);
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    height: 180px;
    padding: 0 8px;
}

.chart-bar-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 100%;
    justify-content: flex-end;
}

.chart-bar {
    width: 100%;
    max-width: 56px;
    min-height: 8px;
    border-radius: 6px 6px 2px 2px;
    background: var(--primary);
    transition: height 0.6s;
}

.chart-bar-label {
    font-size: 11px;
    color: var(--muted);
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.chart-container {
    position: relative;
    height: 220px;
}

.completion-big {
    font-size: 48px;
    font-weight: 800;
    color: var(--success);
    text-align: center;
}

.completion-track {
    height: 10px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 18px;
}

.completion-fill {
    height: 100%;
    background: var(--success);
    border-radius: 999px;
}

/* ================================================
   TABLES
   ================================================ */
.table-wrapper, .tm-table-wrap {
    overflow-x: auto;
}

table, .tm-table, .dtable, .signer-grid, .matrix {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

    thead th, .tm-table thead th, .dtable th {
        text-align: left;
        padding: 12px 16px;
        font-size: 12px;
        font-weight: 600;
        color: var(--muted);
        text-transform: uppercase;
        letter-spacing: .05em;
        border-bottom: 1px solid var(--border);
        background: var(--bg-alt);
        white-space: nowrap;
    }

    tbody td, .tm-table td, .dtable td {
        padding: 14px 16px;
        border-bottom: 1px solid var(--border-light);
        vertical-align: middle;
    }

    tbody tr, .dtable tbody tr {
        transition: background var(--transition);
    }

        tbody tr:hover, .dtable tbody tr:hover {
            background: var(--primary-light);
        }

        tbody tr:last-child td, .dtable tr:last-child td {
            border-bottom: none;
        }

    .tbl-name, .dtable .name-link {
        color: var(--primary);
        font-weight: 600;
        text-decoration: none;
    }

        .tbl-name:hover, .dtable .name-link:hover {
            text-decoration: underline;
        }

.tbl-actions, .table-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* action links */
.act-view {
    color: var(--primary);
    font-weight: 500;
    font-size: .875rem;
    background: none;
    border: none;
    cursor: pointer;
}

    .act-view:hover {
        text-decoration: underline;
    }

.act-edit {
    color: var(--text);
    font-weight: 500;
    font-size: .875rem;
    background: none;
    border: none;
    cursor: pointer;
}

    .act-edit:hover {
        color: var(--primary);
    }

.act-dup {
    color: #0284c7;
    font-weight: 500;
    font-size: .875rem;
    background: none;
    border: none;
    cursor: pointer;
}

    .act-dup:hover {
        color: #0369a1;
    }

.act-del {
    color: var(--danger);
    font-weight: 600;
    font-size: .875rem;
    background: none;
    border: none;
    cursor: pointer;
}

    .act-del:hover {
        color: #b91c1c;
    }

.act-activate {
    color: var(--success);
    font-weight: 500;
    font-size: .875rem;
    background: none;
    border: none;
    cursor: pointer;
}

    .act-activate:hover {
        color: #047857;
    }

/* ================================================
   BADGES / PILLS
   ================================================ */
.badge, .pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}

    .badge::before {
        content: '';
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: currentColor;
        margin-right: 5px;
    }

.badge-active, .pill-active, .pill-completed, .pill-signed {
    background: var(--success-light);
    color: var(--success);
}

.badge-draft, .pill-draft, .pill-pending, .pill-sent {
    background: var(--warning-light);
    color: var(--warning);
}

.badge-inactive, .pill-inactive, .pill-disabled {
    background: var(--bg-alt);
    color: var(--muted);
}

.badge-sent, .badge-viewed, .pill-viewed, .pill-progress,
.pill-info {
    background: var(--info-light);
    color: var(--info);
}

.badge-expired, .pill-expired {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-completed {
    background: var(--success-light);
    color: var(--success);
}

.badge-archived {
    background: var(--bg-alt);
    color: var(--muted);
}

.badge-disabled {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-progress {
    background: var(--warning-light);
    color: var(--warning);
}

/* role tag */
.role-tag {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--primary-light);
    color: var(--primary);
}

/* ================================================
   PAGER
   ================================================ */
.tm-pager, .pg-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
    background: var(--card);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.pager-info, .pg-info {
    font-size: .875rem;
    color: var(--muted);
}

    .pager-info b {
        font-weight: 600;
        color: var(--text);
    }

.pager-nav, .pg-btns {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.pager-btn, .pg-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--card);
    color: var(--text);
    font-size: .875rem;
    cursor: pointer;
    transition: all .15s;
}

    .pager-btn:hover:not(:disabled):not(.active),
    .pg-btn:hover:not([disabled]):not(.active) {
        border-color: var(--primary);
        color: var(--primary);
        background: var(--primary-light);
    }

    .pager-btn.active, .pg-btn.active {
        background: var(--primary);
        border-color: var(--primary);
        color: #fff;
        font-weight: 600;
    }

    .pager-btn:disabled, .pg-btn[disabled] {
        opacity: .4;
        cursor: not-allowed;
    }

.pg-ellipsis {
    font-size: 13px;
    color: var(--muted);
    padding: 0 4px;
}

/* ================================================
   FORMS
   ================================================ */
.form-group {
    margin-bottom: 18px;
}

    .form-group label {
        display: block;
        font-size: 13px;
        font-weight: 600;
        margin-bottom: 6px;
        color: var(--text);
    }

.form-control, .input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--card);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

    .form-control:focus, .input:focus {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(27,58,107,.12);
    }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-select, .select, .tm-select, .filter-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7A8D' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.form-select, .select {
    height: 40px;
    padding: 0 32px 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--card);
    color: var(--text);
    outline: none;
    cursor: pointer;
}

    .form-select:focus, .select:focus {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(27,58,107,.12);
    }

/* search bars */
.search-bar, .tm-search-wrap, .search-wrap {
    position: relative;
}

    .search-bar svg, .tm-search-wrap svg, .search-wrap svg {
        position: absolute;
        left: 12px;
        top: 50%;
        transform: translateY(-50%);
        width: 16px;
        height: 16px;
        color: var(--muted);
        pointer-events: none;
    }

    .search-bar input, .tm-search, .search-wrap .input {
        width: 100%;
        padding: 9px 14px 9px 36px;
        border: 1px solid var(--border);
        border-radius: 8px;
        font-size: 14px;
        background: var(--card);
        color: var(--text);
        outline: none;
        transition: border-color var(--transition);
    }

        .search-bar input:focus, .tm-search:focus, .search-wrap .input:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(27,58,107,.12);
        }

.filters-bar, .filters {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.filter-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

.filter-date {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: .85rem;
    outline: none;
    background: var(--card);
    color: var(--text);
}

    .filter-date:focus {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(27,58,107,.12);
    }

.filter-select {
    padding: 8px 30px 8px 12px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: .85rem;
    background-color: var(--card);
    outline: none;
    color: var(--text);
    min-width: 140px;
    cursor: pointer;
    height: 36px;
}

    .filter-select:focus {
        border-color: var(--primary);
    }

/* filter action buttons */
.btn-apply {
    padding: 8px 20px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}

    .btn-apply:hover {
        background: var(--primary-hover);
    }

.btn-reset {
    padding: 8px 16px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
}

    .btn-reset:hover {
        border-color: var(--danger);
        color: var(--danger);
    }

.btn-export {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    font-size: .875rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
}

    .btn-export:hover {
        border-color: var(--primary);
        color: var(--primary);
    }

    .btn-export svg {
        width: 16px;
        height: 16px;
    }

/* view toggle (table/cards) */
.tm-toolbar, .tm-toolbar-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.tm-spacer {
    flex: 1;
}

.view-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

    .view-toggle button {
        padding: 8px 18px;
        border: none;
        background: var(--card);
        font-size: .875rem;
        font-weight: 500;
        color: var(--muted);
        cursor: pointer;
        transition: all .15s;
    }

        .view-toggle button.active {
            background: var(--primary);
            color: #fff;
        }

        .view-toggle button:not(.active):hover {
            background: var(--primary-light);
            color: var(--primary);
        }

/* toggle switch */
.toggle {
    width: 44px;
    height: 24px;
    background: var(--border);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background var(--transition);
    flex-shrink: 0;
}

    .toggle.active {
        background: var(--primary);
    }

    .toggle::after {
        content: '';
        position: absolute;
        top: 3px;
        left: 3px;
        width: 18px;
        height: 18px;
        background: white;
        border-radius: 50%;
        transition: transform var(--transition);
        box-shadow: var(--shadow-sm);
    }

    .toggle.active::after {
        transform: translateX(20px);
    }

/* ================================================
   ALERTS / LOADING
   ================================================ */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: .84rem;
    margin-bottom: 12px;
}

.alert-success {
    background: var(--success-light);
    border: 1px solid #bbf7d0;
    color: #166534;
}

.alert-error {
    background: var(--danger-light);
    border: 1px solid #fecaca;
    color: #991b1b;
}

.a-danger {
    background: var(--danger-light);
    color: #b91c1c;
}

.a-success {
    background: var(--success-light);
    color: #15803d;
}

.tm-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 80px 0;
}

.spin {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.tm-empty, .empty {
    text-align: center;
    padding: 64px 32px;
    color: var(--muted);
    font-size: .9rem;
}

    .tm-empty a, .empty a {
        color: var(--primary);
    }

/* ================================================
   MODALS
   ================================================ */
.modal-overlay, .modal-back {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.5);
    z-index: 500;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    backdrop-filter: blur(3px);
}

    .modal-overlay.open, .modal-back.show {
        display: flex;
    }

.modal, .modal-box {
    background: var(--card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalIn .25s ease;
}

.modal-lg {
    max-width: 640px;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(.96) translateY(8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

    .modal-header h3 {
        font-size: 17px;
        font-weight: 700;
    }

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 22px;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

    .modal-close:hover {
        background: var(--border-light);
        color: var(--text);
    }

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-message {
    color: var(--muted);
    line-height: 1.6;
    font-size: 14px;
}

/* ================================================
   TOAST
   ================================================ */
.toast, .app-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: white;
    background: var(--text);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    max-width: 360px;
}

    .toast.show, .app-toast.show {
        transform: translateY(0);
        opacity: 1;
    }

.toast-success, .app-toast-success {
    background: var(--success);
}

.toast-error, .app-toast-error, .app-toast-danger {
    background: var(--danger);
}

/* ================================================
   DROPDOWN
   ================================================ */
.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    z-index: 60;
    display: none;
    overflow: hidden;
}

    .dropdown-menu.open {
        display: block;
    }

.dropdown-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    color: var(--text);
    transition: background var(--transition);
}

    .dropdown-item:hover {
        background: var(--primary-light);
        color: var(--primary);
    }

    .dropdown-item.danger {
        color: var(--danger);
    }

        .dropdown-item.danger:hover {
            background: var(--danger-light);
        }

/* ================================================
   TIMELINE / AUDIT
   ================================================ */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.timeline-item {
    display: flex;
    gap: 14px;
    padding: 14px 0;
    position: relative;
}

    .timeline-item:not(:last-child)::before {
        content: '';
        position: absolute;
        left: 15px;
        top: 38px;
        bottom: -2px;
        width: 2px;
        background: var(--border);
    }

.timeline-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    z-index: 1;
}

    .timeline-dot svg {
        width: 14px;
        height: 14px;
    }

    .timeline-dot.green {
        background: var(--success-light);
        color: var(--success);
    }

    .timeline-dot.amber {
        background: var(--warning-light);
        color: var(--warning);
    }

.timeline-content {
    flex: 1;
    min-width: 0;
}

    .timeline-content strong {
        font-size: 14px;
        font-weight: 600;
        display: block;
    }

    .timeline-content span {
        font-size: 13px;
        color: var(--muted);
    }

.timeline-time {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

/* audit event badges */
.act-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
}

    .act-badge::before {
        content: '';
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: currentColor;
    }

.act-Viewed {
    background: var(--info-light);
    color: var(--info);
}

.act-Signed {
    background: var(--success-light);
    color: var(--success);
}

.act-Resent, .act-TokenResent {
    background: var(--warning-light);
    color: var(--warning);
}

.act-PacketCreated {
    background: #f3e8ff;
    color: #7e22ce;
}

.act-PacketSent {
    background: #e0f2fe;
    color: #0369a1;
}

.act-Expired {
    background: var(--danger-light);
    color: var(--danger);
}

.act-default {
    background: var(--bg-alt);
    color: var(--muted);
}

/* ================================================
   TEMPLATE CARDS
   ================================================ */
.templates-grid, .tm-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.template-card, .tm-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition);
}

    .template-card:hover, .tm-card:hover {
        box-shadow: var(--shadow-md);
        transform: translateY(-2px);
    }

.template-card-preview {
    height: 120px;
    background: linear-gradient(160deg, var(--primary-light) 0%, var(--bg) 70%);
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--border-light);
    position: relative;
}

    .template-card-preview svg {
        width: 40px;
        height: 40px;
        color: var(--primary-muted);
    }

.template-card-body, .tm-card-body {
    padding: 18px;
}

    .template-card-body h3, .tm-card-name {
        font-size: 15px;
        font-weight: 600;
        margin-bottom: 6px;
    }

/* ================================================
   BUILDER
   ================================================ */
.builder {
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    gap: 0;
    height: calc(100vh - var(--topbar-height));
    border-top: 1px solid var(--border);
}

.builder-col {
    overflow-y: auto;
    padding: 10px 14px;
}

.builder-left {
    border-right: 1px solid var(--border);
    background: var(--card);
}

.builder-center {
    background: #525866;
    display: flex;
    flex-direction: column;
}

.builder-right {
    border-left: 1px solid var(--border);
    background: var(--card);
}

.builder-toolbar {
    background: #3f4550;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 7px 16px;
    font-size: 13px;
    justify-content: center;
}

    .builder-toolbar button {
        color: #fff;
    }

.pdf-stage {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    padding: 12px;
}

.pdf-page {
    position: relative;
    background: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

    .pdf-page canvas {
        display: block;
    }

.builder-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    background: var(--card);
    border-top: 1px solid var(--border);
}

/* DOCX preview (mammoth-rendered) — fixed table layout so column widths
   are deterministic (container-width based) instead of content-based auto
   layout, which was reflowing differently between the builder and the
   signer page for the same document. */
.docx-content table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    margin: 8px 0;
}

.docx-content td, .docx-content th {
    border: 1px solid #d1d5db;
    padding: 4px 6px;
    font-size: 12px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    text-align: left;
}

.docx-content p {
    margin: 0 0 6px;
}

.docx-content h1, .docx-content h2, .docx-content h3 {
    margin: 10px 0 6px;
}

.field-box {
    position: absolute;
    border: 1.5px solid var(--primary);
    background: rgba(27,58,107,.10);
    font-size: 11px;
    color: var(--primary);
    padding: 2px 4px;
    cursor: move;
    border-radius: 3px;
    overflow: hidden;
}

    .field-box.sel {
        box-shadow: 0 0 0 2px var(--primary);
    }

    .field-box .fb-resize {
        position: absolute;
        right: -4px;
        bottom: -4px;
        width: 10px;
        height: 10px;
        background: var(--primary);
        border-radius: 50%;
        cursor: se-resize;
    }

    .field-box.t-signature {
        border-color: #3b82f6;
        background: rgba(59,130,246,.12);
        color: #2563eb;
    }

    .field-box.t-date {
        border-color: #16a34a;
        background: rgba(22,163,74,.12);
        color: #16a34a;
    }

    .field-box.t-text {
        border-color: #8b5cf6;
        background: rgba(139,92,246,.12);
        color: #7c3aed;
    }

    .field-box.t-initial {
        border-color: #f59e0b;
        background: rgba(245,158,11,.12);
        color: #d97706;
    }

/* palette */
.palette {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

    .palette .pal {
        display: flex;
        align-items: center;
        gap: 8px;
        border: 1px solid var(--border);
        border-radius: 9px;
        padding: 10px;
        font-size: 13px;
        font-weight: 600;
        cursor: grab;
        background: var(--card);
    }

        .palette .pal:hover {
            border-color: var(--primary);
            background: var(--primary-light);
            color: var(--primary);
        }

        .palette .pal .dot {
            width: 12px;
            height: 12px;
            border-radius: 3px;
        }

/* role-opt dropdown */
.role-opt {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s;
}

    .role-opt:hover {
        background: var(--primary-light);
        color: var(--primary);
    }

    .role-opt:first-child {
        border-radius: 8px 8px 0 0;
    }

    .role-opt:last-child {
        border-radius: 0 0 8px 8px;
    }

/* ================================================
   WIZARD
   ================================================ */
.wizard, .wz-wizard {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin: 8px 0 28px;
    flex-wrap: wrap;
}

.wz-step, .wizard-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.wz-dot, .wizard-step-num {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--bg-alt);
    color: var(--muted);
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border);
}

.wz-step.active .wz-dot, .wizard-step.active .wizard-step-num {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.wz-step.done .wz-dot, .wizard-step.done .wizard-step-num {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.wz-label, .wizard-step span {
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.wz-step.active .wz-label, .wz-step.done .wz-label,
.wizard-step.active, .wizard-step.done {
    color: var(--text);
}

.wz-line, .wizard-connector {
    width: 80px;
    height: 2px;
    background: var(--border);
    margin: 0 4px 26px;
}

    .wz-line.done, .wizard-connector.done {
        background: var(--success);
    }

.wz-card, .wizard-card {
    max-width: 760px;
    margin: 0 auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow);
}

.wz-actions, .wizard-footer {
    max-width: 760px;
    margin: 20px auto 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}

/* template options */
.tpl-option, .template-option {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 12px;
    cursor: pointer;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    transition: all var(--transition);
}

    .tpl-option.sel, .template-option.selected {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px var(--primary-light);
        background: var(--primary-light);
    }

    .tpl-option:hover, .template-option:hover {
        border-color: var(--primary-muted);
    }

.tpl-radio {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: var(--primary);
}

/* ================================================
   SETTINGS / ROLES
   ================================================ */
.settings-grid {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 24px;
}

.settings-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.settings-nav-item {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    transition: all var(--transition);
}

    .settings-nav-item:hover {
        background: var(--primary-light);
        color: var(--primary);
    }

    .settings-nav-item.active {
        background: var(--primary-light);
        color: var(--primary);
        font-weight: 600;
    }

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--border-light);
}

    .toggle-row:last-child {
        border-bottom: none;
    }

.toggle-info strong {
    font-size: 14px;
    display: block;
    margin-bottom: 2px;
}

.toggle-info span {
    font-size: 13px;
    color: var(--muted);
}

.role-grid {
    display: grid;
    grid-template-columns: repeat(2,1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.role-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
}

    .role-card .rc-head {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 10px;
    }

    .role-card h4 {
        font-size: 18px;
        font-weight: 700;
    }

    .role-card p {
        color: var(--muted);
        font-size: 14px;
        margin-bottom: 14px;
    }

    .role-card .assigned {
        color: #94a3b8;
        font-size: 13px;
    }

.matrix td.tick {
    text-align: center;
    color: var(--success);
    font-weight: 700;
}

.matrix td.cross {
    text-align: center;
    color: var(--border);
}

/* ================================================
   USERS
   ================================================ */
.user-avatar-circle {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

/* ================================================
   EMPTY STATES
   ================================================ */
.empty-state {
    text-align: center;
    padding: 64px 32px;
}

.empty-illustration {
    width: 140px;
    height: 140px;
    margin: 0 auto 24px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .empty-illustration svg {
        width: 64px;
        height: 64px;
        color: var(--primary);
        opacity: .7;
    }

.empty-state h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--muted);
    font-size: 14px;
    max-width: 400px;
    margin: 0 auto 24px;
}

/* ================================================
   UTILITY
   ================================================ */
.hidden {
    display: none !important;
}

.text-muted {
    color: var(--muted);
}

.text-sm {
    font-size: 13px;
}

.text-primary {
    color: var(--primary);
}

.text-accent {
    color: var(--accent);
}

.mt-4 {
    margin-top: 16px;
}

.mb-4 {
    margin-bottom: 16px;
}

.clickable {
    cursor: pointer;
}

.link {
    color: var(--link);
    font-weight: 500;
    cursor: pointer;
}

    .link:hover {
        text-decoration: underline;
    }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 16px;
    font-weight: 500;
}

    .back-link:hover {
        color: var(--primary);
    }

    .back-link svg {
        width: 16px;
        height: 16px;
    }

/* workflow steps */
.workflow-step {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 10px;
    text-align: center;
    font-weight: 600;
    font-size: 13px;
}

    .workflow-step.done {
        background: var(--success-light);
        border-color: #bbf7d0;
        color: var(--success);
    }

    .workflow-step.active {
        background: var(--primary-light);
        border-color: #b8cde8;
        color: var(--primary);
    }

.wf-arrow {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 2px;
}

/* order list */
.order-list .order-item {
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    text-align: center;
    font-weight: 600;
}

    .order-list .order-item.first {
        background: var(--primary-light);
        border-color: #b8cde8;
    }

.order-arrow {
    text-align: center;
    color: var(--muted);
    padding: 6px;
}

/* review rows */
.review-row, .review-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
}

    .review-row:last-child, .review-item:last-child {
        border-bottom: none;
    }

    .review-row .k, .review-item span {
        color: var(--muted);
    }

    .review-row .v {
        font-weight: 600;
    }

/* signer rows */
.signer-row {
    display: grid;
    grid-template-columns: 1fr 1fr 140px 80px 40px;
    gap: 12px;
    align-items: end;
    margin-bottom: 12px;
    padding: 16px;
    background: var(--bg-alt);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
}

/* ================================================
   RESPONSIVE — Tablet (≤1200px)
   ================================================ */
@media (max-width: 1200px) {
    .stats-grid, .stat-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .dashboard-grid, .dash-grid {
        grid-template-columns: 1fr;
    }

    .builder {
        grid-template-columns: 240px 1fr 240px;
    }

    .role-grid {
        grid-template-columns: 1fr;
    }
}

/* ================================================
   RESPONSIVE — Small desktop / large tablet (≤1024px)
   ================================================ */
@media (max-width: 1024px) {
    .stats-grid, .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .builder {
        grid-template-columns: 200px 1fr 200px;
    }

    .tm-wrap, .page {
        padding: 22px 24px;
    }
}

/* ================================================
   RESPONSIVE — Tablet portrait (≤900px)
   ================================================ */
@media (max-width: 900px) {
    /* Sidebar becomes drawer */
    .sidebar {
        transform: translateX(-100%);
    }

        .sidebar.open {
            transform: translateX(0);
        }

    .sidebar-close {
        display: block;
    }

    .main-wrapper {
        margin-left: 0;
    }

    /* Topbar */
    .topbar {
        padding: 0 16px;
    }

    .topbar-search {
        max-width: none;
        flex: 1;
    }

    .user-info {
        display: none;
    }

    /* Page content */
    .tm-wrap, .page {
        padding: 20px 16px;
    }

    .filter-bar {
        padding: 12px 14px;
        gap: 10px;
    }

    /* Builder full-column */
    .builder {
        grid-template-columns: 1fr;
        height: auto;
    }

    .builder-left, .builder-right {
        border: none;
        border-bottom: 1px solid var(--border);
    }

    /* Settings */
    .settings-grid {
        grid-template-columns: 1fr;
    }

    /* Notification panel */
    .notification-panel {
        left: 16px;
        right: 16px;
        width: auto;
    }

    /* Auth */
    .auth-page {
        flex-direction: column;
    }

    .auth-brand {
        padding: 32px 24px;
        min-height: auto;
    }

        .auth-brand h1 {
            font-size: 24px;
        }

    .auth-panel {
        max-width: none;
    }
}

/* ================================================
   RESPONSIVE — Mobile (≤640px)
   ================================================ */
@media (max-width: 640px) {
    :root {
        --topbar-height: 56px;
    }

    .stats-grid, .stat-grid {
        grid-template-columns: 1fr 1fr;
    }

    .dashboard-grid, .dash-grid {
        grid-template-columns: 1fr;
    }

    .role-grid {
        grid-template-columns: 1fr;
    }

    /* Topbar */
    .topbar {
        padding: 0 12px;
        gap: 8px;
    }

    .topbar-search {
        display: none;
    }

    /* Page head */
    .tm-head, .page-head {
        flex-direction: column;
        gap: 12px;
    }

    .tm-head-left h1, .page-title {
        font-size: 1.35rem;
    }

    .tm-wrap, .page {
        padding: 16px 14px;
    }

    /* Tables → horizontal scroll */
    .table-wrapper, .tm-table-wrap {
        -webkit-overflow-scrolling: touch;
    }

    table, .tm-table, .dtable {
        min-width: 540px;
    }

    /* Toolbar */
    .tm-toolbar {
        gap: 8px;
    }

    .view-toggle {
        display: none;
    }
    /* hide cards/table toggle on mobile */

    /* Forms */
    .form-row {
        grid-template-columns: 1fr;
    }

    .signer-row {
        grid-template-columns: 1fr;
    }

    /* Filter bar */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

        .filter-bar > * {
            width: 100%;
        }

    .filter-date, .filter-select {
        width: 100%;
    }

    /* Stat cards */
    .stat-card {
        padding: 14px 16px;
    }

    .stat-num, .stat-value {
        font-size: 1.6rem;
    }

    /* Wizard */
    .wizard-progress, .wizard {
        flex-wrap: wrap;
        gap: 8px;
    }

    .wizard-connector, .wz-line {
        width: 30px;
    }

    .wz-card, .wizard-card {
        padding: 20px 16px;
    }

    /* Modal */
    .modal, .modal-box {
        margin: 12px;
        max-width: calc(100vw - 24px);
    }

    /* Toast */
    .toast, .app-toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
        max-width: none;
    }

    /* Audit */
    .stat-cards {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .audit-card {
        grid-template-columns: 1fr;
    }

    .audit-time {
        text-align: left;
    }

    /* Pager */
    .tm-pager, .pg-wrap {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .pager-nav, .pg-btns {
        flex-wrap: wrap;
    }

    .btn-fab {
        bottom: 16px;
        right: 16px;
    }
}

/* ================================================
   RESPONSIVE — Extra small (≤400px)
   ================================================ */
@media (max-width: 400px) {
    .stats-grid, .stat-grid {
        grid-template-columns: 1fr;
    }

    .stat-cards {
        grid-template-columns: 1fr;
    }

    .role-grid {
        grid-template-columns: 1fr;
    }
}

/* ================================================
   SIGN PAGE (external / internal signer)
   ================================================ */
.sign-page {
    min-height: 100vh;
    background: var(--bg);
    font-family: var(--font);
}

.sign-header {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sign-header-logo {
    font-weight: 800;
    font-size: 18px;
}

.sign-header-sub {
    font-size: 12px;
    opacity: .8;
}

.sign-body {
    max-width: 860px;
    margin: 0 auto;
    padding: 24px 16px;
}

.sign-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 28px;
    margin-bottom: 20px;
}

.sign-doc-preview {
    background: var(--bg-alt);
    border-radius: var(--radius);
    padding: 20px;
    min-height: 300px;
}

/* ================================================
   MISC / PAGE-SPECIFIC
   ================================================ */
/* signer avatar */
.signer-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

/* signature tabs */
.sig-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: var(--bg);
    padding: 4px;
    border-radius: 8px;
}

.sig-tab {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    color: var(--muted);
    text-align: center;
}

    .sig-tab.active {
        background: var(--card);
        color: var(--primary);
        box-shadow: var(--shadow-sm);
    }

.sig-canvas-wrap {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: white;
    touch-action: none;
}

    .sig-canvas-wrap canvas {
        display: block;
        width: 100%;
        height: 140px;
        cursor: crosshair;
    }

/* upload zone */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--muted);
}

    .upload-zone:hover {
        border-color: var(--primary);
        background: var(--primary-light);
        color: var(--primary);
    }

/* sidebar overlay open helper */
.sidebar-overlay.open {
    display: block;
    opacity: 1;
}