/* ========================================
   ConnectAI — Components: Cards, Buttons, Forms, Modals, Badges
   ======================================== */

/* ── Cards ── */
.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-1);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--bg-white);
    color: var(--text-2);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { background: var(--bg-hover); border-color: #D1D5DB; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--radius-xs); }
.btn-blue, .btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-blue:hover, .btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
.btn-red { color: var(--red); border-color: rgba(239,68,68,0.3); }
.btn-red:hover { background: var(--red-dim); }
.btn-green { color: var(--green); border-color: rgba(34,197,94,0.3); }
.btn-green:hover { background: var(--green-dim); }
.btn-ghost { border: 1px solid transparent; background: transparent; color: var(--primary); }
.btn-ghost:hover { border-color: var(--primary); background: var(--primary-dim); }
.btn-icon-edit { color: var(--primary); }
.btn-icon-edit:hover { background: var(--primary-dim); }
.btn-icon-view { color: var(--primary); }
.btn-icon-view:hover { background: var(--primary-dim); }
.btn-icon-delete { color: var(--red); }
.btn-icon-delete:hover { background: var(--red-dim); }
.btn:disabled, .btn[disabled] { opacity: 0.4; pointer-events: none; }

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 72px;
    right: 20px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 10px 25px rgba(0,0,0,0.12);
    animation: toastIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--text-1);
    color: #fff;
}
.toast.success { background: #15803D; }
.toast.error { background: #DC2626; }
.toast.fade-out { opacity: 0; transition: opacity 0.3s; }

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

/* ── Spinner ── */
.spin {
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge.api        { color: var(--primary); background: var(--primary-dim); }
.badge.jira       { color: var(--purple); background: rgba(139,92,246,0.08); }
.badge.financeiro { color: var(--green); background: var(--green-dim); }
.badge.comercial  { color: var(--yellow); background: var(--yellow-dim); }
.badge.web        { color: var(--blue); background: var(--blue-dim); }

/* Type badges */
.badge-tipo { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; padding: 2px 8px; border-radius: 5px; }
.badge-http     { background: var(--blue-dim); color: var(--blue); }
.badge-database { background: var(--green-dim); color: var(--green); }
.badge-webhook  { background: rgba(139,92,246,0.08); color: var(--purple); }
.badge-query    { background: var(--green-dim); color: var(--green); }
.badge-script   { background: var(--yellow-dim); color: var(--yellow); }
.badge-inactive { font-size: 11px; padding: 2px 8px; border-radius: 100px; background: var(--red-dim); color: var(--red); }

.contact-blocked-badge {
    font-size: 10px; font-weight: 700;
    padding: 2px 7px; border-radius: 5px;
    background: var(--red-dim); color: var(--red);
    border: 1px solid rgba(239,68,68,0.15);
    text-transform: uppercase;
}

/* ── Modal ── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
    animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 760px;
    max-height: 85vh;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px rgba(0,0,0,0.15);
    animation: modalIn 0.2s ease;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
    .modal-backdrop { padding: 12px; }
    .modal-box { max-height: 92vh; border-radius: 12px; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    font-size: 16px;
    font-weight: 700;
}
.modal-close {
    width: 32px; height: 32px;
    border: none;
    background: var(--primary-dim);
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    transition: all 0.15s;
}
.modal-close:hover { background: var(--primary); color: #fff; }

.modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 24px 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 18px 24px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.modal-section { display: flex; flex-direction: column; gap: 12px; }
.modal-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-3);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
}

/* ── Forms ── */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > .form-group { flex: 1; min-width: 140px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-3); }
.form-label .hint { font-weight: 400; font-size: 11px; color: var(--text-4); }

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-1);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}
.form-group select {
    width: 100%;
}
.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-dim);
}
.form-group textarea { resize: vertical; min-height: 80px; line-height: 1.6; }

.check-row { display: flex; gap: 16px; align-items: center; padding: 4px 0; }
.check-label {
    display: flex; align-items: center; gap: 6px;
    font-size: 13px; color: var(--text-2); cursor: pointer;
}
.check-label input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }

/* ── Tag Input ── */
.tag-input-wrap {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    min-height: 40px;
    align-items: center;
    cursor: text;
    transition: border-color 0.15s;
}
.tag-input-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim); }

.tag-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 5px 12px 5px 12px;
    border-radius: 100px;
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--border-brand);
    font-size: 12px; font-weight: 500;
}
.tag-chip.purple { background: var(--purple); color: #fff; border-color: var(--purple); }
.tag-chip.green { background: var(--green); color: #fff; border-color: var(--green); }

.tag-chip-x {
    border: none; background: none; color: rgba(255,255,255,.6);
    font-size: 15px; cursor: pointer; padding: 0 0 0 2px; line-height: 1;
    transition: color .15s;
}
.tag-chip-x:hover { color: #fff; }

.tag-input-field {
    border: none; background: transparent; outline: none;
    font-size: 13px; color: var(--text-1);
    min-width: 80px; flex: 1; padding: 2px 0;
}

/* Agent tags (view mode) */
.agent-tag {
    display: inline-flex; padding: 4px 12px; border-radius: 100px;
    font-size: 11px; font-weight: 600;
    background: var(--primary); color: #fff; border: none;
    letter-spacing: .2px;
}
.agent-tag.purple { background: var(--purple); }
.agent-tags { display: flex; flex-wrap: wrap; gap: 5px; }

/* ── Param Row (tool editor) ── */
.param-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
/* ── Custom Select (auto-upgrade) ── */
.cs-wrap { position: relative; width: 100%; }
.cs-trigger {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 14px; background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; transition: all .15s; min-height: 38px;
}
.cs-trigger:hover { border-color: var(--primary); }
.cs-open .cs-trigger { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim); }
.cs-label { flex: 1; font-size: 13px; font-weight: 500; font-family: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-arrow { flex-shrink: 0; opacity: .4; transition: transform .2s; display: flex; }
.cs-open .cs-arrow { transform: rotate(180deg); }
.cs-dropdown {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 300;
    background: var(--bg-white); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,.1); overflow: hidden; max-height: 240px; overflow-y: auto;
    padding: 4px;
}
.cs-group {
    padding: 6px 12px 3px; font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .5px; color: var(--text-4);
}
.cs-option {
    display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 8px 12px; border: none; background: none; border-radius: var(--radius-xs);
    cursor: pointer; font-size: 13px; font-family: inherit; color: var(--text-2);
    text-align: left; transition: all .1s;
}
.cs-option:hover { background: var(--bg-hover); color: var(--text-1); }
.cs-option--active { background: var(--primary-dim); color: var(--primary); font-weight: 600; }
.cs-option-text { flex: 1; }

/* ── Plan Picker (ws-picker style) ── */
.plan-picker { position: relative; }
.plan-picker__trigger {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 14px; background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px; font-weight: 600;
    color: var(--text-1); transition: all .15s;
}
.plan-picker__trigger:hover { border-color: var(--primary); }
.plan-picker.open .plan-picker__trigger {
    border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-dim);
}
.plan-picker__label { flex: 1; }
.plan-picker__arrow { flex-shrink: 0; opacity: .4; transition: transform .2s; }
.plan-picker.open .plan-picker__arrow { transform: rotate(180deg); }
.plan-picker__dropdown {
    position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; z-index: 300;
    background: var(--bg-white); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: 0 -12px 32px rgba(0,0,0,.12);
    overflow: hidden;
}
.plan-picker__search {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-4);
}
.plan-picker__search input {
    border: none; background: transparent; outline: none;
    font-size: 13px; font-family: inherit; color: var(--text-1); flex: 1;
}
.plan-picker__search input::placeholder { color: var(--text-4); }
.plan-picker__list { max-height: 240px; overflow-y: auto; padding: 4px; }
.plan-picker__item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-xs);
    cursor: pointer; font-size: 13px; color: var(--text-2); transition: all .1s;
    border: none; background: none; width: 100%; text-align: left; font-family: inherit;
}
.plan-picker__item:hover { background: var(--bg-hover); color: var(--text-1); }
.plan-picker__item--active { background: var(--primary-dim); color: var(--primary); font-weight: 600; }
.plan-picker__item-icon {
    width: 28px; height: 28px; border-radius: 6px;
    background: var(--primary-dim); color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.plan-picker__item--active .plan-picker__item-icon { background: var(--primary); color: #fff; }
.plan-picker__item-info { flex: 1; min-width: 0; }
.plan-picker__item-name { font-weight: 600; }
.plan-picker__item-desc { font-size: 11px; color: var(--text-4); }
.plan-picker__item--active .plan-picker__item-desc { color: var(--primary); opacity: .6; }
.plan-picker__item-check { color: var(--primary); flex-shrink: 0; opacity: 0; }
.plan-picker__item--active .plan-picker__item-check { opacity: 1; }

/* ── Multi-Select (chip toggle) ── */
.ms-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ms-chip-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: 100px;
    border: 1px solid var(--border); background: var(--bg-white);
    font-size: 12px; font-weight: 500; font-family: inherit;
    color: var(--text-2); cursor: pointer; transition: all .15s;
    white-space: nowrap;
}
.ms-chip-toggle:hover { border-color: var(--primary); color: var(--text-1); }
.ms-chip-toggle--on {
    border-color: var(--primary); background: var(--bg-white);
    color: var(--text-1); font-weight: 600;
}
.ms-check {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid var(--border); display: flex;
    align-items: center; justify-content: center;
    flex-shrink: 0; transition: all .15s;
}
.ms-chip-toggle--on .ms-check {
    background: var(--primary); border-color: var(--primary);
}

.param-row > input,
.param-row > select {
    min-width: 0;
}
.param-row .param-remove {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
}

/* ── Empty State ── */
.empty-state { text-align: center; padding: 48px 24px; font-size: 14px; color: var(--text-3); }

/* ── Contact Section Label ── */
.contact-section-label {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.5px; color: var(--text-4); padding: 12px 12px 4px;
}
