﻿/* === Base ============================================================ */
:root {
    --wa-green:       #25D366;
    --wa-dark-green:  #128C7E;
    --sidebar-bg:     #111827;
    --sidebar-hover:  rgba(37,211,102,0.10);
    --sidebar-active: rgba(37,211,102,0.15);
    --sidebar-border: rgba(255,255,255,0.07);
    --content-bg:     #F3F4F6;
}

html, body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background-color: var(--content-bg);
    height: 100%;
}

a, .btn-link {
    color: var(--wa-dark-green);
}

/* === Buttons ========================================================= */
.btn-primary {
    background-color: var(--wa-green);
    border-color: var(--wa-green);
    color: #fff;
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--wa-dark-green);
    border-color: var(--wa-dark-green);
}
.btn-success {
    background-color: var(--wa-green);
    border-color: var(--wa-green);
}
.btn-success:hover, .btn-success:focus {
    background-color: var(--wa-dark-green);
    border-color: var(--wa-dark-green);
}
.btn-outline-success {
    color: var(--wa-green);
    border-color: var(--wa-green);
}
.btn-outline-success:hover {
    background-color: var(--wa-green);
    border-color: var(--wa-green);
    color: #fff;
}

/* === Page layout ===================================================== */
.page {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: 260px;
    min-height: 100vh;
    background-color: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* === Top bar ========================================================= */
.top-bar {
    background: #fff;
    border-bottom: 1px solid #E5E7EB;
    padding: 0 1.5rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.top-bar .page-title {
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
}
.page-content {
    padding: 1.75rem;
    flex: 1;
}

/* === Sidebar brand =================================================== */
.sidebar-brand {
    padding: 1.25rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--sidebar-border);
    text-decoration: none;
}
.brand-logo {
    width: 36px;
    height: 36px;
    background: var(--wa-green);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
    color: #fff;
}
.brand-text {
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
}
.brand-sub {
    color: rgba(255,255,255,0.40);
    font-size: 0.70rem;
}

/* === Sidebar nav ===================================================== */
.nav-section-label {
    color: rgba(255,255,255,0.30);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 1.25rem 1.5rem 0.4rem;
}
.nav-item-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.5rem;
    color: rgba(255,255,255,0.60);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: color .15s, background .15s;
}
.nav-item-link i {
    font-size: 1.05rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}
.nav-item-link:hover {
    color: #fff;
    background: var(--sidebar-hover);
    text-decoration: none;
}
.nav-item-link.active {
    color: var(--wa-green);
    background: var(--sidebar-active);
    border-left-color: var(--wa-green);
}
.sidebar-footer {
    margin-top: auto;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--sidebar-border);
}

/* === Stats cards ===================================================== */
.stat-card .card-body {
    padding: 1.25rem;
}
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}
.bg-success-soft { background: rgba(37,211,102,.12); }
.bg-info-soft    { background: rgba(13,202,240,.12); }
.bg-primary-soft { background: rgba(13,110,253,.12); }
.bg-warning-soft { background: rgba(255,193,7,.12);  }
.bg-danger-soft  { background: rgba(220,53,69,.12);  }

.stat-number {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1;
    color: #111827;
}
.stat-label {
    font-size: 0.8rem;
    color: #6B7280;
    margin-top: 2px;
}

/* === Cards =========================================================== */
.card {
    border-radius: 12px;
}
.card-header {
    border-radius: 12px 12px 0 0 !important;
}

/* === Tables ========================================================== */
.table th {
    font-size: 0.78rem;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-top: none;
}
.table td {
    vertical-align: middle;
    font-size: 0.875rem;
}

/* === Forms =========================================================== */
.form-control, .form-select {
    border-radius: 8px;
    font-size: 0.9rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--wa-green);
    box-shadow: 0 0 0 0.2rem rgba(37,211,102,.20);
}
.form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #374151;
}

/* === Validation ====================================================== */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--wa-green);
}
.invalid { outline: 1px solid #DC2626; }
.validation-message { color: #DC2626; font-size: 0.8rem; }

/* === Blazor error ==================================================== */
.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}
.blazor-error-boundary::after {
    content: "An unhandled error has occurred.";
}

/* === Responsive ====================================================== */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-height: auto;
        position: relative;
        height: auto;
    }
    .page { flex-direction: column; }
}

/* === Bot Builder ===================================================== */
.bot-tree-canvas {
    min-height: 280px;
    overflow-x: auto;
}

/* ── Node wrapper (positions connector lines) ── */
.bot-node-wrapper {
    position: relative;
    margin-bottom: 0.35rem;
    border-radius: 10px;
    transition: outline .12s;
}
.bot-node-drag-over { outline: 2px dashed #0d6efd; outline-offset: 2px; border-radius: 10px; }
.bot-node-dragging  { opacity: .45; }

/* ── Node card ── */
.bot-node-card {
    position: relative;
    background: #fff;
    border: 2px solid #E5E7EB;
    border-radius: 10px;
    padding: 0.65rem 0.9rem 0.65rem 2.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    cursor: grab;
    user-select: none;
    transition: border-color .15s, box-shadow .15s;
}
.bot-node-card:hover {
    border-color: var(--wa-green);
    box-shadow: 0 2px 10px rgba(37,211,102,.15);
}

/* Type-specific left border accent */
.node-type-trigger { border-left-color: #25D366 !important; }
.node-type-message { border-left-color: #0d6efd !important; }
.node-type-options { border-left-color: #ffc107 !important; }
.node-type-answer  { border-left-color: #6610f2 !important; }
.node-type-end     { border-left-color: #dc3545 !important; }

/* ── Drag handle ── */
.bot-node-drag-handle {
    position: absolute;
    left: 0.55rem;
    top: 50%;
    transform: translateY(-50%);
    color: #D1D5DB;
    font-size: .95rem;
    cursor: grab;
    line-height: 1;
}

/* ── Type badge ── */
.bot-node-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: .72rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 6px;
    width: fit-content;
}
.badge-trigger { background: rgba(37,211,102,.13); color: #128C7E; }
.badge-message { background: rgba(13,110,253,.12); color: #0d6efd; }
.badge-options { background: rgba(255,193,7,.16);  color: #856404; }
.badge-answer  { background: rgba(102,16,242,.12); color: #6610f2; }
.badge-end     { background: rgba(220,53,69,.12);  color: #dc3545; }

/* ── Node text ── */
.bot-node-title   { font-size: .85rem; font-weight: 600; color: #111827; }
.bot-node-preview { font-size: .8rem;  color: #6B7280; white-space: pre-wrap; word-break: break-word; }
.bot-node-meta    { font-size: .75rem; color: #9CA3AF; }
.bot-node-meta code { font-size: .75rem; background: #F3F4F6; padding: 1px 5px; border-radius: 4px; }

/* ── Action buttons row ── */
.bot-node-actions {
    display: flex;
    gap: 2px;
    margin-top: 0.15rem;
}
.btn-node-action {
    border: none;
    background: transparent;
    padding: 2px 7px;
    border-radius: 6px;
    color: #9CA3AF;
    cursor: pointer;
    font-size: .85rem;
    line-height: 1.6;
    transition: color .12s, background .12s;
}
.btn-node-action:hover          { background: #F3F4F6; color: #374151; }
.btn-node-action.btn-action-edit:hover   { color: #0d6efd; }
.btn-node-action.btn-action-add:hover    { color: var(--wa-green); }
.btn-node-action.btn-action-delete:hover { color: #dc3545; }

/* ── Children container with tree connectors ── */
.bot-node-children {
    margin-left: 1.5rem;
    padding-left: 1.25rem;
    border-left: 2px solid #E5E7EB;
    margin-top: 0.25rem;
}

.bot-node-children > .bot-node-wrapper {
    position: relative;
}

.bot-node-children > .bot-node-wrapper::before {
    content: '';
    position: absolute;
    left: -1.25rem;
    top: 1.2rem;
    width: 1.1rem;
    height: 2px;
    background: #E5E7EB;
}

/* ═══════════════════════════════════════════════════════════════════════════
   DIAGRAM VIEW  — flowchart style (Section / Row layout like the image)
   ═══════════════════════════════════════════════════════════════════════════ */

/* The canvas is position:relative so the SVG overlay can be absolute */
.bot-tree-canvas {
    position: relative;
    min-height: 320px;
    overflow: auto;
    padding-bottom: 3rem;
}

/* SVG connector overlay */
.diagram-svg-overlay {
    position: absolute;
    top: 0; left: 0;
    pointer-events: none;
    z-index: 0;
    overflow: visible;
}

/* Each root node + its children cluster */
.diagram-row-group {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 0;
    position: relative;
    z-index: 1;
    margin-bottom: 0.5rem;
}

/* The horizontal row: port-in  card  port-out */
.diagram-node-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
}

/* Children stack vertically to the right */
.diagram-children {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start;
}

/* ── Port areas ── */
.diagram-port {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: .7rem;
    color: #6B7280;
    white-space: nowrap;
    min-width: 52px;
}
.diagram-port-in  { justify-content: flex-start; }
.diagram-port-out { justify-content: flex-end;   }

.port-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid #0d6efd;
    background: #fff;
    flex-shrink: 0;
}
.port-dot-in  { order: -1; }
.port-dot-out { order:  1; }

.port-label {
    font-size: .68rem;
    color: #6B7280;
}

/* ── Diagram card ── */
.diagram-node-card {
    width: 210px;
    min-width: 190px;
    background: #fff;
    border: 1.5px dashed #c5d3e8;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
    cursor: grab;
    user-select: none;
    transition: border-color .15s, box-shadow .15s;
    position: relative;
    z-index: 1;
}
.diagram-node-card:hover {
    border-color: #0d6efd;
    box-shadow: 0 4px 14px rgba(13,110,253,.14);
}

/* Left accent stripe */
.diagram-node-card.node-type-trigger { border-left: 3px solid #25D366; }
.diagram-node-card.node-type-message { border-left: 3px solid #0d6efd; }
.diagram-node-card.node-type-options { border-left: 3px solid #ffc107; }
.diagram-node-card.node-type-answer  { border-left: 3px solid #6610f2; }
.diagram-node-card.node-type-end     { border-left: 3px solid #dc3545; }

/* Header strip (type badge row) */
.diagram-card-header {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 8px;
    font-size: .72rem;
    font-weight: 700;
    border-bottom: 1px solid #f0f2f5;
}
.diagram-card-header.badge-trigger { background: rgba(37,211,102,.1);  color: #128C7E; }
.diagram-card-header.badge-message { background: rgba(13,110,253,.09); color: #0d6efd; }
.diagram-card-header.badge-options { background: rgba(255,193,7,.13);  color: #856404; }

/* ======================================================================
   RTL — Arabic layout overrides
   Applied when <html dir="rtl"> (ar-OM culture)
   ====================================================================== */

/* Arabic font stack */
[dir="rtl"] body,
[dir="rtl"] html {
    font-family: "Segoe UI", "Noto Kufi Arabic", "Arial Unicode MS", system-ui, sans-serif;
}

/* ── Sidebar ── */
[dir="rtl"] .nav-item-link {
    border-left: none;
    border-right: 3px solid transparent; 
}
[dir="rtl"] .nav-item-link.active {
    border-left: none;
    border-right-color: var(--wa-green);
}
[dir="rtl"] .nav-section-label {
    letter-spacing: 0;
    text-align: right;
    padding: 1.25rem 1.5rem 0.4rem;
}
[dir="rtl"] .sidebar-brand {
    flex-direction: row-reverse;
}
[dir="rtl"] .sidebar-footer .d-flex {
    flex-direction: row-reverse;
}
[dir="rtl"] .brand-text,
[dir="rtl"] .brand-sub {
    text-align: right;
}

/* ── Bot node tree ── */
[dir="rtl"] .bot-node-drag-handle {
    left: auto;
    right: 0.55rem;
}
[dir="rtl"] .bot-node-card {
    padding: 0.65rem 2.25rem 0.65rem 0.9rem;
}
[dir="rtl"] .bot-node-children {
    margin-left: 0;
    margin-right: 1.5rem;
    padding-left: 0;
    padding-right: 1.25rem;
    border-left: none;
    border-right: 2px solid #E5E7EB;
}
[dir="rtl"] .bot-node-children > .bot-node-wrapper::before {
    left: auto;
    right: -1.25rem;
}

/* ── Diagram accent stripe ── */
[dir="rtl"] .diagram-node-card.node-type-trigger { border-left: none; border-right: 3px solid #25D366; }
[dir="rtl"] .diagram-node-card.node-type-message { border-left: none; border-right: 3px solid #0d6efd; }
[dir="rtl"] .diagram-node-card.node-type-options { border-left: none; border-right: 3px solid #ffc107; }
[dir="rtl"] .diagram-node-card.node-type-answer  { border-left: none; border-right: 3px solid #6610f2; }
[dir="rtl"] .diagram-node-card.node-type-end     { border-left: none; border-right: 3px solid #dc3545; }

/* ── Node type accents in tree view ── */
[dir="rtl"] .bot-node-card { border-left: none; border-right: 4px solid transparent; }
[dir="rtl"] .node-type-trigger { border-right-color: #25D366 !important; border-left: none !important; }
[dir="rtl"] .node-type-message { border-right-color: #0d6efd !important; border-left: none !important; }
[dir="rtl"] .node-type-options { border-right-color: #ffc107 !important; border-left: none !important; }
[dir="rtl"] .node-type-answer  { border-right-color: #6610f2 !important; border-left: none !important; }
[dir="rtl"] .node-type-end     { border-right-color: #dc3545 !important; border-left: none !important; }

/* ── Tables ── */
[dir="rtl"] .table th,
[dir="rtl"] .table td {
    text-align: right;
}

/* ── Pagination chevrons — mirror arrows ── */
[dir="rtl"] .bi-chevron-left::before  { content: "\F285"; }
[dir="rtl"] .bi-chevron-right::before { content: "\F284"; }

/* ── Input groups — flip border radii ── */
[dir="rtl"] .input-group > :first-child:not(.dropdown-toggle):not(.dropdown-menu) {
    border-radius: 0 8px 8px 0 !important;
}
[dir="rtl"] .input-group > :last-child:not(.dropdown-toggle):not(.dropdown-menu) {
    border-radius: 8px 0 0 8px !important;
}

/* ── Inline icon margins — flip me/ms ── */
[dir="rtl"] .me-1 { margin-right: 0 !important; margin-left: 0.25rem !important; }
[dir="rtl"] .me-2 { margin-right: 0 !important; margin-left: 0.5rem  !important; }
[dir="rtl"] .me-3 { margin-right: 0 !important; margin-left: 1rem    !important; }
[dir="rtl"] .ms-1 { margin-left:  0 !important; margin-right: 0.25rem !important; }
[dir="rtl"] .ms-2 { margin-left:  0 !important; margin-right: 0.5rem  !important; }
[dir="rtl"] .ms-auto { margin-left: 0 !important; margin-right: auto   !important; }

/* ── Step bar in Bulk Message ── */
[dir="rtl"] .step-bar { transform: scaleX(-1); }

/* ── Dismiss button in error UI ── */
[dir="rtl"] #blazor-error-ui .dismiss {
    right: auto;
    left: 0.75rem;
}

/* ── Alert close button ── */
[dir="rtl"] .alert .btn-close {
    margin-right: auto;
    margin-left: 0;
}
.diagram-card-header.badge-answer  { background: rgba(102,16,242,.09); color: #6610f2; }
.diagram-card-header.badge-end     { background: rgba(220,53,69,.09);  color: #dc3545; }

.diag-type-icon { font-size: 1rem; line-height: 1; }
.diag-type-label { font-size: .72rem; font-weight: 700; }

/* Card body */
.diagram-card-body {
    padding: 6px 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.diag-title   { font-size: .8rem;  font-weight: 600; color: #0d6efd; }
.diag-preview { font-size: .75rem; color: #6B7280;   white-space: pre-wrap; word-break: break-word; }
.diag-meta    { font-size: .7rem;  color: #9CA3AF; }
.diag-meta code { font-size: .7rem; background: #F3F4F6; padding: 1px 4px; border-radius: 3px; }

/* Action buttons inside header */
.diag-actions {
    display: flex;
    gap: 1px;
}
.btn-diag-action {
    border: none;
    background: transparent;
    padding: 1px 5px;
    border-radius: 4px;
    color: #9CA3AF;
    cursor: pointer;
    font-size: .78rem;
    line-height: 1.6;
    transition: color .12s, background .12s;
}
.btn-diag-action:hover               { background: rgba(0,0,0,.06); color: #374151; }
.btn-diag-action.btn-action-edit:hover   { color: #0d6efd; }
.btn-diag-action.btn-action-add:hover    { color: var(--wa-green, #25D366); }
.btn-diag-action.btn-action-delete:hover { color: #dc3545; }

/* Drag states */
.bot-node-drag-over .diagram-node-card { outline: 2px dashed #0d6efd; outline-offset: 2px; }
.bot-node-dragging  .diagram-node-card { opacity: .45; }
