/* ==================== Design System & CSS Variables ==================== */
:root {
    /* Light Theme */
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --text-main: #1E293B;
    --text-muted: #64748B;
    --border: #E2E8F0;
    --shadow: rgba(0, 0, 0, 0.05);
    
    /* UI Colors */
    --danger: #EF4444;
    --primary: #3B82F6;
}

.dark {
    /* Dark Theme */
    --bg: #121212;
    --surface: #1E1E1E;
    --text-main: #F1F5F9;
    --text-muted: #94A3B8;
    --border: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
}

/* ==================== Global Rules ==================== */
html, body {
    font-family: 'Itim', cursive;
    background-color: var(--bg);
    color: var(--text-main);
    margin: 0;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.3s ease, color 0.3s ease;
    
    /* เพิ่ม 3 บรรทัดนี้เพื่อล็อคไม่ให้หน้าจอหลักเด้งหลุดขอบ */
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

/* ปิดการลากคลุมข้อความทั้งแอป */
body {
    -webkit-user-select: none; /* สำหรับ Safari */
    user-select: none;
}

/* ยกเว้นให้ช่อง Input และ Textarea สามารถลากคลุมและพิมพ์ได้ปกติ */
input, textarea, select {
    -webkit-user-select: auto;
    user-select: auto;
}

/* Container Limit (Mobile First) */
.app-container {
    max-width: 480px;
    margin: 0 auto;
    
    /* แก้จาก min-height: 100vh เป็น height: 100% */
    height: 100%;
    position: relative;
    background-color: var(--bg);
    box-shadow: 0 0 20px var(--shadow);
    display: flex;
    flex-direction: column;
    
    /* เพิ่ม overflow: hidden เพื่อจำกัดขอบเขตแอปให้อยู่แค่ในนี้ */
    overflow: hidden; 
}

/* ==================== Components ==================== */
.surface-card {
    background-color: var(--surface);
    border: 1px solid var(--border);
}

.input-field {
    background-color: var(--bg);
    color: var(--text-main);
    border: 1px solid var(--border);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
}

.input-error {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 1px var(--danger);
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ==================== Animations ==================== */
@keyframes popIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes popOut {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.95); }
}

.dialog-overlay {
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none; /* ป้องกันการคลิกตอนซ่อน */
}
.dialog-overlay.active { 
    opacity: 1; 
    pointer-events: auto;
}

.dialog-content {
    animation: popIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.dialog-overlay.closing .dialog-content {
    animation: popOut 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* ==================== Chart Specifics ==================== */
.chart-wrapper {
    height: 70vh; /* 70% of viewport */
    max-height: 500px;
    min-height: 350px;
}
.chart-bar-container {
    display: flex;
    flex-direction: column-reverse; /* Stack from bottom */
    
    /* 1. เพิ่มความกว้างของแท่งกราฟ */
    width: 60%; /* แก้จาก 30% เป็น 60% (เพิ่มขึ้น 50% ของขนาดเดิม) */
    max-width: 120px; /* ขยาย max-width เผื่อจอใหญ่ขึ้นด้วย (จาก 80px) */
    
    border-radius: 8px 8px 0 0;
    overflow: hidden;
    background-color: var(--border); /* Background track */
    position: relative;
    transition: height 0.5s ease-out;
}
.chart-segment {
    width: 100%;
    transition: height 0.3s ease;
    position: relative;
}

/* Drag & Drop */
.draggable-item.dragging {
    opacity: 0.5;
    background-color: var(--border);
}

/* ==================== SortableJS Styles ==================== */

/* 1. ตัวที่ลอยตามเมาส์/นิ้ว (Drag) */
.sortable-drag {
    opacity: 0 !important; /* ซ่อนตัวที่ลอยตามเมาส์แบบที่คุณต้องการ */
}

/* 2. ตัวที่แทรกอยู่ใน List (Ghost) */
.sortable-ghost {
    opacity: 1 !important; /* ให้สีชัดเจน */
    background-color: var(--bg) !important;
    border: 2px dashed var(--primary) !important; /* เพิ่มกรอบเส้นประสีฟ้าให้ดูรู้ว่ากำลังจับตัวนี้อยู่ */
}