/* Shared slate/red theme for the BS4, BS5 and public layouts. */
body.erp-theme {
    --erp-radius-sm: .25rem;
    --erp-radius: .375rem;
    --erp-radius-lg: .5rem;
    --erp-border-color: #e5e9ef;
    --erp-input-border-color: #d8dee7;
    --erp-success: #198754;
    --erp-success-hover: #157347;
    --erp-success-active: #146c43;
    --bs-border-color: var(--erp-border-color);
    --bs-border-radius: var(--erp-radius);
    --bs-border-radius-sm: var(--erp-radius-sm);
    --bs-border-radius-lg: var(--erp-radius-lg);
}

/* Action colors express intent across BS4 and BS5 layouts.
   Positive actions (Approve, Verify, Confirm, Save) use .btn-success.
   Reject/Delete use .btn-danger; neutral actions use .btn-outline-secondary. */
body.erp-theme .btn-success {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--erp-success);
    --bs-btn-border-color: var(--erp-success);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--erp-success-hover);
    --bs-btn-hover-border-color: var(--erp-success-hover);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--erp-success-active);
    --bs-btn-active-border-color: var(--erp-success-active);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--erp-success);
    --bs-btn-disabled-border-color: var(--erp-success);
    --bs-btn-focus-shadow-rgb: 25, 135, 84;
    color: #fff;
    background-color: var(--erp-success);
    border-color: var(--erp-success);
}

body.erp-theme .btn-outline-success {
    --bs-btn-color: var(--erp-success);
    --bs-btn-border-color: var(--erp-success);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--erp-success);
    --bs-btn-hover-border-color: var(--erp-success);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--erp-success-active);
    --bs-btn-active-border-color: var(--erp-success-active);
    --bs-btn-disabled-color: var(--erp-success);
    --bs-btn-disabled-bg: transparent;
    --bs-btn-disabled-border-color: var(--erp-success);
    --bs-btn-focus-shadow-rgb: 25, 135, 84;
    color: var(--erp-success);
    background-color: transparent;
    border-color: var(--erp-success);
}

body.erp-theme :is(.btn-success, .btn-outline-success):not(:disabled):not(.disabled):hover {
    color: #fff;
    background-color: var(--erp-success-hover);
    border-color: var(--erp-success-hover);
}

body.erp-theme :is(.btn-success, .btn-outline-success):not(:disabled):not(.disabled):is(:active, .active),
body.erp-theme .btn-check:checked + :is(.btn-success, .btn-outline-success) {
    color: #fff;
    background-color: var(--erp-success-active);
    border-color: var(--erp-success-active);
}

body.erp-theme :is(.btn-success, .btn-outline-success):focus {
    box-shadow: 0 0 0 .2rem rgba(25, 135, 84, .3);
}

/* Important radii replace the square resets in existing page styles.
   Keep deliberate circles/pills and joined control edges intact. */
body.erp-theme :is(.btn, .form-control, .form-select, .custom-select,
    .input-group-text, .alert, .dropdown-menu, .list-group,
    .nav-pills .nav-link, .action-btn, .approval-submit, .notice-button,
    .bookmark-item, .quick-link-list a, .attendance-stat, .profile-photo,
    .empty-state, .mode-toggle, .panel-note, .validation-summary-errors,
    .quotation-tax-option, .quotation-tax-alert, .status-panel, .selected-client,
    .file-preview, .ajax-indicator, .timeline-bubble, .ip-alert):where(:not(.rounded-circle):not(.rounded-pill)) {
    border-radius: var(--erp-radius) !important;
}

body.erp-theme :is(.card, .page-hero, .modal-content, .so-card, .summary-card,
    .bookmark-panel, .attendance-summary-card, .layout-section, .login-card,
    .quotation-lines-card, .quotation-tax-card, .quotation-card, .totals-card,
    .erp-card, .stat-card, .filter-card, .memo-thread) {
    border-radius: var(--erp-radius-lg) !important;
}

body.erp-theme :is(.badge, .status-badge, .select2-selection__choice):where(:not(.rounded-circle):not(.rounded-pill)) {
    border-radius: var(--erp-radius-sm) !important;
}

/* Round painted headers and footers without clipping menus or focus rings. */
body.erp-theme :is(.card-header, .modal-header, .so-card-header,
    .bookmark-panel-header, .login-header, .quotation-tax-card__header,
    .layout-section > summary):first-child {
    border-radius: calc(var(--erp-radius-lg) - 1px) calc(var(--erp-radius-lg) - 1px) 0 0 !important;
}

body.erp-theme :is(.card-footer, .modal-footer, .bookmark-panel-footer):last-child {
    border-radius: 0 0 calc(var(--erp-radius-lg) - 1px) calc(var(--erp-radius-lg) - 1px) !important;
}

body.erp-theme .nav-tabs .nav-link {
    border-radius: var(--erp-radius) var(--erp-radius) 0 0 !important;
}

body.erp-theme .list-group-item:first-child {
    border-top-left-radius: inherit !important;
    border-top-right-radius: inherit !important;
}

body.erp-theme .list-group-item:last-child {
    border-bottom-left-radius: inherit !important;
    border-bottom-right-radius: inherit !important;
}

body.erp-theme :is(.card, .modal-content, .so-card, .summary-card,
    .bookmark-panel, .layout-section, .login-card, .quotation-lines-card,
    .quotation-tax-card, .quotation-card, .totals-card, .erp-card, .stat-card, .filter-card,
    .memo-thread, .empty-state, .mode-toggle, .ip-alert) {
    border-color: var(--erp-border-color);
}

/* Retain the red header underline and other intentional accent edges. */
body.erp-theme :is(.page-hero, .attendance-summary-card) {
    border-top-color: var(--erp-border-color);
    border-right-color: var(--erp-border-color);
    border-left-color: var(--erp-border-color);
}

body.erp-theme .reissue-page .summary-card {
    border-left-color: #dc3545;
}

body.erp-theme .memo-thread {
    border-left-color: #2c3e50;
}

body.erp-theme :is(.card-footer, .modal-footer, .bookmark-panel-footer,
    .profile-field, .layout-link) {
    border-top-color: var(--erp-border-color);
}

body.erp-theme .table {
    --bs-table-border-color: var(--erp-border-color);
    border-color: var(--erp-border-color);
}

body.erp-theme .table > :not(caption) > * > * {
    border-color: var(--erp-border-color);
}

body.erp-theme :is(.form-control, .form-select, .custom-select, .input-group-text) {
    border-width: 1px !important;
}

body.erp-theme :is(.form-control, .form-select, .custom-select):not(:focus):not(.is-invalid):not(.is-valid):not(.input-validation-error):where(:not(.was-validated *)),
body.erp-theme .input-group-text {
    border-color: var(--erp-input-border-color);
}

/* Header search uses a borderless pill with a visible keyboard focus ring. */
body.erp-theme #header input.form-control[name="keyword"] {
    border-width: 0 !important;
    border-radius: 999px !important;
    min-width: 0;
    padding-left: 1rem;
    padding-right: 1rem;
}

body.erp-theme #header input.form-control[name="keyword"]:focus {
    box-shadow: 0 0 0 3px rgba(0, 123, 255, .15);
}

body.erp-theme :is(.form-control, .form-select, .custom-select).is-invalid,
body.erp-theme .input-validation-error,
body.erp-theme .was-validated :is(.form-control, .form-select, .custom-select):invalid {
    border-color: #dc3545;
}

body.erp-theme :is(.form-control, .form-select, .custom-select).is-valid,
body.erp-theme .was-validated :is(.form-control, .form-select, .custom-select):valid {
    border-color: #198754;
}

body.erp-theme .dashboard-page :is(.bookmark-item, .quick-link-list a):not(:hover):not(:focus):not(:focus-within),
body.erp-theme .dashboard-page .profile-photo {
    border-color: var(--erp-input-border-color);
}

body.erp-theme .dashboard-page .action-grid .btn:not(.btn-primary-action):not(:hover):not(:focus):not(:active),
body.erp-theme .btn-outline-secondary:not(:hover):not(:focus):not(:active):not(.active):where(:not(.btn-check:checked + .btn)) {
    border-color: #b8c2ce;
}

/* Both Select2 generations are used by the ERP. */
body.erp-theme .select2-container :is(.select2-selection, .select2-choice, .select2-choices),
body.erp-theme :is(.select2-dropdown, .select2-drop) {
    border-radius: var(--erp-radius) !important;
    border-width: 1px;
    border-color: var(--erp-input-border-color);
}

body.erp-theme :is(.select2-container--focus, .select2-container--open) .select2-selection,
body.erp-theme .select2-container-active :is(.select2-choice, .select2-choices),
body.erp-theme .select2-dropdown-open .select2-choice {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, .15);
}

body.erp-theme .select2-container--open.select2-container--below .select2-selection,
body.erp-theme .select2-dropdown-open:not(.select2-drop-above) .select2-choice,
body.erp-theme .select2-dropdown--above,
body.erp-theme .select2-drop.select2-drop-above {
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

body.erp-theme .select2-container--open.select2-container--above .select2-selection,
body.erp-theme .select2-dropdown-open.select2-drop-above .select2-choice,
body.erp-theme .select2-dropdown--below,
body.erp-theme .select2-drop:not(.select2-drop-above) {
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
}

/* Preserve Bootstrap's connected button and input groups. */
body.erp-theme .btn-group > .btn:not(:last-child):not(.dropdown-toggle),
body.erp-theme .btn-group > .btn-group:not(:last-child) > .btn,
body.erp-theme .input-group > :is(.form-control, .form-select, .btn, .input-group-text):not(:last-child),
body.erp-theme .input-group-prepend > :is(.btn, .input-group-text) {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

body.erp-theme .btn-group > .btn:nth-child(n + 3),
body.erp-theme .btn-group > :not(.btn-check) + .btn,
body.erp-theme .btn-group > .btn-group:not(:first-child) > .btn,
body.erp-theme .input-group > :is(.form-control, .form-select, .btn, .input-group-text):not(:first-child),
body.erp-theme .input-group-append > :is(.btn, .input-group-text) {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

body.erp-theme .btn-group-vertical > .btn:not(:last-child):not(.dropdown-toggle) {
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

body.erp-theme .btn-group-vertical > .btn ~ .btn {
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
}

body.erp-theme .page-item:first-child .page-link {
    border-radius: var(--erp-radius) 0 0 var(--erp-radius) !important;
}

body.erp-theme .page-item:last-child .page-link {
    border-radius: 0 var(--erp-radius) var(--erp-radius) 0 !important;
}

body.erp-theme .rounded-circle {
    border-radius: 50% !important;
}

body.erp-theme .rounded-pill {
    border-radius: 50rem !important;
}

/* These older page rules use IDs and otherwise beat component defaults. */
body.erp-theme #issueMemoModal .modal-content {
    border-radius: var(--erp-radius-lg) !important;
}

body.erp-theme #issueMemoModal :is(.form-control, .btn) {
    border-radius: var(--erp-radius) !important;
}

body.erp-theme #issueMemoModal .modal-header {
    border-radius: calc(var(--erp-radius-lg) - 1px) calc(var(--erp-radius-lg) - 1px) 0 0 !important;
}

body.erp-theme #column-filter-dropdown {
    border-radius: var(--erp-radius) !important;
    border-color: var(--erp-border-color);
}

/* Global card and section heading typography. Data belongs in regular text,
   and action controls retain their own casing even inside a card header. */
body.erp-theme :is(h1, h2, h3, h4, h5, h6, .card-title, .section-title,
    .panel-title, .modal-title, .card-header, .section-header, .so-card-header,
    .bookmark-panel-header, .layout-section > summary) {
    text-transform: uppercase;
}
body.erp-theme :is(.card-header, .section-header, .so-card-header, .bookmark-panel-header)
    :is(.btn, .form-control, .form-select, input, select, textarea, .dropdown-menu) {
    text-transform: none;
}
