/* ═══════════════════════════════════════════════════════════════════════
   THE EMAIL TAB (PLAN 4.7 "Email templates fold in"; docs/claude/SURFACES.md
   "The email canvas") - the Surface Builder's Page | Email tabs and the email
   editor (UI.Portal/Components/Surfaces/Email/SurfaceEmailEditor): the
   languages as chips, Subject / HTML / Plain text, the 'Used for' handle, the
   live issues and the sandboxed preview. Calm by default; colour only for
   meaning (the selected tab and language, an error, a warning). Every sfe-*
   class is owned by THIS file alone; --theme-* tokens only (no hex), so a
   light and a dark tenant theme both read.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── The Page | Email tabs (under the builder's toolbar) ── */

.sfe-tabs {
    display: flex;
    gap: 4px;
    padding: 0 16px;
    border-bottom: 1px solid var(--theme-border);
    background: var(--theme-background);
}

.sfe-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--theme-text-muted);
    font-family: var(--theme-font);
    font-size: var(--theme-font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: color var(--theme-transition, 150ms ease), border-color var(--theme-transition, 150ms ease);
}

.sfe-tab:hover {
    color: var(--theme-text);
}

.sfe-tab:focus-visible {
    outline: 2px solid var(--theme-primary);
    outline-offset: -2px;
}

.sfe-tab--on {
    color: var(--theme-primary);
    border-bottom-color: var(--theme-primary);
}

.sfe-tab-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--theme-primary);
}

/* ── The editor ── */

.sfe {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 16px;
    font-family: var(--theme-font);
    color: var(--theme-text);
}

.sfe-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.sfe-head-text {
    max-width: 640px;
}

.sfe-title {
    margin: 0 0 4px;
    font-size: var(--theme-font-size-lg, 1.125rem);
    font-weight: 600;
    color: var(--theme-text-emphasis);
}

.sfe-hint,
.sfe-field-hint {
    margin: 0;
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-sm);
}

.sfe-field-hint {
    display: block;
    margin-top: 4px;
}

.sfe-usedfor {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 240px;
    max-width: 360px;
}

.sfe-label {
    font-size: var(--theme-font-size-sm);
    font-weight: 600;
    color: var(--theme-text-emphasis);
}

.sfe-gap {
    margin-top: 16px;
}

.sfe-banner {
    margin: 0;
    padding: 8px 12px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-subtle);
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-sm);
}

/* The languages - one chip each, the selected one in the primary hue. */
.sfe-langs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.sfe-lang {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-button);
    background: var(--theme-background-raised);
    color: var(--theme-text);
    font-size: var(--theme-font-size-sm);
    cursor: pointer;
}

.sfe-lang:hover {
    border-color: var(--theme-primary);
}

.sfe-lang:focus-visible {
    outline: 2px solid var(--theme-primary);
    outline-offset: 2px;
}

.sfe-lang--on {
    border-color: var(--theme-primary);
    background: color-mix(in srgb, var(--theme-primary) 12%, var(--theme-background-raised));
    color: var(--theme-text-emphasis);
    font-weight: 600;
}

.sfe-lang-code {
    color: var(--theme-text-muted);
    font-family: var(--theme-font-mono, monospace);
    font-size: 0.75rem;
}

.sfe-add {
    width: auto;
    min-width: 160px;
}

.sfe-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 32px 16px;
    border: 1px dashed var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-subtle);
    color: var(--theme-text-muted);
    text-align: center;
}

.sfe-empty p {
    margin: 0;
}

.sfe-empty-icon {
    font-size: 1.75rem;
    color: var(--theme-primary);
}

/* Editor beside preview; stacked on a narrow screen. */
.sfe-body {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    gap: 16px;
}

@media (max-width: 960px) {
    .sfe-body {
        grid-template-columns: minmax(0, 1fr);
    }
}

.sfe-editor,
.sfe-preview {
    padding: 16px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-raised);
    box-shadow: var(--theme-shadow);
    min-width: 0;
}

.sfe-plain-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.sfe-plain {
    font-family: var(--theme-font-mono, monospace);
    font-size: var(--theme-font-size-sm);
}

.sfe-remove {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.sfe-preview {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sfe-preview-head {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* The frame shows the email as an inbox would - its own white page whatever the Portal's theme. */
.sfe-frame {
    width: 100%;
    min-height: 420px;
    flex: 1;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-raised);
}

.sfe-preview-empty {
    margin: 0;
    padding: 24px 8px;
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-sm);
    text-align: center;
}

.sfe-preview-subject {
    font-size: var(--theme-font-size-sm);
    color: var(--theme-text);
    overflow-wrap: anywhere;
}

.sfe-preview-subject-label {
    color: var(--theme-text-muted);
    font-weight: 600;
    margin-right: 4px;
}

/* ── The live issues ── */

.sfe-issues {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sfe-issues-none {
    margin: 0;
    color: var(--theme-success);
    font-size: var(--theme-font-size-sm);
}

.sfe-issue-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sfe-issue {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 10px;
    border-left: 3px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-subtle);
    font-size: var(--theme-font-size-sm);
}

.sfe-issue--error {
    border-left-color: var(--theme-danger);
}

.sfe-issue--error .bi {
    color: var(--theme-danger);
}

.sfe-issue--warning {
    border-left-color: var(--theme-warning);
}

.sfe-issue--warning .bi {
    color: var(--theme-warning);
}

.sfe-issue-code {
    color: var(--theme-text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.sfe-issue-message {
    color: var(--theme-text);
}

@media (prefers-reduced-motion: reduce) {
    .sfe-tab {
        transition: none;
    }
}
