/* ============================================
   DeepTRIZ — Mobile-first Responsive Styles
   ============================================ */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: #f0f2f5;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

/* ---------- Layout Wrapper ---------- */
.page-wrapper {
    max-width: 800px;
    margin: 0 auto;
    padding: 12px;
}

@media (min-width: 768px) {
    .page-wrapper { padding: 20px; }
}

/* ---------- Container (content area) ---------- */
.container {
    max-width: 800px;
    margin: 0 auto;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.08);
    overflow: hidden;
}

/* ---------- Header (full-width background image + floating slogan) ---------- */
.page-header {
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    min-height: clamp(180px, 30vw, 280px);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 16px;
    position: relative;
}

/* ===== Glass-panel slogan floating on top of background image ===== */
.header-overlay {
    position: relative;
    z-index: 1;
    max-width: 720px;
    padding: 18px 32px;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 4px 24px rgba(0,0,0,0.25);
}

.page-title {
    margin: 0;
    font-size: clamp(26px, 5.5vw, 42px);
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.page-subtitle {
    margin: 6px 0 0;
    font-size: clamp(14px, 3vw, 18px);
    color: rgba(255,255,255,0.92);
    text-shadow: 0 1px 6px rgba(0,0,0,0.45);
}

/* Old header-img no longer used — keep selector for backward compat, hide */
.header-img { display: none; }

/* ---------- Input ---------- */
.input-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    border-bottom: 1px solid #eee;
    flex-wrap: wrap;
}

.input-label {
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    font-size: 15px;
}

#user-input {
    flex: 1 1 200px;
    padding: 12px 14px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;           /* ≥16px to prevent iOS zoom */
    transition: border-color 0.2s;
    min-width: 0;
}

#user-input:focus {
    outline: none;
    border-color: #6f42c1;
    box-shadow: 0 0 0 3px rgba(111,66,193,0.15);
}

/* ---------- Buttons ---------- */
.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px;
    justify-content: center;
}

.btn-action {
    flex: 1 1 auto;
    min-width: calc(50% - 8px);   /* 2 per row on small screens */
    padding: 12px 16px;
    background: #51a5f4;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    touch-action: manipulation;
    white-space: nowrap;
}

.btn-action:active {
    transform: scale(0.97);
    background: #6f42c1;
}

.btn-icon { margin-right: 2px; }

/* 3-4 buttons on wider screens */
@media (min-width: 500px) {
    .btn-action {
        min-width: calc(25% - 8px);
    }
}

/* ---------- Chat Box ---------- */
#chat-box-full {
    min-height: 300px;
    max-height: 55vh;
    overflow-y: auto;
    padding: 16px;
    background: #fafafa;
    -webkit-overflow-scrolling: touch;
}

.chat-placeholder {
    text-align: center;
    color: #999;
    padding: 60px 20px;
    font-size: 14px;
}

/* ---------- Messages ---------- */
.user-msg, .bot-msg {
    margin: 10px 0;
    padding: 12px 16px;
    border-radius: 10px;
    max-width: 100%;
    font-size: 15px;
    line-height: 1.7;
}

.user-msg {
    background: #e3f2fd;
    margin-left: auto;
    max-width: 85%;
    border-bottom-right-radius: 4px;
}

.bot-msg {
    background: #fff;
    border: 1px solid #e8e8e8;
    margin-right: auto;
    border-bottom-left-radius: 4px;
    position: relative;
}

/* Markdown content inside bot messages */
.bot-msg h1, .bot-msg h2, .bot-msg h3 { margin-top: 0.8em; margin-bottom: 0.4em; }
.bot-msg p { margin: 0.5em 0; }
.bot-msg ul, .bot-msg ol { padding-left: 1.5em; }
.bot-msg code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    word-break: break-word;
}
.bot-msg pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
}
.bot-msg pre code { background: none; padding: 0; color: inherit; }
.bot-msg img, .bot-msg table { max-width: 100%; height: auto; }
.bot-msg blockquote {
    border-left: 4px solid #6f42c1;
    margin: 0.5em 0;
    padding: 0.5em 1em;
    background: #f9f5ff;
    color: #555;
}

.error {
    color: #d32f2f;
    background: #ffebee;
    padding: 12px;
    border-radius: 8px;
    margin: 8px 0;
    font-size: 14px;
}

/* ---------- Copy Button ---------- */
.copy-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 14px;
    background: #eee;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 12px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn:hover { background: #6f42c1; color: #fff; border-color: #6f42c1; }
.copy-btn.copied { background: #4caf50; color: #fff; border-color: #4caf50; }

/* ---------- Footer ---------- */
footer {
    text-align: center;
    padding: 12px;
    background: #eef0f2;
    color: #888;
    font-size: 12px;
}

footer a { color: #6f42c1; text-decoration: none; }

/* ---------- Top Navigation Bar ---------- */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto 12px;
    padding: 0;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 8px rgba(0,0,0,0.06);
    overflow: hidden;
}

@media (max-width: 820px) {
    .top-nav {
        margin-left: 8px;
        margin-right: 8px;
    }
}

.nav-brand {
    flex-shrink: 0;
    padding: 12px 16px;
    font-size: 18px;
    font-weight: 700;
    color: #6f42c1;
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.nav-links {
    display: flex;
    gap: 2px;
    padding: 0 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;          /* Firefox */
}

.nav-links::-webkit-scrollbar { display: none; }  /* Chrome/Safari */

.nav-links a {
    flex-shrink: 0;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 500;
    color: #555;
    text-decoration: none;
    border-radius: 8px;
    white-space: nowrap;
    transition: all 0.2s;
}

.nav-links a:hover,
.nav-links a:focus-visible {
    background: #f3e8ff;
    color: #6f42c1;
}

.nav-links a.active {
    background: #6f42c1;
    color: #fff;
}

/* Nav color variants per section */
.top-nav.triz .nav-brand,
.top-nav.triz .nav-links a:hover { color: #6f42c1; }
.top-nav.triz .nav-links a.active { background: #6f42c1; }

.top-nav.cosin .nav-brand,
.top-nav.cosin .nav-links a:hover { color: #2e7d32; }
.top-nav.cosin .nav-links a.active { background: #2e7d32; }

.top-nav.taoyi .nav-brand,
.top-nav.taoyi .nav-links a:hover { color: #00838f; }
.top-nav.taoyi .nav-links a.active { background: #00838f; }

/* Energy loop nav theme */
.top-nav.triz .nav-links a.active { background: #6f42c1; }
.top-nav.cosin .nav-links a.active { background: #2e7d32; }
.top-nav.taoyi .nav-links a.active { background: #00838f; }

.nav-links a:hover { background: #f0f0f0; }
.top-nav.triz .nav-links a:hover { background: #f3e8ff; }
.top-nav.cosin .nav-links a:hover { background: #e8f5e9; }
.top-nav.taoyi .nav-links a:hover { background: #e0f7fa; }

/* ---------- Breadcrumbs ---------- */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px 0;
    font-size: 13px;
    color: #999;
    flex-wrap: wrap;
}

.breadcrumb a {
    color: #6f42c1;
    text-decoration: none;
}

.breadcrumb a:hover { text-decoration: underline; }

.breadcrumb .sep {
    color: #ccc;
    font-size: 16px;
    line-height: 1;
}

.breadcrumb .current {
    color: #555;
    font-weight: 500;
}

/* ---------- Page color themes ---------- */
.page-header-cosin,
.page-header-taoyi { /* background set inline */ }

/* ---------- Button color variants ---------- */
.btn-cosin { background: #43a047; }
.btn-cosin:active { background: #2e7d32; }
.btn-taoyi { background: #00897b; }
.btn-taoyi:active { background: #00695c; }

/* ---------- Form styles (Taoyi) ---------- */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px;
}

.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field-wide { grid-column: 1 / -1; }

.form-input {
    width: 100%;
    padding: 11px 14px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.form-input:focus {
    outline: none;
    border-color: #00897b;
    box-shadow: 0 0 0 3px rgba(0,137,123,0.15);
}

/* Radio buttons */
.radio-group {
    display: flex;
    gap: 20px;
    align-items: center;
    padding: 6px 0;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 16px;
    cursor: pointer;
    padding: 8px 0;
}

.radio-label input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: #00897b;
}

/* 6-btn grid for cosin — 2 cols on mobile, 3 on tablet */
.btn-group:has(.btn-cosin) .btn-action {
    min-width: calc(33.33% - 8px);
}
@media (max-width: 420px) {
    .btn-group:has(.btn-cosin) .btn-action {
        min-width: calc(50% - 8px);
    }
}

/* ============================================
   Mobile adjustments — smaller glass panel
   ============================================ */
@media (max-width: 767px) {
    .page-header {
        min-height: clamp(150px, 35vw, 200px);
        padding: 20px 12px;
    }
    .header-overlay {
        padding: 12px 20px;
        border-radius: 10px;
        max-width: 90vw;
    }
}

/* ============================================
   Larger screens — modest enhancements
   ============================================ */
@media (min-width: 768px) {

    #chat-box-full {
        min-height: 400px;
        max-height: 60vh;
    }

    .btn-action {
        font-size: 16px;
        padding: 14px 20px;
    }

    .form-grid {
        grid-template-columns: 1fr 1fr 1fr 1fr;
        gap: 16px;
        padding: 20px;
    }
    .form-field-wide { grid-column: span 2; }
}
