/*
|--------------------------------------------------------------------------
| AI Data Chat workspace
|--------------------------------------------------------------------------
*/

.aidata-workspace {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0;
    align-items: stretch;
    box-sizing: border-box;
}


/*
|--------------------------------------------------------------------------
| Shared panel styles
|--------------------------------------------------------------------------
*/

.aidata-schema-shell,
.aidata-chat-shell {
    min-width: 0;
    height: calc(100vh - 170px);
    min-height: 720px;

    background: #ffffff;
    border: 1px solid #dce5ee;
    border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 18px 48px rgba(20, 53, 79, 0.10);
}

.aidata-chat-shell {
    width: 100%;
}

.aidata-chat-messages {
    width: 100%;
    box-sizing: border-box;
}

/*
|--------------------------------------------------------------------------
| Database explorer
|--------------------------------------------------------------------------
*/

.aidata-schema-shell {
    display: flex;
    flex-direction: column;
}

.aidata-schema-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: 28px 30px 22px;
    border-bottom: 1px solid #e5edf4;
    background: linear-gradient(
        135deg,
        #f8fbfd 0%,
        #eef5fa 100%
    );
}

.aidata-schema-header h2 {
    margin: 0 0 6px;
    font-size: 30px;
    line-height: 1.15;
    color: #102f49;
}

.aidata-schema-header p {
    margin: 0;
    font-size: 14px;
    color: #667b8d;
}

#aidata-schema-refresh {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 9px 16px;
    border: 1px solid #b8cedd;
    border-radius: 10px;
    background: #ffffff;
    color: #1475a7;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        transform 0.2s ease;
}

#aidata-schema-refresh:hover {
    background: #edf7fc;
    border-color: #1797cf;
}

#aidata-schema-refresh:active {
    transform: translateY(1px);
}

#aidata-schema-refresh:disabled {
    cursor: wait;
    opacity: 0.6;
}


/*
|--------------------------------------------------------------------------
| Schema search and status
|--------------------------------------------------------------------------
*/

.aidata-schema-tools {
    padding: 18px 30px 12px;
}

#aidata-schema-search {
    width: 100%;
    min-height: 46px;
    padding: 11px 14px;
    border: 1px solid #ccd9e3;
    border-radius: 11px;
    background: #ffffff;
    color: #183448;
    font-size: 15px;
    outline: none;
    box-sizing: border-box;
}

#aidata-schema-search:focus {
    border-color: #168ac1;
    box-shadow: 0 0 0 3px rgba(22, 138, 193, 0.12);
}

.aidata-schema-status {
    padding: 0 30px 15px;
    color: #718494;
    font-size: 13px;
    line-height: 1.5;
}


/*
|--------------------------------------------------------------------------
| Schema tree
|--------------------------------------------------------------------------
*/

.aidata-schema-tree {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0 30px 30px;
    scrollbar-width: thin;
}

.aidata-schema-table {
    margin: 0 0 10px;
    border: 1px solid #dce6ee;
    border-radius: 12px;
    background: #ffffff;
    overflow: hidden;
}

.aidata-schema-table[open] {
    box-shadow: 0 8px 22px rgba(30, 73, 101, 0.08);
}

.aidata-table-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 48px;
    padding: 11px 15px;
    cursor: pointer;
    list-style: none;
    background: #f7fafc;
    color: #18364c;
    user-select: none;
}

.aidata-table-summary::-webkit-details-marker {
    display: none;
}

.aidata-table-summary::before {
    content: "▶";
    flex: 0 0 auto;
    margin-right: 2px;
    color: #5c7b90;
    font-size: 10px;
    transition: transform 0.2s ease;
}

.aidata-schema-table[open] > .aidata-table-summary::before {
    transform: rotate(90deg);
}

.aidata-table-name {
    flex: 1;
    min-width: 0;
    font-size: 15px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.aidata-table-meta {
    flex: 0 0 auto;
    color: #7890a1;
    font-size: 12px;
    white-space: nowrap;
}

.aidata-table-body {
    padding: 18px;
    border-top: 1px solid #e2eaf0;
}

.aidata-schema-section-title {
    margin: 0 0 12px;
    font-size: 15px;
    line-height: 1.3;
    color: #15354d;
}

.aidata-schema-section-title:not(:first-child) {
    margin-top: 24px;
}


/*
|--------------------------------------------------------------------------
| Column list
|--------------------------------------------------------------------------
*/

.aidata-columns-list {
    display: grid;
    gap: 8px;
}

.aidata-column-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 40px;
    padding: 9px 12px;
    border: 1px solid #e1e9ef;
    border-radius: 9px;
    background: #fbfdfe;
}

.aidata-column-name {
    min-width: 0;
    color: #15374e;
    font-size: 13px;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.aidata-column-type {
    min-width: 0;
    color: #607a8c;
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.aidata-column-key,
.aidata-column-required {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
}

.aidata-column-key {
    background: #e6f5fd;
    color: #087bb4;
}

.aidata-column-required {
    background: #eef1f4;
    color: #566a79;
}


/*
|--------------------------------------------------------------------------
| Sample data table
|--------------------------------------------------------------------------
*/

.aidata-sample-wrapper {
    width: 100%;
    overflow: auto;
    border: 1px solid #dde6ed;
    border-radius: 10px;
}

.aidata-sample-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    background: #ffffff;
    font-size: 12px;
}

.aidata-sample-table th,
.aidata-sample-table td {
    padding: 10px 12px;
    border-right: 1px solid #e2e8ed;
    border-bottom: 1px solid #e2e8ed;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.aidata-sample-table th:last-child,
.aidata-sample-table td:last-child {
    border-right: 0;
}

.aidata-sample-table tbody tr:last-child td {
    border-bottom: 0;
}

.aidata-sample-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f3f7fa;
    color: #435e72;
    font-weight: 700;
}

.aidata-sample-table td {
    color: #60798b;
}

.aidata-empty-message {
    margin: 0;
    padding: 14px;
    color: #7a8e9d;
    font-size: 13px;
}


/*
|--------------------------------------------------------------------------
| Chat shell
|--------------------------------------------------------------------------
*/

.aidata-chat-shell {
    display: flex;
    flex-direction: column;
}

.aidata-chat-header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 22px 22px;
    background: linear-gradient(
        135deg,
        #10344f 0%,
        #1d658d 100%
    );
    color: #ffffff;
}

.aidata-chat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 13px;
    background: rgba(255, 255, 255, 0.10);
    font-weight: 700;
}

.aidata-chat-title {
    min-width: 0;
}

.aidata-chat-title h1 {
    margin: 0 0 5px;
    color: #ffffff;
    font-size: 20px;
    line-height: 1.2;
}

.aidata-chat-title p {
    margin: 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 12px;
    line-height: 1.4;
}

.aidata-chat-header-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    font-size: 12px;
}

.aidata-chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.aidata-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #42dd8b;
    box-shadow: 0 0 0 5px rgba(66, 221, 139, 0.15);
}

.aidata-chat-user {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/*
|--------------------------------------------------------------------------
| Chat messages
|--------------------------------------------------------------------------
*/

.aidata-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 22px 18px;
    background: #f2f7fa;
}

.aidata-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 18px;
}

.aidata-user-message {
    flex-direction: row-reverse;
}

.aidata-avatar {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: 10px;
    background: #167da9;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    box-sizing: border-box;
}

.aidata-user-message .aidata-avatar {
    background: #173448;
}

.aidata-message-content {
    max-width: 82%;
    padding: 14px 16px;
    border: 1px solid #d4e1e9;
    border-radius: 15px;
    background: #ffffff;
    color: #173348;
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.aidata-user-message .aidata-message-content {
    border-color: #197da9;
    background: #197da9;
    color: #ffffff;
}


/*
|--------------------------------------------------------------------------
| Chat examples and form
|--------------------------------------------------------------------------
*/

.aidata-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px 18px 10px;
    border-top: 1px solid #dce6ed;
    background: #ffffff;
}

.aidata-examples button {
    padding: 7px 11px;
    border: 1px solid #bfd2df;
    border-radius: 999px;
    background: #ffffff;
    color: #315d78;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
}

.aidata-examples button:hover {
    border-color: #168bc2;
    color: #087cb4;
}

.aidata-chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 0 18px 14px;
    background: #ffffff;
}

#aidata-chat-input {
    width: 100%;
    min-height: 56px;
    max-height: 140px;
    resize: vertical;
    padding: 14px;
    border: 1px solid #c8d8e3;
    border-radius: 12px;
    color: #173448;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    box-sizing: border-box;
    outline: none;
}

#aidata-chat-input:focus {
    border-color: #168bc2;
    box-shadow: 0 0 0 3px rgba(22, 139, 194, 0.12);
}

#aidata-chat-send {
    min-width: 88px;
    padding: 0 17px;
    border: 0;
    border-radius: 12px;
    background: #167aa6;
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
}

#aidata-chat-send:hover {
    background: #12698f;
}

#aidata-chat-send:disabled {
    cursor: wait;
    opacity: 0.6;
}

.aidata-chat-disclaimer {
    margin: 0;
    padding: 0 18px 16px;
    background: #ffffff;
    color: #8697a4;
    font-size: 10px;
    line-height: 1.4;
    text-align: center;
}


/*
|--------------------------------------------------------------------------
| WordPress helpers
|--------------------------------------------------------------------------
*/

.screen-reader-text {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/*
|--------------------------------------------------------------------------
| Full-width WordPress integration
|--------------------------------------------------------------------------
*/

.aidata-workspace,
.aidata-workspace * {
    box-sizing: border-box;
}

.entry-content:has(.aidata-workspace),
.wp-block-post-content:has(.aidata-workspace),
.site-main:has(.aidata-workspace) {
    width: 100% !important;
    max-width: none !important;
}

.entry-content:has(.aidata-workspace),
.wp-block-post-content:has(.aidata-workspace) {
    padding-left: 24px !important;
    padding-right: 24px !important;
}


/*
|--------------------------------------------------------------------------
| Rich assistant responses
|--------------------------------------------------------------------------
*/

.aidata-assistant-message {
    width: 100%;
}

.aidata-assistant-message .aidata-message-content {
    max-width: calc(100% - 52px);
}

.aidata-assistant-message:has(.aidata-chart-wrapper)
.aidata-message-content,
.aidata-assistant-message:has(.aidata-response-table-wrapper)
.aidata-message-content {
    width: calc(100% - 52px);
    max-width: calc(100% - 52px);
}

.aidata-response-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.55;
}

.aidata-response-description {
    margin: 0 0 14px;
    white-space: pre-wrap;
    line-height: 1.5;
}

.aidata-response-error {
    margin: 0;
    color: #b42318;
    line-height: 1.5;
}

.aidata-response-table-wrapper {
    width: 100%;
    overflow-x: auto;
    border: 1px solid #dce6ed;
    border-radius: 10px;
    background: #ffffff;
}

.aidata-response-table {
    width: 100%;
    min-width: 500px;
    border-collapse: collapse;
    font-size: 12px;
}

.aidata-response-table th,
.aidata-response-table td {
    padding: 9px 11px;
    border-right: 1px solid #e1e8ed;
    border-bottom: 1px solid #e1e8ed;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.aidata-response-table th {
    background: #f2f7fa;
    color: #294d64;
    font-weight: 700;
}

.aidata-response-table th:last-child,
.aidata-response-table td:last-child {
    border-right: 0;
}

.aidata-response-table tbody tr:last-child td {
    border-bottom: 0;
}

.aidata-response-table-footer {
    margin-top: 8px;
    color: #718494;
    font-size: 11px;
}

.aidata-chart-wrapper {
    position: relative;
    width: 100%;
    height: 380px;
    margin-top: 14px;
}

.aidata-column-separator {
    color: #9aaab6;
}


/*
|--------------------------------------------------------------------------
| Responsive layout
|--------------------------------------------------------------------------
*/

@media (max-width: 1000px) {
    .entry-content:has(.aidata-workspace),
    .wp-block-post-content:has(.aidata-workspace) {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    .aidata-workspace {
        grid-template-columns: 1fr;
        gap: 18px;
        width: 100%;
        max-width: none;
        margin: 0 auto;
    }

    .aidata-schema-shell,
    .aidata-chat-shell {
        height: 720px;
        min-height: 0;
    }
}

@media (max-width: 850px) {
    .aidata-schema-shell,
    .aidata-chat-shell {
        height: 680px;
    }

    .aidata-schema-header {
        padding: 22px;
    }

    .aidata-schema-tools,
    .aidata-schema-status,
    .aidata-schema-tree {
        padding-left: 22px;
        padding-right: 22px;
    }
}

@media (max-width: 560px) {
    .aidata-workspace {
        gap: 14px;
    }

    .aidata-schema-shell,
    .aidata-chat-shell {
        height: 640px;
        border-radius: 15px;
    }

    .aidata-schema-header {
        flex-direction: column;
        align-items: stretch;
    }

    #aidata-schema-refresh {
        width: 100%;
    }

    .aidata-column-row {
        align-items: flex-start;
        gap: 6px;
    }

    .aidata-chat-header {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .aidata-chat-header-meta {
        grid-column: 1 / -1;
        align-items: flex-start;
        padding-left: 62px;
    }

    .aidata-chat-form {
        grid-template-columns: 1fr;
    }

    #aidata-chat-send {
        min-height: 48px;
    }

    .aidata-message-content,
    .aidata-assistant-message .aidata-message-content {
        max-width: 88%;
    }

    .aidata-assistant-message:has(.aidata-chart-wrapper)
    .aidata-message-content,
    .aidata-assistant-message:has(.aidata-response-table-wrapper)
    .aidata-message-content {
        width: calc(100% - 46px);
        max-width: calc(100% - 46px);
    }

    .aidata-chart-wrapper {
        height: 300px;
    }
}


/* ---------- Compact welcome message ---------- */

.aidata-welcome-message {
    margin-bottom: 14px;
}

.aidata-welcome {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 18px 20px;
    white-space: normal;
}

.aidata-welcome-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0 0 10px;
    color: #173348;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
}

.aidata-welcome-text {
    max-width: 440px;
    margin: 0 auto 14px;
    color: #53697a;
    font-size: 14px;
    line-height: 1.55;
    text-align: center;
}

.aidata-welcome-section {
    max-width: 440px;
    margin: 0 auto;
    padding: 13px 16px;
    border: 1px solid #dfe8ef;
    border-radius: 11px;
    background: #f7fafc;
}

.aidata-welcome-section-title {
    margin: 0 0 7px;
    color: #18334f;
    font-size: 13px;
    font-weight: 700;
}

.aidata-welcome-list {
    display: grid;
    gap: 5px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.aidata-welcome-list li {
    position: relative;
    margin: 0;
    padding-left: 16px;
    color: #4d6577;
    font-size: 13px;
    line-height: 1.4;
}

.aidata-welcome-list li::before {
    position: absolute;
    left: 0;
    content: "•";
    color: #168bc2;
    font-weight: 700;
}

@media (max-width: 700px) {
    .aidata-welcome {
        padding: 15px;
    }

    .aidata-welcome-title {
        font-size: 19px;
    }

    .aidata-welcome-text {
        font-size: 13px;
    }

    .aidata-welcome-section {
        padding: 11px 13px;
    }
}
