/* ===============================================================
   KPI page (/kpis)
   Built on the Settings page look (hero, section cards, field labels), so only what is
   specific to the KPI list, its editor and the function manual is defined here.
   =============================================================== */

.kpi-layout {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
}

.kpi-main {
    flex: 1 1 55%;
    min-width: 0;
}

.kpi-manual {
    flex: 1 1 45%;
    min-width: 0;
    position: sticky;
    top: 1.5rem;
}

@media (max-width: 1100px) {
    .kpi-layout {
        flex-direction: column;
    }

    .kpi-main,
    .kpi-manual {
        flex: 1 1 auto;
        width: 100%;
        position: static;
    }
}

.kpi-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.kpi-card-body {
    padding-top: 1rem;
}

.kpi-empty {
    margin: 0.5rem 0;
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.kpi-message {
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
}

.kpi-message--ok {
    color: var(--servitecno-green-dark);
    background: var(--background-light);
}

.kpi-message--error {
    color: #b91c1c;
    background: rgba(185, 28, 28, 0.08);
}

:root[data-theme="dark"] .kpi-message--error {
    color: #ff8a80;
}

/* ===== List ===== */
.kpi-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.kpi-table th {
    padding: 0.4rem 0.5rem;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.kpi-table td {
    padding: 0.55rem 0.5rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    color: var(--text-dark);
}

.kpi-table tr.kpi-row--editing td {
    background: var(--background-light);
}

.kpi-col-show {
    width: 4.5rem;
}

.kpi-col-name {
    font-weight: 600;
    word-break: break-word;
}

.kpi-col-unit {
    width: 5rem;
    color: var(--text-secondary);
}

.kpi-col-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.kpi-expression {
    font-size: 0.8rem;
    word-break: break-word;
    white-space: pre-wrap;
    color: var(--text-dark);
}

.kpi-icon-btn {
    border: none;
    background: transparent;
    padding: 0.2rem 0.4rem;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
}

.kpi-icon-btn:hover:not(:disabled) {
    background: var(--background-light);
    color: var(--text-dark);
}

.kpi-icon-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

.kpi-icon-btn--danger:hover:not(:disabled) {
    color: #b91c1c;
}

.kpi-confirm {
    margin-right: 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
}

/* ===== Editor ===== */
.kpi-editor {
    margin-top: 1.25rem;
    padding: 1rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--background-light);
}

.kpi-editor-title {
    margin: 0 0 0.75rem;
    font-weight: 700;
    color: var(--text-dark);
}

.kpi-editor-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.kpi-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1 1 14rem;
    margin-bottom: 0.75rem;
}

.kpi-field--small {
    flex: 0 1 8rem;
}

.kpi-optional {
    font-weight: 400;
    color: var(--text-secondary);
}

.kpi-expression-input {
    font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
    font-size: 0.85rem;
}

.kpi-valid {
    font-size: 0.78rem;
    color: var(--servitecno-green-dark);
}

.kpi-show-switch {
    margin: 0.5rem 0 0.9rem;
}

.kpi-editor-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* ===== Manual ===== */
.kpi-manual-filter {
    margin-top: 0.5rem;
}

.kpi-manual-body {
    max-height: calc(100vh - 14rem);
    overflow-y: auto;
}

.kpi-manual-section {
    margin-top: 1rem;
}

.kpi-manual-section > h6 {
    margin: 0 0 0.5rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--servitecno-green-dark);
}

.kpi-manual-notes {
    margin: 0;
    padding-left: 1.1rem;
    font-size: 0.82rem;
    color: var(--text-dark);
}

.kpi-manual-notes li {
    margin-bottom: 0.3rem;
}

.kpi-doc {
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}

.kpi-doc:last-child {
    border-bottom: none;
}

.kpi-doc-signature {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-dark);
}

.kpi-doc-description {
    margin: 0.25rem 0 0.4rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.kpi-example {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.3rem 0.5rem;
    margin-bottom: 0.3rem;
    border-radius: 6px;
    background: var(--background-light);
}

.kpi-example-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kpi-example-text code {
    font-size: 0.78rem;
    word-break: break-word;
    color: var(--text-dark);
}

.kpi-example-explanation {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.kpi-example-insert {
    flex: 0 0 auto;
    padding: 0.1rem 0.5rem;
    font-size: 0.75rem;
}

/* ===== Custom series dialog (opened from the Series Details grid) =====
   A large template-style dialog: the series and their editor on the left, the formula manual on the
   right. The chart pages load this file but not settings.css, so what the editor takes from the
   settings look (field labels, errors) is defined here, inside the dialog. */
.template-dialog-shell-xl {
    width: min(90rem, calc(100% - 3rem));
    max-height: calc(100% - 2rem);
}

.custom-series-dialog {
    font-size: 1rem;
}

.custom-series-dialog .modal-header {
    padding: 1rem 1.5rem;
}

.custom-series-dialog .modal-title {
    font-size: 1.35rem;
    font-weight: 700;
}

.custom-series-dialog .modal-footer {
    padding: 0.85rem 1.5rem;
}

.custom-series-dialog .modal-body.custom-series-body {
    display: flex;
    align-items: stretch;
    gap: 1.75rem;
    height: min(78vh, 52rem);
    max-height: none;
    padding: 1.25rem 1.5rem;
    overflow: hidden;
}

.custom-series-main,
.custom-series-manual {
    min-width: 0;
    overflow-y: auto;
}

.custom-series-main {
    flex: 1 1 56%;
    padding-right: 0.5rem;
}

.custom-series-manual {
    flex: 1 1 44%;
    padding-left: 1.75rem;
    border-left: 1px solid var(--border);
}

.custom-series-manual .kpi-manual-body {
    max-height: none;
}

.custom-series-manual-title {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-dark);
}

.custom-series-dialog .settings-field-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
}

.custom-series-dialog .settings-field-error {
    font-size: 0.9rem;
    color: #b91c1c;
}

:root[data-theme="dark"] .custom-series-dialog .settings-field-error {
    color: #ff8a80;
}

.custom-series-dialog .form-control,
.custom-series-dialog .form-control-sm {
    font-size: 1rem;
    padding: 0.45rem 0.7rem;
}

.custom-series-dialog .form-control-color {
    width: 4.5rem;
    height: 2.6rem;
    padding: 0.25rem;
}

.custom-series-dialog .kpi-field {
    margin-bottom: 1rem;
}

.custom-series-dialog .kpi-field--small {
    flex: 0 1 10rem;
}

.custom-series-dialog .kpi-expression-input {
    min-height: 7rem;
    font-size: 1rem;
}

.custom-series-dialog .kpi-table {
    font-size: 0.95rem;
}

.custom-series-dialog .kpi-editor {
    padding: 1.25rem 1.4rem;
}

.custom-series-dialog .kpi-editor-title {
    font-size: 1.15rem;
}

.custom-series-dialog .kpi-valid {
    font-size: 0.9rem;
}

.custom-series-dialog .kpi-doc-signature {
    font-size: 1rem;
}

.custom-series-dialog .kpi-doc-description,
.custom-series-dialog .kpi-manual-notes {
    font-size: 0.92rem;
}

.custom-series-dialog .kpi-example-text code {
    font-size: 0.88rem;
}

.custom-series-dialog .kpi-example-explanation {
    font-size: 0.82rem;
}

.custom-series-intro {
    margin: 0 0 1rem;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.custom-series-table {
    margin-bottom: 1rem;
}

.custom-series-new {
    margin-top: 0.25rem;
}

.custom-series-warning {
    margin-left: 0.35rem;
    color: #b45309;
    cursor: help;
}

.custom-series-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.custom-series-chips .settings-field-label {
    flex: 0 0 100%;
}

.custom-series-chip {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 0.3rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-dark);
    font-size: 0.9rem;
    cursor: pointer;
    word-break: break-all;
    text-align: left;
}

.custom-series-chip:hover {
    background: var(--background-light);
    border-color: var(--servitecno-green);
}

@media (max-width: 1000px) {
    .custom-series-dialog .modal-body.custom-series-body {
        flex-direction: column;
        height: min(82vh, 52rem);
        overflow-y: auto;
    }

    .custom-series-main,
    .custom-series-manual {
        flex: 0 0 auto;
        width: 100%;
        padding-left: 0;
        padding-right: 0;
        border-left: none;
        overflow-y: visible;
    }
}


/* Scheduled series: keep the form compact and let a long series list scroll independently. */
.scheduled-series-shell {
    width: min(52rem, 100%);
    max-height: 100%;
}

.scheduled-series-dialog {
    max-height: calc(100vh - 2rem);
    display: flex;
    flex-direction: column;
}

.scheduled-series-dialog .modal-header {
    flex-shrink: 0;
}

.scheduled-series-dialog .modal-body {
    max-height: none;
    min-height: 0;
    overflow-y: auto;
}

.scheduled-series-dialog .modal-body > p {
    margin-bottom: 0.75rem;
}

.scheduled-series-list {
    max-height: min(20vh, 10rem);
    overflow: auto;
    margin-bottom: 0.75rem;
}

.scheduled-series-dialog .kpi-editor {
    margin-top: 0;
}

.scheduled-series-dialog .kpi-field {
    margin-bottom: 0;
    min-width: 0;
}

@media (max-width: 576px) {
    .scheduled-series-shell { width: 100%; }
    .scheduled-series-dialog .kpi-field { flex-basis: 100%; }
}
