:root {
    --bg-main: #f3f4f6;
    --bg-card: #ffffff;
    --color-brand: #78368b;
    --color-brand-light: #f3ebf5;
    --color-brand-dark: #632c73;
    --text-main: #111827;
    --text-muted: #4b5563;
    --text-tertiary: #6b7280;
    --border-color: #e5e7eb;
    --status-success: #16a34a;
    --status-error: #dc2626;
    --status-warning: #f59e0b;

    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --transition: 0.2s ease;
}

[x-cloak] { display: none !important; }

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Headings */
h1,
h2,
h3,
h4 {
    font-family: inherit;
}

h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.3;
}

h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.35;
}

h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.4;
}

h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-tertiary);
    line-height: 1.4;
}

/* Layout */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-x: hidden;
    overflow-x: clip;
    transition: margin-left var(--transition);
}

.page-content {
    flex: 1;
    padding: 24px 32px;
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    overflow-wrap: break-word;
}

/* Page Header */
.page-header {
    margin-bottom: 24px;
}

/* Header com busca à direita (título/subtítulo à esquerda) */
.page-header-with-search {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-header-info {
    min-width: 0;
}

.page-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-main);
}

.page-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-main);
}

.card-body {
    padding: 20px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--transition), color var(--transition), box-shadow var(--transition);
    border: none;
    font-family: inherit;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--bg-main);
    color: var(--text-main);
}

/* Login Page */
.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.login-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-container {
    width: 100%;
    max-width: 448px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo {
    margin-bottom: 16px;
}

.login-logo-img {
    width: 285px;
    height: 125px;
    object-fit: contain;
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 12px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 32px 16px;
    box-shadow: var(--shadow-md);
    border-top: 3px solid var(--color-brand);
}

@media (min-width: 640px) {
    .login-card {
        padding: 32px 40px;
    }
}

/* Forms */
.login-form {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
}

/* Label em cor de destaque (vermelho do sistema) */
.form-label-danger {
    color: var(--status-error);
}

.form-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    color: var(--text-main);
    background: var(--bg-card);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px var(--color-brand-light);
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

.form-input[type="number"]::-webkit-outer-spin-button,
.form-input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.form-input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Campos de data padronizados — largura máxima de 230px */
.form-input[type="date"],
.form-input[type="month"],
.form-input[type="datetime-local"],
.form-input[type="time"] {
    max-width: 230px;
}

.form-links {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.form-link {
    font-size: 14px;
    color: var(--color-brand);
    font-weight: 500;
    transition: color var(--transition);
}

.form-link:hover {
    color: var(--color-brand-dark);
}

/* Alerts */
.alert {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 24px;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 4px solid var(--status-error);
    color: var(--status-error);
}

.alert-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--status-error);
    color: white;
    border-radius: 50%;
    font-weight: 700;
    font-size: 11px;
}

/* Buttons Extended */
.btn-primary {
    background: var(--color-brand);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--color-brand-dark);
}

.btn-primary:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 4px var(--color-brand);
}

.btn-block {
    width: 100%;
}

.btn-loading {
    opacity: 0.75;
    cursor: not-allowed;
}

.hidden {
    display: none;
}

/* Footer */
.app-footer {
    background: var(--bg-main);
    border-top: 1px solid var(--border-color);
    margin-top: 24px;
}

.footer-container {
    padding: 24px 32px;
    max-width: 99%;
    margin: 0 auto;
    width: 100%;
}

.footer-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

@media (min-width: 768px) {
    .footer-inner {
        flex-direction: row;
        justify-content: space-between;
    }
}

.footer-left,
.footer-right {
    display: flex;
    justify-content: center;
}

@media (min-width: 768px) {
    .footer-left {
        justify-content: flex-start;
    }

    .footer-right {
        justify-content: flex-end;
    }
}

.footer-text {
    font-size: 14px;
    color: var(--text-muted);
}

.footer-text-flex {
    display: flex;
    align-items: center;
}

.footer-icon {
    width: 16px;
    height: 16px;
    margin-right: 4px;
    color: var(--text-tertiary);
}

.footer-brand {
    font-weight: 600;
    color: var(--text-main);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: width var(--transition);
}

.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-logo-img {
    height: 60px;
    width: auto;
    object-fit: contain;
}

.sidebar-logo-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-logo-title {
    font-weight: 700;
    font-size: 18px;
    color: var(--text-main);
    line-height: 1.2;
}

.sidebar-logo-subtitle {
    font-size: 13px;
    color: var(--text-tertiary);
    line-height: 1.2;
    white-space: nowrap;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    margin-bottom: 4px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: background-color var(--transition), color var(--transition);
    font-size: 14px;
}

.nav-item:hover {
    background: var(--color-brand-light);
    color: var(--color-brand);
}

.nav-item.active {
    color: var(--color-brand);
    background: var(--color-brand-light);
    font-weight: 600;
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* Sidebar colapsada */
.app-layout.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

.app-layout.sidebar-collapsed .sidebar-header {
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.app-layout.sidebar-collapsed .sidebar-logo {
    justify-content: center;
}

.app-layout.sidebar-collapsed .sidebar-logo-img {
    height: 40px;
}

.app-layout.sidebar-collapsed .nav-text {
    display: none;
}

.app-layout.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 10px;
}

.app-layout.sidebar-collapsed .nav-icon {
    margin: 0;
}

.app-layout.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* Botão recolher (moderno, no cabeçalho da sidebar) */
.sidebar-toggle {
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: background-color var(--transition), color var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.sidebar-toggle:hover {
    background: var(--color-brand-light);
    color: var(--color-brand);
}

.sidebar-toggle-icon {
    transition: transform var(--transition);
}

.sidebar-toggle-icon-collapsed {
    transform: rotate(180deg);
}

/* Item de menu "Sair" (último item da navegação, padrão de destaque do sistema) */
.nav-item.nav-item-danger {
    color: var(--status-error);
    font-weight: 600;
}

.nav-item.nav-item-danger:hover {
    background: #fef2f2;
    color: var(--status-error);
}

.nav-logout-form {
    margin: 0;
}

.nav-logout-btn {
    width: 100%;
    border: 0;
    background: none;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

/* Mobile Menu Toggle (abre a sidebar como gaveta) */
.menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border: none;
    background: var(--color-brand);
    color: white;
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    -webkit-tap-highlight-color: transparent;
}

.menu-toggle:hover {
    background: var(--color-brand-dark);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
}

/* Mobile */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
        transition: transform var(--transition);
    }

    .app-layout.sidebar-collapsed .sidebar {
        width: var(--sidebar-width);
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-open .sidebar-overlay {
        display: block;
    }

    .main-content,
    .app-layout.sidebar-collapsed .main-content {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: none;
    }

    .menu-toggle {
        display: flex;
    }

    .grid-cols-3 {
        grid-template-columns: 1fr;
    }
}

/* Sidebar — grupo em acordeão (Gestão Institucional) */
.nav-group-toggle {
    width: 100%;
    background: transparent;
    border: none;
    font-family: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.nav-caret {
    margin-left: auto;
    color: var(--text-tertiary);
    flex-shrink: 0;
    transition: transform var(--transition);
}

.nav-caret-open {
    transform: rotate(180deg);
}

.nav-submenu {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0 0 4px 22px;
    padding-left: 12px;
    border-left: 1px solid var(--border-color);
}

.nav-subitem {
    display: block;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 13.5px;
    transition: background-color var(--transition), color var(--transition);
}

.nav-subitem:hover {
    background: var(--color-brand-light);
    color: var(--color-brand);
}

.nav-subitem.active {
    color: var(--color-brand);
    background: var(--color-brand-light);
    font-weight: 600;
}

.app-layout.sidebar-collapsed .nav-caret {
    display: none;
}

.app-layout.sidebar-collapsed .nav-submenu {
    display: none !important;
}

/* Form Grid */
.form-row {
    display: grid;
    gap: 16px;
}

.form-row-2 {
    grid-template-columns: 1fr 1fr;
}

.form-row-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 768px) {
    .form-row-2,
    .form-row-3 {
        grid-template-columns: 1fr;
    }
}

/* Linhas compostas só por campos de data (2 colunas de até 230px) */
.form-row-datas {
    grid-template-columns: repeat(2, minmax(0, 230px));
}

/* Identificação da Unidade: Decreto (200px), Artigo (área restante), datas (230px) + botão Salvar */
.form-row-ident-datas {
    grid-template-columns: minmax(0, 200px) minmax(0, 1fr) minmax(0, 230px) minmax(0, 230px) auto;
}

@media (max-width: 768px) {
    .form-row-datas,
    .form-row-ident-datas {
        grid-template-columns: 1fr;
    }
}

/* Responsável da Unidade: datas limitadas a 230px + botão Salvar centralizado na altura dos campos */
.form-row-resp {
    grid-template-columns: minmax(0, 1fr) minmax(0, 230px) minmax(0, 230px) auto;
}

.form-label-ghost {
    visibility: hidden;
}

.form-group-btn {
    flex: 1;
    display: flex;
    align-items: center;
}

@media (max-width: 768px) {
    .form-row-resp {
        grid-template-columns: 1fr;
    }

    .form-label-ghost {
        display: none;
    }
}

/* Botão remover da linha de caixa adicional — ao lado do campo Etiqueta */
.btn-icon-fim {
    align-self: end;
}

.btn-remove {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition);
}

.btn-remove:hover {
    color: var(--status-error);
    border-color: var(--status-error);
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    margin-bottom: 24px;
}

/* Table */
.table-card {
    margin-top: 24px;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table-count {
    font-size: 13px;
    color: var(--text-tertiary);
    font-weight: 400;
}

.table-container {
    overflow-x: auto;
}

/* Variante sem recorte: permite que o tooltip da Especificação extrapole a tabela */
.table-container-visible {
    overflow: visible;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 500;
    color: var(--text-tertiary);
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
}

/* Proporção fixa das colunas da Tabela de Temporalidade
   (Cód 8% · Título 40% · Especificação 25% · Destinação 17% · Ações 10%) */
.table-temporalidade {
    table-layout: fixed;
}

.table-temporalidade th:nth-child(1),
.table-temporalidade td:nth-child(1) { width: 8%; }

.table-temporalidade th:nth-child(2),
.table-temporalidade td:nth-child(2) { width: 40%; }

.table-temporalidade th:nth-child(3),
.table-temporalidade td:nth-child(3) { width: 25%; }

.table-temporalidade th:nth-child(4),
.table-temporalidade td:nth-child(4) { width: 17%; }

.table-temporalidade th:nth-child(5),
.table-temporalidade td:nth-child(5) { width: 10%; }

.table-temporalidade td:nth-child(2) {
    overflow-wrap: anywhere;
}

/* Badge da Especificação sempre em uma linha, com reticências */
.table-temporalidade td:nth-child(3) .badge {
    display: inline-block;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

/* Proporção fixa das colunas da listagem de Unidades
   (Nome 45% · Sigla 8% · Órgão 8% · Responsável 23% · Status 6% · Ações 10%) */
.table-unidades {
    table-layout: fixed;
}

.table-unidades th:nth-child(1),
.table-unidades td:nth-child(1) { width: 45%; }

.table-unidades th:nth-child(2),
.table-unidades td:nth-child(2) { width: 8%; }

.table-unidades th:nth-child(3),
.table-unidades td:nth-child(3) { width: 8%; }

.table-unidades th:nth-child(4),
.table-unidades td:nth-child(4) { width: 23%; }

.table-unidades th:nth-child(5),
.table-unidades td:nth-child(5) { width: 6%; }

.table-unidades th:nth-child(6),
.table-unidades td:nth-child(6) { width: 10%; }

.table-unidades th,
.table-unidades td {
    padding-left: 12px;
    padding-right: 12px;
}

.table-unidades td:nth-child(1) {
    overflow-wrap: anywhere;
}

/* Sigla/Órgão/Status: não deixam o conteúdo vazar para a coluna vizinha */
.table-unidades td:nth-child(2),
.table-unidades td:nth-child(3),
.table-unidades td:nth-child(5) {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table tbody tr:hover {
    background: var(--bg-main);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table-actions {
    display: flex;
    gap: 8px;
}

.table-link {
    color: var(--color-brand);
    font-weight: 600;
    text-decoration: none;
    transition: text-decoration var(--transition);
}

.table-link:hover {
    text-decoration: underline;
}

.btn-icon {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition), background-color var(--transition);
}

.btn-icon:hover {
    background: var(--bg-main);
    color: var(--text-main);
    border-color: var(--text-tertiary);
}

.btn-icon.btn-icon-danger:hover {
    color: var(--status-error);
    border-color: var(--status-error);
}

.empty-state {
    padding: 40px 16px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 14px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

/* Dashboard */
.search-inline {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0 12px;
    width: 420px;
    max-width: 100%;
    margin-left: auto;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.search-inline:focus-within {
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px var(--color-brand-light);
}

.search-inline-icon {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.search-inline .form-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 9px 0;
    box-shadow: none;
}

.search-inline .form-input:focus {
    box-shadow: none;
}

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

@media (max-width: 1024px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    transition: box-shadow var(--transition);
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
}

.kpi-card.ativo {
    border-color: var(--color-brand);
    box-shadow: var(--shadow-md), 0 0 0 3px var(--color-brand-light);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon-brand {
    background: var(--color-brand-light);
    color: var(--color-brand);
}

.kpi-icon-success {
    background: #dcfce7;
    color: var(--status-success);
}

.kpi-icon-warning {
    background: #fef3c7;
    color: var(--status-warning);
}

.kpi-icon-error {
    background: #fee2e2;
    color: var(--status-error);
}

.kpi-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
}

.kpi-label {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-top: 4px;
    line-height: 1.3;
}

/* Dashboard Table */
.dashboard-table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.dashboard-table-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.dashboard-table-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-main);
}

.dashboard-table-count {
    font-size: 13px;
    color: var(--text-tertiary);
    font-weight: 400;
}

/* Badge Status */
.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-neutral {
    background: var(--bg-main);
    color: var(--text-tertiary);
}

/* Table Header Actions */
.table-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.form-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 14px;
}

/* ── Combobox de busca (autocompletar nos selects do modal) ── */
.combobox {
    position: relative;
}

.combobox-input {
    padding-right: 56px;
}

.combobox-caret {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

.combobox-clear {
    position: absolute;
    top: 50%;
    right: 30px;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--color-brand);
    cursor: pointer;
    transition: background-color var(--transition), color var(--transition);
}

.combobox-clear:hover {
    background: var(--color-brand-light);
    color: var(--color-brand-dark);
}

.search-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--color-brand);
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color var(--transition), color var(--transition);
}

.search-clear:hover {
    background: var(--color-brand-light);
    color: var(--color-brand-dark);
}

.combobox-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 60;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
}

.combobox-item {
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color var(--transition), color var(--transition);
}

.combobox-item:hover,
.combobox-item.ativo {
    background: var(--color-brand-light);
    color: var(--color-brand);
}

/* Linha secundária do item (ex.: nomenclatura antiga da unidade) */
.combobox-item-hist {
    display: block;
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-tertiary);
}

.combobox-vazio {
    padding: 9px 12px;
    font-size: 13px;
    color: var(--text-tertiary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    z-index: 200;
    overflow-y: auto;
}

.modal {
    width: 100%;
    max-width: 800px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: modal-in 0.2s ease;
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}

.modal-close {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color var(--transition), background-color var(--transition);
}

.modal-close:hover {
    background: var(--bg-main);
    color: var(--text-main);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    .modal-overlay {
        padding: 16px;
    }
}

/* Modal Subsections */
.modal-subsection {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.modal-subtitle {
    margin-bottom: 12px;
}

.modal-status {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: 0 4px;
}

/* Document List (minimalista, 2 linhas) */
.doc-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.doc-item {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    padding: 14px 16px;
    transition: border-color var(--transition), background-color var(--transition);
}

.doc-item:hover {
    border-color: var(--color-brand-light);
    background: var(--bg-main);
}

.doc-item-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.doc-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    min-width: 0;
}

.doc-item-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
}

.doc-item-badges {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.doc-item-meta {
    display: flex;
    flex-wrap: wrap;
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-tertiary);
}

.doc-meta:not(:last-child)::after {
    content: '·';
    margin: 0 8px;
    color: var(--text-tertiary);
    opacity: 0.6;
}

.doc-meta-label {
    font-weight: 600;
    color: var(--text-muted);
}

/* ── Badge Group ── */
.badge-group {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* ── Row subtitle (sob o título na tabela) ── */
.row-subtitle {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 400;
    margin-top: 2px;
    line-height: 1.5;
}

/* ── Botões variantes ── */
.btn-sm {
    padding: 8px 12px;
    font-size: 13px;
}

.btn-outline {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background: var(--bg-main);
    border-color: var(--text-tertiary);
}

.btn-outline-brand {
    background: transparent;
    color: var(--color-brand);
    border: 1px solid var(--color-brand);
    font-size: 13px;
    padding: 6px 12px;
}

.btn-outline-brand:hover {
    background: var(--color-brand-light);
}

.btn-icon.btn-icon-brand {
    color: var(--color-brand);
    border-color: var(--color-brand-light);
    background: var(--color-brand-light);
}

.btn-icon.btn-icon-brand:hover {
    background: var(--color-brand);
    color: white;
    border-color: var(--color-brand);
}

/* ── Modal Sections (formulário com seções nomeadas) ── */
.modal-section {
    padding-bottom: 20px;
    margin-bottom: 4px;
}

.modal-section + .modal-section {
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
}

.modal-section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    margin-bottom: 14px;
}

/* ── View (leitura: modal de visualização) ── */
.view-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 24px;
}

.view-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
    min-width: 0;
}

.view-item-full {
    grid-column: 1 / -1;
}

/* Variante de 3 colunas (ex.: Sigla / Órgão / Status na mesma linha) */
.view-list-3 {
    grid-template-columns: repeat(3, 1fr);
}

.view-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.view-label::after {
    content: ':';
}

.view-value {
    font-size: 14px;
    color: var(--text-main);
    word-break: break-word;
    min-width: 0;
}

@media (max-width: 600px) {
    .view-list,
    .view-list-3 {
        grid-template-columns: 1fr;
    }
}

/* ── Histórico em colunas (responsáveis + unidade) ── */
.modal-section-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.hist-col {
    min-width: 0;
}

.hist-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hist-item {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 14px;
    color: var(--text-main);
    min-width: 0;
}

.hist-item-block {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-main);
}

.hist-period {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.hist-name {
    word-break: break-word;
    min-width: 0;
}

/* Histórico da Unidade: período na primeira linha e nome/sigla na linha seguinte. */
.hist-list-stacked .hist-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "periodo lateral"
        "nome nome";
    align-items: start;
    row-gap: 2px;
    column-gap: 12px;
}

.hist-list-stacked .hist-period { grid-area: periodo; }
.hist-list-stacked .hist-name { grid-area: nome; }
.hist-list-stacked .hist-item > .badge,
.hist-list-stacked .hist-item > .table-actions { grid-area: lateral; align-self: start; }

.hist-head {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hist-fields {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.hist-field {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.hist-field-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    min-width: 56px;
}

.hist-field-label::after {
    content: ':';
}

.hist-field-value {
    font-size: 13px;
    color: var(--text-main);
    min-width: 0;
    word-break: break-word;
}

.hist-old {
    color: var(--text-tertiary);
    text-decoration: line-through;
}

.hist-arrow {
    color: var(--text-tertiary);
    margin: 0 4px;
}

.hist-new {
    color: var(--color-brand);
    font-weight: 600;
}

.hist-same {
    color: var(--text-main);
}

.hist-empty {
    font-size: 13px;
    color: var(--text-tertiary);
}

.badge-sigla {
    background: var(--color-brand);
    color: #fff;
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.3px;
}

@media (max-width: 768px) {
    .modal-section-cols {
        grid-template-columns: 1fr;
    }
}

/* ── Modal wide (formulário de Documento) ── */
.modal-wide {
    max-width: 900px;
}

/* ── Grid 5 colunas (Fases com campos de data limitados a 230px) ── */
.form-row-5 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 230px) minmax(0, 230px) minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
}

@media (max-width: 900px) {
    .form-row-5 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 600px) {
    .form-row-5 {
        grid-template-columns: 1fr;
    }
}

/* ── Grid 6 colunas ── */
.form-row-6 {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 16px;
}

@media (max-width: 1100px) {
    .form-row-6 {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

@media (max-width: 600px) {
    .form-row-6 {
        grid-template-columns: 1fr;
    }
}

/* ── Identificação/Processo e Localização (layouts específicos) ── */
.form-row-id-top {
    grid-template-columns: 2fr 1fr 1fr;
}

.form-row-id-mid {
    grid-template-columns: 2fr 1fr 1fr;
    align-items: start;
}

/* O dossiê ocupa as duas colunas da direita, alinhando com o 2º campo da 1ª linha */
.form-row-id-dossie {
    grid-column: span 2;
}

/* Impede que os campos (inputs de data) forcem a coluna a crescer */
.form-row-id-top > *,
.form-row-id-mid > *,
.form-row-id-datas > *,
.form-row-loc-top > *,
.form-row-loc-left > * {
    min-width: 0;
}

.form-row-id-datas {
    grid-template-columns: minmax(0, 230px) minmax(0, 230px) minmax(0, 2fr);
}

.form-row-loc-top {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

.form-row-loc-left {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
}

/* Caixas (Localização): campos em 3 colunas; exclusão fica na coluna da direita */
.form-row-caixas {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
}

.form-row-caixas > * {
    min-width: 0;
}

/* Identificação da Unidade: Nome ~70% + Sigla/Órgão/Status ~10% cada */
.form-row-unidade > * {
    min-width: 0;
}

@media (max-width: 900px) {
    .form-row-unidade {
        grid-template-columns: 1fr 1fr !important;
    }
}

@media (max-width: 600px) {
    .form-row-unidade {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 900px) {
    .form-row-id-top {
        grid-template-columns: 1fr 1fr;
    }

    .form-row-id-mid,
    .form-row-loc-top {
        grid-template-columns: 1fr;
    }

    .form-row-id-dossie {
        grid-column: auto;
    }
}

@media (max-width: 768px) {
    .form-row-id-datas,
    .form-row-loc-left {
        grid-template-columns: 1fr;
    }
}

/* ── Label opcional ── */
.form-label-optional {
    font-weight: 400;
    color: var(--text-tertiary);
    font-size: 12px;
}

/* ── Tooltip (ícone de ajuda de campo) ── */
.tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

.tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    padding: 0;
    color: var(--color-brand);
    cursor: help;
    transform: translateY(-1px);
    transition: color var(--transition);
}

.tooltip-icon:hover,
.tooltip-icon:focus-visible {
    color: var(--color-brand-dark);
    outline: none;
}

.tooltip-content {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    z-index: 60;
    width: max-content;
    max-width: 470px;
    padding: 8px 10px;
    background: var(--color-brand);
    color: #fff;
    font-size: 12.5px;
    font-weight: 400;
    line-height: 1.45;
    text-align: left;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transform: translateY(2px);
    transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
    pointer-events: none;
}

.tooltip:hover .tooltip-content,
.tooltip:focus-within .tooltip-content {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ── Botão de perigo (exclusão) ── */

.btn-danger {
    background: var(--status-error);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-danger:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 4px var(--status-error);
}

/* ── Motivo obrigatório da exclusão ── */
.form-textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.char-counter { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-top:6px; font-size:12px; color:var(--text-tertiary); }
.modal-motivo { max-width:520px; border-top:3px solid var(--status-warning); }
.modal-motivo .modal-header { border-bottom:1px solid var(--border-color); }
.modal-motivo .form-textarea:focus { border-color: var(--color-brand); box-shadow:0 0 0 3px var(--color-brand-light); }

/* ── Modal de confirmação de exclusão ── */
.modal-overlay-confirm {
    align-items: center;
}

.modal-confirm {
    max-width: 420px;
    border-top: 3px solid var(--status-error);
}

.modal-confirm-body {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 24px 24px 20px;
}

.modal-confirm-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: #fee2e2;
    color: var(--status-error);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-confirm-content {
    flex: 1;
    min-width: 0;
}

.modal-confirm-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 6px;
}

.modal-confirm-desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 8px;
}

.modal-confirm-warn {
    font-size: 12px;
    font-weight: 600;
    color: var(--status-error);
}

.modal-confirm-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-main);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── Aviso de sucesso (padrão do sistema, centralizado) ── */
.modal-confirm-success {
    border-top-color: var(--status-success);
}

.modal-confirm-icon-success {
    background: #dcfce7;
    color: var(--status-success);
}

/* ── Paginação padrão do sistema (10 por página) ── */
.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 0 2px;
    border-top: 1px solid var(--border-color);
    margin-top: 16px;
    flex-wrap: wrap;
}

.table-pagination-info {
    font-size: 13px;
    color: var(--text-tertiary);
    font-weight: 400;
}

.table-pagination-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.table-pagination-controls .btn-icon:disabled,
.table-pagination-controls .btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.pagination-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    font-size: 13px;
    color: var(--text-tertiary);
    user-select: none;
}

/* compat: mantém .pagination legado caso usado */
.pagination { display: flex; }

@media (max-width: 600px) {
    .table-pagination {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    .table-pagination-controls {
        justify-content: center;
    }
    /* Localização/Identificação: empilha colunas no mobile */
    .form-row-local-duas,
    .form-row-id-top {
        grid-template-columns: 1fr !important;
    }
}

/* Permissões — Gestão de Usuários */
.permissoes-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 24px;
}
.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-main);
    cursor: pointer;
    user-select: none;
}
.form-check input[type="checkbox"],
.form-check input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-brand);
    cursor: pointer;
}
.form-check-highlight {
    grid-column: 1 / -1;
    padding: 8px 10px;
    background: var(--color-brand-light);
    border: 1px solid #e9d5ff;
    border-radius: var(--radius-sm);
    font-weight: 600;
    color: var(--color-brand-dark);
}
@media (max-width: 600px) {
    .permissoes-grid { grid-template-columns: 1fr; }
}

/* ── Extinção de unidade: documentos com destino por item ── */
.extincao-modos {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.extincao-lista {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}


.extincao-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 260px);
    gap: 12px;
    align-items: center;
}

.extincao-item-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.extincao-item-info strong {
    min-width: 0;
    line-height: 1.3;
    overflow-wrap: anywhere;
    white-space: normal;
}

.extincao-item-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

@media (max-width: 768px) {
    .extincao-item {
        grid-template-columns: 1fr;
    }
}


