/* =========================================================
   IDENTIDADE SIPP - FUNDAÇÃO VISUAL
   Camada incremental sobre Bootstrap/Materia.
   ========================================================= */
:root,
body[data-theme="light"] {
    --sipro-primary: #0b63a5;
    --sipro-primary-hover: #084f85;
    --sipro-on-primary: #ffffff;
    --sipro-primary-container: #d9ebf8;
    --sipro-on-primary-container: #123a55;
    --sipro-secondary: #287566;
    --sipro-secondary-hover: #1f5f53;
    --sipro-success: #1f6b50;
    --sipro-success-text: #164d3a;
    --sipro-success-container: #dcefe6;
    --sipro-success-container-hover: #c9e5d8;
    --sipro-warning-text: #6f5008;
    --sipro-warning-container: #fff0c2;
    --sipro-info-text: #155c6d;
    --sipro-info-container: #d8eef3;
    --sipro-danger: #b3261e;
    --sipro-danger-text: #8c1d18;
    --sipro-danger-container: #ffdad6;
    --sipro-danger-container-hover: #ffc6c0;
    --sipro-danger-focus: rgba(179, 38, 30, .14);
    --sipro-surface: #ffffff;
    --sipro-surface-subtle: #f5f7fa;
    --sipro-surface-container: #edf1f4;
    --sipro-surface-strong: #e4e9ed;
    --sipro-outline: #a8b2b9;
    --sipro-field-outline: #727b83;
    --sipro-outline-variant: #c1c9cf;
    --sipro-text: #17232c;
    --sipro-muted: #5e6c76;
    --sipro-focus: rgba(11, 99, 165, .22);
    --sipro-state-hover: rgba(23, 35, 44, .08);
    --sipro-shadow-1: 0 1px 2px rgba(23, 35, 44, .16), 0 1px 3px 1px rgba(23, 35, 44, .08);
    --sipro-shadow-2: 0 2px 6px 2px rgba(23, 35, 44, .12), 0 1px 2px rgba(23, 35, 44, .16);

    --bs-primary: var(--sipro-primary);
    --bs-primary-rgb: 11, 99, 165;
    --bs-secondary: var(--sipro-secondary);
    --bs-secondary-rgb: 40, 117, 102;
    --bs-body-bg: var(--sipro-surface-subtle);
    --bs-body-color: var(--sipro-text);
    --bs-secondary-color: var(--sipro-muted);
    --bs-border-color: var(--sipro-outline-variant);
    --bs-border-radius: 8px;
    --bs-border-radius-sm: 4px;
    --bs-border-radius-lg: 8px;
}

body[data-theme="dark"] {
    --sipro-primary: #72b7ea;
    --sipro-primary-hover: #9bcdf0;
    --sipro-on-primary: #00344f;
    --sipro-primary-container: #183f58;
    --sipro-on-primary-container: #d7efff;
    --sipro-secondary: #68c7b1;
    --sipro-secondary-hover: #8ed7c6;
    --sipro-success: #8ed7b8;
    --sipro-success-text: #a8e9cc;
    --sipro-success-container: #214438;
    --sipro-success-container-hover: #2b5547;
    --sipro-warning-text: #f0cd73;
    --sipro-warning-container: #493c1d;
    --sipro-info-text: #8fd5e2;
    --sipro-info-container: #203f47;
    --sipro-danger: #ffb4ab;
    --sipro-danger-text: #ffb4ab;
    --sipro-danger-container: #5f201d;
    --sipro-danger-container-hover: #76302c;
    --sipro-danger-focus: rgba(255, 180, 171, .16);
    --sipro-surface: #1d2327;
    --sipro-surface-subtle: #15191c;
    --sipro-surface-container: #232a2f;
    --sipro-surface-strong: #272e33;
    --sipro-outline: #566169;
    --sipro-field-outline: #89939a;
    --sipro-outline-variant: #465159;
    --sipro-text: #edf2f5;
    --sipro-muted: #b6c0c6;
    --sipro-focus: rgba(114, 183, 234, .28);
    --sipro-state-hover: rgba(237, 242, 245, .08);
    --sipro-shadow-1: 0 1px 2px rgba(0, 0, 0, .28), 0 3px 10px rgba(0, 0, 0, .18);
    --sipro-shadow-2: 0 6px 18px rgba(0, 0, 0, .32);

    --bg: var(--sipro-surface-subtle);
    --surface: var(--sipro-surface);
    --surface-2: var(--sipro-surface-strong);
    --border: var(--sipro-outline);
    --text: var(--sipro-text);
    --muted: var(--sipro-muted);
    --dm-bg: var(--sipro-surface-subtle);
    --dm-surface: var(--sipro-surface);
    --dm-surface-2: var(--sipro-surface-strong);
    --dm-border: var(--sipro-outline);
    --dm-text: var(--sipro-text);
    --dm-muted: var(--sipro-muted);
    --dm-input: #20272c;

    --bs-primary: var(--sipro-primary);
    --bs-primary-rgb: 114, 183, 234;
    --bs-secondary: var(--sipro-secondary);
    --bs-secondary-rgb: 104, 199, 177;
    --bs-body-bg: var(--sipro-surface-subtle);
    --bs-body-color: var(--sipro-text);
    --bs-secondary-color: var(--sipro-muted);
    --bs-border-color: var(--sipro-outline-variant);
}

body:not(.login-page) {
    background: var(--sipro-surface-subtle);
    color: var(--sipro-text);
    font-family: Roboto, "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
    letter-spacing: 0;
}

/* Navegação compartilhada */
#sidebar {
    background: var(--sipro-surface);
    border-right: 1px solid var(--sipro-outline-variant);
    box-shadow: none;
}

#sidebar .sidebar-header {
    min-height: 64px;
    border-bottom: 1px solid var(--sipro-outline-variant);
}

#sidebar .nav-link {
    min-height: 44px;
    margin: 3px 10px;
    padding: .65rem .9rem;
    border: 0;
    border-radius: 22px;
    color: var(--sipro-muted);
    font-weight: 600;
}

#sidebar .nav-link:hover {
    background: var(--sipro-state-hover);
    color: var(--sipro-text);
    transform: none;
}

#sidebar .nav-link.active {
    background: var(--sipro-primary-container);
    color: var(--sipro-on-primary-container);
    border-left-color: transparent;
    box-shadow: none;
}

#sidebar .nav-link i {
    width: 24px;
    font-size: 1.05rem;
    text-align: center;
}

.sidebar-section-label {
    min-height: 28px;
    padding: .55rem 1.15rem .2rem;
    display: block;
    color: var(--sipro-muted);
    font-size: .62rem;
    font-weight: 700;
    text-transform: uppercase;
}

body.sidebar-collapsed .sidebar-section-label {
    height: 12px;
    min-height: 12px;
    padding: 0;
    overflow: hidden;
    font-size: 0;
}

header {
    min-height: 64px;
    padding: .45rem .25rem;
    background: var(--sipro-surface);
    border-bottom: 1px solid var(--sipro-outline-variant);
    box-shadow: var(--sipro-shadow-1);
}

header .btn-user {
    margin: 0;
}

/* Controles e comandos */
.btn {
    min-height: 38px;
    padding: .48rem .9rem;
    border-radius: 8px;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    box-shadow: none;
}

.btn:hover,
.btn:active,
.card:hover {
    transform: none;
}

.btn:hover {
    box-shadow: none;
}

.btn:focus-visible,
.nav-link:focus-visible,
.dropdown-item:focus-visible,
.accordion-button:focus-visible {
    outline: 3px solid var(--sipro-focus);
    outline-offset: 2px;
    box-shadow: none !important;
}

.btn-primary {
    --bs-btn-bg: var(--sipro-primary);
    --bs-btn-color: var(--sipro-on-primary);
    --bs-btn-border-color: var(--sipro-primary);
    --bs-btn-hover-bg: var(--sipro-primary-hover);
    --bs-btn-hover-border-color: var(--sipro-primary-hover);
    --bs-btn-active-bg: var(--sipro-primary-hover);
    --bs-btn-active-border-color: var(--sipro-primary-hover);
    background-image: none;
    box-shadow: none;
}

.btn-primary:hover,
.btn-primary:focus-visible {
    box-shadow: none;
}

.btn-outline-primary {
    --bs-btn-color: var(--sipro-primary);
    --bs-btn-border-color: var(--sipro-primary);
    --bs-btn-hover-bg: var(--sipro-primary-container);
    --bs-btn-hover-border-color: var(--sipro-primary);
    --bs-btn-hover-color: var(--sipro-on-primary-container);
    --bs-btn-active-bg: var(--sipro-primary-container);
    --bs-btn-active-color: var(--sipro-on-primary-container);
}

.btn-outline-secondary {
    --bs-btn-color: var(--sipro-muted);
    --bs-btn-border-color: var(--sipro-field-outline);
    --bs-btn-hover-bg: var(--sipro-surface-strong);
    --bs-btn-hover-border-color: var(--sipro-field-outline);
    --bs-btn-hover-color: var(--sipro-text);
}

.btn-sm {
    min-height: 32px;
    padding: .35rem .75rem;
    border-radius: 8px;
}

.logo.logo-light {
    display: block !important;
}

.logo.logo-dark {
    display: none !important;
}

body[data-theme="dark"] .logo.logo-light {
    display: none !important;
}

body[data-theme="dark"] .logo.logo-dark {
    display: block !important;
}

.sipro-icon-button {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    display: inline-grid;
    place-items: center;
    color: var(--sipro-text);
    background: transparent;
    border: 0;
    border-radius: 50%;
}

.sipro-icon-button:hover,
.sipro-icon-button:active {
    color: var(--sipro-text);
    background: var(--sipro-state-hover);
}

.sipro-profile-button {
    max-width: 260px;
    color: var(--sipro-text);
    background: var(--sipro-surface-container);
    border: 0;
}

.sipro-profile-button:hover,
.sipro-profile-button:active,
.sipro-profile-button.show {
    color: var(--sipro-text);
    background: var(--sipro-surface-strong);
}

.sipro-profile-button:not(.show) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-close,
.btn-icon,
#toggle-theme {
    border-radius: 50%;
}

.form-control,
.form-select,
.input-group-text {
    min-height: 44px;
    border-color: var(--sipro-field-outline);
    border-radius: 4px;
    background-color: var(--sipro-surface);
    color: var(--sipro-text);
}

.form-control:hover,
.form-select:hover {
    border-color: var(--sipro-text);
}

.form-control:focus,
.form-select:focus,
body[data-theme="dark"] .form-control:focus,
body[data-theme="dark"] .form-select:focus,
body[data-theme="dark"] textarea:focus {
    border-color: var(--sipro-primary) !important;
    outline: 0 !important;
    box-shadow: 0 0 0 3px var(--sipro-focus) !important;
}

.form-label {
    color: var(--sipro-text);
    font-size: .82rem;
    font-weight: 600;
}

.form-check-input {
    border-color: var(--sipro-field-outline);
}

.form-check-input:checked {
    background-color: var(--sipro-primary);
    border-color: var(--sipro-primary);
}

.form-text,
.text-muted {
    color: var(--sipro-muted) !important;
}

/* Superfícies */
.card,
.modal-content,
.dropdown-menu,
.accordion-item {
    border-color: var(--sipro-outline-variant);
    border-radius: 8px;
    background: var(--sipro-surface);
    color: var(--sipro-text);
    box-shadow: var(--sipro-shadow-1);
}

.card:hover {
    box-shadow: var(--sipro-shadow-1);
}

.card-header,
.modal-header,
.modal-footer,
.accordion-button {
    background: var(--sipro-surface);
    color: var(--sipro-text);
    border-color: var(--sipro-outline-variant);
}

.card-header,
.modal-header {
    min-height: 56px;
}

.accordion-button:not(.collapsed) {
    background: var(--sipro-primary-container);
    color: var(--sipro-on-primary-container);
    box-shadow: inset 0 -1px 0 var(--sipro-outline-variant);
}

.modal-content {
    overflow: hidden;
    box-shadow: var(--sipro-shadow-2);
}

.dropdown-item {
    color: var(--sipro-text);
    min-height: 40px;
    display: flex;
    align-items: center;
    border-radius: 4px;
}

.dropdown-menu {
    padding: .5rem;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background: var(--sipro-primary-container);
    color: var(--sipro-on-primary-container);
}

.table {
    --bs-table-bg: var(--sipro-surface);
    --bs-table-color: var(--sipro-text);
    --bs-table-border-color: var(--sipro-outline-variant);
    --bs-table-hover-bg: var(--sipro-surface-subtle);
    --bs-table-hover-color: var(--sipro-text);
}

.table thead th {
    background: var(--sipro-surface-container);
    color: var(--sipro-muted);
    font-weight: 700;
}

.table > :not(caption) > * > * {
    padding-top: .7rem;
    padding-bottom: .7rem;
}

.badge {
    padding: .38rem .62rem;
    border-radius: 12px;
    letter-spacing: 0;
}

.footer {
    background: var(--sipro-surface) !important;
    color: var(--sipro-muted) !important;
    border-color: var(--sipro-outline) !important;
}

body[data-theme="dark"] #sidebar,
body[data-theme="dark"] header,
body[data-theme="dark"] .card,
body[data-theme="dark"] .modal-content,
body[data-theme="dark"] .dropdown-menu,
body[data-theme="dark"] .accordion-item,
body[data-theme="dark"] .serralheria-stat {
    background: var(--sipro-surface) !important;
    color: var(--sipro-text) !important;
    border-color: var(--sipro-outline-variant) !important;
}

body[data-theme="dark"] .card-header,
body[data-theme="dark"] .modal-header,
body[data-theme="dark"] .modal-footer,
body[data-theme="dark"] .accordion-button {
    background: var(--sipro-surface) !important;
    border-color: var(--sipro-outline-variant) !important;
}

body[data-theme="dark"] #sidebar .nav-link.active {
    background: var(--sipro-primary-container);
    color: var(--sipro-on-primary-container) !important;
    border-left-color: var(--sipro-primary);
}

body[data-theme="dark"] .form-control,
body[data-theme="dark"] .form-select,
body[data-theme="dark"] .input-group-text {
    background: var(--dm-input) !important;
    color: var(--sipro-text) !important;
    border-color: var(--sipro-field-outline) !important;
}

body[data-theme="dark"] .btn-primary {
    --bs-btn-color: #102b3d;
    --bs-btn-hover-color: #102b3d;
    --bs-btn-active-color: #102b3d;
}

body[data-theme="dark"] .table thead th,
body[data-theme="dark"] .table thead td {
    background: var(--sipro-surface-container) !important;
    color: var(--sipro-muted) !important;
    border-color: var(--sipro-outline-variant) !important;
}

@media (max-width: 767px) {
    #main-content.p-4 {
        padding: 1rem !important;
    }

    header {
        min-height: 56px;
    }

    .btn {
        min-height: 36px;
    }

    .serralheria-toolbar {
        width: 100%;
        min-width: 0;
    }

    .serralheria-toolbar .serralheria-search {
        width: auto;
        min-width: 0;
        flex: 1 1 auto;
    }
}
