/* =========================================================
   BYGGEKLODSER

   To spalter: klodserne til venstre, den valgte til hoejre.
   Raekkerne er den tunge del, og de faar plads nok til, at
   en opbygning kan laeses i et hug.
========================================================= */

.templates__header-actions {
    display: flex;
    gap: 8px;
}

.templates__layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 18px;
    align-items: start;
}

/* ---------------------------------------------------------
   LISTEN
--------------------------------------------------------- */

.templates__list {
    display: grid;
    gap: 8px;
    position: sticky;
    top: 12px;
    max-height: calc(100vh - 160px);
    overflow-y: auto;
    padding-right: 4px;
}

.templates__item {
    display: grid;
    gap: 3px;
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--color-border, #E2E8F0);
    border-radius: 10px;
    background: #FFFFFF;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.12s, box-shadow 0.12s;
}

.templates__item:hover {
    border-color: #94A3B8;
}

.templates__item.is-selected {
    border-color: #1F5135;
    box-shadow: 0 0 0 1px #1F5135;
}

.templates__item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.templates__item-head strong {
    font-size: 13px;
    color: #1D2C23;
}

.templates__item-meta {
    font-size: 10px;
    color: #94A3B8;
}

.templates__badge {
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
    background: #E8F1EB;
    color: #1F5135;
}

/* ---------------------------------------------------------
   PANELET
--------------------------------------------------------- */

.templates__detail {
    min-width: 0;
}

.templates__panel {
    padding: 18px;
    border: 1px solid var(--color-border, #E2E8F0);
    border-radius: 12px;
    background: #FFFFFF;
}

.templates__panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.templates__panel-head h3 {
    margin: 0;
    font-size: 15px;
    color: #1D2C23;
}

.templates__panel-actions {
    display: flex;
    gap: 8px;
}

.templates__grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.templates__grid label,
.templates__row-grid label,
.templates__modal-field {
    display: grid;
    gap: 5px;
    font-size: 10px;
    font-weight: 720;
    color: #64748B;
}

.templates__rows-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.templates__rows-head h4 {
    flex: 1;
    margin: 0;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #1F5135;
}

.templates__hint {
    margin: 0 0 14px;
    font-size: 11px;
    line-height: 1.5;
    color: #64748B;
}

/* ---------------------------------------------------------
   RAEKKERNE

   Resultatraekken markeres tydeligt. Den er den ene raekke,
   totalen laegger sammen, og den, et andet budget henter -
   og det skal kunne ses uden at klikke.
--------------------------------------------------------- */

.templates__rows {
    display: grid;
    gap: 10px;
}

.templates__row {
    padding: 12px 14px;
    border: 1px solid #E2E8F0;
    border-radius: 10px;
    background: #FCFDFE;
}

.templates__row.is-output {
    border-color: #1F5135;
    background: #F6FAF7;
}

.templates__row-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.templates__row-kind {
    flex: 1;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #64748B;
}

.templates__output {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 10px;
    font-weight: 720;
    color: #1F5135;
    cursor: pointer;
}

.templates__remove {
    border: 0;
    background: none;
    font-size: 18px;
    line-height: 1;
    color: #94A3B8;
    cursor: pointer;
}

.templates__remove:hover {
    color: #B91C1C;
}

.templates__row-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}

.templates__empty-rows {
    padding: 22px;
    border: 1px dashed #CBD5E1;
    border-radius: 10px;
    font-size: 12px;
    text-align: center;
    color: #94A3B8;
}

/* ---------------------------------------------------------
   FORMLEN
--------------------------------------------------------- */

.templates__formula {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #E2E8F0;
}

.templates__formula-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 6px 8px;
    border: 1px solid #E2E8F0;
    border-radius: 8px;
    background: #FFFFFF;
}

.templates__formula-empty {
    font-size: 11px;
    color: #94A3B8;
}

.templates__token {
    padding: 4px 9px;
    border: 1px solid #CBD5E1;
    border-radius: 7px;
    background: #F8FAFC;
    font-size: 11px;
    color: #1D2C23;
    cursor: pointer;
}

.templates__token:hover {
    border-color: #B91C1C;
    color: #B91C1C;
}

.templates__token--operator {
    background: #E8F1EB;
    border-color: #C7DDCE;
    font-weight: 700;
}

.templates__token--constant {
    font-family: ui-monospace, Menlo, monospace;
}

.templates__formula-tokens {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.templates__token-button {
    padding: 4px 9px;
    border: 1px solid #E2E8F0;
    border-radius: 7px;
    background: #FFFFFF;
    font-size: 11px;
    color: #475569;
    cursor: pointer;
}

.templates__token-button:hover {
    border-color: #1F5135;
    color: #1F5135;
}

.templates__token-button--operator {
    font-weight: 700;
    min-width: 32px;
}

/* ---------------------------------------------------------
   TOMME TILSTANDE OG FEJL
--------------------------------------------------------- */

.templates__empty {
    display: grid;
    gap: 10px;
    place-items: center;
    padding: 40px 20px;
    border: 1px dashed #CBD5E1;
    border-radius: 12px;
    text-align: center;
    color: #94A3B8;
    font-size: 12px;
}

.templates__empty div {
    font-size: 26px;
}

.templates__loading {
    padding: 20px;
    font-size: 12px;
    color: #94A3B8;
}

.templates__error {
    padding: 14px;
    border: 1px solid #FCA5A5;
    border-radius: 10px;
    background: #FEF2F2;
    font-size: 12px;
    color: #991B1B;
}

/* ---------------------------------------------------------
   MODAL
--------------------------------------------------------- */

.templates__overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.45);
}

.templates__modal {
    width: min(460px, 100%);
    border-radius: 14px;
    background: #FFFFFF;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.2);
    overflow: hidden;
}

.templates__modal header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid #F1F5F9;
}

.templates__modal header h3 {
    margin: 0;
    font-size: 14px;
    color: #1D2C23;
}

.templates__close {
    border: 0;
    background: none;
    font-size: 20px;
    line-height: 1;
    color: #94A3B8;
    cursor: pointer;
}

.templates__modal-body {
    display: grid;
    gap: 12px;
    padding: 18px;
    max-height: 60vh;
    overflow-y: auto;
}

.templates__modal footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid #F1F5F9;
    background: #F8FAFC;
}

/* ---------------------------------------------------------
   SMALLE SKAERME
--------------------------------------------------------- */

@media (max-width: 1100px) {
    .templates__layout {
        grid-template-columns: 1fr;
    }

    .templates__list {
        position: static;
        max-height: none;
    }
}
