/* =============================================================================
   DEX Portal - Email Templates

   The templates table, and the builder panel: palette on the left, the email
   itself on the right. The canvas wears the template's own design settings
   inline (background, width, type), so this file styles the furniture around
   the email rather than the email.
   ============================================================================= */

/* ---- The Custom and Core tabs -------------------------------------------- */

/* .record-tabs is drawn for a panel body: it pulls itself up and out to the
   panel's edges with negative margins. On a page that lifts the tabs over the
   header's description, so here they sit in the flow, on the page gutter. The
   page is a flex column, and a row that may shrink is a row that gets clipped. */
.record-tabs.tpl-tabs {
    flex: none;
    margin: 0;
    padding: 0 var(--gutter);
}

/* ---- The templates table -------------------------------------------------- */

.tpl-table-holder {
    margin-top: 14px;
}

.tpl-table__column--name { width: 26%; }
.tpl-table__column--subject { width: 34%; }
.tpl-table__column--updated { width: 18%; }
.tpl-table__column--author { width: 12%; }
.tpl-table__column--actions { width: 10%; }

.tpl-table__row { cursor: pointer; }

/* Orders Wave 4: a section heading row in the Core table (Orders). */
.tpl-table__section th {
    padding-top: 18px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: left;
    color: var(--text-muted);
    background: var(--surface-subtle);
    border-bottom: 1px solid var(--border-subtle);
}

.tpl-table__row:hover td { background: var(--surface-subtle); }

.tpl-table__name {
    font-weight: 600;
    color: var(--text-primary);
}

.tpl-table__subject { color: var(--text-secondary); }

.tpl-table .data-table__actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* ---- Chips: one look in the palette and in the email ----------------------- */

.tpl-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border: 1px solid var(--am-blue-soft-hover);
    border-radius: var(--radius-chip, 4px);
    background: var(--am-blue-soft);
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    cursor: grab;
}

/* Inside the email the chip shrinks to the text around it. */
.tpl-page .tpl-chip {
    font-size: 0.82em;
    cursor: default;
    user-select: none;
    margin: 0 1px;
    vertical-align: baseline;
}

/* ---- The toolbar ----------------------------------------------------------- */

.tpl-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 5px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-button);
    background: var(--surface-panel);
    position: sticky;
    top: 0;
    z-index: 5;
}

.tpl-toolbar__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 29px;
    height: 29px;
    padding: 0;
    border: none;
    border-radius: var(--radius-button);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
}

.tpl-toolbar__button:hover {
    background: var(--surface-subtle);
    color: var(--text-primary);
}

.tpl-toolbar__divider {
    width: 1px;
    height: 20px;
    background: var(--border-subtle);
    margin: 0 5px;
}

/* ---- The design bar -------------------------------------------------------- */

.tpl-design {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-button);
    background: var(--surface-panel);
}

.tpl-page {
    max-width: 100%;
    min-height: 320px;
    /* A thin grey edge, not a drop shadow: the canvas already frames the
       page, and a floating shadow read as a card lifting off the screen. */
    border: 1px solid var(--border-subtle, #e9ecf3);
    outline: none;
    line-height: 1.6;
    overflow-wrap: break-word;
}

.tpl-page:focus { outline: none; }

.tpl-page hr {
    border: none;
    border-top: 1px solid var(--border-default);
    margin: 18px 0;
}

.tpl-page img { max-width: 100%; height: auto; }

/* Paragraph rhythm that matches the sent email exactly: a bottom-only gap,
   no top margin. Mail clients that will not collapse margins would otherwise
   double a plain <p>'s top+bottom, so the design view is kept in step with
   what renderEmailBody / wrapInScaffold state inline on send. */
.tpl-page > p { margin: 0 0 14px; }
.tpl-page > p:last-child { margin-bottom: 0; }

.tpl-page blockquote {
    margin: 12px 0;
    padding: 6px 16px;
    border-left: 3px solid var(--am-blue-soft-hover);
    color: inherit;
    opacity: 0.85;
}

.slide-over__header-action--active {
    background: rgba(255, 255, 255, 0.18);
    color: var(--text-on-dark);
}

/* ---- Compose: the template picker and preview ------------------------------- */

/* The rendered template is EDITABLE - a live document dressed in the
   template's own design, not a picture of one. It reflows to the pane, so a
   mobile-width template reads at its true size beside a project. */
.mail-compose__edit-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--border-default);
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    background: var(--surface-panel);
}

.mail-compose__edit-holder {
    border: 1px solid var(--border-default);
    border-radius: 0 0 5px 5px;
    background: var(--surface-subtle);
    padding: 18px 12px;
    max-height: 58vh;
    overflow-y: auto;
}

.mail-compose__edit {
    margin: 0 auto;
    min-height: 220px;
    outline: none;
    line-height: 1.6;
    overflow-wrap: break-word;
    /* Flat: a thin grey edge, no shadow, no rounded corner - the message is
       a document, not a floating card. */
    border: 1px solid var(--border-subtle, #e9ecf3);
    border-radius: 0;
}

/* One press of Enter is one paragraph, with one gap under it. The browser
   makes a new block per press and gives it no margin, so people press twice
   and end up with a blank block; a template's own <p> brings 1em top AND
   bottom. Both are settled here, and again on send, so what is typed is what
   arrives. Shift+Enter still gives a plain line break. */
.mail-compose__edit > p,
.mail-compose__edit > div {
    margin: 0 0 14px;
}

.mail-compose__edit > p:last-child,
.mail-compose__edit > div:last-child {
    margin-bottom: 0;
}

.mail-compose__edit img { max-width: 100%; height: auto; }

.mail-compose__edit table { max-width: 100%; }

.mail-compose__template-note {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

/* ---- Small screens ---------------------------------------------------------- */

/* ---- The signature editor (beside Connected Apps) --------------------------- */

.signature-editor__tabs {
    margin-bottom: 10px;
}

.signature-editor__toolbar {
    border-radius: 5px 5px 0 0;
    border-bottom: none;
}

.signature-editor__surface {
    border: 1px solid var(--border-default);
    border-radius: 0 0 5px 5px;
    background: var(--surface-panel);
    padding: 14px;
    min-height: 180px;
}

.signature-editor__editable {
    min-height: 150px;
    outline: none;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.6;
}

.signature-editor__editable img { max-width: 100%; height: auto; }

.signature-editor__html {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    font-size: 12.5px;
}

/* ---- The verify tick and cross on a mailbox row ----------------------------- */

.mailbox-verify {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    vertical-align: middle;
}

.mailbox-verify--ok {
    background: var(--status-success-tint);
    color: var(--status-success);
}

.mailbox-verify--fail {
    background: var(--status-danger-tint);
    color: var(--status-danger);
}
