﻿/* CSS Reset สำหรับ WebView */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    -webkit-text-size-adjust: 100%;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Base Typography */
body {
    font-family: "Segoe UI", "Kanit", "Noto Sans Thai", "Roboto", sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #f5faff 0%, #e8f4fd 100%);
    min-height: 100vh;
}

h1, h2, h3, h4 {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

h1 {
    font-size: 1.8rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.3rem;
}

h4 {
    font-size: 1.1rem;
}

/* Container Layouts */
form {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: linear-gradient(135deg, #0077cc 0%, #005499 100%);
    color: white;
    text-align: center;
    padding: 1.5rem 1rem;
    box-shadow: 0 2px 10px rgba(0,119,204,0.3);
}

main {
    flex: 1;
    padding: 1rem;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

footer {
    background: #f8f9fa;
    padding: 1rem;
    text-align: center;
    font-size: 0.9rem;
    color: #666;
    border-top: 1px solid #e0e0e0;
}

/* Form Controls Responsive */
.controls {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.control-group {
    margin-bottom: 1rem;
}

    .control-group:last-child {
        margin-bottom: 0;
    }

label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #555;
}

.datetime-input, .region-select, .date-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    background: white;
    transition: border-color 0.3s ease;
}

    .datetime-input:focus, .region-select:focus, .date-input:focus {
        outline: none;
        border-color: #0077cc;
        box-shadow: 0 0 0 3px rgba(0,119,204,0.1);
    }

.analyze-btn {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 1rem;
}

    .analyze-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 15px rgba(40,167,69,0.3);
    }

/* Canvas Touch Optimization - แก้ไขปัญหาการ scroll */
.visualization {
    text-align: center;
    margin-bottom: 1.5rem;
    background: white;
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    overflow: visible !important;
    -webkit-overflow-scrolling: touch !important;
}

#orbitCanvas {
    max-width: 100%;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: radial-gradient(circle at center, #000814 0%, #001d3d 100%);
    touch-action: pan-y pan-x !important;
    -webkit-overflow-scrolling: touch !important;
    pointer-events: auto !important;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* สำหรับ iOS Safari */
@supports (-webkit-touch-callout: none) {
    #orbitCanvas {
        -webkit-touch-callout: none;
    }
}

/* Analysis Output Styling */
.analysis-results {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

    .analysis-results h2 {
        background: linear-gradient(135deg, #6f42c1 0%, #8b5cf6 100%);
        color: white;
        padding: 1rem 1.5rem;
        margin: 0;
    }

.result-group {
    padding: 1.5rem;
    border-bottom: 1px solid #f0f0f0;
}

    .result-group:last-child {
        border-bottom: none;
    }

    .result-group h3 {
        color: #6f42c1;
        margin-bottom: 1rem;
        padding-bottom: 0.5rem;
        border-bottom: 2px solid #f0f0f0;
    }

/* Data Lists */
.astro-data, .climate-data, .planetary-data, .distance-data {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 0.75rem;
    align-items: start;
}

    .astro-data dt, .climate-data dt, .planetary-data dt, .distance-data dt {
        font-weight: 600;
        color: #555;
    }

    .astro-data dd, .climate-data dd, .planetary-data dd, .distance-data dd {
        color: #333;
    }

/* Plant Categories */
.plant-categories {
    display: grid;
    gap: 1rem;
}

.category-item {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid #28a745;
}

    .category-item h4 {
        color: #28a745;
        margin-bottom: 0.5rem;
    }

    .category-item p {
        color: #666;
        font-size: 0.95rem;
    }

/* Region Analysis */
.region-analysis {
    background: #f8f9fa;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

    .region-analysis h4 {
        color: #495057;
        margin-bottom: 0.75rem;
    }

/* Animation Controls */
.animation-controls {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 12px;
}

.play-btn {
    padding: 0.6rem 1.2rem;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 4px 15px rgba(40,167,69,0.3);
    transition: all 0.3s ease;
    min-height: 40px;
    position: relative;
    z-index: 1000;
    pointer-events: auto;
}

/* Media Queries */
@media (max-width: 768px) {
    /* Mobile Styles */
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.3rem;
    }

    h3 {
        font-size: 1.1rem;
    }

    main {
        padding: 0.5rem;
    }

    .controls {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .control-group {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

        .control-group label {
            min-width: auto;
        }

    .date-input {
        max-width: none;
        font-size: 18px !important;
        padding: 15px 20px !important;
        min-height: 50px !important;
    }

    .analyze-btn {
        padding: 1rem;
        width: 100%;
        margin-top: 0.5rem;
    }

    .astro-data, .climate-data, .planetary-data, .distance-data {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

        .astro-data dt, .climate-data dt, .planetary-data dt, .distance-data dt {
            font-weight: 700;
            margin-bottom: 0.25rem;
        }

    .result-group {
        padding: 1rem;
    }

    .region-analysis {
        margin-bottom: 0.75rem;
        padding: 0.75rem;
    }

    #orbitCanvas {
        width: 100%;
        max-width: 350px;
    }

    .play-btn {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        min-height: 50px;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    /* Tablet Styles */
    main {
        max-width: 700px;
    }

    .plant-categories {
        grid-template-columns: 1fr 1fr;
    }

    #orbitCanvas {
        max-width: 450px;
    }
}

@media (min-width: 1025px) {
    /* PC Styles */
    main {
        max-width: 800px;
    }

    .plant-categories {
        grid-template-columns: 1fr 1fr;
    }

    .control-group {
        display: flex;
        align-items: center;
        gap: 1rem;
        margin-bottom: 0;
    }

        .control-group label {
            min-width: 120px;
            margin-bottom: 0;
        }

    .date-input {
        flex: 1;
        max-width: 200px;
    }

    .analyze-btn {
        padding: 0.75rem 1.5rem;
        width: auto;
        margin-top: 0;
        white-space: nowrap;
    }

    #orbitCanvas {
        max-width: 500px;
    }
}

/* WebView Specific Fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* WebKit/Chrome specific */
    input[type="datetime-local"], input[type="date"] {
        -webkit-appearance: none;
    }

    select {
        -webkit-appearance: none;
        background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3E%3Cpath fill='%23666' d='M2 0L0 2h4zm0 5L0 3h4z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.7rem center;
        background-size: 0.65rem auto;
        padding-right: 2rem;
    }
}

/* Animation Effects */
.analysis-results {
    animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.category-item {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

    .category-item:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    }

/* Thai Font Optimization */
@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&display=swap');

body {
    font-feature-settings: "liga" 1, "kern" 1;
    text-rendering: optimizeLegibility;
}

/* High DPI Display Support */
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) {

    #orbitCanvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}
