/* components.css — Modals, Forms, Loading, Toast, Template Editor, Notifications, Responsive */

/* ============================================
   MODALS
   ============================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-detail {
    max-width: 520px;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-head h2 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.btn-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-close:hover {
    background: var(--red-subtle);
    color: var(--red-text);
}

.modal-scroll {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-foot-detail {
    justify-content: space-between;
}

.foot-actions {
    display: flex;
    gap: 8px;
}

/* ============================================
   FORMS
   ============================================ */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.9rem;
    transition: all var(--transition);
    outline: none;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder {
    color: var(--text-muted);
}

textarea.form-input {
    resize: vertical;
    min-height: 60px;
}

select.form-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%238b90a0' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

/* Date Input — Thai DD/MM/YYYY */
.date-input-wrap {
    position: relative;
    cursor: pointer;
}

.date-input-wrap #expireDateDisplay {
    cursor: pointer;
    padding-right: 40px;
}

.date-input-hidden {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 2;
}

.date-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    z-index: 1;
}

input[type="date"].form-input {
    color-scheme: dark;
}

[data-theme="light"] input[type="date"].form-input {
    color-scheme: light;
}

/* Category Grid */
.category-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.cat-option input {
    display: none;
}

.cat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-align: center;
}

.cat-card:hover {
    border-color: var(--text-muted);
    background: var(--bg-surface);
}

.cat-option input:checked + .cat-card {
    border-color: var(--accent);
    background: var(--accent-subtle);
}

.cat-icon {
    font-size: 1.5rem;
}

.cat-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.cat-option input:checked + .cat-card .cat-name {
    color: var(--accent);
}

/* LINE Avatar Preview */
.line-avatar-preview {
    display: none;
    margin-top: 10px;
}

.line-user-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
}

.line-user-preview img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.line-user-preview span {
    font-weight: 600;
    font-size: 0.9rem;
}

/* ============================================
   EVENT DETAIL MODAL
   ============================================ */
.detail-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 20px;
}

.detail-status.expired {
    background: var(--red-subtle);
    color: var(--red-text);
}
.detail-status.today {
    background: #7f1d1d;
    color: #fca5a5;
}
.detail-status.tomorrow {
    background: #78350f;
    color: #fde68a;
}
.detail-status.warning {
    background: var(--amber-subtle);
    color: var(--amber-text);
}

.detail-status.active {
    background: var(--green-subtle);
    color: var(--green-text);
}

.detail-grid {
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-card);
}

.detail-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 500;
}

.detail-value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: right;
    max-width: 60%;
    word-break: break-word;
}

.detail-note {
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
}

.detail-note-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.detail-note-text {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ============================================
   LOADING
   ============================================ */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 23, 0.8);
    backdrop-filter: blur(4px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.loading-overlay.active {
    display: flex;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    position: relative;
    margin: 0 auto 16px;
}

.spinner-ring {
    position: absolute;
    inset: 0;
    border: 3px solid transparent;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner-ring:nth-child(2) {
    inset: 6px;
    border-top-color: var(--accent-hover);
    animation-duration: 0.8s;
    animation-direction: reverse;
}

.spinner-ring:nth-child(3) {
    inset: 12px;
    border-top-color: rgba(108, 92, 231, 0.4);
    animation-duration: 1.2s;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ============================================
   TOAST
   ============================================ */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    color: white;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 360px;
}

.toast.success {
    background: linear-gradient(135deg, #2ed573 0%, #1cb85c 100%);
}

.toast.error {
    background: linear-gradient(135deg, #ff4757 0%, #e0313f 100%);
}

.toast.info {
    background: linear-gradient(135deg, #6c5ce7 0%, #5a4bd1 100%);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(100px); }
    to { opacity: 1; transform: translateX(0); }
}


/* ============================================
   EMAIL TEMPLATE EDITOR — 2 Column + Tab Layout
   ============================================ */
.tpl-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    height: calc(100vh - var(--topbar-h) - 80px);
    min-height: 500px;
}

/* Template List */
.tpl-sidebar {
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tpl-sidebar-head {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.tpl-sidebar-head h3 { font-size: 0.9rem; font-weight: 700; }

.tpl-list { flex: 1; overflow-y: auto; padding: 8px; }

.tpl-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    cursor: pointer; transition: all var(--transition); margin-bottom: 2px;
}
.tpl-item:hover { background: var(--bg-card-hover); }
.tpl-item.active { background: var(--accent-subtle); }
.tpl-item-icon { font-size: 1.2rem; flex-shrink: 0; }
.tpl-item-info { min-width: 0; }
.tpl-item-name { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-item.active .tpl-item-name { color: var(--accent); }
.tpl-item-desc { font-size: 0.72rem; color: var(--text-muted); }
.tpl-item-status { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.tpl-item-status.saved { background: var(--green); }
.tpl-item-status.modified { background: var(--amber); }

/* Main Area */
.tpl-main {
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tpl-editor-empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; color: var(--text-muted); gap: 12px; opacity: 0.4;
}
.tpl-editor-empty p { font-size: 0.9rem; }

.tpl-editor-content {
    display: flex; flex-direction: column; height: 100%; overflow: hidden;
}

/* Toolbar */
.tpl-editor-toolbar {
    display: flex; align-items: center; padding: 10px 20px;
    border-bottom: 1px solid var(--border); flex-shrink: 0; gap: 12px;
}
.tpl-editor-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tpl-badge {
    font-size: 0.72rem; font-weight: 600; padding: 3px 10px;
    border-radius: 20px; background: var(--accent-subtle); color: var(--accent); white-space: nowrap;
}
.tpl-editor-info h3 { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-editor-actions { display: flex; gap: 8px; flex-shrink: 0; margin-left: auto; }

/* Tabs */
.tpl-tabs {
    display: flex; gap: 2px; background: var(--bg-surface); border-radius: var(--radius-sm); padding: 3px;
}
.tpl-tab {
    display: flex; align-items: center; gap: 5px; padding: 6px 14px;
    border: none; background: none; color: var(--text-muted); font-size: 0.8rem;
    font-weight: 500; cursor: pointer; border-radius: var(--radius-sm);
    transition: all var(--transition); font-family: var(--font-main); white-space: nowrap;
}
.tpl-tab:hover { color: var(--text-primary); }
.tpl-tab.active { background: var(--bg-card); color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }

/* Panels */
.tpl-panel {
    display: none; flex: 1; overflow: hidden;
}
.tpl-panel.active {
    display: flex; flex-direction: column;
}

/* Editor Form — 2 Column Grid */
.tpl-form-scroll { flex: 1; overflow-y: auto; padding: 24px; }

.tpl-form-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px;
}

.tpl-form-col { display: flex; flex-direction: column; }

.tpl-section {
    margin-bottom: 20px; padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}
.tpl-section:last-child { border-bottom: none; margin-bottom: 0; }

.tpl-section-head {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.82rem; font-weight: 600; color: var(--text-primary); margin-bottom: 8px;
}
.tpl-section-icon { font-size: 0.95rem; }

.tpl-hint {
    margin-top: 6px; font-size: 0.73rem; color: var(--text-muted); line-height: 1.5;
}
.tpl-hint code {
    background: var(--bg-surface); padding: 1px 5px; border-radius: 3px;
    font-family: var(--font-mono); font-size: 0.68rem; color: var(--accent);
}

/* Color Picker */
.tpl-color-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tpl-color-picker {
    width: 36px; height: 32px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); cursor: pointer; background: none; padding: 2px;
}
.tpl-color-text { width: 90px !important; font-family: var(--font-mono); font-size: 0.8rem !important; }
.tpl-color-presets { display: flex; gap: 4px; }
.tpl-preset {
    width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent;
    cursor: pointer; transition: all var(--transition);
}
.tpl-preset:hover { transform: scale(1.2); border-color: white; }

/* Info Rows */
.tpl-info-rows { display: flex; flex-direction: column; gap: 6px; }
.tpl-info-row {
    display: grid; grid-template-columns: auto 1fr 1fr auto; gap: 6px; align-items: center;
}
.tpl-drag-handle { color: var(--text-muted); cursor: grab; padding: 4px; font-size: 0.85rem; }
.tpl-row-input {
    padding: 6px 8px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary); font-family: var(--font-main);
    font-size: 0.8rem; outline: none; transition: border-color var(--transition);
}
.tpl-row-input:focus { border-color: var(--accent); }
.tpl-row-remove {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    padding: 4px; border-radius: var(--radius-sm); transition: all var(--transition);
}
.tpl-row-remove:hover { color: var(--red-text); background: var(--red-subtle); }
.tpl-add-row { margin-top: 6px; font-size: 0.8rem !important; padding: 5px 10px !important; }

/* CTA Grid */
.tpl-cta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Variables Reference */
.tpl-vars-ref {
    background: var(--bg-surface); border-radius: var(--radius-sm); padding: 14px !important;
    margin-top: 4px; border-bottom: none !important;
}
.tpl-vars-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.tpl-var { display: flex; align-items: center; gap: 6px; font-size: 0.73rem; }
.tpl-var code {
    background: var(--bg-card); padding: 2px 5px; border-radius: 3px;
    font-family: var(--font-mono); font-size: 0.68rem; color: var(--accent); white-space: nowrap;
}
.tpl-var span { color: var(--text-muted); }

/* Preview Panel */
.tpl-preview-frame {
    flex: 1; background: #e5e7eb; padding: 24px; overflow: auto;
    display: flex; justify-content: center;
}
.tpl-preview-frame iframe {
    width: 100%; max-width: 640px; height: 100%; border: none;
    border-radius: 8px; background: white; min-height: 500px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.btn-sm { padding: 5px 10px !important; font-size: 0.78rem !important; }

/* Template Responsive */
@media (max-width: 768px) {
    .tpl-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: auto; min-height: auto;
    }
    .tpl-sidebar { max-height: 180px; }
    .tpl-form-grid { grid-template-columns: 1fr; }
    .tpl-cta-grid { grid-template-columns: 1fr; }
    .tpl-vars-grid { grid-template-columns: 1fr 1fr; }
    .tpl-info-row { grid-template-columns: 1fr 1fr auto; }
    .tpl-drag-handle { display: none; }
    .tpl-editor-toolbar { flex-wrap: wrap; }
}

/* ============================================
   NOTIFICATION PICKER MODAL
   ============================================ */
.modal-notify {
    max-width: 560px;
}

.notify-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}

.notify-select-all {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.notify-select-all input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
}

.notify-filter-chips {
    display: flex;
    gap: 6px;
}

.notify-list {
    display: flex;
    flex-direction: column;
}

.notify-item {
    display: grid;
    grid-template-columns: auto auto 1fr auto auto;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background var(--transition);
}

.notify-item:last-child {
    border-bottom: none;
}

.notify-item:hover {
    background: var(--bg-card-hover);
}

.notify-item.selected {
    background: var(--accent-subtle);
}

.notify-check {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.notify-icon {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    flex-shrink: 0;
}

.notify-info {
    min-width: 0;
}

.notify-name {
    font-weight: 600;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notify-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.notify-channel {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    white-space: nowrap;
}

.notify-status-tag {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.notify-status-tag.expired { background: var(--red-subtle); color: var(--red-text); }
.notify-status-tag.today { background: #7f1d1d; color: #fca5a5; }
.notify-status-tag.tomorrow { background: #78350f; color: #fde68a; }
.notify-status-tag.warning { background: var(--amber-subtle); color: var(--amber-text); }
.notify-status-tag.active { background: var(--green-subtle); color: var(--green-text); }

.notify-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.notify-summary {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.notify-summary span {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--accent);
}

.notify-sending {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0;
}

.notify-progress-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    font-size: 0.85rem;
}

.notify-progress-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.notify-progress-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notify-progress-status {
    font-weight: 600;
    font-size: 0.78rem;
    flex-shrink: 0;
}

.notify-progress-status.sending { color: var(--amber-text); }
.notify-progress-status.sent { color: var(--green-text); }
.notify-progress-status.failed { color: var(--red-text); }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .mobile-header {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding: 0 16px 32px;
        padding-top: 56px;
    }

    .topbar {
        padding-top: 20px;
    }

    .topbar .btn-accent {
        display: none;
    }

    .cal-day {
        min-height: 52px;
        padding: 4px;
    }

    .day-num {
        width: 22px;
        height: 22px;
        font-size: 0.72rem;
    }

    .cal-event {
        font-size: 0.6rem;
        padding: 1px 3px;
    }

    .svc-row {
        grid-template-columns: auto 1fr auto;
        gap: 10px;
        padding: 10px 12px;
    }

    .svc-date {
        display: none;
    }

    .filter-chips {
        flex-wrap: wrap;
    }

    .modal-panel {
        max-height: 95vh;
        margin: 10px;
    }

    .modal-foot-detail {
        flex-direction: column;
        gap: 10px;
    }

    .foot-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

@media (max-width: 480px) {
    .calendar-toolbar {
        flex-direction: column;
        gap: 12px;
        padding: 14px 16px;
    }

    .cal-month {
        font-size: 1rem;
        min-width: auto;
    }

    .category-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .cat-card {
        padding: 10px 6px;
    }

    .cat-icon {
        font-size: 1.2rem;
    }

    .list-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toast-container {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }

    .toast {
        max-width: 100%;
    }
}

/* ============================================
   CUSTOMERS PAGE
   ============================================ */
.customers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.customers-search-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    max-width: 400px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 14px;
}

.customers-search-wrap svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.customers-search-wrap .form-input {
    border: none;
    background: none;
    padding: 10px 0;
}

.customers-search-wrap .form-input:focus {
    box-shadow: none;
}

.customers-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.customers-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.customers-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 20px;
    font-size: 0.95rem;
}

/* Customer Row */
.cust-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: background var(--transition);
}

.cust-row:hover {
    background: var(--bg-card-hover);
}

.cust-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    flex: 1;
}

/* Avatar */
.cust-pic {
    position: relative;
    flex-shrink: 0;
}

.cust-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
}

.cust-avatar-fallback {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}

.cust-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-card);
}

.cust-status-dot.status-ok { background: var(--green); }
.cust-status-dot.status-warning { background: var(--amber); }
.cust-status-dot.status-expired { background: var(--red); }

/* Info */
.cust-info {
    min-width: 0;
}

.cust-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cust-line-id {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.cust-line-name {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Rename Input */
.cust-rename-input {
    padding: 4px 10px !important;
    font-size: 0.95rem !important;
    width: 200px;
    font-weight: 600;
}

/* Actions */
.cust-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

@media (max-width: 640px) {
    .customers-header {
        flex-direction: column;
        align-items: stretch;
    }
    .customers-search-wrap {
        max-width: 100%;
    }
    .cust-line-id {
        max-width: 120px;
    }
}

/* ============================================
   CHANNEL TABS (Email / LINE)
   ============================================ */
.tpl-channel-tabs {
    display: flex;
    gap: 4px;
    padding: 16px 24px 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.tpl-channel-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    border-radius: 8px 8px 0 0;
    transition: all 0.2s;
}
.tpl-channel-tab:hover {
    color: var(--text-primary);
    background: rgba(99, 102, 241, 0.05);
}
.tpl-channel-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: rgba(99, 102, 241, 0.08);
}
.tpl-channel-panel {
    display: none;
}
.tpl-channel-panel.active {
    display: block;
}

/* LINE badge */
.line-badge {
    background: #06c755 !important;
}

/* Toggle label */
.tpl-toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
}
.tpl-toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* ============================================
   LINE FLEX MESSAGE PREVIEW
   ============================================ */
.line-preview-container {
    display: flex;
    justify-content: center;
    padding: 32px 20px;
    background: #f0f0f0;
    min-height: 500px;
}
.line-preview-phone {
    width: 340px;
    background: #7494c0;
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.line-preview-phone-header {
    background: #6b8db5;
    color: #fff;
    text-align: center;
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
}
.line-preview-chat {
    background: #7494c0;
    padding: 20px 16px 32px;
    min-height: 380px;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
}

/* Flex Bubble */
.line-flex-bubble {
    width: 260px;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.line-flex-header {
    padding: 14px 16px;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.4;
}
.line-flex-body {
    padding: 16px;
}
.line-flex-title {
    font-size: 16px;
    font-weight: 700;
    color: #1f2937;
    line-height: 1.4;
    margin-bottom: 2px;
}
.line-flex-subtitle {
    font-size: 14px;
    font-weight: 700;
    color: #ef4444;
    margin-bottom: 4px;
}
.line-flex-separator {
    height: 1px;
    background: #e5e7eb;
    margin: 12px 0;
}
.line-flex-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.line-flex-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 12px;
}
.line-flex-icon {
    flex-shrink: 0;
    font-size: 12px;
}
.line-flex-label {
    color: #6b7280;
    flex-shrink: 0;
    min-width: 50px;
}
.line-flex-value {
    color: #1f2937;
    font-weight: 700;
    word-break: break-all;
}
.line-flex-value.date {
    color: #dc2626;
}
.line-flex-footer-msg {
    font-size: 11px;
    color: #6b7280;
    line-height: 1.5;
    margin-top: 4px;
}
.line-flex-footer {
    padding: 12px 16px;
    border-top: 1px solid #f3f4f6;
}
.line-flex-cta {
    display: block;
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

/* ============================================
   ADD SERVICE DROPDOWN
   ============================================ */
.add-service-dropdown {
    position: relative;
    display: flex;
}
.add-service-dropdown > .btn:first-child {
    border-radius: 8px 0 0 8px;
}
.add-dropdown-toggle {
    border-radius: 0 8px 8px 0 !important;
    padding: 0 8px !important;
    min-width: 34px;
    border-left: 1px solid rgba(255,255,255,0.2) !important;
}
.add-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--surface-raised, #1e1e2e);
    border: 1px solid var(--border, #333);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    min-width: 260px;
    z-index: 100;
    padding: 6px;
    animation: fadeIn 0.15s ease;
}
.add-dropdown-menu.show {
    display: block;
}
.add-dropdown-menu button {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: transparent;
    color: var(--text-primary, #e0e0e0);
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.add-dropdown-menu button:hover {
    background: rgba(99, 102, 241, 0.12);
}
.add-menu-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
}
.add-menu-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.add-menu-title {
    font-size: 0.85rem;
    font-weight: 600;
}
.add-menu-desc {
    font-size: 0.72rem;
    color: var(--text-secondary, #888);
}

/* Form hint */
.form-hint {
    font-size: 0.72rem;
    color: var(--text-secondary, #888);
    margin-top: 4px;
    line-height: 1.4;
}

.btn-outline {
    background: transparent;
    border: 1px dashed var(--border, #2a2a3a);
    color: var(--text-secondary, #888);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all .2s;
}
.btn-outline:hover {
    border-color: var(--accent, #6366f1);
    color: var(--accent, #6366f1);
}

/* Toggle Switch */
.toggle-switch { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background: #374151; border-radius: 26px; transition: .3s;
}
.toggle-slider::before {
    content: ''; position: absolute; height: 20px; width: 20px; left: 3px; bottom: 3px;
    background: #fff; border-radius: 50%; transition: .3s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent, #6366f1); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(22px); }

/* Trello Pending */
.btn-pending {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    animation: pendingPulse 2s ease-in-out infinite;
}
.btn-pending:hover { transform: scale(1.05); }
.pending-badge {
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75em;
    font-weight: 700;
}
@keyframes pendingPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,0.4); }
    50% { box-shadow: 0 0 0 8px rgba(245,158,11,0); }
}
.modal-lg { max-width: 700px; }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }

/* Wider modal-detail for Traffic report */
.modal-detail { max-width: 600px; }
@media (min-width: 768px) { .modal-detail { max-width: 650px; } }

/* Traffic Report Modal */
.traffic-report-panel { max-width: 800px !important; }
@media (max-width: 768px) { 
    .traffic-report-panel { max-width: 95vw !important; }
    .traffic-report-panel .tr-card { padding: 6px !important; }
}

/* KPI Cards */
.tr-card {
    background: #0f172a;
    border-radius: 10px;
    padding: 10px;
    text-align: center;
    border: 1px solid #1e293b;
}
.tr-card-label { font-size: 0.65em; color: #64748b; margin-bottom: 2px; }
.tr-card-value { font-size: 1.15em; font-weight: 700; line-height: 1.3; }
.tr-card-sub { font-size: 0.55em; color: #475569; }

/* Credits Badge in Topbar */
.credits-badge { position: relative; margin-right: 4px; }
.credits-badge-inner {
    display: flex; align-items: center; gap: 5px;
    padding: 6px 12px; background: #1e293b; border: 1px solid #334155;
    border-radius: 8px; cursor: pointer; font-size: 0.85em; color: #e2e8f0;
    transition: all 0.2s;
}
.credits-badge-inner:hover { background: #334155; }
.credits-total { font-weight: 700; color: #34d399; }
.credits-warn { font-size: 0.8em; }
.credits-dropdown {
    display: none; position: absolute; top: 100%; right: 0; margin-top: 6px;
    background: #1e293b; border: 1px solid #334155; border-radius: 10px;
    padding: 12px 16px; min-width: 200px; z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.credits-dropdown.show { display: block; }
.credits-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 0; font-size: 0.85em; color: #94a3b8;
    border-bottom: 1px solid #0f172a;
}
.credits-row:last-of-type { border-bottom: none; }

/* ============================================
   LIGHT THEME OVERRIDES
   ============================================ */
[data-theme="light"] .modal-overlay {
    background: rgba(0, 0, 0, 0.4);
}

[data-theme="light"] .loading-overlay {
    background: rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .detail-status.today {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

[data-theme="light"] .detail-status.tomorrow {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
}

[data-theme="light"] .notify-status-tag.today {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

[data-theme="light"] .notify-status-tag.tomorrow {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
}

[data-theme="light"] .toggle-slider {
    background: #cbd5e1;
}

[data-theme="light"] .tr-card {
    background: #f8fafc;
    border-color: #e2e8f0;
}

[data-theme="light"] .credits-badge-inner {
    background: #f1f5f9;
    border-color: #e2e8f0;
    color: #1a202c;
}

[data-theme="light"] .credits-badge-inner:hover {
    background: #e2e8f0;
}

[data-theme="light"] .credits-dropdown {
    background: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

[data-theme="light"] .credits-row {
    color: #64748b;
    border-bottom-color: #f1f5f9;
}

[data-theme="light"] .add-dropdown-menu {
    background: #ffffff;
    border-color: #e2e8f0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}

[data-theme="light"] .tpl-preview-frame {
    background: #f1f5f9;
}
