/**
 * Demo HubMessenger — Fase 6: interface administrativa responsiva
 */

:root {
    --demo-primary: #1e40af;
    --demo-primary-hover: #1d4ed8;
    --demo-sidebar-bg: #0f172a;
    --demo-sidebar-text: #e2e8f0;
    --demo-sidebar-muted: #94a3b8;
    --demo-sidebar-active: rgba(59, 130, 246, 0.22);
    --demo-topbar-h: 3.5rem;
    --demo-sidebar-w: 17rem;
    --demo-radius: 0.75rem;
    --demo-shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
    --demo-danger: #b91c1c;
    --demo-success: #047857;
    --demo-warning: #b45309;
    --demo-border: #e2e8f0;
    --demo-surface: #ffffff;
    --demo-bg: #f1f5f9;
    --demo-text: #0f172a;
    --demo-muted: #64748b;
    --demo-btn-compact: 2rem;
    --demo-touch-min: 3rem;
}

/* Layout administrativo */
.demo-admin {
    min-height: 100vh;
    background: var(--demo-bg);
}

.demo-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: var(--demo-topbar-h);
    padding: 0 1rem;
    background: var(--demo-surface);
    border-bottom: 1px solid var(--demo-border);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.demo-menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: var(--demo-touch-min);
    height: var(--demo-touch-min);
    padding: 0.5rem;
    border: 1px solid var(--demo-border);
    border-radius: 0.5rem;
    background: var(--demo-surface);
    cursor: pointer;
}

.demo-menu-toggle span {
    display: block;
    width: 1.25rem;
    height: 2px;
    background: var(--demo-text);
    border-radius: 1px;
}

.demo-topbar-brand a {
    font-weight: 700;
    color: var(--demo-text);
    text-decoration: none;
}

.demo-topbar-brand a:hover {
    color: var(--demo-primary);
}

.demo-topbar-sub {
    display: block;
    font-size: 0.8125rem;
    color: var(--demo-muted);
    font-weight: 500;
}

.demo-user-menu {
    margin-left: auto;
    position: relative;
}

.demo-user-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.5rem;
    padding: 0.25rem 0.75rem 0.25rem 0.25rem;
    border: 1px solid var(--demo-border);
    border-radius: 999px;
    background: var(--demo-surface);
    cursor: pointer;
}

.demo-user-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--demo-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
}

.demo-user-label {
    display: flex;
    flex-direction: column;
    text-align: left;
    line-height: 1.2;
    font-size: 0.8125rem;
}

.demo-user-label small {
    color: var(--demo-muted);
    font-weight: 400;
}

.demo-user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 0.35rem);
    min-width: 14rem;
    background: var(--demo-surface);
    border: 1px solid var(--demo-border);
    border-radius: var(--demo-radius);
    box-shadow: var(--demo-shadow);
    padding: 0.35rem;
    z-index: 1060;
}

.demo-user-menu.is-open .demo-user-dropdown {
    display: block;
}

.demo-user-dropdown a,
.demo-user-dropdown form {
    display: block;
    padding: 0.55rem 0.75rem;
    border-radius: 0.5rem;
    color: var(--demo-text);
    text-decoration: none;
}

.demo-user-dropdown a:hover {
    background: var(--demo-bg);
}

.demo-user-dropdown-info {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--demo-muted);
    border-bottom: 1px solid var(--demo-border);
    margin-bottom: 0.25rem;
}

.demo-shell {
    display: flex;
    min-height: calc(100vh - var(--demo-topbar-h));
}

.demo-sidebar {
    width: var(--demo-sidebar-w);
    flex-shrink: 0;
    background: var(--demo-sidebar-bg);
    color: var(--demo-sidebar-text);
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--demo-topbar-h));
    max-height: calc(100vh - var(--demo-topbar-h));
    position: sticky;
    top: var(--demo-topbar-h);
    overflow: hidden;
}

.demo-sidebar-inner {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0.5rem 1rem;
    -webkit-overflow-scrolling: touch;
}

.demo-sidebar-brand {
    padding: 0.5rem 0.75rem 0.75rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--demo-sidebar-muted);
    border-bottom: 1px solid rgba(148, 163, 184, 0.15);
    margin-bottom: 0.5rem;
}

.demo-nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.5rem;
    color: var(--demo-sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 0.1rem;
}

.demo-nav-link .ti {
    font-size: 1.1rem;
    opacity: 0.9;
    flex-shrink: 0;
}

.demo-nav-link:hover,
.demo-nav-link.is-active {
    background: var(--demo-sidebar-active);
    color: #fff;
    text-decoration: none;
}

.demo-nav-group-title {
    display: block;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--demo-sidebar-muted);
    margin: 0.85rem 0.75rem 0.35rem;
    padding-top: 0.25rem;
}

.demo-nav-children .demo-nav-link {
    padding-left: 2.15rem;
    font-size: 0.85rem;
}

.demo-main {
    flex: 1;
    min-width: 0;
    padding: 1.25rem 1.5rem 2rem;
}

.demo-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1040;
    pointer-events: none;
}

.demo-backdrop.is-visible {
    display: block;
    pointer-events: auto;
}

body.demo-sidebar-open {
    overflow: hidden;
}

/* Páginas */
.demo-page {
    max-width: 100%;
}

.demo-page-back {
    margin-bottom: 0.75rem;
}

.demo-page-toolbar,
.demo-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.demo-page-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--demo-text);
}

.demo-page-subtitle {
    margin: 0.35rem 0 0;
    color: var(--demo-muted);
    font-size: 0.9375rem;
}

.demo-page-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Cards */
.demo-card {
    background: var(--demo-surface);
    border: 1px solid var(--demo-border);
    border-radius: var(--demo-radius);
    box-shadow: var(--demo-shadow);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.demo-form-card {
    padding: 1.5rem;
}

/* Botões */
.demo-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 2.375rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    background: var(--demo-surface);
    color: var(--demo-text);
    white-space: nowrap;
}

.demo-btn:hover {
    text-decoration: none;
}

.demo-btn-primary {
    background: var(--demo-primary);
    color: #fff;
    border-color: var(--demo-primary);
}

.demo-btn-primary:hover {
    background: var(--demo-primary-hover);
    color: #fff;
}

.demo-btn-secondary {
    background: var(--demo-surface);
    border-color: var(--demo-border);
    color: var(--demo-text);
}

.demo-btn-secondary:hover {
    background: var(--demo-bg);
}

.demo-btn-danger {
    background: #fef2f2;
    border-color: #fecaca;
    color: var(--demo-danger);
}

.demo-btn-danger:hover {
    background: #fee2e2;
}

.demo-btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--demo-muted);
}

.demo-btn-ghost:hover {
    background: var(--demo-bg);
    color: var(--demo-text);
}

.demo-btn-sm {
    min-height: 2rem;
    padding: 0.35rem 0.65rem;
    font-size: 0.8125rem;
}

.demo-inline-form {
    display: inline-flex;
    margin: 0;
}

.demo-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

/* Tabelas desktop */
.demo-table-panel {
    overflow-x: auto;
}

.demo-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.demo-table th,
.demo-table td {
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid var(--demo-border);
    text-align: left;
    vertical-align: top;
}

.demo-table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--demo-muted);
}

.demo-table tbody tr:hover {
    background: #f8fafc;
}

/* Listagem mobile */
.demo-mobile-list {
    display: none;
    flex-direction: column;
    gap: 0.75rem;
}

.demo-mobile-card {
    background: var(--demo-surface);
    border: 1px solid var(--demo-border);
    border-radius: var(--demo-radius);
    padding: 1rem;
    box-shadow: var(--demo-shadow);
}

.demo-mobile-card-title {
    font-weight: 700;
    font-size: 1rem;
    margin: 0 0 0.5rem;
    word-break: break-word;
}

.demo-mobile-card-meta {
    display: grid;
    gap: 0.35rem;
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
}

.demo-mobile-card-meta dt {
    font-weight: 600;
    color: var(--demo-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.demo-mobile-card-meta dd {
    margin: 0 0 0.35rem;
}

.demo-mobile-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--demo-border);
}

.demo-mobile-card-actions .demo-btn {
    flex: 1 1 auto;
    min-height: calc(var(--demo-btn-compact) * 1.5);
    padding: 0.85rem 1.15rem;
    font-size: 1rem;
}

/* Filtros */
.demo-filter-card {
    margin-bottom: 1rem;
}

.demo-filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
    gap: 0.85rem 1rem;
    margin-bottom: 1rem;
}

.demo-filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Formulários */
.demo-form .demo-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 1rem 1.25rem;
}

.demo-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.demo-field-full {
    grid-column: 1 / -1;
}

.demo-field label,
.demo-field > .demo-label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--demo-text);
}

.demo-field input,
.demo-field select,
.demo-field textarea {
    width: 100%;
    max-width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--demo-border);
    border-radius: 0.5rem;
    font: inherit;
    background: var(--demo-surface);
}

.demo-field input:focus,
.demo-field select:focus,
.demo-field textarea:focus {
    outline: 2px solid rgba(37, 99, 235, 0.35);
    border-color: var(--demo-primary);
}

.demo-check {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.demo-check input {
    width: auto;
}

.demo-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--demo-border);
}

.demo-form-actions .demo-btn {
    min-height: 2.5rem;
}

.demo-permissions-block {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--demo-border);
}

.demo-permissions-block h2 {
    margin: 0 0 0.5rem;
    font-size: 1.125rem;
}

/* Dashboard */
.demo-dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
    gap: 1rem;
}

.demo-dash-card {
    background: var(--demo-surface);
    border: 1px solid var(--demo-border);
    border-radius: var(--demo-radius);
    padding: 1.15rem;
    box-shadow: var(--demo-shadow);
}

.demo-dash-card h3 {
    margin: 0 0 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--demo-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.demo-dash-value {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.demo-dash-value-sm {
    font-size: 1rem;
}

.demo-dash-card small {
    color: var(--demo-muted);
    font-size: 0.8125rem;
}

/* Detalhe / show */
.demo-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.demo-detail-item strong {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--demo-muted);
    margin-bottom: 0.2rem;
}

.demo-detail-item p {
    margin: 0;
}

.demo-detail-block {
    margin-bottom: 1.25rem;
}

.demo-detail-block h2 {
    font-size: 1.125rem;
    margin: 0 0 0.75rem;
}

.demo-comment-list,
.demo-history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.demo-comment-list li,
.demo-history-list li {
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--demo-border);
}

.demo-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 0.35rem;
    background: #e2e8f0;
    color: var(--demo-text);
    margin-left: 0.35rem;
}

.demo-badge-internal {
    background: #fef3c7;
    color: #92400e;
}

.demo-status-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: capitalize;
}

.demo-status-aberto { background: #dbeafe; color: #1e40af; }
.demo-status-em_atendimento { background: #e0e7ff; color: #3730a3; }
.demo-status-aguardando_informacao { background: #fef3c7; color: #92400e; }
.demo-status-resolvido { background: #d1fae5; color: #047857; }
.demo-status-encerrado { background: #f1f5f9; color: #475569; }
.demo-status-cancelado { background: #fee2e2; color: #b91c1c; }

.demo-audit-pre {
    max-width: 16rem;
    max-height: 6rem;
    overflow: auto;
    font-size: 0.7rem;
    white-space: pre-wrap;
    margin: 0;
    background: #f8fafc;
    padding: 0.35rem;
    border-radius: 0.35rem;
}

/* Flash dentro do layout demo */
.demo-main .flash-messages {
    margin-bottom: 1rem;
}

/* Erro 403 */
.demo-error-card {
    text-align: center;
    max-width: 28rem;
    margin: 2rem auto;
}

.demo-error-card h1 {
    margin-top: 0;
}

/* Responsivo */
@media (max-width: 991.98px) {
    .demo-menu-toggle {
        display: flex;
    }

    .demo-sidebar {
        position: fixed;
        left: 0;
        top: var(--demo-topbar-h);
        bottom: 0;
        z-index: 1050;
        width: min(var(--demo-sidebar-w), 88vw);
        max-height: none;
        min-height: 0;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
    }

    .demo-sidebar.is-open {
        transform: translateX(0);
    }

    .demo-main {
        padding: 1rem;
    }

    .demo-desktop-only {
        display: none !important;
    }

    .demo-mobile-list {
        display: flex;
    }

    .demo-form-actions .demo-btn,
    .demo-filter-actions .demo-btn {
        min-height: var(--demo-touch-min);
        font-size: 0.9375rem;
    }

    .demo-user-label {
        display: none;
    }
}

@media (min-width: 992px) {
    .demo-mobile-only {
        display: none !important;
    }
}

/* Painéis gerenciais — Fase 6.5 */
.demo-analytics-scope-note { margin: 0 0 1rem; padding: 0.75rem 1rem; background: #eff6ff; border-radius: 8px; font-size: 0.875rem; color: #1e40af; }
.demo-analytics-charts { display: grid; gap: 1rem; margin-top: 1rem; }
@media (min-width: 768px) { .demo-analytics-charts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.demo-chart-card-wide { grid-column: 1 / -1; }
.demo-chart { min-height: 280px; margin-top: 0.75rem; }
.demo-chart-empty { padding: 2rem 1rem; text-align: center; }
.demo-dash-card-accent { border-color: #93c5fd; background: linear-gradient(180deg, #f8fafc 0%, #eff6ff 100%); }
.demo-dash-card-wide { grid-column: 1 / -1; }
@media (min-width: 576px) { .demo-analytics-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .demo-analytics-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.demo-filter-locked { display: flex; flex-direction: column; gap: 0.25rem; }
.demo-analytics-table-card { margin-top: 1rem; }

/* Auth — harmonização leve com admin */
.auth-body.demo-auth-body {
    background: linear-gradient(145deg, #dbeafe 0%, #f1f5f9 55%, #fff 100%);
}

.auth-card.demo-auth-card {
    border: 1px solid var(--demo-border);
}

.auth-card.demo-auth-card .demo-btn-primary {
    width: 100%;
    min-height: var(--demo-touch-min);
}

/* Documentação online — Fase 6.6 */
.demo-doc-hub .demo-doc-search-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}
.demo-doc-search-field { flex: 1 1 16rem; min-width: 12rem; }
.demo-doc-meta { margin: 0 0 1.25rem; }
.demo-doc-featured { margin-bottom: 1.5rem; }
.demo-doc-featured h2 { margin: 0 0 0.75rem; font-size: 1.125rem; }
.demo-doc-featured-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.demo-doc-featured-card {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.demo-doc-featured-card:hover { border-color: #93c5fd; box-shadow: 0 4px 14px rgba(37, 99, 235, 0.12); }
.demo-doc-featured-card h3 { margin: 0 0 0.35rem; font-size: 1rem; }
.demo-doc-featured-card p { margin: 0.25rem 0 0; font-size: 0.875rem; }
.demo-doc-index-group { margin-bottom: 1rem; }
.demo-doc-index-group h2 { margin: 0 0 0.65rem; font-size: 1.05rem; }
.demo-doc-index-list { list-style: none; margin: 0; padding: 0; }
.demo-doc-index-list li { border-bottom: 1px solid var(--demo-border, #e2e8f0); }
.demo-doc-index-list a {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.65rem 0;
    text-decoration: none;
    color: inherit;
}
.demo-doc-index-list a:hover .demo-doc-index-title { color: #2563eb; }
.demo-doc-index-title { font-weight: 600; }
.demo-doc-index-path { font-size: 0.8125rem; }
.demo-doc-empty { padding: 1.5rem; text-align: center; }
.demo-doc-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.demo-doc-header h1 { margin: 0 0 0.35rem; font-size: 1.5rem; }
.demo-doc-toc { margin-bottom: 1rem; }
.demo-doc-toc-title { margin: 0 0 0.5rem; font-size: 1rem; }
.demo-doc-toc ol { margin: 0; padding-left: 1.25rem; }
.demo-doc-toc-l2 { margin-left: 0.75rem; }
.demo-doc-toc-l3 { margin-left: 1.25rem; }
.demo-doc-article { padding: 1.25rem; }
.demo-doc-content { line-height: 1.65; font-size: 0.9375rem; word-wrap: break-word; }
.demo-doc-content h1, .demo-doc-content h2, .demo-doc-content h3 { margin-top: 1.25rem; margin-bottom: 0.5rem; }
.demo-doc-content p { margin: 0.75rem 0; }
.demo-doc-pre, .demo-doc-raw {
    background: #0f172a;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.8125rem;
    line-height: 1.45;
}
.demo-doc-inline-code {
    background: #f1f5f9;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.875em;
}
.demo-doc-table-wrap { overflow-x: auto; margin: 1rem 0; }
.demo-doc-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.demo-doc-table th, .demo-doc-table td {
    border: 1px solid var(--demo-border, #e2e8f0);
    padding: 0.5rem 0.65rem;
    text-align: left;
}
.demo-doc-quote {
    border-left: 4px solid #93c5fd;
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    background: #f8fafc;
}
.demo-doc-hr { border: none; border-top: 1px solid #e2e8f0; margin: 1.25rem 0; }
.demo-doc-print-body { margin: 0; padding: 1.5rem; background: #fff; color: #0f172a; }
.demo-doc-print-header { border-bottom: 2px solid #e2e8f0; margin-bottom: 1rem; padding-bottom: 0.75rem; }
.demo-doc-print-app { margin: 0; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: #64748b; }
.demo-doc-print-meta { margin: 0.35rem 0 0; font-size: 0.875rem; color: #64748b; }
.demo-doc-print-actions { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.demo-doc-print-content { font-size: 11pt; line-height: 1.5; }
@media print {
    .no-print, .demo-doc-print-actions { display: none !important; }
    .demo-doc-print-body { padding: 0; }
}
@media (max-width: 991.98px) {
    .demo-doc-featured-grid { grid-template-columns: 1fr; }
}
