/* =========================
   群發（CRM → 群發：草稿列表、編輯、條件組合器）
========================= */

.broadcast-page {
    max-width: 960px;

    /* 左下角的 DEV 標記（測試環境）不要蓋住最底下的按鈕。 */
    padding-bottom: 56px;
}

.broadcast-page .page-header p {
    margin: 4px 0 0;
    color: #6b7280;
}

/* ===== 草稿列表 ===== */

.bc-table-wrap {
    overflow-x: auto;

    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}

.bc-table {
    width: 100%;
    border-collapse: collapse;
}

.bc-table th,
.bc-table td {
    padding: 12px 14px;

    border-bottom: 1px solid #f3f4f6;

    text-align: left;
    vertical-align: top;
}

.bc-table th {
    background: #f9fafb;
    color: #6b7280;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.bc-table tbody tr:last-child td {
    border-bottom: none;
}

.bc-criteria-cell {
    min-width: 220px;
    max-width: 420px;
    color: #4b5563;
    font-size: 14px;
}

.bc-actions-cell {
    white-space: nowrap;
}

.bc-actions-cell button + button {
    margin-left: 8px;
}

/* ===== 編輯畫面 ===== */

.bc-card {
    margin-bottom: 16px;
    padding: 16px 18px;

    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}

.bc-card h2 {
    margin: 0 0 12px;
    font-size: 16px;
}

.bc-field {
    display: flex;
    flex-direction: column;
    gap: 4px;

    font-size: 13px;
    color: #6b7280;
}

.bc-field input,
.bc-field textarea {
    padding: 8px 10px;

    background: white;
    color: #111827;

    border: 1px solid #d1d5db;
    border-radius: 8px;

    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
    width: 100%;
}

.bc-field textarea {
    resize: vertical;
    line-height: 1.6;
}

.bc-counter {
    margin-top: 4px;
    text-align: right;
    color: #6b7280;
    font-size: 12px;
}

.bc-counter.bc-over {
    color: #b91c1c;
    font-weight: 600;
}

.bc-summary {
    margin: 14px 0 10px;
    padding: 10px 12px;

    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 8px;

    line-height: 1.7;
}

.bc-summary .bc-muted,
.bc-summary .bc-warn-text {
    display: block;
}

.bc-summary.bc-error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

.bc-muted {
    color: #6b7280;
    font-size: 13px;
}

.bc-warn-text {
    color: #b45309;
    font-size: 13px;
}

.bc-test {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;

    margin-top: 10px;
}

.bc-secondary {
    background: white;
    color: var(--primary-color, #2563eb);
    border: 1px solid var(--primary-color, #2563eb);
}

.bc-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;

    margin: 4px 0 10px;
}

.bc-actions button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.bc-message {
    margin: 8px 0;
    padding: 8px 12px;

    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;

    font-size: 14px;
}

.bc-message.bc-error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

.bc-message.bc-warn {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

/* ===== 狀態標籤、發送進度 ===== */

.bc-status {
    display: inline-block;
    padding: 2px 10px;

    border-radius: 999px;
    background: #f3f4f6;
    color: #374151;

    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.bc-status-sending {
    background: #dbeafe;
    color: #1d4ed8;
}

.bc-status-sent {
    background: #dcfce7;
    color: #166534;
}

.bc-status-failed {
    background: #fee2e2;
    color: #b91c1c;
}

.bc-status-cancelled {
    background: #fef3c7;
    color: #92400e;
}

.bc-status-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;

    margin-bottom: 10px;
}

.bc-progress {
    height: 12px;
    overflow: hidden;

    background: #e5e7eb;
    border-radius: 999px;
}

.bc-progress-bar {
    width: 0;
    height: 100%;

    background: var(--primary-color, #2563eb);
    border-radius: 999px;

    transition: width 0.4s ease;
}

.bc-counts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;

    margin: 12px 0;
}

/* ===== 確認群發視窗 ===== */

.bc-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 16px;

    background: rgba(17, 24, 39, 0.55);
}

.bc-dialog {
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    box-sizing: border-box;

    padding: 20px 22px;

    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.bc-dialog h2 {
    margin: 0 0 8px;
    font-size: 18px;
}

.bc-dialog-lead {
    margin: 0 0 10px;
}

.bc-dialog-facts {
    margin: 0 0 12px;
    padding-left: 20px;

    line-height: 1.7;
}

.bc-dialog-bad {
    color: #b91c1c;
    font-weight: 600;
}

.bc-dialog-label {
    margin-bottom: 4px;

    color: #6b7280;
    font-size: 13px;
}

.bc-dialog-preview {
    max-height: 180px;
    overflow-y: auto;
    margin: 0 0 16px;
    padding: 10px 12px;

    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;

    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.bc-dialog-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.bc-dialog-actions button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ===== 條件組合器 ===== */

.aud-match {
    margin-bottom: 12px;
    max-width: 240px;
}

.aud-field {
    display: flex;
    flex-direction: column;
    gap: 4px;

    min-width: 0;

    font-size: 12px;
    color: #6b7280;
}

.aud-field select,
.aud-field input,
.aud-multi summary {
    padding: 7px 9px;

    background: white;
    color: #111827;

    border: 1px solid #d1d5db;
    border-radius: 8px;

    font-size: 14px;
    box-sizing: border-box;
    width: 100%;
}

.aud-rules {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.aud-rule {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) minmax(160px, 1.6fr) auto;
    align-items: end;
    gap: 10px;

    padding: 10px;

    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}

.aud-rule-incomplete {
    border-color: #fcd34d;
    background: #fffbeb;
}

.aud-hint {
    display: none;

    grid-column: 1 / -1;
    margin: 0;

    color: #92400e;
    font-size: 12px;
}

.aud-rule-incomplete .aud-hint {
    display: block;
}

.aud-remove {
    padding: 6px 10px;

    background: white;
    color: #6b7280;

    border: 1px solid #d1d5db;
    border-radius: 8px;

    cursor: pointer;
}

.aud-remove:hover {
    color: #b91c1c;
    border-color: #fca5a5;
}

.aud-add {
    margin-top: 12px;

    background: white;
    color: var(--primary-color, #2563eb);
    border: 1px dashed var(--primary-color, #2563eb);
}

.aud-empty,
.aud-muted {
    margin: 0;
    color: #6b7280;
    font-size: 13px;
}

.aud-inline {
    display: flex;
    align-items: center;
    gap: 6px;
}

.aud-mini {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.aud-multi {
    position: relative;
}

.aud-multi summary {
    cursor: pointer;
    list-style: none;
}

.aud-multi summary::after {
    content: "▾";
    float: right;
    color: #6b7280;
}

.aud-multi-list {
    position: absolute;
    z-index: 20;
    left: 0;
    right: 0;

    display: flex;
    flex-direction: column;
    gap: 2px;

    max-height: 220px;
    overflow-y: auto;
    margin-top: 4px;
    padding: 6px;

    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.aud-check {
    display: flex;
    align-items: center;
    gap: 8px;

    padding: 6px 8px;
    border-radius: 6px;

    color: #111827;
    font-size: 14px;
    cursor: pointer;
}

.aud-check:hover {
    background: #f3f4f6;
}

.aud-check input {
    width: auto;
}

@media (max-width: 700px) {
    .aud-rule {
        grid-template-columns: 1fr;
    }

    .aud-remove {
        justify-self: start;
    }

    .aud-match {
        max-width: none;
    }
}
