/* battu-luan-giai.css - Bát Tự Luận Giải Premium Dark Theme */

:root {
    --bg-primary: #fffdf0;
    --bg-secondary: #fefce8;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-glass: rgba(0, 0, 0, 0.03);
    --text-primary: #333333;
    --text-secondary: #555555;
    --text-muted: #777777;
    --border-color: rgba(217, 119, 6, 0.2);
    --accent: #d97706;
    --accent-glow: rgba(217, 119, 6, 0.2);
    --moc: #15803d;
    --hoa: #b91c1c;
    --tho: #a16207;
    --kim: #0369a1;
    --thuy: #6b21a8;
    --moc-bg: rgba(21, 128, 61, 0.1);
    --hoa-bg: rgba(185, 28, 28, 0.1);
    --tho-bg: rgba(161, 98, 7, 0.1);
    --kim-bg: rgba(3, 105, 161, 0.1);
    --thuy-bg: rgba(107, 33, 168, 0.1);
    --shadow: 0 4px 15px rgba(217, 119, 6, 0.1);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --transition: all 0.3s cubic-bezier(.4, 0, .2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(ellipse at 20% 50%, rgba(251, 191, 36, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(245, 158, 11, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.page-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 1;
}

/* YouTube Tutorial Section */
.youtube-tutorial-section {
    margin-bottom: 24px;
}

.youtube-container {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
    /* 16:9 Aspect Ratio */
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
}

.youtube-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--radius-sm);
}

.tutorial-text {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    padding: 16px;
    margin-top: 16px;
}

.tutorial-text p {
    margin: 8px 0;
    line-height: 1.6;
    color: var(--text-secondary);
}

.tutorial-text strong {
    color: var(--text-primary);
}

.tutorial-text code {
    background: rgba(217, 119, 6, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    color: #b45309;
}

/* Header */
.page-header {
    text-align: center;
    padding: 40px 20px 30px;
    margin-bottom: 30px;
}

.page-header h1 {
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #d97706, #b45309, #92400e);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    letter-spacing: -0.5px;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Cards */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.card:hover {
    border-color: rgba(124, 77, 255, 0.2);
}

.card-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title .icon {
    font-size: 1.4rem;
}

/* Input Form */
.input-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.form-group input,
.form-group select {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    padding: 12px 14px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-group select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-primary {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #78350f;
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px 32px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(217, 119, 6, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Bát Tự Chart */
.battu-chart {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.pillar {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px 12px;
    text-align: center;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.pillar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
}

.pillar.nhat-chu {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

.pillar.nhat-chu::after {
    content: '★ Nhật Chủ';
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 0.65rem;
    color: var(--accent);
    font-weight: 700;
}

.pillar-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    font-weight: 600;
}

.thap-than-label {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-glass);
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: inline-block;
}

.can-box,
.chi-box {
    font-size: 1.6rem;
    font-weight: 800;
    padding: 10px;
    border-radius: var(--radius-xs);
    margin: 4px 0;
    transition: var(--transition);
}

.can-box:hover,
.chi-box:hover {
    transform: scale(1.05);
}

.element-label {
    font-size: 0.7rem;
    opacity: 0.8;
    margin-top: 2px;
}

.tang-can-box {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.tang-can-item {
    display: inline-block;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    margin: 2px;
    font-weight: 500;
}

.nap-am-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-style: italic;
}

.truong-sinh-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-top: 4px;
    padding: 2px 8px;
    background: var(--bg-glass);
    border-radius: 8px;
    display: inline-block;
}

/* Ngũ Hành specific backgrounds */
.ngh-moc {
    background: var(--moc-bg);
    color: var(--moc);
}

.ngh-hoa {
    background: var(--hoa-bg);
    color: var(--hoa);
}

.ngh-tho {
    background: var(--tho-bg);
    color: var(--tho);
}

.ngh-kim {
    background: var(--kim-bg);
    color: var(--kim);
}

.ngh-thuy {
    background: var(--thuy-bg);
    color: var(--thuy);
}

/* Ngũ Hành Distribution */
.ngu-hanh-dist {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.nh-bar-container {
    flex: 1;
    min-width: 100px;
    text-align: center;
}

.nh-bar {
    height: 8px;
    border-radius: 4px;
    margin: 6px 0;
    transition: width 0.8s cubic-bezier(.4, 0, .2, 1);
}

.nh-label {
    font-size: 0.8rem;
    font-weight: 600;
}

.nh-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Detail Sections */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.detail-section {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.detail-section h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--accent);
}

.detail-item {
    font-size: 0.85rem;
    padding: 4px 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.detail-item strong {
    color: var(--text-primary);
}

/* Đại Vận Timeline */
.dai-van-timeline {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 16px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) var(--bg-glass);
}

.dai-van-timeline::-webkit-scrollbar {
    height: 4px;
}

.dai-van-timeline::-webkit-scrollbar-track {
    background: var(--bg-glass);
    border-radius: 4px;
}

.dai-van-timeline::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

.dv-item {
    min-width: 100px;
    text-align: center;
    padding: 12px 10px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    flex-shrink: 0;
    transition: var(--transition);
    cursor: default;
}

.dv-item:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.dv-item.active {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.dv-canchi {
    font-size: 1.1rem;
    font-weight: 700;
}

.dv-age {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.dv-year {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.dv-napam {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 2px;
    font-style: italic;
}

/* Chat Section */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 600px;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.chat-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header .model-select {
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    padding: 6px 12px;
    color: var(--text-primary);
    font-size: 0.8rem;
    outline: none;
    cursor: pointer;
}

.chat-header .model-select:focus {
    border-color: var(--accent);
}

.chat-header .model-select option {
    background: var(--bg-secondary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

.message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    line-height: 1.6;
    font-size: 0.9rem;
    animation: msgIn 0.3s ease;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #78350f;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message.assistant h1,
.message.assistant h2,
.message.assistant h3 {
    margin: 12px 0 6px;
    font-size: 1rem;
    color: var(--accent);
}

.message.assistant h2 {
    font-size: 0.95rem;
}

.message.assistant h3 {
    font-size: 0.9rem;
}

.message.assistant strong {
    color: #b45309;
}

.message.assistant ul,
.message.assistant ol {
    padding-left: 20px;
    margin: 6px 0;
}

.message.assistant li {
    margin: 4px 0;
}

.message.assistant p {
    margin: 6px 0;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 14px 18px;
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

.chat-input-area {
    padding: 14px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
}

.chat-input-area input {
    flex: 1;
    background: var(--bg-glass);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xs);
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.chat-input-area input:focus {
    border-color: var(--accent);
}

.chat-input-area input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #78350f;
    border: none;
    border-radius: var(--radius-xs);
    padding: 12px 20px;
    cursor: pointer;
    font-size: 1rem;
    transition: var(--transition);
}

.btn-send:hover {
    box-shadow: 0 4px 16px rgba(217, 119, 6, 0.4);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Thần Sát Tags */
.than-sat-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.than-sat-tag {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.1), rgba(245, 158, 11, 0.1));
    border: 1px solid rgba(217, 119, 6, 0.2);
    color: #b45309;
}

/* Hidden initially */
.chart-section,
.chat-section {
    display: none;
}

.chart-section.visible,
.chat-section.visible {
    display: block;
}

/* Responsive */
@media (max-width: 768px) {
    .page-container {
        padding: 10px;
    }

    .page-header {
        padding: 24px 12px 20px;
    }

    .page-header h1 {
        font-size: 1.6rem;
    }

    .card {
        padding: 18px;
    }

    .battu-chart {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .input-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* === CHAT SECTION - MUCH BIGGER ON MOBILE === */
    .chat-section.visible {
        /* Remove card padding for full-width chat */
        padding: 0 !important;
        margin-left: -10px;
        margin-right: -10px;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
        margin-bottom: 0 !important;
    }

    .chat-section .card-title {
        padding: 14px 16px;
        margin-bottom: 0;
        background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.1));
        border-bottom: 1px solid var(--border-color);
        font-size: 1.1rem;
        position: sticky;
        top: 0;
        z-index: 5;
        backdrop-filter: blur(10px);
    }

    .chat-container {
        height: calc(100vh - 180px) !important;
        min-height: 450px !important;
        max-height: 700px;
        border-radius: 0 !important;
        border: none !important;
    }

    .chat-messages {
        padding: 12px;
        gap: 10px;
        flex: 1;
        -webkit-overflow-scrolling: touch;
    }

    .message {
        max-width: 95%;
        padding: 12px 14px;
        font-size: 0.92rem;
        line-height: 1.65;
    }

    .message.assistant {
        max-width: 98%;
    }

    .message.assistant ul,
    .message.assistant ol {
        padding-left: 16px;
    }

    /* Chat input - larger, sticky at bottom */
    .chat-input-area {
        padding: 10px 12px;
        gap: 8px;
        border-top: 1px solid var(--border-color);
        background: rgba(255, 253, 240, 0.95);
        backdrop-filter: blur(10px);
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .chat-input-area input {
        padding: 14px 16px !important;
        font-size: 16px !important;
        /* Prevent iOS zoom */
        border-radius: 22px !important;
        min-height: 48px;
        background: white;
    }

    .btn-send {
        min-width: 52px;
        min-height: 48px;
        border-radius: 22px !important;
        padding: 12px 16px;
        font-size: 1.1rem;
    }

    /* Chat header compact */
    .chat-header {
        padding: 10px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .chat-header .model-select {
        padding: 6px 10px;
        font-size: 0.78rem;
        min-height: 36px;
    }

    /* Đại Vận */
    .dai-van-timeline {
        gap: 6px;
    }

    .dv-item {
        min-width: 80px;
        padding: 10px 6px;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .message {
        max-width: 92%;
    }

    .pillar.nhat-chu::after {
        font-size: 0.55rem;
    }

    /* Mobile YouTube container adjustments */
    .youtube-container {
        padding-bottom: 56.25%;
        /* Maintain 16:9 aspect ratio */
        margin-bottom: 16px;
    }

    .tutorial-text {
        padding: 12px;
    }

    .tutorial-text p {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .battu-chart {
        grid-template-columns: repeat(2, 1fr);
    }

    .input-grid {
        grid-template-columns: 1fr;
    }

    .can-box,
    .chi-box {
        font-size: 1.3rem;
        padding: 8px;
    }

    /* Further mobile adjustments */
    .youtube-container {
        padding-bottom: 56.25%;
    }

    .card {
        padding: 16px;
    }

    .card-title {
        font-size: 1.1rem;
    }

    /* Chat even bigger on small phones */
    .chat-container {
        height: calc(100vh - 160px) !important;
        min-height: 400px !important;
    }

    .message {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .chat-input-area {
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }
}

/* Landscape mode for chat */
@media (max-height: 500px) and (orientation: landscape) {
    .chat-container {
        height: calc(100vh - 120px) !important;
        min-height: 250px !important;
    }

    .chat-messages {
        padding: 8px;
        gap: 6px;
    }

    .message {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
}