/* ============================================================
   AI Report Viewer — [midas_ai_report] & [midas_ai_report_public]
   ============================================================ */

/* ── Wrapper ─────────────────────────────────────────────── */
.midas-ai-report-wrap {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: #1a1a1a;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

.midas-ai-report-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    color: #555;
    font-size: 15px;
}

.midas-ai-report-loading .spinner {
    flex-shrink: 0;
}

.midas-ai-report-error,
.midas-ar-error {
    background: #fff3f3;
    border: 1px solid #e57373;
    border-radius: 6px;
    padding: 16px 20px;
    color: #c62828;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
}

/* ── Report Header ───────────────────────────────────────── */
.midas-ar-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 16px;
    border-bottom: 2px solid #e3f2fd;
    margin-bottom: 0;
    flex-wrap: wrap;
}

.midas-ar-meta {
    flex: 1 1 220px;
    min-width: 220px;
}

.midas-ar-title {
    font-size: 22px;
    font-weight: 700;
    color: #0d47a1;
    margin: 0 0 4px 0;
    line-height: 1.3;
}

.midas-ar-date {
    font-size: 12px;
    color: #888;
}

.midas-ar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    flex-shrink: 0;
}

/* ── Buttons ─────────────────────────────────────────────── */
.midas-ar-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    white-space: nowrap;
    line-height: 1.5;
}

.midas-ar-btn .dashicons {
    font-size: 15px;
    width: 15px;
    height: 15px;
}

.midas-ar-btn--primary {
    background: #1565c0;
    color: #fff;
    border-color: #1565c0;
}

.midas-ar-btn--primary:hover {
    background: #0d47a1;
    border-color: #0d47a1;
    color: #fff;
}

.midas-ar-btn--secondary {
    background: #fff;
    color: #333;
    border-color: #c5c5c5;
}

.midas-ar-btn--secondary:hover {
    background: #f0f4f8;
    border-color: #1565c0;
    color: #1565c0;
}

.midas-ar-btn.is-active {
    background: #e3f2fd;
    border-color: #1565c0;
    color: #1565c0;
}

.midas-ar-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ── Edit Hint ───────────────────────────────────────────── */
.midas-ar-edit-hint {
    background: #e3f2fd;
    border-left: 3px solid #1565c0;
    padding: 8px 14px;
    font-size: 13px;
    color: #0d47a1;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ── Report Body (iframe) ────────────────────────────────── */
.midas-ar-body {
    width: 100%;
    flex: 1;
}

.midas-ar-body iframe,
#midas-ar-iframe {
    width: 100%;
    height: calc(100vh - 200px);
    min-height: 400px;
    border: none;
    display: block;
    background: #fff;
}

/* ── Dialogs ─────────────────────────────────────────────── */
.midas-ar-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.midas-ar-dialog {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.22);
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
}

.midas-ar-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.midas-ar-dialog-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.midas-ar-dialog-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #888;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
}

.midas-ar-dialog-close:hover {
    background: #f5f5f5;
    color: #333;
}

.midas-ar-dialog-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.midas-ar-dialog-hint {
    font-size: 13px;
    color: #555;
    margin: 0 0 16px 0;
    line-height: 1.5;
}

.midas-ar-dialog-footer {
    padding: 14px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-shrink: 0;
}

/* ── Form Elements in Dialogs ────────────────────────────── */
.midas-ar-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #444;
    margin-bottom: 5px;
}

.midas-ar-input {
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 7px 10px;
    font-size: 13px;
    box-sizing: border-box;
    transition: border-color 0.15s;
}

.midas-ar-input:focus {
    outline: none;
    border-color: #1565c0;
    box-shadow: 0 0 0 2px rgba(21, 101, 192, 0.15);
}

.midas-ar-refine-prompt,
.midas-ar-template-desc,
.midas-ar-email-body,
.midas-ar-ml-body {
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    box-sizing: border-box;
    resize: vertical;
    transition: border-color 0.15s;
}

.midas-ar-refine-prompt:focus,
.midas-ar-template-desc:focus,
.midas-ar-email-body:focus,
.midas-ar-ml-body:focus {
    outline: none;
    border-color: #1565c0;
}

/* ── Reports List ────────────────────────────────────────── */
.midas-ar-list-header {
    padding: 0 0 16px 0;
    border-bottom: 2px solid #e3f2fd;
    margin-bottom: 16px;
}

.midas-ar-list-header h2 {
    font-size: 20px;
    font-weight: 700;
    color: #0d47a1;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.midas-ar-list-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.midas-ar-list-table th,
.midas-ar-list-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    text-align: left;
    vertical-align: middle;
}

.midas-ar-list-table th {
    background: #f8fafc;
    font-weight: 600;
    color: #555;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.midas-ar-list-table tr:hover td {
    background: #f0f7ff;
}

.midas-ar-list-link {
    color: #1565c0;
    font-weight: 500;
    text-decoration: none;
}

.midas-ar-list-link:hover {
    text-decoration: underline;
}

.midas-ar-list-actions {
    white-space: nowrap;
}

.midas-ar-empty {
    text-align: center;
    padding: 60px 20px;
    color: #888;
}

.midas-ar-empty .dashicons {
    font-size: 48px;
    width: 48px;
    height: 48px;
    color: #c8d6e5;
    display: block;
    margin: 0 auto 12px;
}

.midas-ar-empty p {
    margin: 6px 0;
    font-size: 15px;
}

.midas-ar-hint {
    font-size: 13px !important;
    color: #aaa !important;
}

/* ── Public Page ─────────────────────────────────────────── */
.midas-ai-report-wrap--public {
    padding-top: 0;
}

.midas-ai-report-public-header,
.midas-ar-public-header {
    background: #0d47a1;
    color: #fff;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin: -24px -20px 24px;
}

.midas-ar-public-header .midas-ar-btn--secondary {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-color: rgba(255,255,255,0.3);
}

.midas-ar-public-header .midas-ar-btn--secondary:hover {
    background: rgba(255,255,255,0.25);
}

.midas-ai-report-logo {
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.midas-ar-public-title {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    margin: 0;
}

.midas-ar-public-meta {
    font-size: 12px;
    color: rgba(255,255,255,0.7);
}

/* ── Chat Panel ──────────────────────────────────────────── */
.midas-ar-chat-panel {
    margin-top: 24px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.midas-ar-chat-header {
    background: #f0f4f8;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 14px;
    color: #0d47a1;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.midas-ar-chat-messages {
    padding: 16px;
    min-height: 100px;
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.midas-ar-chat-msg {
    font-size: 13px;
    line-height: 1.55;
    padding: 10px 14px;
    border-radius: 6px;
    max-width: 90%;
}

.midas-ar-chat-msg--user {
    background: #e3f2fd;
    align-self: flex-end;
    color: #0d47a1;
}

.midas-ar-chat-msg--assistant {
    background: #f5f5f5;
    align-self: flex-start;
    color: #1a1a1a;
}

.midas-ar-chat-msg--assistant.error {
    background: #fff3f3;
    color: #c62828;
}

.midas-ar-chat-thinking .spinner {
    display: inline-block;
    float: none;
    vertical-align: middle;
    margin: 0 4px 0 0;
}

.midas-ar-chat-input-row {
    display: flex;
    gap: 6px;
    padding: 0;
    align-items: stretch;   /* alle Elemente gleich hoch */
}

.midas-ar-chat-input-row .midas-ar-btn,
.midas-ar-chat-input-row button {
    flex: 0 0 auto;
    white-space: nowrap;
    align-self: stretch;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.midas-ar-chat-textarea {
    flex: 1;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    box-sizing: border-box;
}

.midas-ar-chat-textarea:focus {
    outline: none;
    border-color: #1565c0;
}

.midas-ar-chat-hint {
    font-size: 11px;
    color: #aaa;
    margin: 0;
    padding: 6px 16px 10px;
    text-align: center;
}

/* ── Toast Notifications ─────────────────────────────────── */
.midas-ar-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 200000;
    background: #323232;
    color: #fff;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 13px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.25s, transform 0.25s;
    max-width: 320px;
    pointer-events: none;
}

.midas-ar-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.midas-ar-toast--success { background: #2e7d32; }
.midas-ar-toast--error   { background: #c62828; }
.midas-ar-toast--info    { background: #1565c0; }

/* ── Public Tabs (Bericht | Fragen) ──────────────────────── */
.midas-ar-tabs {
    display: flex;
    gap: 6px;
}

.midas-ar-tab {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    position: relative;
}

.midas-ar-tab.is-active {
    background: #fff;
    color: #0d47a1;
    border-color: #fff;
    font-weight: 600;
}

.midas-ar-tab .dashicons { font-size: 15px; width: 15px; height: 15px; }

.midas-ar-tab-badge {
    background: #ff5252;
    color: #fff;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 11px;
    text-align: center;
    margin-left: 4px;
}

/* Panes: desktop shows both stacked; mobile shows one at a time (see media query) */
.midas-ar-pane { display: block; }
/* Report pane breaks out of the wrap's 20px horizontal padding so the report
   uses the full content width (less stacked indentation). */
.midas-ar-pane--report { padding: 0; position: relative; margin: 0 -20px; }
.midas-ar-pane--chat { padding: 16px 20px 40px; }

.midas-ar-block-toolbar {
    display: flex;
    justify-content: flex-end;
    padding: 6px 8px;
}

.midas-ar-report-iframe {
    width: 100%;
    height: calc(100vh - 150px);
    min-height: 360px;
    border: none;
    background: #fff;
    display: block;
}

.midas-ar-answer-iframe {
    width: 100%;
    height: 70vh;
    min-height: 320px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: #fff;
    display: block;
}

/* Chat thread */
.midas-ar-thread {
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* Input below the history (standard chat layout: Verlauf oben, Input unten) */
.midas-ar-chat-inputwrap {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid #e0e0e0;
}

.midas-ar-turn {
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    overflow: hidden;
    background: #fafbfc;
}

.midas-ar-turn-q {
    background: #e3f2fd;
    color: #0d47a1;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.midas-ar-turn-q .dashicons { font-size: 16px; width: 16px; height: 16px; }

.midas-ar-turn-a { padding: 10px 14px; position: relative; }

.midas-ar-turn.is-collapsed .midas-ar-turn-a { display: none; }

.midas-ar-turn-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: #1565c0;
    font-size: 11px;
    padding: 0 4px 0 0;
    line-height: 1;
    flex-shrink: 0;
}

.midas-ar-turn-text { font-size: 14px; line-height: 1.6; color: #1a1a1a; white-space: pre-wrap; }

.midas-ar-turn-error { color: #c62828; font-size: 13px; padding: 6px 0; }

.midas-ar-thinking {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #555;
    font-size: 13px;
    padding: 6px 0;
}

.midas-ar-elapsed { opacity: 0.7; }

/* Desktop: no tabs, both panes visible (report then chat) */
@media (min-width: 769px) {
    .midas-ar-tabs { display: none; }
    .midas-ar-pane { display: block !important; }
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Tabbed single-pane behavior — eliminates the nested-scroll conflict */
    .midas-ar-pane { display: none; }
    .midas-ar-pane.is-active { display: block; }
    .midas-ar-report-iframe { height: calc(100vh - 130px); }
    .midas-ar-answer-iframe { height: 75vh; }
    .midas-ar-public-header { flex-direction: column; align-items: stretch; gap: 10px; }
    .midas-ar-tabs { width: 100%; }
    .midas-ar-tab { flex: 1; justify-content: center; }

    .midas-ar-header {
        flex-direction: column;
    }

    .midas-ar-actions {
        width: 100%;
    }

    /* Stretch only the authenticated header actions full-width on mobile —
       NOT the print button in the report/chat toolbars. */
    .midas-ar-actions .midas-ar-btn {
        flex: 1;
        justify-content: center;
    }

    .midas-ar-body iframe,
    #midas-ar-iframe {
        height: 60vh;
    }

    .midas-ar-dialog {
        max-width: 100%;
        margin: 0;
        border-radius: 8px 8px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 85vh;
    }

    .midas-ar-dialog-overlay {
        align-items: flex-end;
        padding: 0;
    }
}
