/* The Setting menu's WhatsApp page and its template editor.
 *
 * The list screen borrows .top-btns-container / .master-table-container / .master-content-table1
 * wholesale — those are declared in SaleAccount.css, which index.html loads globally, and every
 * master screen in the app is drawn with them. Only the column widths are set here, because that
 * file's defaults are sized for the account masters.
 *
 * Everything under .wa-tpl-popup is this editor's own. It is NOT the WhatsApp send popup
 * (WhatsAppPopup.razor.css, scoped): that one composes a single message, this one writes the
 * template a message is later built from. */

/*======================================== Template list ========================================*/

/* Message takes whatever is left — its cell holds a flattened one-line summary, with the full
   text on the title attribute.

   Index is left alone on purpose. SaleAccount.css pins the first three columns at left: 0 / 50px /
   150px, so narrowing Index to fit its numbers moves column 3's real edge to 120px while it stays
   pinned at 150 — and the 30px of Voucher Type underneath it never comes out from behind. */
.whatsapp-template-table .master-content-table1 th:nth-child(3),
.whatsapp-template-table .master-content-table1 td:nth-child(3) {
    width: 220px;
}

.whatsapp-template-table .master-content-table1 th:nth-child(4),
.whatsapp-template-table .master-content-table1 td:nth-child(4) {
    width: 180px;
}

.whatsapp-template-table .master-content-table1 th:nth-child(5),
.whatsapp-template-table .master-content-table1 td:nth-child(5) {
    width: 90px;
    text-align: center;
}

.whatsapp-template-table .master-content-table1 th:nth-child(6),
.whatsapp-template-table .master-content-table1 td:nth-child(6) {
    width: 420px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/*======================================== Editor dialog ========================================*/

/* Two columns of content, so it needs more room than the one-field Create/Edit popups, which use
   ModalSize.Automatic — but a bounded amount of it.

   Sized the way Blazored's own .size-large is, and for the same reason: .blazored-modal carries
   margin: 1.75rem, so a width of 100% resolves to the full viewport and then puts 3.5rem of margin
   outside it. That is what pushed the right-hand edge of this dialog off screen. width: auto fills
   what is left between the margins instead, and the max-width caps it on a wide monitor.

   Nothing sets a height: the dialog is as tall as the message box and preview below make it, so it
   cannot run past the bottom of a laptop screen the way a min-height in vh did. */
.whatsapp-template-custom-size-modal {
    width: auto !important;
    max-width: 860px !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

.wa-tpl-popup {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.wa-tpl-head {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
}

/* .form-item's own margin-bottom is meant for a stacked form; this row aligns its three controls
   on one line instead. */
.wa-tpl-head .form-item,
.wa-tpl-head .form-item-1 {
    margin-bottom: 0;
}

/* .form-item-check is declared only under .invoice-editor-popup in BarcodeEditorPopup.css, so the
   checkbox row is repeated here rather than reached for. */
.wa-tpl-popup .form-item-check {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.wa-tpl-popup .form-item-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #3399ff;
    cursor: pointer;
    flex-shrink: 0;
}

.wa-tpl-popup .form-item-check label {
    position: static;
    font-size: 12px;
    font-weight: bold;
    color: #555;
    cursor: pointer;
}

/*======================================== Message / preview ====================================*/

.wa-tpl-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.wa-tpl-editor,
.wa-tpl-preview-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
}

.wa-tpl-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* The field picker takes the row, the bold button sits beside it at the same height. */
.wa-tpl-toolbar .form-item-1 {
    flex: 1 1 auto;
    min-width: 0;
}

.wa-tpl-toolbar .form-item {
    margin-bottom: 0;
}

.wa-tpl-bold-btn {
    height: 30px;
    width: 30px;
    flex-shrink: 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: solid 1px #ccc;
    border-radius: 4px;
    background: #eef0f3;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.wa-tpl-bold-btn:hover {
    background: #f5f7fa;
    border-color: #3399ff;
}

.wa-tpl-bold-btn svg {
    fill: #444;
    height: 18px;
    width: 18px;
}

.wa-tpl-text {
    width: 100%;
    min-height: 150px;
    resize: vertical;
    padding: 10px 12px;
    border: solid 1px #ccc;
    border-radius: 4px;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s ease;
}

.wa-tpl-text:focus {
    border-color: #0078d4;
}

.wa-tpl-hint {
    font-size: 11px;
    line-height: 1.6;
    color: #777;
}

.wa-tpl-hint code {
    background: #eef0f3;
    border-radius: 3px;
    padding: 1px 4px;
    color: #444;
}

.wa-tpl-preview-title {
    font-size: 12px;
    font-weight: bold;
    color: #555;
}

/* The chat ground behind the bubble. WhatsApp's own wallpaper is an image; a flat tint of it is
   enough to read the bubble against without shipping one. */
.wa-tpl-preview {
    flex: 1 1 auto;
    min-height: 150px;
    max-height: 260px;
    overflow-y: auto;
    padding: 16px 14px;
    background: #ece5dd;
    border: 1px solid #dcd5cc;
    border-radius: 8px;
    scrollbar-width: thin;
    scrollbar-color: #b9b2a8 #ece5dd;
}

/* An outgoing message: WhatsApp's green, pushed to the right, with the tail corner squared off. */
.wa-tpl-bubble {
    margin-left: auto;
    max-width: 85%;
    width: fit-content;
    padding: 8px 10px;
    background: #dcf8c6;
    border-radius: 8px 0 8px 8px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
    font-size: 13px;
    line-height: 1.5;
    color: #111;
    /* The template's own line breaks are the message's line breaks — the preview keeps them
       instead of turning them into <br>, and still wraps a long line. */
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.wa-tpl-bubble code {
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    color: #111;
}

.wa-tpl-empty {
    color: #7a8a70;
    font-style: italic;
}

/* A placeholder, shown by its field name. Deliberately not styled as text: the point of the
   preview is to tell at a glance which parts of the message are fixed and which are filled in. */
.wa-tpl-token {
    display: inline-block;
    padding: 0 6px;
    border-radius: 10px;
    background: #b6e2a1;
    border: 1px solid #93cc7a;
    font-size: 11px;
    font-weight: 600;
    color: #23491a;
    white-space: nowrap;
}

/*======================================== Responsive ===========================================*/

@media (max-width: 820px) {
    .wa-tpl-head {
        grid-template-columns: minmax(0, 1fr);
        gap: 14px;
    }

    .wa-tpl-body {
        grid-template-columns: minmax(0, 1fr);
    }

    .wa-tpl-text {
        min-height: 130px;
    }

    .wa-tpl-preview {
        min-height: 130px;
        max-height: 200px;
    }
}
