/* ============================================================
   Medical AI Tool — Front-end Stylesheet
   Uses CSS custom properties set inline via PHP (--mat-primary)
   ============================================================ */

/* ── Reset & Base ─────────────────────────────────────────── */
.mat-tool *, .mat-tool *::before, .mat-tool *::after {
    box-sizing: border-box;
}

.mat-tool {
    --mat-primary: #2563eb;
    --mat-primary-dark: #1d4ed8;
    --mat-radius: 12px;
    --mat-shadow: 0 4px 24px rgba(0,0,0,.08);
    --mat-border: #e5e7eb;
    --mat-bg: #ffffff;
    --mat-bg-soft: #f8fafc;
    --mat-text: #1e293b;
    --mat-muted: #64748b;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--mat-text);
    background: var(--mat-bg);
    border: 1px solid var(--mat-border);
    border-radius: var(--mat-radius);
    box-shadow: var(--mat-shadow);
    padding: 28px;
    margin: 24px 0;
    max-width: 780px;
}

/* ── Header ───────────────────────────────────────────────── */
.mat-tool__header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 2px solid var(--mat-primary);
}
.mat-tool__icon { font-size: 1.6rem; }
.mat-tool__title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--mat-primary);
}

/* ── Inputs ───────────────────────────────────────────────── */
.mat-input, .mat-textarea, .mat-select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--mat-border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--mat-text);
    background: var(--mat-bg);
    transition: border-color .2s;
    margin-bottom: 12px;
}
.mat-input:focus, .mat-textarea:focus, .mat-select:focus {
    outline: none;
    border-color: var(--mat-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--mat-primary) 15%, transparent);
}
.mat-textarea { resize: vertical; min-height: 100px; }
.mat-select { cursor: pointer; }

/* ── Buttons ──────────────────────────────────────────────── */
.mat-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 11px 22px;
    background: var(--mat-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, transform .1s;
    margin-top: 4px;
}
.mat-btn:hover  { background: var(--mat-primary-dark); }
.mat-btn:active { transform: scale(.97); }
.mat-btn:disabled { opacity: .6; cursor: not-allowed; }
.mat-btn--sm { padding: 9px 16px; font-size: 13px; }
.mat-btn--outline {
    background: transparent;
    color: var(--mat-primary);
    border: 1.5px solid var(--mat-primary);
}
.mat-btn--outline:hover { background: var(--mat-primary); color: #fff; }

/* ── Layout helpers ───────────────────────────────────────── */
.mat-row { display: flex; gap: 16px; flex-wrap: wrap; }
.mat-col { flex: 1 1 160px; }
.mat-col label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; color: var(--mat-muted); }

/* ── Result card ──────────────────────────────────────────── */
.mat-result {
    margin-top: 20px;
    animation: matFadeIn .3s ease;
}
@keyframes matFadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.mat-result-card {
    background: var(--mat-bg-soft);
    border: 1px solid var(--mat-border);
    border-radius: var(--mat-radius);
    padding: 20px;
}
.mat-result-card h3 { margin: 0 0 8px; font-size: 1.1rem; color: var(--mat-primary); }
.mat-result-card h4 { margin: 16px 0 8px; font-size: .9rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--mat-muted); }

/* ── Result header row ────────────────────────────────────── */
.mat-result-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

/* ── Badges ───────────────────────────────────────────────── */
.mat-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.mat-badge--green  { background: #dcfce7; color: #166534; }
.mat-badge--yellow { background: #fef9c3; color: #854d0e; }
.mat-badge--red    { background: #fee2e2; color: #991b1b; }
.mat-badge--blue   { background: #dbeafe; color: #1e40af; }
.mat-badge--gray   { background: #f1f5f9; color: #475569; }

/* ── Lists ────────────────────────────────────────────────── */
.mat-list { margin: 0 0 12px; padding-left: 20px; }
.mat-list li { margin-bottom: 4px; }
.mat-list--red li::marker { color: #ef4444; }

/* ── Alerts ───────────────────────────────────────────────── */
.mat-alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 0;
    font-size: 14px;
}
.mat-alert--error   { background: #fee2e2; color: #991b1b; border-left: 4px solid #ef4444; }
.mat-alert--warning { background: #fef9c3; color: #854d0e; border-left: 4px solid #eab308; }
.mat-alert--info    { background: #dbeafe; color: #1e40af; border-left: 4px solid #3b82f6; }

/* ── Disclaimer ───────────────────────────────────────────── */
.mat-disclaimer {
    font-size: 12px;
    color: var(--mat-muted);
    margin-top: 12px;
    padding: 8px 12px;
    background: #fef9c3;
    border-radius: 6px;
    border-left: 3px solid #eab308;
}

.mat-muted { color: var(--mat-muted); font-size: 14px; }

/* ── Conditions ───────────────────────────────────────────── */
.mat-conditions { display: flex; flex-direction: column; gap: 10px; }
.mat-condition-item {
    background: var(--mat-bg);
    border: 1px solid var(--mat-border);
    border-radius: 8px;
    padding: 12px;
}
.mat-condition-item p { margin: 4px 0 0; font-size: 13px; color: var(--mat-muted); }
.mat-condition-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }

/* ── Disease sections ─────────────────────────────────────── */
.mat-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.mat-section {
    background: var(--mat-bg);
    border: 1px solid var(--mat-border);
    border-radius: 8px;
    padding: 12px;
}

/* ── BMI Calculator ───────────────────────────────────────── */
.mat-bmi-display {
    text-align: center;
    padding: 24px;
    border: 3px solid;
    border-radius: 12px;
    margin-bottom: 16px;
}
.mat-bmi-number { font-size: 3.5rem; font-weight: 800; line-height: 1; }
.mat-bmi-label  { font-size: .85rem; color: var(--mat-muted); text-transform: uppercase; letter-spacing: .08em; }
.mat-bmi-category { font-size: 1.2rem; font-weight: 700; margin-top: 4px; }
.mat-bmi-scale { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.mat-scale-item {
    flex: 1 1 80px;
    text-align: center;
    padding: 8px 4px;
    border: 2px solid;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}
.mat-advice { font-size: 13px; color: var(--mat-muted); }

/* ── Lab report table ─────────────────────────────────────── */
.mat-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13px; }
.mat-table th, .mat-table td { padding: 9px 12px; border: 1px solid var(--mat-border); text-align: left; }
.mat-table th { background: var(--mat-bg-soft); font-weight: 700; }
.mat-table tr:hover td { background: var(--mat-bg-soft); }

/* ── File Upload ──────────────────────────────────────────── */
.mat-upload-area {
    border: 2px dashed var(--mat-border);
    border-radius: 10px;
    padding: 28px;
    text-align: center;
    margin-bottom: 12px;
    transition: border-color .2s;
}
.mat-upload-area:hover { border-color: var(--mat-primary); }
.mat-upload-icon { font-size: 2.5rem; display: block; margin-bottom: 8px; }
.mat-upload-area input[type=file] { display: none; }
.mat-upload-area p { color: var(--mat-muted); font-size: 13px; margin: 0 0 10px; }
.mat-file-name { font-size: 12px; color: var(--mat-muted); display: block; margin-top: 6px; }

/* ── Chatbot ──────────────────────────────────────────────── */
.mat-chat__window {
    height: 320px;
    overflow-y: auto;
    padding: 12px;
    background: var(--mat-bg-soft);
    border: 1px solid var(--mat-border);
    border-radius: 10px;
    margin-bottom: 12px;
    scroll-behavior: smooth;
}
.mat-chat__msg {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 16px;
    margin-bottom: 10px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.mat-chat__msg--bot {
    background: var(--mat-bg);
    border: 1px solid var(--mat-border);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}
.mat-chat__msg--user {
    background: var(--mat-primary);
    color: #fff;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.mat-chat__msg--error { background: #fee2e2; color: #991b1b; }
.mat-chat__input-row { display: flex; gap: 8px; }
.mat-chat__input-row .mat-input { margin-bottom: 0; flex: 1; }

/* ── Loading dots animation ───────────────────────────────── */
.mat-loading-dots span {
    animation: matDot 1.2s infinite;
    display: inline-block;
}
.mat-loading-dots span:nth-child(2) { animation-delay: .2s; }
.mat-loading-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes matDot { 0%,80%,100% { opacity: .2; } 40% { opacity: 1; } }

/* ── Diet macros ──────────────────────────────────────────── */
.mat-macros {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin: 12px 0 16px;
}
.mat-macro {
    flex: 1 1 80px;
    background: var(--mat-bg);
    border: 1px solid var(--mat-border);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
}
.mat-macro-val { display: block; font-size: 1.2rem; font-weight: 800; color: var(--mat-primary); }
.mat-macro span:last-child { font-size: 11px; color: var(--mat-muted); text-transform: uppercase; }

/* ── Tabs ─────────────────────────────────────────────────── */
.mat-tab-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 12px;
}
.mat-tab-btn {
    padding: 6px 12px;
    border: 1.5px solid var(--mat-border);
    border-radius: 6px;
    background: none;
    font-size: 13px;
    cursor: pointer;
    transition: all .15s;
}
.mat-tab-btn.active {
    background: var(--mat-primary);
    color: #fff;
    border-color: var(--mat-primary);
}
.mat-tab-panel { display: none; }
.mat-tab-panel.active { display: block; }
.mat-meal {
    padding: 8px 0;
    border-bottom: 1px solid var(--mat-border);
    font-size: 14px;
}
.mat-meal:last-child { border-bottom: none; }

/* ── Monetization zones ───────────────────────────────────── */
.mat-ads {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed var(--mat-border);
    text-align: center;
}
.mat-affiliate {
    margin-top: 16px;
    padding: 16px;
    background: #fefce8;
    border: 1px solid #fde68a;
    border-radius: 10px;
}
.mat-affiliate h4 { margin: 0 0 8px; font-size: .9rem; color: #92400e; }

/* ── Prose (plain text fallback) ──────────────────────────── */
.mat-prose { white-space: pre-wrap; font-size: 14px; line-height: 1.7; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
    .mat-tool { padding: 16px; margin: 12px 0; }
    .mat-row  { flex-direction: column; gap: 0; }
    .mat-sections { grid-template-columns: 1fr; }
    .mat-bmi-number { font-size: 2.5rem; }
    .mat-chat__msg { max-width: 92%; }
    .mat-table { font-size: 12px; }
    .mat-table th, .mat-table td { padding: 6px 8px; }
}
