/* ====================================================================
   TÁCH CÂU & TẠO PROMPT - Public CSS
   Layout 1 cột, style đồng bộ với bản nội bộ.
   ==================================================================== */

:root {
    --tctp-red: #ff0000;
    --tctp-red-dark: #cc0000;
    --tctp-red-deep: #8b0000;
    --tctp-bg: #f7f7f8;
    --tctp-card: #ffffff;
    --tctp-border: #e3e3e3;
    --tctp-text: #161616;
    --tctp-muted: #666666;
}

#tctp-app {
    box-sizing: border-box;
    width: 100%;
    color: var(--tctp-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#tctp-app *, #tctp-app *::before, #tctp-app *::after { box-sizing: border-box; }

/* ----- Tab Bar ----- */
.tctp-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--tctp-border);
    margin: 28px 0 20px;
    overflow-x: auto;
    padding: 0 32px;
}
.tctp-tab {
    padding: 12px 24px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: #666;
    letter-spacing: 0.5px;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.tctp-tab:hover { color: var(--tctp-red-dark); background: #fff6f6; }
.tctp-tab.tctp-tab-active {
    color: var(--tctp-red-deep);
    border-bottom-color: var(--tctp-red);
    background: #fff6f6;
}

/* ----- Panes ----- */
.tctp-pane { display: none; }
.tctp-pane.tctp-pane-active { display: block; }

.tctp-shell {
    width: 100%;
    max-width: 100%;
    margin: 0 0 28px 0;
    padding: 20px 32px;
}
.tctp-h2 {
    font-size: 22px;
    margin: 0 0 12px;
    color: var(--tctp-red-deep);
}

/* ----- Privacy Banner ----- */
.tctp-privacy-banner {
    background: linear-gradient(135deg, #fff6f6 0%, #fff0f0 100%);
    border: 1px solid #f0d4d4;
    border-left: 4px solid var(--tctp-red);
    padding: 14px 18px;
    margin-bottom: 20px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.6;
    color: #4a2c2c;
}

/* ----- Onboarding Hint ----- */
.tctp-onboard-hint {
    background: #fff8e1;
    border-left: 4px solid #f5b800;
    padding: 12px 16px;
    margin-bottom: 16px;
    border-radius: 12px;
    font-size: 13px;
}
.tctp-onboard-hint a { color: var(--tctp-red-dark); text-decoration: underline; }

/* ----- 1-Column Grid (giống bản gốc) ----- */
.tctp-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}
.tctp-card {
    background: var(--tctp-card);
    border: 1px solid var(--tctp-border);
    border-radius: 18px;
    padding: 20px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.04);
}
.tctp-card-full { width: 100%; }
.tctp-card h3 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 18px;
    color: var(--tctp-red-deep);
}

.tctp-label {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
    margin-top: 12px;
    color: #2a2a2a;
}
.tctp-hint-inline {
    font-weight: normal;
    color: var(--tctp-muted);
    font-size: 12px;
}

#tctp-app input[type="text"],
#tctp-app input[type="password"],
#tctp-app input[type="number"],
#tctp-app textarea,
#tctp-app select {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid #d9d9d9;
    border-radius: 12px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--tctp-text);
}
#tctp-app textarea { resize: vertical; line-height: 1.5; }
#tctp-app input:focus,
#tctp-app textarea:focus,
#tctp-app select:focus {
    outline: none;
    border-color: var(--tctp-red);
    box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.08);
}

/* ----- Save Requirement Row ----- */
.tctp-save-row {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.tctp-save-hint {
    font-size: 12px;
    color: var(--tctp-muted);
}

/* ----- Content Type ----- */
.tctp-content-type {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}
.tctp-content-type-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border: 1px solid #d9d9d9;
    border-radius: 12px;
    background: #fff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin: 0;
    transition: border-color .15s, background .15s;
}
.tctp-content-type-item input[type="radio"] {
    width: 17px;
    height: 17px;
    margin: 0;
    accent-color: var(--tctp-red);
    cursor: pointer;
}
.tctp-content-type-item:hover { border-color: var(--tctp-red); }
.tctp-content-type-item.tctp-active {
    border-color: var(--tctp-red);
    background: rgba(255, 0, 0, 0.05);
}
.tctp-content-type-help { margin-left: 0; }

/* ----- Split Options ----- */
.tctp-split-options { margin-top: 6px; }
.tctp-split-option-row.tctp-opt-disabled,
.tctp-split-option-help.tctp-opt-disabled {
    opacity: .45;
}
.tctp-split-option-row.tctp-opt-disabled .tctp-split-option-label,
.tctp-split-option-row.tctp-opt-disabled input { cursor: not-allowed; }
.tctp-split-option-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}
.tctp-split-option-label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    margin: 0;
    font-weight: normal;
    color: var(--tctp-text);
    white-space: nowrap;
    cursor: pointer;
}
.tctp-split-option-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--tctp-red);
    cursor: pointer;
}
#tctp-app .tctp-split-option-row input[type="number"] {
    width: 90px;
    flex: 0 0 90px;
    padding: 8px 10px;
    text-align: center;
}
.tctp-split-option-help { font-size: 12px; color: var(--tctp-muted); margin-bottom: 10px; margin-left: 26px; }

/* ----- Buttons ----- */
.tctp-btn {
    padding: 10px 16px;
    border: 1px solid var(--tctp-red);
    background: #fff;
    color: var(--tctp-red-dark);
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.12s ease;
    line-height: 1.2;
}
.tctp-btn:hover { background: var(--tctp-red); color: #fff; }
.tctp-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f0f0f0;
    color: #999;
    border-color: #ccc;
}
.tctp-btn:disabled:hover { background: #f0f0f0; color: #999; }

.tctp-btn-primary { background: var(--tctp-red); color: #fff; }
.tctp-btn-primary:hover { background: var(--tctp-red-dark); border-color: var(--tctp-red-dark); }

.tctp-btn-secondary {
    background: #fff6f6;
    border-color: #f0c4c4;
    color: var(--tctp-red-dark);
}

.tctp-btn-gray {
    border-color: #c8c8c8;
    color: #555;
}
.tctp-btn-gray:hover { background: #555; color: #fff; border-color: #555; }

.tctp-btn-danger {
    border-color: #d63638;
    color: #d63638;
    background: #fff;
}
.tctp-btn-danger:hover { background: #d63638; color: #fff; }

.tctp-button-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    margin: 8px 0 4px;
}

/* Override .tctp-btn riêng cho nhóm Thao tác - xanh dương, to, nổi */
.tctp-button-group .tctp-btn {
    padding: 14px 26px;
    font-size: 15px;
    font-weight: 700;
    background: #2271b1;
    color: #fff;
    border-color: #2271b1;
    box-shadow: 0 4px 12px rgba(34, 113, 177, 0.22);
    min-width: 140px;
    border-radius: 12px;
    transition: all 0.15s ease;
}
.tctp-button-group .tctp-btn:hover:not(:disabled) {
    background: #1a5a96;
    border-color: #1a5a96;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(34, 113, 177, 0.32);
}
.tctp-button-group .tctp-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(34, 113, 177, 0.25);
}

/* "Chạy tất cả" - nhấn mạnh hơn bằng gradient */
.tctp-button-group .tctp-btn-primary {
    background: linear-gradient(135deg, #1e40af 0%, #2271b1 100%);
    border-color: #1e40af;
    box-shadow: 0 4px 14px rgba(30, 64, 175, 0.32);
}
.tctp-button-group .tctp-btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #1e3a8a 0%, #1a5a96 100%);
    border-color: #1e3a8a;
    box-shadow: 0 6px 18px rgba(30, 64, 175, 0.42);
}

/* "Xóa tất cả" - xám */
.tctp-button-group .tctp-btn-gray {
    background: #6b7280;
    border-color: #6b7280;
    color: #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}
.tctp-button-group .tctp-btn-gray:hover:not(:disabled) {
    background: #4b5563;
    border-color: #4b5563;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.18);
}

#tctp-status-box {
    margin-top: 16px;
    padding: 12px 16px;
    background: #fff6f6;
    border-left: 3px solid var(--tctp-red);
    font-size: 14px;
    border-radius: 0 12px 12px 0;
    color: #4a2c2c;
}

/* ----- Table (result) ----- */
.tctp-result-title {
    margin: 0 0 12px;
    font-size: 18px;
    color: var(--tctp-red-deep);
}
.tctp-table-view-mode {
    font-size: 14px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}
#tctp-app .tctp-table-view-mode select {
    width: auto;
    display: inline-block;
    padding: 6px 10px;
    flex: 0 0 auto;
    min-width: 100px;
}
.tctp-table-hint {
    margin: 0 0 12px;
    padding: 10px 14px;
    background: #fff8e1;
    border-left: 3px solid #f5b800;
    border-radius: 0 10px 10px 0;
    font-size: 13px;
    color: #5a4a1a;
    line-height: 1.5;
}
.tctp-table-hint strong { color: #1a1a1a; }
.tctp-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--tctp-border);
    border-radius: 12px;
    background: #fff;
}
#tctp-result-main-table,
#tctp-req-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    background: #fff;
}
#tctp-result-main-table th,
#tctp-result-main-table td,
#tctp-req-table th,
#tctp-req-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    text-align: left;
    vertical-align: top;
}
#tctp-result-main-table th,
#tctp-req-table th {
    background: #fff6f6;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--tctp-red-deep);
}
.tctp-copyable-col { cursor: pointer; }
.tctp-copyable-col:hover { background: #ffe8e8; }

#tctp-result-main-table td.cell-clip {
    max-width: 280px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#tctp-result-main-table td.cell-wrap {
    max-width: 280px;
    white-space: normal;
    word-wrap: break-word;
}

/* ----- API Tab: Provider Cards ----- */
.tctp-provider-card {
    background: var(--tctp-card);
    border: 1px solid var(--tctp-border);
    border-radius: 18px;
    padding: 18px 22px;
    margin-bottom: 16px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.03);
}
.tctp-provider-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 8px;
}
.tctp-provider-name {
    font-size: 17px;
    font-weight: 700;
    color: var(--tctp-red-deep);
}
.tctp-provider-badge {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #fff6f6;
    color: var(--tctp-red-dark);
    font-weight: 600;
    border: 1px solid #f0d4d4;
}
.tctp-provider-toggle { display: flex; align-items: center; gap: 8px; }
.tctp-provider-toggle label { cursor: pointer; margin: 0; }
.tctp-provider-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--tctp-red);
}

.tctp-provider-fields { display: grid; gap: 10px; margin-top: 10px; }
.tctp-field-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tctp-field-row label {
    width: 80px;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}
.tctp-field-row input,
.tctp-field-row select { flex: 1; min-width: 220px; }
.tctp-field-row .tctp-input-with-eye {
    flex: 1;
    min-width: 220px;
    position: relative;
}
.tctp-input-with-eye input {
    width: 100%;
    padding-right: 44px !important;
}
.tctp-eye-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 6px 8px;
    font-size: 17px;
    line-height: 1;
    border-radius: 8px;
    user-select: none;
    transition: background 0.12s ease;
}
.tctp-eye-toggle:hover {
    background: #fff0f0;
}
.tctp-eye-toggle:active {
    background: #ffd6d6;
}

.tctp-api-link {
    margin-left: 92px;
    margin-top: -4px;
    font-size: 13px;
}
.tctp-api-link a { color: var(--tctp-red-dark); text-decoration: none; font-weight: 500; }
.tctp-api-link a:hover { text-decoration: underline; }

.tctp-autosave-note {
    margin-top: 18px;
    padding: 10px 14px;
    border: 1px solid #cde9d3;
    background: #f2fbf4;
    border-radius: 12px;
    font-size: 13px;
    color: #2e5c3a;
    transition: background .2s, border-color .2s;
}
.tctp-autosave-note.tctp-autosave-saved {
    border-color: #9ed3ae;
    background: #e4f7e9;
}
.tctp-autosave-note.tctp-autosave-warn {
    border-color: #f0cf9a;
    background: #fff8ec;
    color: #7a5314;
}
.tctp-autosave-note.tctp-autosave-error {
    border-color: #f0aaa5;
    background: #fdeceb;
    color: #97231c;
}

.tctp-api-actions {
    margin-top: 14px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ----- Requirements Tab ----- */
.tctp-req-actions {
    margin-top: 20px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.tctp-req-edit-btn {
    background: transparent;
    border: 1px solid #d9d9d9;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    padding: 6px 12px;
    line-height: 1;
    transition: all 0.12s ease;
}
.tctp-req-edit-btn:hover {
    background: #fff6f6;
    border-color: var(--tctp-red);
}

#tctp-req-summary { color: var(--tctp-muted); font-size: 14px; margin-bottom: 14px; }

/* ----- Modal ----- */
.tctp-modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.tctp-modal-overlay.tctp-modal-open { display: flex; }
.tctp-modal {
    background: #fff;
    border-radius: 18px;
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.tctp-modal-head {
    padding: 18px 22px;
    border-bottom: 1px solid var(--tctp-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.tctp-modal-head h3 { margin: 0; font-size: 18px; color: var(--tctp-red-deep); }
.tctp-modal-close {
    background: transparent;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #888;
    line-height: 1;
    padding: 0 4px;
}
.tctp-modal-close:hover { color: #d63638; }
.tctp-modal-body {
    padding: 18px 22px;
    overflow-y: auto;
    flex: 1;
}
.tctp-modal-foot {
    padding: 14px 22px;
    border-top: 1px solid var(--tctp-border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* ----- Toast (fixed góc phải, dùng cho thông báo chung) ----- */
#tctp-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.tctp-toast {
    background: #1a1a1a;
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
    animation: tctp-toast-in 0.2s ease-out;
    max-width: 340px;
}
.tctp-toast.tctp-toast-success { background: #178a3a; }
.tctp-toast.tctp-toast-error { background: #d63638; }
@keyframes tctp-toast-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ----- Inline Toast - hiện ngay cạnh element vừa bấm ----- */
.tctp-inline-toast {
    position: absolute;
    background: #178a3a;
    color: #fff;
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    z-index: 10001;
    pointer-events: none;
    white-space: nowrap;
    transition: opacity 0.25s ease, transform 0.25s ease;
    animation: tctp-inline-toast-pop 0.18s ease-out;
}
.tctp-inline-toast::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #178a3a;
}
.tctp-inline-toast-error {
    background: #d63638;
}
.tctp-inline-toast-error::after {
    border-top-color: #d63638;
}
.tctp-inline-toast-below::after {
    bottom: auto;
    top: -6px;
    border-top: none;
    border-bottom: 6px solid #178a3a;
}
.tctp-inline-toast-below.tctp-inline-toast-error::after {
    border-bottom-color: #d63638;
}
@keyframes tctp-inline-toast-pop {
    from { transform: scale(0.85) translateY(4px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

/* ----- Responsive ----- */
@media (max-width: 768px) {
    .tctp-shell { padding: 14px; }
    .tctp-tabs { padding: 0 14px; }
    .tctp-tab { padding: 10px 14px; font-size: 13px; }
    .tctp-field-row label { width: auto; }
    .tctp-api-link { margin-left: 0; }
    .tctp-card { padding: 16px; }
}

/* ====================================================================
   Nơi lưu dữ liệu (trình duyệt / tài khoản) + khung yêu cầu đăng nhập
   ==================================================================== */

.tctp-storage-picker {
    background: var(--tctp-card);
    border: 1px solid var(--tctp-border);
    border-radius: 14px;
    padding: 16px 18px;
    margin-bottom: 16px;
}

.tctp-storage-picker.is-busy {
    opacity: .55;
    pointer-events: none;
}

.tctp-storage-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    font-size: 15px;
}

.tctp-storage-current {
    font-size: 12px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 99px;
    background: #eef2ff;
    color: #3730a3;
}

.tctp-storage-current.is-server {
    background: #dcfce7;
    color: #166534;
}

.tctp-storage-opts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.tctp-storage-opt {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border: 1px solid var(--tctp-border);
    border-radius: 12px;
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.tctp-storage-opt:hover {
    border-color: #b9c0cc;
    background: #fafbfc;
}

.tctp-storage-opt input {
    margin-top: 3px;
    flex: 0 0 auto;
}

.tctp-storage-opt strong {
    display: block;
    font-size: 14px;
    margin-bottom: 3px;
}

.tctp-storage-opt small {
    display: block;
    color: var(--tctp-muted);
    font-size: 12px;
    line-height: 1.5;
}

.tctp-privacy-banner.tctp-privacy-server {
    background: linear-gradient(135deg, #f2fbf5 0%, #ecfaf1 100%);
    border-color: #cbe9d5;
    border-left-color: #16a34a;
    color: #22402c;
}

.tctp-key-forget {
    margin-left: 12px;
    border: none;
    background: none;
    padding: 0;
    color: #b91c1c;
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline;
}

/* ----- Khung yêu cầu đăng nhập (dùng khi chưa cài Sơn Zim Auth) ----- */

.tctp-gate {
    max-width: 460px;
    margin: 40px auto;
    background: var(--tctp-card);
    border: 1px solid var(--tctp-border);
    border-radius: 18px;
    padding: 34px 28px;
    text-align: center;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .08);
}

.tctp-gate-icon {
    font-size: 40px;
    line-height: 1;
    margin-bottom: 10px;
}

.tctp-gate h3 {
    margin: 0 0 10px;
    font-size: 22px;
}

.tctp-gate p {
    margin: 0 0 20px;
    color: var(--tctp-muted);
    font-size: 14px;
    line-height: 1.6;
}

.tctp-gate .login-username,
.tctp-gate .login-password {
    text-align: left;
    margin-bottom: 12px;
}

.tctp-gate label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 5px;
}

.tctp-gate input[type="text"],
.tctp-gate input[type="password"] {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 12px;
    border: 1px solid var(--tctp-border);
    border-radius: 10px;
    font-size: 14px;
}

.tctp-gate .button,
.tctp-gate #wp-submit {
    width: 100%;
    background: var(--tctp-red);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 12px 18px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
}

.tctp-gate-alt {
    margin: 14px 0 0;
    font-size: 13px;
}

.tctp-storage-opt.is-disabled {
    opacity: .55;
    cursor: not-allowed;
    background: #fafafa;
}
