:root {
    --primary: #1e3a8a;
    /* Deep blue from mockup headers */
    --secondary: #64748b;
    /* Slate for text */
    --accent: #0284c7;
    /* Sky blue for active states/buttons */
    --text: #1e293b;
    --light-bg: #e2e8f0;
    --white: rgba(255, 255, 255, 0.85);
    --border: rgba(255, 255, 255, 0.6);
    --shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.05);
    /* Softer shadow */
    --glass-bg: rgba(255, 255, 255, 0.45);
    /* More transparent for frosted look */
    --inner-card-bg: rgba(255, 255, 255, 0.85);
    /* Whiter inside cards */
    --glass-border: rgba(255, 255, 255, 0.8);
    --app-bg-gradient: radial-gradient(circle at top left, #dbeafe 0%, transparent 30%),
        radial-gradient(circle at bottom right, #f1f5f9 0%, transparent 40%),
        linear-gradient(135deg, #cbd5e1 0%, #e2e8f0 100%);
    /* The darker, soft bluish-gray backplate from mockup */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--app-bg-gradient);
    background-attachment: fixed;
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ==========================================
   GLASSMORPHISM APP LAYOUT
   ========================================== */
.app-container {
    display: flex;
    height: 100vh;
    padding: 1rem;
    gap: 1.5rem;
}

/* Sidebar Glass */
.glass-sidebar {
    width: 250px;
    background: transparent;
    /* Mockup sidebar blends with background deeply */
    border: none;
    border-right: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    overflow-y: auto;
    flex-shrink: 0;
}

.glass-sidebar::-webkit-scrollbar {
    width: 4px;
}

.glass-sidebar::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 4px;
}

/* Sidebar Navigation */
.sidebar-nav-list {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.8rem 1rem;
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    border-radius: 10px;
    transition: all 0.2s ease-in-out;
}

.sidebar-nav-item i {
    width: 20px;
    text-align: center;
    color: var(--secondary);
    transition: color 0.2s;
}

.sidebar-nav-item:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: none;
    /* Removed the jumping effect */
}

.sidebar-nav-item:hover i {
    color: var(--primary);
}

.sidebar-nav-item.active {
    font-weight: 600;
    background: rgba(255, 255, 255, 0.8);
    color: var(--primary);
    box-shadow: var(--shadow);
    border-radius: 8px;
    /* Softer radius in mockup */
}

.sidebar-nav-item.active i {
    color: var(--primary);
}

/* Main Content Area */
.main-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: hidden;
}

/* Header Glass */
.glass-header {
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 1rem 0rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    position: relative;
    z-index: 1000;
    margin-bottom: 0.5rem;
}

/* Glass Widget Cards */
.glass-widget {
    background: var(--inner-card-bg) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 12px !important;
    padding: 1.5rem !important;
    border: 1px solid var(--glass-border) !important;
    transition: all 0.3s ease;
    cursor: default;
    box-shadow: var(--shadow) !important;
}

.glass-widget:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px 0 rgba(0, 0, 0, 0.08) !important;
}

/* Scrollable Content */
.main-content {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-right: 0.5rem;
}

.main-content::-webkit-scrollbar {
    width: 6px;
}

.main-content::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.4);
    border-radius: 6px;
}

/* Dashboard Header (Screen Only) */
.dashboard-header {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0.6rem 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo {
    font-size: 1.2rem;
    /* Slightly smaller */
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.logo span {
    color: var(--secondary);
}

.controls-wrapper {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-grow: 1;
    margin: 0 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.search-container {
    position: relative;
    width: auto;
    flex-grow: 1;
    min-width: 200px;
    max-width: 300px;
}

.search-container input {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 2.8rem;
    border: none;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    font-size: 0.9rem;
    transition: all 0.2s;
    outline: none;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
    color: var(--text);
}

.search-container input:focus {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
}

.search-container i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
}

.filter-group {
    display: flex;
    gap: 10px;
}

.filter-select {
    padding: 0.6rem 1rem;
    border: none;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 500;
    outline: none;
    cursor: pointer;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
}

.filter-select:hover {
    background: rgba(255, 255, 255, 0.9);
}

.filter-dropdown-btn {
    padding: 0.6rem 1rem;
    border: none;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 600;
    outline: none;
    cursor: pointer;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.filter-dropdown-btn:hover {
    background: rgba(255, 255, 255, 0.95);
}

.actions {
    display: flex;
    gap: 10px;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    box-shadow: 0 2px 10px rgba(2, 132, 199, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.8);
    color: var(--secondary);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    box-shadow: var(--shadow);
}

.btn-secondary:hover {
    background-color: #f8f9fa;
}


/* TOC inside Sidebar */
.sidebar-toc {
    width: 100%;
    margin-top: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    flex-grow: 1;
}

.sidebar-toc h3 {
    font-size: 1rem;
    color: var(--primary);
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.sortable-toc {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-item,
.toc-subitem {
    padding: 8px 10px;
    margin-bottom: 5px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.8rem;
    color: #334155;
    cursor: grab;
    transition: background 0.2s, color 0.2s;
    font-weight: 500;
    white-space: normal;
    /* Allow text to wrap to prevent cut off */
    word-break: break-word;
    display: flex;
    align-items: flex-start;
}

.toc-item:hover,
.toc-subitem:hover {
    background: #e2e8f0;
    color: var(--primary);
}

.toc-sublist {
    list-style: none;
    padding-left: 15px;
    margin-top: 5px;
    margin-bottom: 5px;
    border-left: 2px dashed #cbd5e1;
}

.toc-subitem {
    font-size: 0.75rem;
    background: #f8fafc;
    padding: 6px 8px;
}

.toc-ghost {
    opacity: 0.4;
    background-color: #dbeafe;
    border: 2px dashed #93c5fd;
}

.app-main-view {
    flex-grow: 1;
    overflow-y: auto;
    font-family: Arial, sans-serif;
    padding-bottom: 40px;
    /* Spacer for copyright */
}

/* Document Container */
.document-container {
    padding: 0 10px;
    margin: 0 auto 2rem auto;
}

/* Document Typography */
.doc-header {
    text-align: center;
    margin-bottom: 2rem;
    border-bottom: 3px solid var(--primary);
    padding-bottom: 1.5rem;
}

.doc-header h1 {
    font-family: Arial, sans-serif;
    font-size: 1.5rem;
    color: var(--primary);
    text-transform: uppercase;
    margin-bottom: 5px;
    text-align: center;
}

.doc-header h2 {
    font-size: 0.95rem;
    color: #64748b;
    font-weight: 400;
    margin-bottom: 15px;
}

.doc-date {
    font-size: 0.85rem;
    color: #999;
    margin-top: 10px;
}

/* Organ Sections */
.organ-section {
    margin-bottom: 2rem;
    break-inside: avoid;
    border: none;
    background: transparent;
    border-radius: 12px;
    overflow: hidden;
}

.organ-header {
    background-color: transparent;
    padding: 1rem 0;
    border-bottom: 2px solid rgba(255, 255, 255, 0.6);
}

.organ-title {
    font-family: 'Inter', sans-serif;
    color: var(--primary);
    margin: 0;
    font-weight: 700;
}

.organ-title h2 {
    font-size: 1.05rem;
    margin: 0;
}

/* Sphere Badges */
.sphere-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: white;
    margin-right: 5px;
}

.badge-exec-est {
    background-color: #2e7d32;
}

/* Green */
.badge-leg-est {
    background-color: #1565c0;
}

/* Blue */
.badge-jud {
    background-color: #c62828;
}

/* Red */
.badge-exec-mun {
    background-color: #00838f;
}

/* Teal */
.badge-leg-mun {
    background-color: #f57f17;
}

/* Yellow/Orange */

/* Department Styles */
.dept-section {
    margin-bottom: 1.5rem;
    padding: 0 1rem;
}

.dept-header-info {
    font-size: 0.85rem;
    color: #555;
    background-color: #f8f9fa;
    padding: 10px;
    margin-bottom: 15px;
    border-left: 4px solid var(--secondary);
    border-radius: 0 4px 4px 0;
}

/* SortableJS Ghost Classes (iPhone Reorder Style) */
.sortable-ghost {
    opacity: 0.4;
    background-color: #f0f0f0;
    border: 2px dashed #999;
    transform: scale(0.95);
}

.sortable-drag {
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    cursor: grabbing !important;
    max-width: 350px !important;
}

.empty-dropzone {
    min-height: 60px;
    border: 2px dashed #bbf;
    background-color: #f8faff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #88a;
    font-size: 0.85rem;
    font-weight: 500;
}

.empty-dropzone::after {
    content: "Arraste cartões para cá";
}

.dept-title-box {
    background-color: transparent;
    padding: 8px 0px;
    margin: 15px 0 10px 0;
    border-radius: 0px;
    border-left: none;
}

.dept-title h3 {
    font-family: 'Inter', sans-serif;
    font-size: 1.0rem;
    font-weight: 600;
    color: var(--primary);
    margin: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.5);
    padding-bottom: 5px;
}

.subdept-title h4 {
    font-family: Arial, sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    color: #2c3e50;
    margin: 0;
    text-transform: uppercase;
}

/* Address/Info Text */
.dept-info {
    /* Now handled by dept-header-info wrapper logic if we group them */
    display: block;
    font-size: 0.8rem;
    color: #444;
    margin-bottom: 4px;
}


/* Authorities Grid */
.authorities-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}

.authority-card {
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 20px;
    padding-bottom: 55px !important;
    background: var(--inner-card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    break-inside: avoid;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
}

.authority-card[draggable="true"] {
    cursor: grab;
}

.authority-card[draggable="true"]:active {
    cursor: grabbing;
    opacity: 0.6;
}

.authority-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.95);
}

/* Card Highlights */
.highlight-chief {
    background-color: #fffbeb !important;
    /* light yellow/gold */
    border: 1px solid #f59e0b !important;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}

.highlight-deputy {
    background-color: #f8fafc !important;
    /* light slate/blueish */
    border: 1px solid #94a3b8 !important;
    box-shadow: 0 2px 8px rgba(148, 163, 184, 0.2);
}

.merge-highlight {
    border: 3px dashed #f97316 !important;
    background-color: #fff7ed !important;
    transform: scale(1.05);
    opacity: 0.9 !important;
    box-shadow: 0 0 20px rgba(249, 115, 22, 0.5);
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.merge-highlight::after {
    content: "⨁ SOLTE PARA MESCLAR";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 247, 237, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 900;
    color: #ea580c;
    pointer-events: none;
    z-index: 10;
}

.card-actions {
    position: absolute;
    top: 5px;
    right: 5px;
    display: flex;
    flex-wrap: wrap;
    /* Let the trash icon drop down naturally instead of overlapping */
    gap: 4px;
    justify-content: flex-end;
    max-width: 100px;
    /* Allow wider wrap */
}




.context-organ {
    font-weight: 600;
    color: var(--primary);
}

.context-dept {
    color: #666;
}

.authority-role {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--primary);
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: 0.5px;
    border-bottom: 1px dashed #eee;
    padding-bottom: 4px;
    display: inline-block;
    text-align: center;
}

.authority-name {
    font-family: Arial, sans-serif;
    font-size: 1rem;
    /* Slightly reduced */
    font-weight: 700;
    color: #000;
    margin-bottom: 5px;
    line-height: 1.3;
    text-align: center;
}

.authority-party {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 0.7rem;
    color: #fff;
    background-color: var(--secondary);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-align: center;
}

.authority-details {
    font-size: 0.8rem;
    color: #555;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
}

.detail-item {
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.detail-item i {
    color: #999;
    width: 14px;
    text-align: center;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 25px;
    border: 1px solid #888;
    width: 80%;
    max-width: 800px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover {
    color: black;
}

.side-panel-editor {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    height: 100vh;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid var(--border);
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.1);
    z-index: 3000;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.side-panel-header {
    background: #f8fafc;
    padding: 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.side-panel-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Modern Form Styles */
.form-group {
    margin-bottom: 1.2rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #444;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-family: Arial, sans-serif;
    font-size: 1rem;
    box-sizing: border-box;
    /* Crucial to prevent squeezing */
    transition: border-color 0.2s;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 61, 89, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.card {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #eee;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.card h3 {
    margin-bottom: 15px;
    color: var(--primary);
    font-size: 1.1rem;
    border-bottom: 2px solid var(--secondary);
    padding-bottom: 8px;
    display: inline-block;
}

.history-list {
    list-style: none;
    max-height: 250px;
    overflow-y: auto;
}

.history-list li {
    padding: 10px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.btn-restore {
    background: white;
    border: 1px solid #ddd;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    color: #555;
    transition: all 0.2s;
}

.btn-restore:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.status-waiting {
    color: #888;
}

.status-success {
    color: green;
    font-weight: 600;
}

.status-error {
    color: red;
    font-weight: 600;
}

/* Responsive Header (Tablets/Mobile) */
@media (max-width: 900px) {
    .dashboard-header {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
        gap: 15px;
    }

    .logo {
        justify-content: center;
        margin-bottom: 5px;
    }

    .controls-wrapper {
        flex-direction: column;
        width: 100%;
        margin: 0;
    }

    .search-container {
        width: 100%;
        max-width: none;
    }

    .filter-group {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 5px;
        /* Scrollbar space */
        justify-content: flex-start;
    }

    .filter-select {
        flex-shrink: 0;
    }

    .actions {
        justify-content: center;
        width: 100%;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
        justify-content: center;
    }
}

/* =========================================
   View Modes: Continuous & Form 
   ========================================= */

/* Continuous Mode - overrides max-width */
.view-continuous {
    max-width: 98% !important;
    margin: 1rem auto !important;
}

.view-continuous .authorities-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)) !important;
}

/* Form View (Card-by-Card) Layout */
.form-view-layout {
    display: none;
    /* toggled by JS */
    align-items: center;
    justify-content: center;
    min-height: 70vh;
    padding: 2rem;
    gap: 2rem;
}

.form-view-active .form-view-layout {
    display: flex;
}

.form-view-active #docContainer {
    display: none;
}

.btn-nav-giant {
    background: transparent;
    border: none;
    font-size: 3rem;
    color: var(--primary);
    cursor: pointer;
    transition: transform 0.2s, color 0.2s;
    opacity: 0.7;
}

.btn-nav-giant:hover {
    transform: scale(1.1);
    color: var(--secondary);
    opacity: 1;
}

.form-card-central {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    width: 600px;
    max-width: 90vw;
    position: relative;
    transform: scale(0.85);
    /* Default scale to fit 100% browser zoom comfortably */
    transform-origin: center top;
    margin-top: -20px;
}

.form-card-central .authority-name {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.form-card-central .authority-role {
    font-size: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--secondary);
    padding-bottom: 0.5rem;
}

.form-card-central .detail-item {
    font-size: 1rem;
    padding: 8px 0;
    border-bottom: 1px dashed #eee;
}

/* Print Styles */
@media print {
    @page {
        size: A4 portrait;
        margin: 1cm 0.5cm 1cm 0.5cm;
    }

    body {
        background: white;
        font-size: 9pt;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Hide Screen Elements */
    .no-print,
    .dashboard-header,
    .toc {
        display: none !important;
    }

    .no-screen {
        display: block !important;
    }

    /* Fixed Print Header - Hidden to save space and avoid redundancy */
    .print-header {
        display: block !important;
    }

    /* Main Container Reset */
    .app-layout {
        display: block !important;
        position: static !important;
        height: auto !important;
        overflow: visible !important;
        margin: 0 !important;
    }

    .app-main-view {
        overflow: visible !important;
    }

    .document-container {
        box-shadow: none;
        margin: 0;
        padding: 0;
        max-width: none;
        width: 100%;
    }

    .doc-header {
        margin-top: 0;
        margin-bottom: 10px;
        page-break-after: avoid;
        text-align: center;
    }

    .doc-header h1 {
        font-size: 16pt;
        margin: 2px 0;
    }

    .doc-header h2 {
        font-size: 12pt;
        margin: 2px 0;
    }

    /* Organs & Hierarchy */
    .organ-section {
        page-break-inside: avoid;
        border: 1px solid #ccc;
        padding: 3px;
        margin-bottom: 5px;
        break-inside: avoid;
    }

    .organ-title {
        font-size: 12pt;
        border-bottom: 1px solid #000;
        color: #000;
        margin-bottom: 5px;
        padding-bottom: 2px;
    }

    .dept-title-box {
        background: #eee !important;
        /* Force background print */
        border: 1px solid #999;
        color: #000;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        padding: 2px 5px;
        margin-bottom: 5px;
    }

    .dept-name {
        color: #000;
        font-size: 10pt;
    }

    .dept-info {
        font-size: 8pt;
        margin-bottom: 2px;
    }

    /* Allow containers to break across pages to prevent large empty white spaces */
    .organ-section,
    .dept-section,
    .departments-container,
    .subdepts-container,
    .authorities-grid {
        break-inside: auto !important;
        page-break-inside: auto !important;
    }

    /* Card Grid Optimization -> 1 column elegant list format */
    .authorities-grid {
        display: grid;
        grid-template-columns: 1fr !important;
        gap: 0;
        margin-bottom: 6px;
        border: 1px solid #aaa;
        border-radius: 4px;
        background: #fff;
    }

    .authority-card {
        border: none;
        border-bottom: 1px solid #ddd !important;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
        box-shadow: none !important;
        padding: 6px 10px !important;
        font-size: 8pt !important;
        /* CRITICAL: Prevents long unbroken text (like emails) from stretching the grid */
        min-width: 0;
        word-wrap: break-word;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .authority-card:last-child {
        border-bottom: none !important;
    }

    .highlight-chief {
        background-color: #fffbeb !important;
        border: 1px solid #f59e0b !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .highlight-deputy {
        background-color: #f8fafc !important;
        border: 1px solid #94a3b8 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .authority-name {
        font-size: 7.5pt;
        margin-bottom: 1px;
        line-height: 1.1;
    }

    .authority-role {
        color: #000;
        font-weight: 900;
        font-size: 6.5pt;
        margin-bottom: 1px;
        line-height: 1.1;
    }

    .detail-item {
        font-size: 6pt;
        padding: 0;
        margin-bottom: 0;
        line-height: 1.1;
    }

    .authority-party {
        border: 1px solid #000;
        background: none !important;
        color: #000 !important;
        font-size: 6pt;
        padding: 1px 3px;
    }

    /* Footer */
    .doc-footer {
        border-top: 1px solid #000;
        margin-top: 15px;
        padding-top: 5px;
        text-align: center;
        font-size: 8pt;
    }

    .copyright {
        font-weight: bold;
        margin-top: 3px;
    }
}

/* Discreet Copyright for Screen */
.fixed-copyright {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
    color: #a0aec0;
    padding: 6px 0;
    background: transparent;
    pointer-events: none;
    z-index: 100;
}

/* --- MODERN MINIMALIST ICONS REDESIGN --- */

.header-icon-modern {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-left: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    background: transparent;
    color: #64748b;
    /* Sleek slate gray */
    border-radius: 6px;
    transition: all 0.2s ease;
    vertical-align: middle;
}

.header-icon-modern:hover {
    background: #ffffff;
    color: #0f172a;
    border-color: #cbd5e1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.header-icon-modern.demote:hover {
    color: #d97706;
    /* High contrast amber/orange */
    border-color: #fcd34d;
    background: #fffbeb;
}

.card-actions-modern {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 2px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid #f1f5f9;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.03);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.authority-card:hover .card-actions-modern {
    opacity: 1;
    transform: translateY(0);
}

.btn-icon-modern {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #94a3b8;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon-modern:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.btn-icon-modern.delete:hover {
    background: #fef2f2;
    color: #ef4444;
}

.btn-icon-modern.promote:hover {
    background: #eff6ff;
    color: #2563eb;
}

.btn-icon-modern.dept:hover {
    background: #f0fdf4;
    color: #16a34a;
}

/* --- BULK ACTIONS & MULTI-SELECT --- */

.multi-select-cb {
    position: absolute;
    top: 8px;
    left: 8px;
    right: auto;
    width: 16px;
    height: 16px;
    cursor: pointer;
    z-index: 5;
    accent-color: var(--primary);
    opacity: 0.6;
    transition: opacity 0.2s;
}

.authority-card:hover .multi-select-cb,
.multi-select-cb:checked {
    opacity: 1;
}

.star-permanent {
    position: absolute;
    top: -12px;
    right: -12px;
    left: auto;
    background: white;
    border-radius: 50%;
    padding: 3px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    color: #f59e0b;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-selected {
    border-color: var(--primary) !important;
    background-color: #f8fafc;
    box-shadow: 0 0 0 1px var(--primary);
}

.toc-checkbox {
    margin-right: 6px;
    cursor: pointer;
    accent-color: var(--primary);
}

.bulk-action-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bulk-action-bar.hidden {
    opacity: 0;
    transform: translate(-50%, 20px);
    pointer-events: none;
}

.btn-bulk {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s;
}

.btn-bulk:hover {
    background: #2563eb;
}

.btn-organize-toc {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    width: 100%;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-organize-toc:hover {
    background: #f1f5f9;
    color: #0f172a;
}

/* ==========================================
   CLEANGLASS AESTHETIC OVERRIDES
   ========================================== */

/* Organ headers: softer green, no heavy saturation */
.organ-header {
    background: linear-gradient(135deg, rgba(240, 253, 244, 0.85), rgba(236, 253, 245, 0.7)) !important;
    border: 1px solid #d1fae5 !important;
    border-radius: 10px !important;
    backdrop-filter: blur(6px) !important;
}

/* ===== REDESIGNED AUTHORITY CARD (PRD v2 Prototype) ===== */
.authority-card {
    background: white !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 14px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04) !important;
    transition: box-shadow 0.25s, border-color 0.25s, transform 0.25s !important;
    position: relative;
    overflow: hidden;
    padding: 0 !important;
    padding-bottom: 0 !important;
}

.authority-card:hover {
    border-color: #cbd5e1 !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08) !important;
    transform: translateY(-2px);
}

/* Grid: avatar | info */
.card-body-grid {
    display: grid;
    grid-template-columns: var(--avatar-container-size, 56px) 1fr;
    gap: var(--avatar-gap, 12px);
    padding: 16px 16px 12px 16px;
    align-items: start;
}

/* Avatar circle with initials */
.card-avatar {
    width: var(--avatar-size, 48px);
    height: var(--avatar-size, 48px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.card-avatar span {
    color: white;
    font-weight: 700;
    font-size: var(--avatar-font-size, 0.95rem);
    letter-spacing: 0.5px;
    line-height: 1;
}

/* Info column */
.card-info {
    min-width: 0;
    /* prevent overflow */
    word-break: break-word;
    /* prevent squeeze */
}

/* Header row: Name + Badge */
.card-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
}

.authority-name {
    font-weight: 700 !important;
    color: #0f172a !important;
    letter-spacing: 0.01em;
    font-size: var(--name-font-size, 0.85rem) !important;
    line-height: 1.25;
    margin: 0 !important;
    text-align: left !important;
}

/* Modificadores para quando não é modo A/1 coluna, apertamos o layout */
.authorities-grid.grid-2-col .authority-card,
.authorities-grid.grid-3-col .authority-card {
    --avatar-container-size: 40px;
    --avatar-gap: 8px;
    --avatar-size: 36px;
    --avatar-font-size: 0.8rem;
    --name-font-size: 0.75rem;
}

.authorities-grid.grid-2-col .card-body-grid,
.authorities-grid.grid-3-col .card-body-grid {
    padding: 12px 12px 8px 12px;
}

.authorities-grid.grid-2-col .authority-role,
.authorities-grid.grid-3-col .authority-role {
    font-size: 0.65rem !important;
}

.authorities-grid.grid-2-col .detail-item,
.authorities-grid.grid-3-col .detail-item {
    font-size: 0.65rem !important;
    margin-bottom: 4px;
}

.authority-name {
    font-weight: 700 !important;
    color: #0f172a !important;
    letter-spacing: 0.01em;
    font-size: 0.85rem !important;
    line-height: 1.25;
    margin: 0 !important;
    text-align: left !important;
}

/* Badge ATIVO */
.badge-active {
    display: inline-flex;
    align-items: center;
    background: #dcfce7;
    color: #15803d;
    font-size: 0.55rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
    letter-spacing: 0.8px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-top: 2px;
}

/* Party badge: inline, not absolute */
.authority-party {
    position: static !important;
    display: inline-block !important;
    font-size: 0.55rem !important;
    color: #fff !important;
    background-color: #64748b !important;
    padding: 1px 6px !important;
    border-radius: 3px !important;
    font-weight: 600 !important;
    text-align: left !important;
    margin: 2px 0 4px 0 !important;
    letter-spacing: 0.5px;
}

.authority-role {
    color: #475569 !important;
    font-weight: 500 !important;
    text-align: left !important;
    font-size: 0.7rem !important;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
    border-bottom: none !important;
}

/* Card context: very light, small */
.authority-context {
    font-size: 0.6rem !important;
    color: #94a3b8 !important;
    background: transparent !important;
    padding: 2px 0 !important;
    border: none !important;
}

/* Detail items: clean, minimal icons */
.authority-details {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
}

.detail-item {
    color: #475569 !important;
    font-size: 0.75rem !important;
    padding: 2px 0 !important;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.detail-item i {
    color: #94a3b8 !important;
    font-size: 0.7rem !important;
    width: 14px;
    text-align: center;
}

/* Keep identification colors ONLY for specific icons */
.detail-item i.fa-cake-candles {
    color: #c084fc !important;
}

.detail-item i.fa-whatsapp {
    color: #22c55e !important;
}

.detail-item i.fa-envelope {
    color: #60a5fa !important;
}

.detail-item i.fa-phone {
    color: #0ea5e9 !important;
}

.detail-item i.fa-user-tie {
    color: #f59e0b !important;
}

/* ===== CARD FOOTER (Always visible actions) ===== */
.card-footer {
    display: flex;
    justify-content: center;
    gap: 2px;
    padding: 6px 12px;
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
}

.btn-icon-modern {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    color: #94a3b8;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon-modern:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.btn-icon-modern.delete:hover {
    background: #fef2f2;
    color: #ef4444;
}

.btn-icon-modern.promote:hover {
    background: #eff6ff;
    color: #2563eb;
}

.btn-icon-modern:hover {
    color: #475569 !important;
    background: #f1f5f9 !important;
}

.btn-icon-modern.delete:hover {
    color: #ef4444 !important;
    background: #fef2f2 !important;
}

/* Header action buttons: minimal */
.header-icon-modern {
    color: #94a3b8 !important;
    border: none !important;
    background: transparent !important;
    cursor: pointer !important;
    padding: 4px !important;
    border-radius: 4px !important;
}

.header-icon-modern:hover {
    color: #475569 !important;
    background: #f1f5f9 !important;
}

.header-icon-modern.delete:hover {
    color: #ef4444 !important;
}

/* Sphere badges: softer */
.badge-sphere {
    font-size: 0.55rem !important;
    padding: 2px 8px !important;
    border-radius: 12px !important;
    font-weight: 500 !important;
    letter-spacing: 0.5px !important;
    opacity: 0.75 !important;
}

/* Department blocks: cleaner borders */
.dept-block {
    border: 1px solid #f1f5f9 !important;
    background: rgba(255, 255, 255, 0.5) !important;
    border-radius: 8px !important;
}

/* Sidebar: glass effect */
.sidebar-toc {
    background: rgba(255, 255, 255, 0.9) !important;
    backdrop-filter: blur(8px) !important;
    border-right: 1px solid #f1f5f9 !important;
}

/* Highlight cards: subtle gold/gray */
.highlight-chief {
    border-left: 3px solid #fbbf24 !important;
}

.highlight-deputy {
    border-left: 3px solid #d1d5db !important;
}

/* Mode button active: muted blue */
.modo-btn {
    border: 1px solid #e2e8f0 !important;
    background: white !important;
    color: #64748b !important;
    border-radius: 4px !important;
    transition: all 0.15s !important;
}

/* Toolbar action buttons: muted */
.btn-toolbar {
    color: #64748b !important;
    font-weight: 500 !important;
}

/* Star permanent: softer */
.star-permanent {
    opacity: 0.6 !important;
}

/* Print: clean */
@media print {
    .authority-card {
        border: 1px solid #e5e7eb !important;
        box-shadow: none !important;
    }

    .organ-header {
        background: #f0fdf4 !important;
        border: 1px solid #e5e7eb !important;
    }
}

/* Explicit A4 Paper Styling for explicitly requested print views */
.document-container.view-a4 {
    background: white;
    max-width: 210mm;
    padding: 15mm;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
}

@media print {
    .document-container {
        background: white !important;
        max-width: none !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }
}
