/**
 * Kramar — Email Manager Overview
 *
 * Dashboard listing all WooCommerce emails with status toggles,
 * recipient badges, action buttons, and modal overlays.
 *
 * @package Kramar
 * @since   1.0.0
 */

/* ==========================================================================
   Design Tokens
   ========================================================================== */

:root {
    --kramar-em-primary:      #7f54b3;
    --kramar-em-primary-hover:#6b4599;
    --kramar-em-bg:           #f0f0f1;
    --kramar-em-surface:      #fff;
    --kramar-em-border:       #dcdcde;
    --kramar-em-text:         #1d2327;
    --kramar-em-text-muted:   #787c82;
    --kramar-em-danger:       #d63638;
    --kramar-em-success:      #00a32a;
    --kramar-em-warning:      #dba617;
    --kramar-em-radius:       4px;
    --kramar-em-shadow:       0 1px 3px rgba(0,0,0,.08);
    --kramar-em-transition:   150ms ease;
}

/* ==========================================================================
   Page Wrapper
   ========================================================================== */

.kramar-em-wrap {
    max-width: 1200px;
}

/* ==========================================================================
   Page Header
   ========================================================================== */

.kramar-em-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 0 20px;
}

.kramar-em-header .notice,
.kramar-em-wrap .notice,
.kramar-em-wrap > .notice {
    display: none !important;
}

.kramar-em-header__actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.kramar-em-header__btn.button {
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
    text-decoration: none !important;
    line-height: 1;
    vertical-align: middle;
}
.kramar-em-header__btn .dashicons {
    font-size: 16px !important;
    width: 16px !important;
    height: 16px !important;
    line-height: 16px !important;
    vertical-align: middle;
}
.kramar-em-section-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 4px;
    padding: 0;
}
.kramar-em-header h1 {
    font-size: 23px;
    font-weight: 400;
    margin: 0;
    padding: 0;
    line-height: 1.3;
    color: var(--kramar-em-text);
}

/* "Add New Email" — WP button-primary + custom class */
.kramar-em-add-new.button-primary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

/* ==========================================================================
   Tab Navigation — uses WP .nav-tab / .nav-tab-active inside .kramar-em-tabs
   ========================================================================== */

.kramar-em-tabs {
    margin-bottom: 20px;
}

.kramar-em-tabs .nav-tab {
    font-size: 13px;
}

/* ==========================================================================
   Tab Panels
   ========================================================================== */

.kramar-em-emails-tab,
.kramar-em-settings-tab,
.kramar-em-templates-tab,
.kramar-em-business-tab {
    margin-top: 4px;
}

/* ==========================================================================
   Email List Table
   ========================================================================== */

.kramar-em-emails-tab .kramar-em-group-heading {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--kramar-em-text-muted);
    margin: 20px 0 6px;
    padding: 0;
}

.kramar-em-emails-tab .kramar-em-group-heading:first-child {
    margin-top: 0;
}

/* Scroll container: keeps the (wide) table reachable on narrow screens
   without pushing the SUBJECT/ACTIONS columns off the page. */
.kramar-em-emails-tab .kramar-em-table-wrap {
    margin-bottom: 0;
    border: 1px solid var(--kramar-em-border);
    border-radius: var(--kramar-em-radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.kramar-em-emails-tab .kramar-em-table {
    margin-bottom: 0;
    border: none;
}

.kramar-em-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.kramar-em-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--kramar-em-text-muted);
    border-bottom: 1px solid var(--kramar-em-border);
    white-space: nowrap;
    background: #fafafa;
}

.kramar-em-table td {
    padding: 12px 14px;
    vertical-align: middle;
    border-bottom: 1px solid var(--kramar-em-border);
    color: var(--kramar-em-text);
}

.kramar-em-table tr:last-child td { border-bottom: none; }

.kramar-em-table tbody tr:hover td { background: #f5f0fa; }

/* Column widths */
.kramar-em-col-toggle {
    width: 60px;
    text-align: center !important;
}

.kramar-em-col-toggle th,
.kramar-em-col-toggle td {
    text-align: center;
}

.kramar-em-table th.kramar-em-col-toggle { text-align: center; }

.kramar-em-col-actions {
    width: 130px;
    text-align: right !important;
}

.kramar-em-table th.kramar-em-col-actions { text-align: right; }
.kramar-em-table td.kramar-em-col-actions {
    text-align: right;
    white-space: nowrap;
}

/* Email name + description */
.kramar-em-col-name strong {
    display: block;
    font-weight: 600;
    color: var(--kramar-em-text);
    margin: 0 0 2px;
    font-size: 13px;
}

.kramar-em-email-desc {
    display: block;
    font-size: 12px;
    color: var(--kramar-em-text-muted);
    margin: 0;
    line-height: 1.4;
}

/* Subject cell — truncated */
.kramar-em-subject-text {
    display: block;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--kramar-em-text-muted);
    font-size: 12px;
}

/* Trigger cell */
.kramar-em-trigger-text {
    font-size: 12px;
    color: var(--kramar-em-text-muted);
}

/* ==========================================================================
   Toggle Switch
   ========================================================================== */

.kramar-em-toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    cursor: pointer;
    vertical-align: middle;
}

.kramar-em-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.kramar-em-toggle__slider {
    position: absolute;
    inset: 0;
    background: #c3c4c7;
    border-radius: 20px;
    transition: background var(--kramar-em-transition);
}

.kramar-em-toggle__slider::before {
    content: "";
    position: absolute;
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--kramar-em-transition);
    box-shadow: 0 1px 2px rgba(0,0,0,.15);
}

.kramar-em-toggle input:checked + .kramar-em-toggle__slider { background: var(--kramar-em-primary); }
.kramar-em-toggle input:checked + .kramar-em-toggle__slider::before { transform: translateX(16px); }
.kramar-em-toggle input:focus-visible + .kramar-em-toggle__slider {
    outline: 2px solid var(--kramar-em-primary);
    outline-offset: 2px;
}

/* ==========================================================================
   Recipient Badges
   ========================================================================== */

.kramar-em-badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-radius: 10px;
    white-space: nowrap;
}

.kramar-em-badge--customer { background: #e8f2fa; color: #2271b1; }
.kramar-em-badge--admin    { background: #f0f0f1; color: #50575e; }
.kramar-em-badge--custom   { background: #f5f0fa; color: var(--kramar-em-primary); }
.kramar-em-badge--active   { background: #f0fdf4; color: #166534; }

/* ==========================================================================
   Action Buttons
   ========================================================================== */

.kramar-em-col-actions td,
.kramar-em-table td.kramar-em-col-actions {
    display: table-cell;
}

.kramar-em-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--kramar-em-radius);
    border: 1px solid transparent;
    background: none;
    cursor: pointer;
    color: var(--kramar-em-text-muted);
    text-decoration: none;
    transition: all var(--kramar-em-transition);
    font-size: 16px;
    padding: 0;
    vertical-align: middle;
}

.kramar-em-action .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    line-height: 1;
}

.kramar-em-action:hover {
    background: var(--kramar-em-bg);
    border-color: var(--kramar-em-border);
    color: var(--kramar-em-text);
}

.kramar-em-action--delete:hover {
    background: #fef1f1;
    border-color: var(--kramar-em-danger);
    color: var(--kramar-em-danger);
}

/* ==========================================================================
   Preview Modal — .kramar-em-preview-modal with BEM children
   ========================================================================== */

.kramar-em-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kramar-em-preview-modal__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.55);
}

.kramar-em-preview-modal__content {
    position: relative;
    z-index: 1;
    background: var(--kramar-em-surface);
    border-radius: var(--kramar-em-radius);
    box-shadow: 0 8px 40px rgba(0,0,0,.2);
    display: flex;
    flex-direction: column;
    width: 90vw;
    max-width: 760px;
    max-height: 92vh;
    animation: kramarEmFadeIn 160ms ease;
}

.kramar-em-preview-modal__toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--kramar-em-border);
    flex-shrink: 0;
}

.kramar-em-preview-modal__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--kramar-em-text);
    flex: 1;
}

.kramar-em-preview-modal__device-toggle {
    display: flex;
    border: 1px solid var(--kramar-em-border);
    border-radius: var(--kramar-em-radius);
    overflow: hidden;
}

.kramar-em-preview-modal__device-toggle button {
    padding: 5px 10px;
    font-size: 13px;
    border: none;
    background: var(--kramar-em-surface);
    color: var(--kramar-em-text-muted);
    cursor: pointer;
    transition: all var(--kramar-em-transition);
    display: inline-flex;
    align-items: center;
}

.kramar-em-preview-modal__device-toggle button:hover {
    background: var(--kramar-em-bg);
    color: var(--kramar-em-text);
}

.kramar-em-preview-modal__device-toggle button.active {
    background: var(--kramar-em-primary);
    color: #fff;
}

.kramar-em-preview-modal__close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--kramar-em-text-muted);
    border-radius: var(--kramar-em-radius);
    font-size: 18px;
    transition: all var(--kramar-em-transition);
    padding: 0;
}

.kramar-em-preview-modal__close:hover {
    background: var(--kramar-em-bg);
    color: var(--kramar-em-text);
}

.kramar-em-preview-modal__iframe-wrap {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    background: var(--kramar-em-bg);
}

.kramar-em-preview-modal__iframe {
    border: none;
    box-shadow: 0 2px 12px rgba(0,0,0,.12);
    background: #fff;
    width: 600px;
    height: 600px;
    transition: width var(--kramar-em-transition);
}

.kramar-em-preview-modal__iframe[data-device="mobile"] {
    width: 375px;
}

/* ==========================================================================
   Test Send Dialog — .kramar-em-test-dialog with BEM children
   ========================================================================== */

.kramar-em-test-dialog {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kramar-em-test-dialog__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.55);
}

.kramar-em-test-dialog__content {
    position: relative;
    z-index: 1;
    background: var(--kramar-em-surface);
    border-radius: var(--kramar-em-radius);
    box-shadow: 0 8px 40px rgba(0,0,0,.2);
    padding: 20px 24px;
    width: 380px;
    max-width: 95vw;
    animation: kramarEmFadeIn 160ms ease;
}

.kramar-em-test-dialog__content h3 {
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--kramar-em-text);
}

.kramar-em-test-dialog__content p {
    font-size: 13px;
    color: var(--kramar-em-text-muted);
    margin: 0 0 12px;
}

.kramar-em-test-dialog__input {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 12px;
}

.kramar-em-test-dialog__actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.kramar-em-test-dialog__result {
    margin-top: 10px;
    font-size: 12px;
    padding: 8px 10px;
    border-radius: var(--kramar-em-radius);
}

.kramar-em-test-dialog__result.success { background: #f0fdf4; color: #166534; }
.kramar-em-test-dialog__result.error   { background: #fef1f1; color: var(--kramar-em-danger); }

/* ==========================================================================
   Add New Email Dialog — .kramar-em-new-email with BEM children
   ========================================================================== */

.kramar-em-new-email {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kramar-em-new-email__overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.55);
}

.kramar-em-new-email__content {
    position: relative;
    z-index: 1;
    background: var(--kramar-em-surface);
    border-radius: var(--kramar-em-radius);
    box-shadow: 0 8px 40px rgba(0,0,0,.2);
    padding: 24px;
    width: 560px;
    max-width: 95vw;
    max-height: 92vh;
    overflow-y: auto;
    animation: kramarEmFadeIn 160ms ease;
}

.kramar-em-new-email__content h3 {
    margin: 0 0 16px;
    font-size: 16px;
    font-weight: 600;
    color: var(--kramar-em-text);
}

.kramar-em-new-email__step p {
    font-size: 13px;
    color: var(--kramar-em-text-muted);
    margin: 0 0 14px;
}

.kramar-em-new-email__close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--kramar-em-text-muted);
    border-radius: var(--kramar-em-radius);
    font-size: 18px;
    transition: all var(--kramar-em-transition);
    padding: 0;
}

.kramar-em-new-email__close:hover {
    background: var(--kramar-em-bg);
    color: var(--kramar-em-text);
}

.kramar-em-new-email__actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--kramar-em-border);
}

/* ==========================================================================
   Context Cards (inside new email dialog)
   ========================================================================== */

.kramar-em-context-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.kramar-em-context-card {
    padding: 16px 12px;
    border: 2px solid var(--kramar-em-border);
    border-radius: var(--kramar-em-radius);
    cursor: pointer;
    text-align: center;
    background: var(--kramar-em-surface);
    transition: border-color var(--kramar-em-transition), background var(--kramar-em-transition), box-shadow var(--kramar-em-transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.kramar-em-context-card:hover {
    border-color: var(--kramar-em-primary);
    background: #faf8fd;
    box-shadow: 0 0 0 1px var(--kramar-em-primary);
}

.kramar-em-context-card--selected {
    border-color: var(--kramar-em-primary);
    background: #f5f0fa;
    box-shadow: 0 0 0 1px var(--kramar-em-primary);
}

.kramar-em-context-card .dashicons {
    font-size: 28px;
    width: 28px;
    height: 28px;
    color: var(--kramar-em-primary);
}

.kramar-em-context-card strong {
    font-size: 13px;
    font-weight: 600;
    color: var(--kramar-em-text);
    display: block;
}

.kramar-em-context-card span:last-child {
    font-size: 11px;
    color: var(--kramar-em-text-muted);
    line-height: 1.4;
}

/* ==========================================================================
   Template Grid — .kramar-em-template-grid with .kramar-em-template-card children
   ========================================================================== */

.kramar-em-template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin: 12px 0 24px;
}

.kramar-em-template-card {
    background: var(--kramar-em-surface);
    border: 2px solid var(--kramar-em-border);
    border-radius: var(--kramar-em-radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--kramar-em-transition), box-shadow var(--kramar-em-transition);
    position: relative;
}

.kramar-em-template-card:hover {
    border-color: var(--kramar-em-primary);
    box-shadow: 0 0 0 1px var(--kramar-em-primary);
}

.kramar-em-template-card--active {
    border-color: var(--kramar-em-primary);
    box-shadow: 0 0 0 1px var(--kramar-em-primary);
}

/* PHP uses __preview and __info (not __thumb/__body) */
.kramar-em-template-card__preview {
    height: 120px;
    background: var(--kramar-em-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--kramar-em-text-muted);
    font-size: 40px;
}

.kramar-em-template-card__preview .dashicons {
    font-size: 40px;
    width: 40px;
    height: 40px;
    color: var(--kramar-em-text-muted);
}

.kramar-em-template-card__info {
    padding: 12px;
}

.kramar-em-template-card__info h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--kramar-em-text);
    margin: 0 0 4px;
}

.kramar-em-template-card__info p {
    font-size: 12px;
    color: var(--kramar-em-text-muted);
    margin: 0 0 10px;
    line-height: 1.4;
}

.kramar-em-activate-template {
    font-size: 12px;
}

/* ==========================================================================
   Global Settings Form / Business Form — standard WP form-table
   ========================================================================== */

.kramar-em-global-form,
.kramar-em-business-form,
.kramar-em-template-form {
    max-width: 800px;
}

/* ==========================================================================
   Shared Fade-In Animation
   ========================================================================== */

@keyframes kramarEmFadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Responsive — narrow screens
   ========================================================================== */

@media (max-width: 600px) {
    .kramar-em-header {
        flex-wrap: wrap;
    }
    .kramar-em-header h1 {
        width: 100%;
        font-size: 18px;
    }
    .kramar-em-header__actions {
        flex-wrap: wrap;
    }
    .kramar-em-subject-text {
        max-width: 100px;
    }

    /* Prevent page-level horizontal overflow — let the table scroll inside
       its wrapper (which owns overflow-x). Keep the columns at a usable width
       so they don't cram; the wrapper scrolls to reach ACTIONS. */
    .kramar-em-emails-tab .kramar-em-table {
        min-width: 560px;
    }
}

/* ==========================================================================
   Dark Mode (.dark-mode on <body>)
   ========================================================================== */

/* Override design tokens for dark mode */
.dark-mode .kramar-em-wrap {
    --kramar-em-bg:         #23282d;
    --kramar-em-surface:    #1d2327;
    --kramar-em-border:     #3c434a;
    --kramar-em-text:       #f0f0f1;
    --kramar-em-text-muted: #a7aaad;
}

/* Table header */
.dark-mode .kramar-em-table th {
    background: #2c3338;
}
.dark-mode .kramar-em-table tbody tr:hover td {
    background: rgba(127,84,179,.1);
}

/* --- DM-5: Context cards (Add New Email dialog) --- */
.dark-mode .kramar-em-context-card {
    background: #1d2327;
    border-color: #3c434a;
}
.dark-mode .kramar-em-context-card:hover {
    background: #2c3338;
    border-color: var(--kramar-em-primary);
}
.dark-mode .kramar-em-context-card--selected {
    background: rgba(127,84,179,.15);
    border-color: var(--kramar-em-primary);
}
.dark-mode .kramar-em-context-card strong {
    color: #f0f0f1;
}
.dark-mode .kramar-em-context-card span:last-child {
    color: #a7aaad;
}

/* Template cards */
.dark-mode .kramar-em-template-card {
    background: #1d2327;
    border-color: #3c434a;
}
.dark-mode .kramar-em-template-card__preview {
    background: #23282d;
}
.dark-mode .kramar-em-template-card__info h4 {
    color: #f0f0f1;
}
.dark-mode .kramar-em-template-card__info p {
    color: #a7aaad;
}

/* Badges */
.dark-mode .kramar-em-badge--customer { background: rgba(34,113,177,.2); color: #72aee6; }
.dark-mode .kramar-em-badge--admin    { background: #2c3338; color: #a7aaad; }
.dark-mode .kramar-em-badge--custom   { background: rgba(127,84,179,.2); color: #c9a6f5; }
.dark-mode .kramar-em-badge--active   { background: rgba(0,163,42,.15); color: #6ee7b7; }

/* New email dialog content */
.dark-mode .kramar-em-new-email__content {
    background: #1d2327;
    border: 1px solid #3c434a;
}
.dark-mode .kramar-em-new-email__content h3 {
    color: #f0f0f1;
}
.dark-mode .kramar-em-new-email__actions {
    border-top-color: #3c434a;
}

/* Preview modal */
.dark-mode .kramar-em-preview-modal__content {
    background: #1d2327;
}
.dark-mode .kramar-em-preview-modal__toolbar {
    border-bottom-color: #3c434a;
}
.dark-mode .kramar-em-preview-modal__iframe-wrap {
    background: #23282d;
}

/* Test dialog */
.dark-mode .kramar-em-test-dialog__content {
    background: #1d2327;
    border: 1px solid #3c434a;
}
